PrivateObject Class
Allows test code to call methods and properties on the code under test that would be inaccessible because they are not public.
Inheritance Hierarchy
Object
Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject
Namespace: Microsoft.VisualStudio.TestTools.UnitTesting
Assembly: Microsoft.VisualStudio.QualityTools.UnitTestFramework (in Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll)
Syntax
'Declaration
Public Class PrivateObject
public class PrivateObject
public ref class PrivateObject
type PrivateObject = class end
public class PrivateObject
The PrivateObject type exposes the following members.
Constructors
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, array<Object[]) | Initializes a new instance of the PrivateObject class that creates the wrapper for the specified object. | |
PrivateObject(String, String, array<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, array<Type[], array<Object[]) | Initializes a new instance of the PrivateObject class. | |
PrivateObject(String, String, array<Type[], array<Object[]) | Initializes a new instance of the PrivateObject class. This creates an object of the specified type and wraps it in the private object. |
Top
Properties
Name | Description | |
---|---|---|
RealType | Gets the type of the underlying object. | |
Target | Gets or sets the wrapped object. |
Top
Methods
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, array<Int32[]) | Gets the array element by using an array of subscripts for each dimension. | |
GetArrayElement(String, BindingFlags, array<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, array<Object[]) | Gets a property for a wrapped object identified by name. | |
GetProperty(String, BindingFlags, array<Object[]) | Gets a property for a wrapped object identified by name with binding flags. | |
GetProperty(String, array<Type[], array<Object[]) | Gets a property for a wrapped object identified by name. | |
GetProperty(String, BindingFlags, array<Type[], array<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, array<Object[]) | Used to access the members of the private object. | |
Invoke(String, array<Object[], CultureInfo) | Used to access the members of the private object. | |
Invoke(String, BindingFlags, array<Object[]) | Used to access the members of the private object. | |
Invoke(String, array<Type[], array<Object[]) | Used to access the methods of the private object. | |
Invoke(String, BindingFlags, array<Object[], CultureInfo) | Used to access the members of the private object. | |
Invoke(String, BindingFlags, array<Type[], array<Object[]) | Used to access the members of the private object. | |
Invoke(String, array<Type[], array<Object[], CultureInfo) | Used to access the members of the private object. | |
Invoke(String, array<Type[], array<Object[], array<Type[]) | Used to access generic members of a private object. | |
Invoke(String, BindingFlags, array<Type[], array<Object[], CultureInfo) | Used to access the members of the private object. | |
Invoke(String, BindingFlags, array<Type[], array<Object[], CultureInfo, array<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, array<Int32[]) | Sets the array element by using an array of subscripts for each dimension. | |
SetArrayElement(String, BindingFlags, Object, array<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, array<Object[]) | Sets a property for a wrapped object identified by name. | |
SetProperty(String, BindingFlags, Object, array<Object[]) | Sets a property for a wrapped object identified by name with binding flags. | |
SetProperty(String, array<Type[], Object, array<Object[]) | Sets an indexed property for a wrapped object identified by name. | |
SetProperty(String, BindingFlags, Object, array<Type[], array<Object[]) | Sets an indexed property for a wrapped object identified by name. | |
ToString | Returns a string that represents the current object. (Inherited from Object.) |
Top
Remarks
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.
.NET Framework Security
-
The user must have the TypeInformation and MemberAccess flags set to use this type.
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
See Also
Reference
Microsoft.VisualStudio.TestTools.UnitTesting Namespace