I have an events class that I'm creating, that currently looks like the following:
public class SharePointOnErrorEventsArgs : EventArgs
{
public SharePointOnErrorEventsArgs(string message, bool showException, Exception exception)
{
Message = message;
Exception = exception;
ShowException = showException;
}
/// <summary>
/// Property to allow the storage of a more verbose and explainable error message
/// </summary>
public string Message { get; private set; }
/// <summary>
/// Object to store full exception information within
/// </summary>
public Exception Exception { get; private set; }
/// <summary>
/// Boolean value allows for verbose messages to be sent up the stack without
/// the need for displaying a full exception object, or stack trace.
/// </summary>
public bool ShowException { get; private set; }
}
Now, instead of sending true
or false
for showException
I'd like to send one of three values Debug
, Info
or Error
- how can I tackle something like this? I don't really want to use a string as I want to always restrict this to one of those three values, but I'm unsure how to approach this when using properties.
You can use an enum:
public enum ShowExceptionLevel
{
Debug,
Info,
Error
}
So your class will be:
public class SharePointOnErrorEventsArgs : EventArgs
{
public enum ShowExceptionLevel
{
Debug,
Info,
Error
}
public SharePointOnErrorEventsArgs(string message, ShowExceptionLevel showExceptionLevel, Exception exception)
{
Message = message;
Exception = exception;
ShowException = showException;
}
/// <summary>
/// Property to allow the storage of a more verbose and explainable error message
/// </summary>
public string Message { get; private set; }
/// <summary>
/// Object to store full exception information within
/// </summary>
public Exception Exception { get; private set; }
/// <summary>
/// Boolean value allows for verbose messages to be sent up the stack without
/// the need for displaying a full exception object, or stack trace.
/// </summary>
public ShowExceptionLevel ShowException { get; private set; }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With