Determine if a type is static

前端 未结 5 767
梦谈多话
梦谈多话 2020-11-29 08:49

Let\'s say I have a Type called type.

I want to determine if I can do this with my type (without actually doing this to each type):

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-29 09:41

    Type t = typeof(System.GC);
    Console.WriteLine(t.Attributes);
    TypeAttributes attribForStaticClass = TypeAttributes.AutoLayout | TypeAttributes.AnsiClass | TypeAttributes.Class |
    TypeAttributes.Public | TypeAttributes.Abstract | TypeAttributes.Sealed | TypeAttributes.BeforeFieldInit;
    Console.WriteLine((t.Attributes == attribForStaticClass));
    

    I guess, this should work.

提交回复
热议问题