When using Assembly.GetTypes()
I get types that have Type.Name
that begin with <>c....
.
I tried to google if this is an
They're compiler generated types, which would include anonymous types, but also the implementations of IEnumerable<T>
, IEnumerator<T>
, 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.
These are compiler generated display classes. You can distinguish them by looking for the CompilerGeneratedAttribute:
var attr = Attribute.GetCustomAttribute(type, typeof(CompilerGeneratedAttribute));
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;
}