2013-10-04 44 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

相关问题