Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try <a href="http://www.javacamp.org/designPattern/enum.html" rel="noreferrer">type-safe-enum</a> pattern.</p> <pre><code>public sealed class AuthenticationMethod { private readonly String name; private readonly int value; public static readonly AuthenticationMethod FORMS = new AuthenticationMethod (1, "FORMS"); public static readonly AuthenticationMethod WINDOWSAUTHENTICATION = new AuthenticationMethod (2, "WINDOWS"); public static readonly AuthenticationMethod SINGLESIGNON = new AuthenticationMethod (3, "SSN"); private AuthenticationMethod(int value, String name){ this.name = name; this.value = value; } public override String ToString(){ return name; } } </code></pre> <hr> <p><strong>Update</strong> Explicit (or implicit) type conversion can be done by</p> <ul> <li><p>adding static field with mapping</p> <pre><code>private static readonly Dictionary&lt;string, AuthenticationMethod&gt; instance = new Dictionary&lt;string,AuthenticationMethod&gt;(); </code></pre> <ul> <li>n.b. In order that the initialisation of the the "enum member" fields doesn't throw a NullReferenceException when calling the instance constructor, be sure to put the Dictionary field before the "enum member" fields in your class. This is because static field initialisers are called in declaration order, and before the static constructor, creating the weird and necessary but confusing situation that the instance constructor can be called before all static fields have been initialised, and before the static constructor is called.</li> </ul></li> <li><p>filling this mapping in instance constructor</p> <pre><code>instance[name] = this; </code></pre></li> <li><p>and adding <a href="http://msdn.microsoft.com/en-us/library/09479473.aspx" rel="noreferrer">user-defined type conversion operator</a></p> <pre><code>public static explicit operator AuthenticationMethod(string str) { AuthenticationMethod result; if (instance.TryGetValue(str, out result)) return result; else throw new InvalidCastException(); } </code></pre></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload