开发者

C# Type comparison

开发者 https://www.devze.com 2023-01-03 15:03 出处:网络
This has me pooped, is there any reason the following: public abstract class aExtension { public abstract bool LoadExtension(Constants c); // method required in inherit

This has me pooped, is there any reason the following:

public abstract class aExtension
{
    public abstract bool LoadExtension(Constants c); // method required in inherit
    public abstract string Appl开发者_如何转开发iesToModule // property required in inherit
    {
        get;
    }
    public abstract string ExtensionName // property required in inherit
    {
        get;
    }
    public abstract string ExtensionDescription // property required in inherit
    {
        get;
    }
}

public class UK : aExtension
{
    public override bool LoadExtension(Constants c)
    {
        return true;
    }
    public override string AppliesToModule
    {
        get { return "string"; }
    }
    public override string ExtensionName
    {
        get { return "string"; }
    }
    public override string ExtensionDescription
    {
        get { return "string"; }
    }
}

would return false for the following expressions:

                bool a = t.IsAssignableFrom(aExtension));
                bool b = t.BaseType.IsAssignableFrom(aExtension));
                bool c = typeof(aExtension).IsAssignableFrom(t);
                bool d = typeof(aExtension).IsAssignableFrom(t.BaseType);
                bool e = typeof(aExtension).IsSubclassOf(t);
                bool f = typeof(aExtension).IsSubclassOf(t.BaseType);
                bool g = t.IsSubclassOf(typeof(aExtension));
                bool h = t.BaseType.IsSubclassOf(typeof(LBT.AdMeter.aExtension));
                bool i = t.BaseType.Equals(typeof(aExtension));
                bool j = typeof(aExtension).Equals(t.BaseType);

T is the reflected Type from the calss UK.

Stange thing is i do the exact same thing just on an external assembly in the same application and it works as expected...


UK probably inherits aExtension from a different version of the assembly.


Do you have a copy of the same assembly around? If the same assembly is loaded from a different location, the types are not compatible.

Are you loading assemblies by reflection only somewhere? I think I had issues with that.

0

精彩评论

暂无评论...
验证码 换一张
取 消