2013-10-04 92 views
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; } 
} 

現在,而不是發送對showExceptiontruefalse我想送三個值Debug之一,InfoError - 我該如何處理這樣的事情?我真的不想使用字符串,因爲我希望始終將其限制爲這三個值中的一個,但我不確定如何在使用屬性時處理此問題。

+10

這是一個'enum'你要尋找的。 –

回答

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

謝謝你 - 我現在就讀這些。我會盡快接受答案。 – Codingo

相關問題