4

現在、次のようなイベント クラスを作成しています。

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; }
}

trueここで、 orfalseを送信する代わりに、3 つの値のshowExceptionうちの 1 つを送信したいと思いますor - どうすればこのようなことに取り組むことができますか? 文字列を常にこれらの 3 つの値のいずれかに制限したいので、実際には文字列を使用したくありませんが、プロパティを使用するときにこれにアプローチする方法がわかりません。DebugInfoError

4

1 に答える 1

11

列挙型を使用できます:

public enum ShowExceptionLevel
{
    Debug,
    Info,
    Error
}

したがって、クラスは次のようになります。

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; }
}
于 2013-10-04T00:38:26.213 に答える