Is it possible to get access to a private static field inside a static class, using the VS2010 Unit Test class PrivateObject ?
Let say i have the following class:
<
The answer by Deepun can be very useful. I wanted to add a specific example to help people who come this way.
Class with private static member.
public class foo
{
private static int bar;
}
Code to get value.
PrivateType pt = new PrivateType(typeof(foo));
int bar = (int)pt.GetStaticFieldOrProperty("bar");
Code to change value
PrivateType pt = new PrivateType(typeof(foo));
pt.SetStaticFieldOrProperty("bar", 10);
This will work regardless of the class being static or not.