0

I have a class in an assembly I am reflecting through:

public class Example
{
    public List<int> things;
}

When reflecting over the assembly and grabbing type.Name:

foreach(var type in typeof(Example).Assembly.GetTypes())
    var hold = type.Name;

What is stored in the variable hold is just generic brackets, <>, and the type.FullName is Example+<>. What is going on? This works with every other class in the assembly. This class does have two partial files, neither define it to be generic though.

Dagrooms
  • 1,507
  • 2
  • 16
  • 42
  • http://stackoverflow.com/q/6418779/34397 – SLaks Nov 02 '16 at 19:41
  • In `.Name` of a type, the angles `<>` are not related to generic types. A generic type would be something like ``"SomeClass`3[TOne, TTwo, TThree]"`` if you use `.ToString()`, but only ``"SomeClass`3"`` with `.Name`. – Jeppe Stig Nielsen Nov 02 '16 at 20:46
  • SLaks, thank you, I was unable to find that question in my initial search because I did not know I was looking for a compiler-generated class. – Dagrooms Nov 02 '16 at 20:49

1 Answers1

5

These types are generated by the compiler to help make your code work.

They come from lambdas, iterators, or anonymous types.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • To avoid getting this type when doing my assembly reflection I checked if the type had the CompilerGeneratedAttribute. Thanks for your help – Dagrooms Nov 02 '16 at 20:47
  • To see something about the naming of these C# compiler-generated types, see [this answer in another thread](http://stackoverflow.com/a/2509524/1336654). Of course there is no guarantee this will not change in the future. – Jeppe Stig Nielsen Nov 02 '16 at 20:49