RSS Feed for This PostCurrent Article

.NET String Enumeration

Normally you cannot use string in enum. However you can bypass using a trick, as shown below.

/// <summary>
/// Response expected from the gateway
/// </summary>
public enum Response
    /// <summary>
    /// No respons expected, just return the result
    /// </summary>
    /// <summary>
    /// Error response
    /// </summary>
    /// <summary>
    /// Successful response
    /// </summary>

By writing a custom string attribute, using enum string is possible.

This is further described in CodeProject article here.

The only thing is that Reflection is used here, which may have performance implication.

Popularity: 2% [?]

Trackback URL

RSS Feed for This PostPost a Comment