Why would finding a type’s initializer throw a NullReferenceException?

This has got me stumped. I was trying to optimize some tests for Noda Time, where we have some type initializer checking. I thought I’d find out whether a type has a type initializer (static constructor or static variables with initializers) before loading everything into a new AppDomain. To my surprise, a small test of … Read more

Can you use reflection to find the name of the currently executing method?

Like the title says: Can reflection give you the name of the currently executing method. I’m inclined to guess not, because of the Heisenberg problem. How do you call a method that will tell you the current method without changing what the current method is? But I’m hoping someone can prove me wrong there. Update: … Read more

Getting assembly name

C#’s exception class has a source property which is set to the name of the assembly by default. Is there another way to get this exact string (without parsing a different string)? I have tried the following: catch(Exception e) { string str = e.Source; //”EPA” – what I want str = System.Reflection.Assembly.GetExecutingAssembly().FullName; //”EPA, Version=1.0.0.0, Culture=neutral, … Read more

What is the difference between getFields and getDeclaredFields in Java reflection

I’m a little confused about the difference between the getFields method and the getDeclaredFields method when using Java reflection. I read that getDeclaredFields gives you access to all the fields of the class and that getFields only returns public fields. If this is the case, why wouldn’t you just always use getDeclaredFields? Can someone please … Read more