Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The enumeration has duplicate members with the same underlying value as <code>TextArea</code> (<code>Bool</code> and <code>Choices</code>). Although the parse should succeed, the value of <code>ToString</code> on the resulting enum instance is not defined, and may not equal "TextArea" as your assertion is expecting.</p> <p>From the <a href="http://msdn.microsoft.com/en-us/library/a0h36syw.aspx" rel="nofollow" rel="nofollow"><strong><code>Enum.ToString</code></strong></a> documentation:</p> <blockquote> <p>If multiple enumeration members have the same underlying value and you attempt to retrieve the string representation of an enumeration member's name based on its underlying value, your code should not make any assumptions about which name the method will return.</p> </blockquote> <p><strong>EDIT</strong>:</p> <p>In response to your edit, try this assertion:</p> <pre><code>var MaxLength = EnumHelper.ToEnumSafe&lt;anothername&gt;("TextArea"); Assert.AreEqual(anotherName.TextArea, MaxLength); </code></pre> <p>or if you prefer comparing the underlying type:</p> <pre><code>Assert.AreEqual((int)anotherName.TextArea, (int)MaxLength); </code></pre> <p>You appear to be under the impression that an enum member is not associated with an underlying value if its value is not <em>explicitly</em> specified. This is not the case; <em>all</em> members of an enum are associated with an underlying value. The rules for the 'implicit' associations are given by (from the <a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=DFBF523C-F98C-4804-AFBD-459E846B268E" rel="nofollow" rel="nofollow">language specification</a>):</p> <blockquote> <p>• If the enum member is the first enum member declared in the enum type, its associated value is zero. </p> <p>• Otherwise, the associated value of the enum member is obtained by increasing the associated value of the textually preceding enum member by one. This increased value must be within the range of values that can be represented by the underlying type, otherwise a compile-time error occurs.</p> </blockquote>
    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