<?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"
	>
<channel>
	<title>Comments on: Creating user friendly strings for enum values</title>
	<atom:link href="http://www.ytechie.com/2008/05/creating-user-friendly-strings-for-enum-values.html/feed" rel="self" type="application/rss+xml" />
	<link>http://www.ytechie.com/2008/05/creating-user-friendly-strings-for-enum-values.html</link>
	<description>Productive software development using ASP.NET, C#, Adobe Flex, and other technologies and tools.</description>
	<pubDate>Wed, 23 Jul 2008 21:50:45 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
		<item>
		<title>By: Naz</title>
		<link>http://www.ytechie.com/2008/05/creating-user-friendly-strings-for-enum-values.html#comment-436</link>
		<dc:creator>Naz</dc:creator>
		<pubDate>Tue, 03 Jun 2008 16:38:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.ytechie.com/2008/05/creating-user-friendly-strings-for-enum-values.html#comment-436</guid>
		<description>I've done this using extension methods you can check it out here.

http://www.objectreference.net/post/enum-to-friendly-string-extension-method.aspx</description>
		<content:encoded><![CDATA[<p>I&#8217;ve done this using extension methods you can check it out here.</p>
<p><a href="http://www.objectreference.net/post/enum-to-friendly-string-extension-method.aspx" rel="nofollow" onclick="pageTracker._trackPageview('/outgoing/www.objectreference.net/post/enum-to-friendly-string-extension-method.aspx?referer=');">http://www.objectreference.net/post/enum-to-friendly-string-extension-method.aspx</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Your Teacher</title>
		<link>http://www.ytechie.com/2008/05/creating-user-friendly-strings-for-enum-values.html#comment-195</link>
		<dc:creator>Your Teacher</dc:creator>
		<pubDate>Fri, 02 May 2008 20:20:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.ytechie.com/2008/05/creating-user-friendly-strings-for-enum-values.html#comment-195</guid>
		<description>&#62; I think logically.

Oh LOL, this entry is making me laugh my socks off.

Go on Son, reflect the mirror..</description>
		<content:encoded><![CDATA[<p>&gt; I think logically.</p>
<p>Oh LOL, this entry is making me laugh my socks off.</p>
<p>Go on Son, reflect the mirror..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff</title>
		<link>http://www.ytechie.com/2008/05/creating-user-friendly-strings-for-enum-values.html#comment-192</link>
		<dc:creator>Jeff</dc:creator>
		<pubDate>Fri, 02 May 2008 16:34:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.ytechie.com/2008/05/creating-user-friendly-strings-for-enum-values.html#comment-192</guid>
		<description>An atttibute similar to this exists in the framework: System.Xml.Serialization.XmlEnumAttribute.  To use it, it's almost the same as your suggestion:

[System.SerializableAttribute()]
public enum TestEnum 
{
   value1,

   [System.Xml.Serialization.XmlEnumAttribute("hi")]
   value2
}


Then in code:

        public static string ToStringUsingXmlEnumAttribute( Enum value )
        {
            if ( value == null ) throw new ArgumentNullException( "value" );

            XmlEnumAttribute[ ] attribs = (XmlEnumAttribute[ ])value.GetType( ).GetField( value.ToString( ) ).GetCustomAttributes( typeof( XmlEnumAttribute ), true );

            return ( attribs.Length &#62; 0 ) ? attribs[ 0 ].Name : value.ToString( );
        }</description>
		<content:encoded><![CDATA[<p>An atttibute similar to this exists in the framework: System.Xml.Serialization.XmlEnumAttribute.  To use it, it&#8217;s almost the same as your suggestion:</p>
<p>[System.SerializableAttribute()]<br />
public enum TestEnum<br />
{<br />
   value1,</p>
<p>   [System.Xml.Serialization.XmlEnumAttribute("hi")]<br />
   value2<br />
}</p>
<p>Then in code:</p>
<p>        public static string ToStringUsingXmlEnumAttribute( Enum value )<br />
        {<br />
            if ( value == null ) throw new ArgumentNullException( &#8220;value&#8221; );</p>
<p>            XmlEnumAttribute[ ] attribs = (XmlEnumAttribute[ ])value.GetType( ).GetField( value.ToString( ) ).GetCustomAttributes( typeof( XmlEnumAttribute ), true );</p>
<p>            return ( attribs.Length &gt; 0 ) ? attribs[ 0 ].Name : value.ToString( );<br />
        }</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tim</title>
		<link>http://www.ytechie.com/2008/05/creating-user-friendly-strings-for-enum-values.html#comment-191</link>
		<dc:creator>Tim</dc:creator>
		<pubDate>Fri, 02 May 2008 15:24:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.ytechie.com/2008/05/creating-user-friendly-strings-for-enum-values.html#comment-191</guid>
		<description>Or use pseudo enums:
http://www.codeproject.com/KB/cs/DescriptiveEnum.aspx</description>
		<content:encoded><![CDATA[<p>Or use pseudo enums:<br />
<a href="http://www.codeproject.com/KB/cs/DescriptiveEnum.aspx" rel="nofollow" onclick="pageTracker._trackPageview('/outgoing/www.codeproject.com/KB/cs/DescriptiveEnum.aspx?referer=');">http://www.codeproject.com/KB/cs/DescriptiveEnum.aspx</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: superjason</title>
		<link>http://www.ytechie.com/2008/05/creating-user-friendly-strings-for-enum-values.html#comment-189</link>
		<dc:creator>superjason</dc:creator>
		<pubDate>Fri, 02 May 2008 13:40:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.ytechie.com/2008/05/creating-user-friendly-strings-for-enum-values.html#comment-189</guid>
		<description>Lots of great ideas. That's why I love posting stuff like this!</description>
		<content:encoded><![CDATA[<p>Lots of great ideas. That&#8217;s why I love posting stuff like this!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aaron Zalewski</title>
		<link>http://www.ytechie.com/2008/05/creating-user-friendly-strings-for-enum-values.html#comment-186</link>
		<dc:creator>Aaron Zalewski</dc:creator>
		<pubDate>Fri, 02 May 2008 12:32:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.ytechie.com/2008/05/creating-user-friendly-strings-for-enum-values.html#comment-186</guid>
		<description>Good post, I've been using enums most extensively to store the output ColumnNames of returned data.  

RE: formatting
One option might be to use an underscore to seperate "words" and do a simple .Replace("_"," ") when the displayed version of the enum is required.  That way upper/lower case doesn't play into formatting.</description>
		<content:encoded><![CDATA[<p>Good post, I&#8217;ve been using enums most extensively to store the output ColumnNames of returned data.  </p>
<p>RE: formatting<br />
One option might be to use an underscore to seperate &#8220;words&#8221; and do a simple .Replace(&#8221;_&#8221;,&#8221; &#8220;) when the displayed version of the enum is required.  That way upper/lower case doesn&#8217;t play into formatting.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shafqat Ahmed</title>
		<link>http://www.ytechie.com/2008/05/creating-user-friendly-strings-for-enum-values.html#comment-183</link>
		<dc:creator>Shafqat Ahmed</dc:creator>
		<pubDate>Fri, 02 May 2008 08:52:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.ytechie.com/2008/05/creating-user-friendly-strings-for-enum-values.html#comment-183</guid>
		<description>Why go through all the trouble?

Use reflection to populate the list ...
Also for nice Spaced words write a string function that finds the upper case words and adds a space ... like ... "CoolComment" become "Cool Comment". Why add the attributes, another hassle.

Also name your enums in a way that they come as nice words</description>
		<content:encoded><![CDATA[<p>Why go through all the trouble?</p>
<p>Use reflection to populate the list &#8230;<br />
Also for nice Spaced words write a string function that finds the upper case words and adds a space &#8230; like &#8230; &#8220;CoolComment&#8221; become &#8220;Cool Comment&#8221;. Why add the attributes, another hassle.</p>
<p>Also name your enums in a way that they come as nice words</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nathan Baulch</title>
		<link>http://www.ytechie.com/2008/05/creating-user-friendly-strings-for-enum-values.html#comment-178</link>
		<dc:creator>Nathan Baulch</dc:creator>
		<pubDate>Fri, 02 May 2008 00:22:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.ytechie.com/2008/05/creating-user-friendly-strings-for-enum-values.html#comment-178</guid>
		<description>Or even better, use a TypeConverter so that it transparently works with databinding:
http://www.codeproject.com/KB/dotnet/DotNetEnumsNextLevel.aspx?msg=1604037#xx1604037xx</description>
		<content:encoded><![CDATA[<p>Or even better, use a TypeConverter so that it transparently works with databinding:<br />
<a href="http://www.codeproject.com/KB/dotnet/DotNetEnumsNextLevel.aspx?msg=1604037#xx1604037xx" rel="nofollow" onclick="pageTracker._trackPageview('/outgoing/www.codeproject.com/KB/dotnet/DotNetEnumsNextLevel.aspx?msg=1604037_xx1604037xx&amp;referer=');">http://www.codeproject.com/KB/dotnet/DotNetEnumsNextLevel.aspx?msg=1604037#xx1604037xx</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eber Irigoyen</title>
		<link>http://www.ytechie.com/2008/05/creating-user-friendly-strings-for-enum-values.html#comment-177</link>
		<dc:creator>Eber Irigoyen</dc:creator>
		<pubDate>Thu, 01 May 2008 23:12:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.ytechie.com/2008/05/creating-user-friendly-strings-for-enum-values.html#comment-177</guid>
		<description>I prefere the much simpler approach of storing the strings in the resources, which solves localization at the same time</description>
		<content:encoded><![CDATA[<p>I prefere the much simpler approach of storing the strings in the resources, which solves localization at the same time</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dan Rigsby</title>
		<link>http://www.ytechie.com/2008/05/creating-user-friendly-strings-for-enum-values.html#comment-175</link>
		<dc:creator>Dan Rigsby</dc:creator>
		<pubDate>Thu, 01 May 2008 15:36:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.ytechie.com/2008/05/creating-user-friendly-strings-for-enum-values.html#comment-175</guid>
		<description>What about localizing these strings? Names are usually best kept in resource files for these reasons.  What might be better is to add a value for a key in a resource file as well the default name value you have defined.  If there is no resource file or no item for that key, then it can display the default name.</description>
		<content:encoded><![CDATA[<p>What about localizing these strings? Names are usually best kept in resource files for these reasons.  What might be better is to add a value for a key in a resource file as well the default name value you have defined.  If there is no resource file or no item for that key, then it can display the default name.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
