Reflection and static constructors

  • Thread starter Thread starter Dansk
  • Start date Start date
D

Dansk

Hi all,

I have a class with a static constructor that I need to call via reflection.

I've tried lots of combinations with the binding flags and InvokeMethod,
no luck so far.

Do you have any suggestion?

Thanks in advance,
Dansk.
 
Sorry for disturbing, I finally have it:

ConstructorInfo constructorInfo =
type.GetConstructor(BindingFlags.Static | BindingFlags.NonPublic, null,
new Type[0], null);
constructorInfo.Invoke(null, null);


Dansk a écrit :
 
Sorry for disturbing, I finally have it:

ConstructorInfo constructorInfo =
type.GetConstructor(BindingFlags.Static | BindingFlags.NonPublic, null,
new Type[0], null);
constructorInfo.Invoke(null, null);

Or rather simpler: type.TypeInitializer.

Jon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top