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

后端 未结 3 1300
予麋鹿
予麋鹿 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条回答
  •  萌比男神i
    2020-12-10 10:57

    They're compiler generated types, which would include anonymous types, but also the implementations of IEnumerable, IEnumerator, IEnumerable and IEnumerator that are produced by yield and the state-machine structures produced by await.

    They will have the CompilerGeneratedAttribute.

    You describe the names as "strange" and they are deliberately such. They are all names that are valid .NET names, but not valid in common .NET languages, particularly C# and VB.NET. This means you couldn't create such a class with C# coding directly, so there doesn't need to have any logic to check the programmer hasn't created a matching class.

提交回复
热议问题