How to store multiple values ​​in a property?

I have an event class that I am creating that currently looks like this:

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 trueeither falsefor, showExceptionI would like to send one of three values Debug, Infoor Error- how can I do something like this? I really don't want to use a string, because I want to always limit it to one of these three values, but I'm not sure how to approach this when using properties.

+4
source share
1 answer

You can use the enumeration:

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; }
}
+11
source

All Articles