Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I extract the code repetition here?

I am trying to extract out the common code pattern here in an extract method, but am having trouble finding the proper type for the type of Presenter. Any help?

public bool CanGotoHome 
{ 
    get { return !(CurrentPresenter is IHomePresenter) && IsLoggedIn; } 
}
public bool CanGotoImportanceOfAimsAndObjectives 
{ 
    get { return !(CurrentPresenter is IImportanceOfAimsAndObjectivesPresenter) && IsLoggedIn; } 
}
public bool CanGotoGotoAimsAndObjectives 
{ 
    get { return !(CurrentPresenter is IAimsAndObjectivesPresenter) && IsLoggedIn; } 
}
like image 496
Alex Baranosky Avatar asked Dec 04 '22 13:12

Alex Baranosky


1 Answers

Use Generics

private bool SomeFuncName<T>()
{
    return !(CurrentPresenter is T) && IsLoggedIn;
}

usage:

public bool CanGotoGotoAimsAndObjectives { 
    get { return SomeFuncName<IAimsAndObjectivesPresenter>(); } 
}
like image 116
Luke Schafer Avatar answered Jan 01 '23 08:01

Luke Schafer