I have two simple classes.
public class A { } public class B { }
I create and create an instance of class C as shown below.
var assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName("Some.Namespace"), AssemblyBuilderAccess.Run); var moduleBuilder = assemblyBuilder.DefineDynamicModule(assemblyBuilder.GetName().Name);
The problem is that I can successfully create the C class. When I check the type and value of CA , it was very surprising for me.
var c = CreateC(); var field = c.GetType().GetField("A"); var fieldValue = c.GetType().GetField("A").GetValue(c); Console.WriteLine(typeof(A) == field.FieldType);
In short, I have the following classes that work!
public class A { } public class B { } public class C { public AA; public C() { this.A = new B(); } }
My questions:
- How is this possible?
- At what level does the CLR check types?
source share