Utility Class that takes a snapshot of all the fields of an object or the static fields of a type
, in order to reset all the fields back to the saved state.
Inheritance Hierarchy
TypeMockObjectState
Namespace: TypeMock
Assembly: TypeMock (in TypeMock.dll) Version: 9.3.8.0 (9.3.8.0)
Syntax
The ObjectState type exposes the following members.
Constructors
| Name | Description | |
|---|---|---|
| ObjectState(Object) |
Take a snapshot of all the fields of an object, in order to reset
all the fields back to the saved state.
| |
| ObjectState(Type) |
Take a snapshot of all the static fields of a type, in order to reset
all the fields back to the saved state.
|
Methods
| Name | Description | |
|---|---|---|
| Equals | Determines whether the specified Object is equal to the current Object. (Inherited from 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.) | |
| GetField(String) |
Gets the value of a non-public field (member variable) of the managed type.
| |
| GetField(Object, String) |
Gets the value of a non-public field (member variable) of an instance.
| |
| GetField(Type, String) |
Gets the value of a non-public static field (member variable) of a type.
| |
| GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) | |
| GetType | Gets the Type of the current instance. (Inherited from Object.) | |
| MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | |
| ResetState |
Reset the fields back to their original state
| |
| SetField(String, Object) |
Sets the value of a non-public field (member variable) of the managed type.
| |
| SetField(Object, String, Object) |
Sets the value of a non-public field (member variable) of an instance.
| |
| SetField(Type, String, Object) |
Sets the value of a non-public static field (member variable) of a type.
| |
| ToString | Returns a string that represents the current object. (Inherited from Object.) |
Remarks
Examples
public class StatefulClass { static private int count = 0; public int Count {get { return count++ ;}} } [Test] public void Stateful() { StatefulClass stateful = new StatefulClass(); // Save our state ObjectState objState = new ObjectState(state); // Do something to change the state Assert.AreEqual(0,stateful.Count); // lets reset our code for next test objState.ResetState(); Assert.AreEqual(0,stateful.Count); }
See Also