Alex Rivera | Logout

Can i use VS2010 PrivateObject to access a static field inside a static class?

Asked 2011-03-09T16:00:35.950
21

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:

public static class foo
{
    private static bar;
}

Can i use PrivateObject to create a copy of foo, and then get the bar field?

Edit
Report

1 Answer

32

PrivateType class is analogous to PrivateObject for invoking private static members. Overloaded GetStaticFieldOrProperty methods may be used. http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.privatetype(v=VS.100).aspx

answered 2011-10-20T11:43:47.483

Your Answer