【发布时间】:2013-07-31 16:12:10
【问题描述】:
我有课
class ManagerCar : IBlalba
{
public void Render(IViewTemplate template)
{
}
}
我知道参数模板是什么CarViewTemplate 我想检查类型并在IViewTemplate != CarViewTemplate 时抛出异常
我可以检查if(template is typeof(CarViewTemplate))。
但我有很多Managers。
我想在编译时检查此类型并使用[IsType(typeof(CarViewTemplate))]等帮助属性
有可能吗?
更新
我与Render(IViewTemplate template)有接口
【问题讨论】:
-
如果您不能使用
IViewTemplate,请不要接受。您要查找的编译时检查是CarViewTemplate template。 -
我可能在这里遗漏了一些重要的东西,但是你为什么不把 tempate 参数设置为 CarViewTemplate 类型呢?
-
一旦你开始做大量的
typeof检查,你就会知道你有代码异味。 -
如果你有
Render(IViewTemplate template)的接口,那为什么没有ManagerCar : SuchAnInterface? -
@Dimitar Dimitrov,你的声音不错
标签: c#