Wednesday, August 13, 2008

Reflection , qualify nested class

This thing got my attention today when I came across a runtime error in the

code trying to access a nested class via reflection.

The code was something like this:

// The code below gives error "cannot find MyClass.NestedClass in assembly .... bla bla...bla"

Type nestedType = assembly.GetType("MyClass.NetstedClass");

Looking at it for a few minutes I could not think of anything obvious that's wrong until I figured out the use of '+' when qualifying nested class.

Type nestedType = assembly.GetType("MyClass+NetstedClass"); // work just fine :)

No comments: