【发布时间】:2013-09-30 02:05:47
【问题描述】:
我有以下代码,其中 T 是这样定义的泛型:
public abstract class RepositoryBase<T> where T : class, IDataModel
这段代码运行良好:
PropertyInfo propertyInfo = typeof(T).GetProperty(propertyName);
if (propertyInfo.DeclaringType.FullName == typeof(T).FullName) <--- Works just fine
vs 这段代码的结果为假
PropertyInfo propertyInfo = typeof(T).GetProperty(propertyName);
if (propertyInfo.DeclaringType is T) <-- does not work
我在这里做错了什么?
【问题讨论】:
标签: c# reflection properties