Flags and enum to make an linq anyFlags(MyFlag)
<p>this is a basic question I know , and surely a redo of some old recipe made by everyone on planet earth and beyond, but I just get so lost that I need some external advice.</p>

<p>I have an enum like this one :</p>

<pre><code>[Flags]
    public enum MyEnum
    { 
        none=0,  //0000
        toto=1,  //0001
        tata=2,  //0010
        tati=4,  //0100
        titi=8   //1000
    }
</code></pre>

<p>and I have an enum value which is like :</p>

<pre><code>MyEnum s= tata | titi; //(1010) 
</code></pre>

<p>so as to say from what I understood s=10</p>

<p>Now I have a value in my database wich is a short and might be one of these , ie: 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15</p>

<pre><code>id     EnumValue
1      3
2      14
3      10
4      9
5      0
</code></pre>

<p>Now I need to get a linq statement to say which id have at least one othe enum given in s.</p>

<p>I would need at the end :1,2,3,4.</p>

<p>I have done so for theses method :</p>

<pre><code>public static bool HasAllFlags(this short input, Enum matchTo)
{
    return (Convert.ToUInt32(input) &amp; Convert.ToUInt32(matchTo)) == Convert.ToUInt32(matchTo);
}

public static bool IsFlag(this short input, Enum matchTo)
{
    return Convert.ToUInt32(input)== Convert.ToUInt32(matchTo);
}
</code></pre>

<p>but I am stuck with this one :</p>

<pre><code> public static bool HasAnyFlags(this short input, Enum matchTo)
        {
            return ....????....;
        }
</code></pre>

<p>They work pretty well , but I now I need this method which would give me 1,2,3,4 as the desired result. I have tried quite a few things but I cannot get it right. Has any of you any solutions ready made for this?  </p>

<p>Thanks in advance,</p>

<p>PS: I am using c# 3.5</p>
