我试图在提取方法中提取通用代码模式,但找不到适合 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; }
}
最佳答案
使用泛型
private bool SomeFuncName<T>()
{
return !(CurrentPresenter is T) && IsLoggedIn;
}
用法:
public bool CanGotoGotoAimsAndObjectives {
get { return SomeFuncName<IAimsAndObjectivesPresenter>(); }
}
关于c# - 我怎样才能在这里提取代码重复?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1898645/