<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Long overdue Enum goodness in .NET 4</title>
	<atom:link href="http://reedcopsey.com/2009/10/26/long-overdue-enum-goodness-in-net-4/feed/" rel="self" type="application/rss+xml" />
	<link>http://reedcopsey.com/2009/10/26/long-overdue-enum-goodness-in-net-4/</link>
	<description>Thoughts on C#, WPF, .NET, and programming for Scientific Visualization</description>
	<lastBuildDate>Sat, 04 Sep 2010 01:57:48 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: Quagmandir</title>
		<link>http://reedcopsey.com/2009/10/26/long-overdue-enum-goodness-in-net-4/#comment-1135</link>
		<dc:creator>Quagmandir</dc:creator>
		<pubDate>Sun, 08 Aug 2010 02:47:02 +0000</pubDate>
		<guid isPermaLink="false">http://reedcopsey.com/?p=77#comment-1135</guid>
		<description>Sorry for the necromancy but, I found you whilst looking for Enum goodies.

Now, as I have only today found this out myself, I felt I had to point out that the following statement is inaccurate:

&quot;Unfortunately, removing a flag isn’t quite as easy.&quot;

I believe you can use:

variable &amp;= ~TestFlags.Sixteen;

The ( ~ ) operator, apparently, AND&#039;s the _negative_ of the given flag.

Thanks, and enjoy!</description>
		<content:encoded><![CDATA[<p>Sorry for the necromancy but, I found you whilst looking for Enum goodies.</p>
<p>Now, as I have only today found this out myself, I felt I had to point out that the following statement is inaccurate:</p>
<p>&#8220;Unfortunately, removing a flag isn’t quite as easy.&#8221;</p>
<p>I believe you can use:</p>
<p>variable &amp;= ~TestFlags.Sixteen;</p>
<p>The ( ~ ) operator, apparently, AND&#8217;s the _negative_ of the given flag.</p>
<p>Thanks, and enjoy!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Moby Disk</title>
		<link>http://reedcopsey.com/2009/10/26/long-overdue-enum-goodness-in-net-4/#comment-1069</link>
		<dc:creator>Moby Disk</dc:creator>
		<pubDate>Wed, 14 Apr 2010 20:07:59 +0000</pubDate>
		<guid isPermaLink="false">http://reedcopsey.com/?p=77#comment-1069</guid>
		<description>Enum is still missing the most obvious one:

public static TEnum Parse(string value, bool ignoreCase);

It can&#039;t infer the enum type since it is a return value, but it still beats passing typeof(T).  Oh well.</description>
		<content:encoded><![CDATA[<p>Enum is still missing the most obvious one:</p>
<p>public static TEnum Parse(string value, bool ignoreCase);</p>
<p>It can&#8217;t infer the enum type since it is a return value, but it still beats passing typeof(T).  Oh well.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: <img src='http://reedcopsey.com/blog/wp-content/plugins/rpx/images/openid.png'/> Reed</title>
		<link>http://reedcopsey.com/2009/10/26/long-overdue-enum-goodness-in-net-4/#comment-511</link>
		<dc:creator><img src='http://reedcopsey.com/blog/wp-content/plugins/rpx/images/openid.png'/> Reed</dc:creator>
		<pubDate>Thu, 14 Jan 2010 03:21:19 +0000</pubDate>
		<guid isPermaLink="false">http://reedcopsey.com/?p=77#comment-511</guid>
		<description>JD:

You can add to a flag enum using &#124;=, which is very easy and concise:

variable &#124;= TestFlags.Sixteen;

This will add the Sixteen flag to variable.

Unfortunately, removing a flag isn&#039;t quite as easy.  If you know, for sure, that the flag is set, you can do:

variable ^= TestFlags.Sixteen;

However, if the flag is not set, the above will add it (it flips the flag bit, not removes it).

There is no AddFlag/RemoveFlag in .NET 4, though.</description>
		<content:encoded><![CDATA[<p>JD:</p>
<p>You can add to a flag enum using |=, which is very easy and concise:</p>
<p>variable |= TestFlags.Sixteen;</p>
<p>This will add the Sixteen flag to variable.</p>
<p>Unfortunately, removing a flag isn&#8217;t quite as easy.  If you know, for sure, that the flag is set, you can do:</p>
<p>variable ^= TestFlags.Sixteen;</p>
<p>However, if the flag is not set, the above will add it (it flips the flag bit, not removes it).</p>
<p>There is no AddFlag/RemoveFlag in .NET 4, though.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: JD</title>
		<link>http://reedcopsey.com/2009/10/26/long-overdue-enum-goodness-in-net-4/#comment-506</link>
		<dc:creator>JD</dc:creator>
		<pubDate>Wed, 13 Jan 2010 21:14:34 +0000</pubDate>
		<guid isPermaLink="false">http://reedcopsey.com/?p=77#comment-506</guid>
		<description>Also, found this reference here: http://stackoverflow.com/questions/93744/most-common-c-bitwise-operations/417217#417217

Would be nice to have: HasFlag, AddFlag, RemoveFlag</description>
		<content:encoded><![CDATA[<p>Also, found this reference here: <a href="http://stackoverflow.com/questions/93744/most-common-c-bitwise-operations/417217#417217" rel="nofollow">http://stackoverflow.com/questions/93744/most-common-c-bitwise-operations/417217#417217</a></p>
<p>Would be nice to have: HasFlag, AddFlag, RemoveFlag</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: JD</title>
		<link>http://reedcopsey.com/2009/10/26/long-overdue-enum-goodness-in-net-4/#comment-505</link>
		<dc:creator>JD</dc:creator>
		<pubDate>Wed, 13 Jan 2010 20:12:52 +0000</pubDate>
		<guid isPermaLink="false">http://reedcopsey.com/?p=77#comment-505</guid>
		<description>HasFlag looks nice.  I&#039;m trying to see if it will also have methods for flipping on/off a flag?  For example, SetFlag and UnsetFlag...doesn&#039;t look like it from glancing at MS docs.  Would have been useful for easy way to unset a particular flag as this post here indicates you need to OR, then XOR to unset a particular flag - http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/3358c90e-39bd-4516-8207-cafb54877354</description>
		<content:encoded><![CDATA[<p>HasFlag looks nice.  I&#8217;m trying to see if it will also have methods for flipping on/off a flag?  For example, SetFlag and UnsetFlag&#8230;doesn&#8217;t look like it from glancing at MS docs.  Would have been useful for easy way to unset a particular flag as this post here indicates you need to OR, then XOR to unset a particular flag &#8211; <a href="http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/3358c90e-39bd-4516-8207-cafb54877354" rel="nofollow">http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/3358c90e-39bd-4516-8207-cafb54877354</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: <img src='http://reedcopsey.com/blog/wp-content/plugins/rpx/images/openid.png'/> Reed</title>
		<link>http://reedcopsey.com/2009/10/26/long-overdue-enum-goodness-in-net-4/#comment-128</link>
		<dc:creator><img src='http://reedcopsey.com/blog/wp-content/plugins/rpx/images/openid.png'/> Reed</dc:creator>
		<pubDate>Tue, 10 Nov 2009 20:50:52 +0000</pubDate>
		<guid isPermaLink="false">http://reedcopsey.com/?p=77#comment-128</guid>
		<description>Dan,

It&#039;s still a bit odd, usage wise, though - There&#039;s no way to infer T, so you have to write:

Colors color = Enum&lt;Colors&gt;.Parse(colorString);

Also, TryParse is nice because it will not throw if there&#039;s an error, which is a very useful feature.</description>
		<content:encoded><![CDATA[<p>Dan,</p>
<p>It&#8217;s still a bit odd, usage wise, though &#8211; There&#8217;s no way to infer T, so you have to write:</p>
<p>Colors color = Enum<br />
<colors>.Parse(colorString);</p>
<p>Also, TryParse is nice because it will not throw if there&#8217;s an error, which is a very useful feature.</colors>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dan Atkinson</title>
		<link>http://reedcopsey.com/2009/10/26/long-overdue-enum-goodness-in-net-4/#comment-127</link>
		<dc:creator>Dan Atkinson</dc:creator>
		<pubDate>Tue, 10 Nov 2009 20:05:59 +0000</pubDate>
		<guid isPermaLink="false">http://reedcopsey.com/?p=77#comment-127</guid>
		<description>It has &lt;T&gt; on the class, but you can see that.</description>
		<content:encoded><![CDATA[<p>It has &lt;T&gt; on the class, but you can see that.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dan Atkinson</title>
		<link>http://reedcopsey.com/2009/10/26/long-overdue-enum-goodness-in-net-4/#comment-126</link>
		<dc:creator>Dan Atkinson</dc:creator>
		<pubDate>Tue, 10 Nov 2009 20:04:50 +0000</pubDate>
		<guid isPermaLink="false">http://reedcopsey.com/?p=77#comment-126</guid>
		<description>Or you could just write your own extension...

public class Enum
{
  public static T Parse(string value)
  {
    return (T)Enum.Parse(typeof(T), value, true);
  }
}

Usage:
Enum.Parse(colorString);

Now, I don&#039;t know about you, but I think mine is so much cleaner! If you really want, you can handle the try/catch in there, but if you&#039;re concerned about it failing, then you should consider using a concrete class instead.</description>
		<content:encoded><![CDATA[<p>Or you could just write your own extension&#8230;</p>
<p>public class Enum<br />
{<br />
  public static T Parse(string value)<br />
  {<br />
    return (T)Enum.Parse(typeof(T), value, true);<br />
  }<br />
}</p>
<p>Usage:<br />
Enum.Parse(colorString);</p>
<p>Now, I don&#8217;t know about you, but I think mine is so much cleaner! If you really want, you can handle the try/catch in there, but if you&#8217;re concerned about it failing, then you should consider using a concrete class instead.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: <img src='http://reedcopsey.com/blog/wp-content/plugins/rpx/images/openid.png'/> Reed</title>
		<link>http://reedcopsey.com/2009/10/26/long-overdue-enum-goodness-in-net-4/#comment-106</link>
		<dc:creator><img src='http://reedcopsey.com/blog/wp-content/plugins/rpx/images/openid.png'/> Reed</dc:creator>
		<pubDate>Wed, 28 Oct 2009 19:20:37 +0000</pubDate>
		<guid isPermaLink="false">http://reedcopsey.com/?p=77#comment-106</guid>
		<description>Interesting idea.  I&#039;d guess it has to do with being consistent with how flags are handled in the Windows API and other technologies/languages.  It would be odd to all of a sudden be using &quot;and&quot; when everything always used &quot;or&quot; previously (even if it is nicer syntax).  I do like the idea of language support for flags instead of using attributes, very much.</description>
		<content:encoded><![CDATA[<p>Interesting idea.  I&#8217;d guess it has to do with being consistent with how flags are handled in the Windows API and other technologies/languages.  It would be odd to all of a sudden be using &#8220;and&#8221; when everything always used &#8220;or&#8221; previously (even if it is nicer syntax).  I do like the idea of language support for flags instead of using attributes, very much.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Fernando Nicolet</title>
		<link>http://reedcopsey.com/2009/10/26/long-overdue-enum-goodness-in-net-4/#comment-103</link>
		<dc:creator>Fernando Nicolet</dc:creator>
		<pubDate>Wed, 28 Oct 2009 17:53:10 +0000</pubDate>
		<guid isPermaLink="false">http://reedcopsey.com/?p=77#comment-103</guid>
		<description>Very nice feature, indeed and definitely overdue. I always wondered why flags weren&#039;t treated slightly different than regular enums and maybe provide a context keywords such as &quot;in&quot; (has is better though) and flagged for the definition (instead of the attribute). I don&#039;t know, something to hide the bitwise operations that aren&#039;t really more than implementation details.

Something like this:

public &lt;strong&gt;flagged&lt;/strong&gt; enum Days
{
    Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday
}

Days meetingDays = Days.Monday &lt;strong&gt;and&lt;/strong&gt; Days.Tuesday and Days.Thursday;

if (Days.Friday &lt;strong&gt;in&lt;/strong&gt; meetingDays)
{
}

Of course, I&#039;m sure there&#039;s an excellent reason as to why this wasn&#039;t done like this... never really tried to figure it out.

Still, I wasn&#039;t aware of this new feature. Thanks for the heads up!

Fernando</description>
		<content:encoded><![CDATA[<p>Very nice feature, indeed and definitely overdue. I always wondered why flags weren&#8217;t treated slightly different than regular enums and maybe provide a context keywords such as &#8220;in&#8221; (has is better though) and flagged for the definition (instead of the attribute). I don&#8217;t know, something to hide the bitwise operations that aren&#8217;t really more than implementation details.</p>
<p>Something like this:</p>
<p>public <strong>flagged</strong> enum Days<br />
{<br />
    Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday<br />
}</p>
<p>Days meetingDays = Days.Monday <strong>and</strong> Days.Tuesday and Days.Thursday;</p>
<p>if (Days.Friday <strong>in</strong> meetingDays)<br />
{<br />
}</p>
<p>Of course, I&#8217;m sure there&#8217;s an excellent reason as to why this wasn&#8217;t done like this&#8230; never really tried to figure it out.</p>
<p>Still, I wasn&#8217;t aware of this new feature. Thanks for the heads up!</p>
<p>Fernando</p>
]]></content:encoded>
	</item>
</channel>
</rss>
 