9
我有下面的代碼,其中T是被定義爲這樣一個通用:爲什麼我的C#IS語句不起作用?
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此代碼的值爲false
PropertyInfo propertyInfo = typeof(T).GetProperty(propertyName);
if (propertyInfo.DeclaringType is T) <-- does not work
我在這裏做錯了什麼?
http://www.youtube.com/watch?v=j4XT-l-_3y0 – JoelFan