Class Guard
- Namespace
- Support
- Assembly
- Support.dll
A class that can be used to count things (typically executions) and throw an exception if the count exceeds a limit.
public class Guard
- Inheritance
-
Guard
- Inherited Members
- Extension Methods
Remarks
This class is used to implement RecursionDepthGuard and IterationGuard.
This class can be used as a straight forward counter (for example, to count the number of iterations in a loop), or as a counter that can be incremented and decremented (for example, to count the recursion depth).
Constructors
Guard(int, string, string)
A class that can be used to count things (typically executions) and throw an exception if the count exceeds a limit.
public Guard(int defaultLimit, string limitExceededMessage, string incDecMismatchMessage)
Parameters
defaultLimit
intThe default limit that is used if no limit is in Reset().
limitExceededMessage
stringThe error message to display when the limit is exceeded.
incDecMismatchMessage
stringThe error message to display when Dec() has been called more than Inc().
Remarks
This class is used to implement RecursionDepthGuard and IterationGuard.
This class can be used as a straight forward counter (for example, to count the number of iterations in a loop), or as a counter that can be incremented and decremented (for example, to count the recursion depth).
Methods
Dec()
Decrements the counter.
public void Dec()
Remarks
Dec should never be called more times than Inc(); the idea is that this keeps track of scope exists (while Inc keeps track of scope enters).
Exceptions
- See Also
Inc()
Increments the counter.
public void Inc()
Exceptions
- InvalidOperationException
The limit is exceeded.
Reset()
Resets the counter to zero and sets the limit to the default value.
public void Reset()
Reset(int)
Resets the counter to zero and sets the limit to the specified value.
public void Reset(int limit)
Parameters
limit
intThe limit.