Getting all types under a userdefined assembly

I am trying to get all the types defined under a particular userdefined namespace

Assembly.GetEntryAssembly().GetTypes().Where(t => t.Namespace == "namespace")


    <>c__DisplayClass3_0    
    <>c__DisplayClass4_0    
    <>c__DisplayClass6_0    
    <>c__DisplayClass2_0    
    <>c__DisplayClass2_1    
    <>c__DisplayClass2_2    
    <>c__DisplayClass2_3    
    <>c__DisplayClass2_4    
    <>c__DisplayClass2_5    
    <>c__DisplayClass2_6    
    <>c__DisplayClass2_7    
    <>c__DisplayClass2_8

My question Why am i getting these extra type which are not defined under that namespace?

how do i select type that are user defined types?

some one explain me what are these and how they get defined under a userdefined namespace.

Jon Skeet
people
quotationmark

Those are all types generated by the compiler. The C# compiler generates types to implement things like:

  • Lambda expressions and anonymous methods
  • Iterator blocks
  • Async methods
  • Anonymous types

All of them should have the CompilerGeneratedAttribute applied to them, so you can filter them out that way if you want:

var types = Assembly.GetEntryAssembly()
    .GetTypes()
    .Where(t => t.Namespace == "namespace")
    .Where(t => !t.GetTypeInfo().IsDefined(typeof(CompilerGeneratedAttribute), true));

people

See more on this question at Stackoverflow