Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>EDIT: This is now live in version 0.0.0.2 of UnconstrainedMelody.</strong></p> <p>(As requested on my <a href="http://codeblog.jonskeet.uk/2009/09/10/generic-constraints-for-enums-and-delegates/" rel="noreferrer">blog post about enum constraints</a>. I've included the basic facts below for the sake of a standalone answer.)</p> <p>The best solution is to wait for me to include it in <a href="https://github.com/jskeet/unconstrained-melody" rel="noreferrer">UnconstrainedMelody</a><sup>1</sup>. This is a library which takes C# code with "fake" constraints such as</p> <pre><code>where T : struct, IEnumConstraint </code></pre> <p>and turns it into</p> <pre><code>where T : struct, System.Enum </code></pre> <p>via a postbuild step.</p> <p>It shouldn't be too hard to write <code>IsSet</code>... although catering for both <code>Int64</code>-based and <code>UInt64</code>-based flags could be the tricky part. (I smell some helper methods coming on, basically allowing me to treat any flags enum as if it had a base type of <code>UInt64</code>.)</p> <p>What would you want the behaviour to be if you called</p> <pre><code>tester.IsSet(MyFlags.A | MyFlags.C) </code></pre> <p>? Should it check that <em>all</em> the specified flags are set? That would be my expectation.</p> <p>I'll try to do this on the way home tonight... I'm hoping to have a quick blitz on useful enum methods to get the library up to a usable standard quickly, then relax a bit.</p> <p>EDIT: I'm not sure about <code>IsSet</code> as a name, by the way. Options:</p> <ul> <li>Includes</li> <li>Contains</li> <li>HasFlag (or HasFlags)</li> <li>IsSet (it's certainly an option)</li> </ul> <p>Thoughts welcome. I'm sure it'll be a while before anything's set in stone anyway...</p> <hr> <p><sup>1</sup> or submit it as a patch, of course...</p>
    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