我知道这方面有几个问题,但我似乎无法得到它的工作。测试类是否继承了通用接口
我有这样的课;
public class TopLocation<T> : ILocation
{
public string name { get; set; }
public string address { get; set; }
}
当我创建我指定它是一个IRestaurant
或IClub
类。到目前为止没有问题。
但是,如何测试语句中的IClub
或IRestaurant
?
失败;
if (item.trendItem is ILocation<ITopRestaurant>)
,并返回null
Type myInterfaceType = item.trendItem.GetType().GetInterface(
typeof(ITopRestaurant).Name);
我想这在if
声明的原因是因为它在MVC应用程序坐在一个ASCX页面中,我试图呈现部分正确视图。
编辑
响应注释;
所有的public interface ITopClub{}
public interface ITopRestaurant { }
public interface ILocation{}
有一个通用的`ILocation`以及?什么是层次结构?什么是“ITopRestaurant”? – Jon 2011-12-16 02:34:08
ITopRestaunt只是一个空接口,用于识别此项目的ILocation类型 – griegs 2011-12-16 02:35:12
可能的重复http://stackoverflow.com/questions/503263/how-to-determine-if-a-type-implements-a-specific -generic-interface-type – HackedByChinese 2011-12-16 02:36:11