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)
| 归档时间: |
|
| 查看次数: |
222 次 |
| 最近记录: |