22 November 2011

How To Detour a Static Constructor

Static constructors pose a challenge.  Naturally, one can not call the constructor of a static class.  This also means that the Moles Framework does not provide an accessor to detour the constructor of a static class.  However, Moles provides a way to erase static constructors, to prevent them from executing.  Simply add the MolesDisableStaticConstructor assembly attribute to the test class:

[assemblyMolesEraseStaticConstructor(typeof(MyStatic))]

1 comment:

Please provide details, when posting technical comments. If you find an error in sample code or have found bad information/misinformation in a post, please e-mail me details, so I can make corrections as quickly as possible.