Assembly.GetTypes() returns strange type names e.g. “<>c”

后端 未结 3 1307
予麋鹿
予麋鹿 2020-12-10 10:44

When using Assembly.GetTypes() I get types that have Type.Name that begin with <>c.....

I tried to google if this is an

3条回答
  •  误落风尘
    2020-12-10 11:10

    These are the CompilerGeneratedAttribute Class

    Distinguishes a compiler-generated element from a user-generated element. This class cannot be inherited.

    You can check it like

    using System.Runtime.CompilerServices;
    
    
    bool CompilerGen(Type t)
    {
        var attr = Attribute.GetCustomAttribute(t, typeof(CompilerGeneratedAttribute));
        return attr != null;
    }
    

提交回复
热议问题