How To: Manually Run a Type Initializer

A Type Initializer is first called when referencing a static member or creating an instance of the class.
This might cause problems to some developers as the Type Initializers are not called upon loading the AppDomain, loading the Assembly or using Reflection on the Type.

This is solved by using System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(RuntimeTypeHandle), which invokes the Type Initializer.

Personally, I tried using it once and stopped since it’s just too hackish.

Hack Value: [ X X X X ]
Cool Value: [ X X X X ]
Usable Value: [ X X ]
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s