如何在此处提取代码重复?

Ale*_*sky 4 .net c# refactoring dry

我试图在提取方法中提取出常见的代码模式,但是找不到Presenter类型的正确类型.有帮助吗?

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; } 
}
Run Code Online (Sandbox Code Playgroud)

Luk*_*fer 13

使用泛型

private bool SomeFuncName<T>()
{
    return !(CurrentPresenter is T) && IsLoggedIn;
}
Run Code Online (Sandbox Code Playgroud)

用法:

public bool CanGotoGotoAimsAndObjectives { 
    get { return SomeFuncName<IAimsAndObjectivesPresenter>(); } 
}
Run Code Online (Sandbox Code Playgroud)