Invoking the Static Constructor via Reflection

Thursday, June 17, 2010

-- Warning! -- This post may cause the reader a slight feeling of nausea. However, remember that tough situations call for some tough actions! The Situation Imagine that you have to write some-unit tests for a class which uses an existing infrastructure, involving calls to static methods on a static class. To make things worse, this static class also holds some state which, unfortunately, gets carried around between tests without no actual ability to clear it.     public static class MyInfrastructureClass    {        private static Dictionary<int, string> _someState = ...
tags: , , ,
5 comments