C# 类型比较

标签 c# reflection types

这让我大便,是否有以下原因:

public abstract class aExtension
{
    public abstract bool LoadExtension(Constants c); // method required in inherit
    public abstract string AppliesToModule // 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"; }
    }
}

对于以下表达式将返回 false:

                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 是来自 cals UK 的反射类型。

奇怪的是我在同一个应用程序的外部组件上做了完全相同的事情并且它按预期工作......

最佳答案

UK 可能从不同版本的程序集继承 aExtension

关于C# 类型比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3037934/

相关文章:

types - OCaml 联合类型

Java 原始类型 : int vs. 整数

java - Java 类定义中重载类型参数

c# - 在 C# 中从服务器轮询连接的客户端

c# - 在c#中使用openxml和pdfcreator将docx转换为pdf

Java, boolean 值可以从 boolean 值赋值,反之亦然吗?

reflection - 使用反射获取属性时,如何将搜索限制在我感兴趣的子类上?

c# - 将 KeyValuePair 列表转换为 IDictionary "C#"

c# - 如何在 Web 服务客户端请求中配置 SOAP XML 命名空间?

reflection - 在golang中使用reflect打印struct指针字段类型