<?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: 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>
	<lastBuildDate>Fri, 03 Feb 2012 08:52:23 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Rashid</title>
		<link>http://www.ytechie.com/2008/05/creating-user-friendly-strings-for-enum-values.html/comment-page-1#comment-1895</link>
		<dc:creator>Rashid</dc:creator>
		<pubDate>Tue, 23 Aug 2011 09:05:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.ytechie.com/2008/05/creating-user-friendly-strings-for-enum-values.html#comment-1895</guid>
		<description>As an assembly language programmer I went for the simplest solution -- a table, which to our kind often means array.

String arrays indexed into with the enumvalue gives you the description of the value.
It&#039;s trivial to add to it. If you wanted to you could write it as a simple function or something. either way your program code size will increase as some constant + the number of enum entries you have.

k + n

space complexity is thus linear space: k + n = O(k + n) = O(n) 
time complexity for a lookup is constant time: O(1)

but hey, that&#039;s just me. We don&#039;t get fancy for each statements and dictionaries and all that hat on the bare metal of microprocessors and microcontrollers. Heck, you gotta even specify what address in memory to store your crap at. So this was my gut instinct here.

I&#039;d like to hear one good reason not to use it for high-level programming.</description>
		<content:encoded><![CDATA[<p>As an assembly language programmer I went for the simplest solution &#8212; a table, which to our kind often means array.</p>
<p>String arrays indexed into with the enumvalue gives you the description of the value.<br />
It&#8217;s trivial to add to it. If you wanted to you could write it as a simple function or something. either way your program code size will increase as some constant + the number of enum entries you have.</p>
<p>k + n</p>
<p>space complexity is thus linear space: k + n = O(k + n) = O(n)<br />
time complexity for a lookup is constant time: O(1)</p>
<p>but hey, that&#8217;s just me. We don&#8217;t get fancy for each statements and dictionaries and all that hat on the bare metal of microprocessors and microcontrollers. Heck, you gotta even specify what address in memory to store your crap at. So this was my gut instinct here.</p>
<p>I&#8217;d like to hear one good reason not to use it for high-level programming.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Norma Rivie</title>
		<link>http://www.ytechie.com/2008/05/creating-user-friendly-strings-for-enum-values.html/comment-page-1#comment-1797</link>
		<dc:creator>Norma Rivie</dc:creator>
		<pubDate>Fri, 19 Nov 2010 08:25:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.ytechie.com/2008/05/creating-user-friendly-strings-for-enum-values.html#comment-1797</guid>
		<description>Greetings I recently finished reading through through your blog and also I’m very impressed. I really do have a couple concerns for you personally however. Think you’re thinking about doing a follow-up posting about this? Will you be going to keep bringing up-to-date also?</description>
		<content:encoded><![CDATA[<p>Greetings I recently finished reading through through your blog and also I’m very impressed. I really do have a couple concerns for you personally however. Think you’re thinking about doing a follow-up posting about this? Will you be going to keep bringing up-to-date also?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Naz</title>
		<link>http://www.ytechie.com/2008/05/creating-user-friendly-strings-for-enum-values.html/comment-page-1#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&#039;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-page-1#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>&gt; 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-page-1#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&#039;s almost the same as your suggestion:

[System.SerializableAttribute()]
public enum TestEnum 
{
   value1,

   [System.Xml.Serialization.XmlEnumAttribute(&quot;hi&quot;)]
   value2
}


Then in code:

        public static string ToStringUsingXmlEnumAttribute( Enum value )
        {
            if ( value == null ) throw new ArgumentNullException( &quot;value&quot; );

            XmlEnumAttribute[ ] attribs = (XmlEnumAttribute[ ])value.GetType( ).GetField( value.ToString( ) ).GetCustomAttributes( typeof( XmlEnumAttribute ), true );

            return ( attribs.Length &gt; 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-page-1#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-page-1#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&#039;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-page-1#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&#039;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 &quot;words&quot; and do a simple .Replace(&quot;_&quot;,&quot; &quot;) when the displayed version of the enum is required.  That way upper/lower case doesn&#039;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(&#8220;_&#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-page-1#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 ... &quot;CoolComment&quot; become &quot;Cool Comment&quot;. 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-page-1#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>
</channel>
</rss>

