reflection - Why is my C# IS statement not working? -
i have following code, t generic defined such:
public abstract class repositorybase<t> t : class, idatamodel this code works fine:
propertyinfo propertyinfo = typeof(t).getproperty(propertyname); if (propertyinfo.declaringtype.fullname == typeof(t).fullname) <--- works fine vs code evaluates false
propertyinfo propertyinfo = typeof(t).getproperty(propertyname); if (propertyinfo.declaringtype t) <-- not work what doing wrong here?
is uses type comparison between 2 objects. declaringtype of type type , typeof(t) of type t, not equal.
var atype = typeof(propertyinfo.declaringtype); var btype = typeof(t); bool areequal = atype btype; // false, unless t type
Comments
Post a Comment