Mattias Sjögren <ma********************@mvps.org> wrote:
I start with only an instance of the class Type
e.g., typeof(SomeClass), and from that, I would like to
make the runtime call its static constructor, without
creating an instance of it.
System.Runtime.CompilerServices.RuntimeHelpers.Run ClassConstructor(ty
peof(SomeClass).TypeHandle)
Or you can invoke Type.TypeInitializer.
Note that these should be done with great care, as they (at least the
latter) will *rerun* the type initializer as many times as you call
them. Some types may not like that! (For instance, for the normal
singleton pattern implementation, you could end up with multiple
instances...)
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too