PrivateObject Class
Visual Studio 2012
Allows test code to call methods and properties on the code under test that would be inaccessible because they are not public.
Namespace:
Microsoft.VisualStudio.TestTools.UnitTesting
Assembly: Microsoft.VisualStudio.QualityTools.UnitTestFramework (in Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll)
The PrivateObject type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | PrivateObject(Object) | Initializes a new instance of the PrivateObject class that creates the wrapper for the specified object. |
![]() | PrivateObject(Object, PrivateType) | Initializes a new instance of the PrivateObject class that creates the wrapper for the specified object. |
![]() | PrivateObject(Object, String) | Initializes a new instance of the PrivateObject class that creates the wrapper for the specified object. |
![]() | PrivateObject(Type, Object[]) | Initializes a new instance of the PrivateObject class that creates the wrapper for the specified object. |
![]() | PrivateObject(String, String, Object[]) | Initializes a new instance of the PrivateObject class. This creates the object of the specified type and wraps it in the private object. |
![]() | PrivateObject(Type, Type[], Object[]) | Initializes a new instance of the PrivateObject class. |
![]() | PrivateObject(String, String, Type[], Object[]) | Initializes a new instance of the PrivateObject class. This creates an object of the specified type and wraps it in the private object. |
| Name | Description | |
|---|---|---|
![]() | Equals | Returns a value that indicates whether two private objects are encapsulating the same target object. (Overrides Object.Equals(Object).) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() | GetArrayElement(String, Int32[]) | Gets the array element by using an array of subscripts for each dimension. |
![]() | GetArrayElement(String, BindingFlags, Int32[]) | Gets the array element by using an array of subscripts for each dimension. |
![]() | GetField(String) | Gets a value from a named field, based on the name. |
![]() | GetField(String, BindingFlags) | Gets a value from a named field, based on the name and lookup mask. |
![]() | GetFieldOrProperty(String) | Gets a value of a wrapped field or property based on the name. |
![]() | GetFieldOrProperty(String, BindingFlags) | Gets a value of a wrapped field or property based on the name. |
![]() | GetHashCode | Gets the hash code of the wrapped object. (Overrides Object.GetHashCode.) |
![]() | GetProperty(String, Object[]) | Gets a property for a wrapped object identified by name. |
![]() | GetProperty(String, BindingFlags, Object[]) | Gets a property for a wrapped object identified by name with binding flags. |
![]() | GetProperty(String, Type[], Object[]) | Gets a property for a wrapped object identified by name. |
![]() | GetProperty(String, BindingFlags, Type[], Object[]) | Gets an indexed property for a wrapped object identified by name. |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | Invoke(String, Object[]) | Used to access the members of the private object. |
![]() | Invoke(String, Object[], CultureInfo) | Used to access the members of the private object. |
![]() | Invoke(String, BindingFlags, Object[]) | Used to access the members of the private object. |
![]() | Invoke(String, Type[], Object[]) | Used to access the methods of the private object. |
![]() | Invoke(String, BindingFlags, Object[], CultureInfo) | Used to access the members of the private object. |
![]() | Invoke(String, BindingFlags, Type[], Object[]) | Used to access the members of the private object. |
![]() | Invoke(String, Type[], Object[], CultureInfo) | Used to access the members of the private object. |
![]() | Invoke(String, Type[], Object[], Type[]) | Used to access generic members of a private object. |
![]() | Invoke(String, BindingFlags, Type[], Object[], CultureInfo) | Used to access the members of the private object. |
![]() | Invoke(String, BindingFlags, Type[], Object[], CultureInfo, Type[]) | Used to access generic members of a private object. |
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | SetArrayElement(String, Object, Int32[]) | Sets the array element by using an array of subscripts for each dimension. |
![]() | SetArrayElement(String, BindingFlags, Object, Int32[]) | Sets the array element by using an array of subscripts for each dimension. |
![]() | SetField(String, Object) | Sets a value for the field of the wrapped object, identified by name. |
![]() | SetField(String, BindingFlags, Object) | Sets a value for the field of the wrapped object, identified by name. |
![]() | SetFieldOrProperty(String, Object) | Sets a value of a wrapped field or property based on the name. |
![]() | SetFieldOrProperty(String, BindingFlags, Object) | Sets a value of a wrapped field or property based on the name. |
![]() | SetProperty(String, Object, Object[]) | Sets a property for a wrapped object identified by name. |
![]() | SetProperty(String, BindingFlags, Object, Object[]) | Sets a property for a wrapped object identified by name with binding flags. |
![]() | SetProperty(String, Type[], Object, Object[]) | Sets an indexed property for a wrapped object identified by name. |
![]() | SetProperty(String, BindingFlags, Object, Type[], Object[]) | Sets an indexed property for a wrapped object identified by name. |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
The test generator creates most of the calls to these objects. The test generator creates code to wrap the private objects in a wrapper that allows access to the private object's members.
For a list of initial property values for an instance of the PrivateObject class, see the PrivateObject constructor.
This class represents the live non-public internal object in the system.
- ReflectionPermission
The user must have the TypeInformation and MemberAccess flags set to use this type.
