Method BeginAssertionsDefinition
BeginAssertionsDefinition(MemSnapshot, AssertionsThread)
Begins an assertions session and creates an AssertionsDefinition. An assertions session is used to reduce the number of garbage collections performed when doing memory assertions and to avoid memory side effects.
Declaration
public static AssertionsDefinition BeginAssertionsDefinition(MemSnapshot comparisonSnapshot, AssertionsThread assertionsThread = AssertionsThread.Caller)
Parameters
Type | Name | Description |
---|---|---|
MemSnapshot | comparisonSnapshot | The comparison snapshot to use when AssertionsDefinition.Assert is called. |
AssertionsThread | assertionsThread | The |
Returns
Type | Description |
---|---|
AssertionsDefinition | An AssertionsDefinition instance that can be used to perform memory assertions and end the assertions session. |
Remarks
This method returns an AssertionsDefinition instance. If this instance is disposed, it will automatically assert the definition and then call EndAssertions. This allows the definition to be asserted and the assertions session to be ended using the "using" pattern. If the process is not being profiled, this method does not nothing and the Dispose method of the returned AssertionsDefinition will also do nothing.
note
If the AssertionsDefinition.Assert method is called explicitly, then it will not be called when the AssertionsDefinition
instance is disposed.
var comparisonSnapshot = MemProfiler.FastSnapshot();
// Do some operation that will be checked
using( var ad = MemAssertion.BeginAssertionsDefinition(comparisonSnapshot) )
{
ad.NoNewInstances()
.AllowNewInstances( new Type[] { typeof( SomeClass), typeof( SomeOtherClass ) );
}
See Also
BeginAssertionsDefinition(AssertionsThread)
Begins an assertions session and creates an AssertionsDefinition. An assertions session is used to reduce the number of garbage collections performed when doing memory assertions and to avoid memory side effects.
Declaration
public static AssertionsDefinition BeginAssertionsDefinition(AssertionsThread assertionsThread = AssertionsThread.Caller)
Parameters
Type | Name | Description |
---|---|---|
AssertionsThread | assertionsThread |
Returns
Type | Description |
---|---|
AssertionsDefinition | An AssertionsDefinition instance that can be used to perform memory assertions and end the assertions session. |
Remarks
This method returns an AssertionsDefinition instance. If this instance is disposed, it will automatically assert the definition and then call EndAssertions. This allows the definition to be asserted and the assertions session to be ended using the "using" pattern. If the process is not being profiled, this method does not nothing and the Dispose method of the returned AssertionsDefinition will also do nothing.
note
If the AssertionsDefinition.Assert method is called explicitly, then it will not be called when the AssertionsDefinition
instance is disposed.
var comparisonSnapshot = MemProfiler.FastSnapshot();
// Do some operation that will be checked
using( var ad = MemAssertion.BeginAssertionsDefinition(comparisonSnapshot) )
{
ad.NoNewInstances()
.AllowNewInstances( new Type[] { typeof( SomeClass), typeof( SomeOtherClass ) );
}