c# - typeof(interface).IsAssignableFrom(intptr) returns true -
i need go through properties implement interface, , have intptr property passes isassignablefrom condotion.
is there other way check if property implements interface?
this method goes through properties:
protected void setowner() { ienumerable<propertyinfo> sourceproperties = this.gettype().getproperties(); foreach (propertyinfo pi in sourceproperties) { if (pi.name != "owner" && pi.declaringtype.getinterface("iownersystem") != null) //i tried too: typeof(iownersystem).isassignablefrom(pi.declaringtype)) { iownersystem systm = (iownersystem)pi.getvalue(this, null); if (systm != null) { systm.owner = this; } } } }
and class:
public abstract class aircraft : ownersystem { //a bunch of properties... public abstract intptr videowindow { get; } }
pi.declaringtype
type declares property, not type of property. in case, declaringtype
aircraft
or 1 of base classes. should use pi.propertytype
instead.
Comments
Post a Comment