<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Tech &#8211; Gigpeppers</title>
	<atom:link href="https://www.gigpeppers.com/tag/tech/feed" rel="self" type="application/rss+xml" />
	<link>https://www.gigpeppers.com</link>
	<description>Just another WordPress site</description>
	<lastBuildDate>Fri, 03 Aug 2018 19:20:10 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.3</generator>
	<item>
		<title>Targeted Ad’s</title>
		<link>https://www.gigpeppers.com/targeted-ads/</link>
					<comments>https://www.gigpeppers.com/targeted-ads/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Mon, 13 Oct 2008 04:57:03 +0000</pubDate>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Tech]]></category>
		<guid isPermaLink="false">https://www.gigpeppers.com/blog/?p=31</guid>

					<description><![CDATA[Google sure knows the guys who read Slashdot!]]></description>
										<content:encoded><![CDATA[<p>Google sure knows the guys who read Slashdot!</p>
<p><a href="http://assets.gigpeppers.com/TargetedAds_E5B/Slashdotad1.jpg"><img fetchpriority="high" decoding="async" style="display: inline; border: 0px;" title="Slashdotad1" src="http://assets.gigpeppers.com/TargetedAds_E5B/Slashdotad1_thumb.jpg" alt="Slashdotad1" width="499" height="398" border="0" /></a></p>
<div class="wlWriterHeaderFooter" style="text-align: right; margin: 0px; padding: 4px 0px 4px 0px;"></div>
]]></content:encoded>
					
					<wfw:commentRss>https://www.gigpeppers.com/targeted-ads/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Enum with attributes</title>
		<link>https://www.gigpeppers.com/enum-attributes/</link>
					<comments>https://www.gigpeppers.com/enum-attributes/#comments</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sun, 06 Jul 2008 19:08:00 +0000</pubDate>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[C#]]></category>
		<guid isPermaLink="false">https://www.gigpeppers.com/blog/?p=3</guid>

					<description><![CDATA[Recently I came across an implementation where enum is converted to string and vice versa (http://blogs.msdn.com/tims/archive/2004/04/02/106310.aspx ). The disadvantage here is that, say you want get the string for something like this “Not available”. enum Status { Not_Available, Available_For_Game, Available_For_Discussion } The string conversion here for the first one would yield Not_Available. This is not [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Recently I came across an implementation where enum is converted to string and vice versa (<a href="http://blogs.msdn.com/tims/archive/2004/04/02/106310.aspx">http://blogs.msdn.com/tims/archive/2004/04/02/106310.aspx</a> ). The disadvantage here is that, say you want get the string for something like this “Not available”.</p>
<div style="font-size: 8pt; margin: 20px 0px 10px; overflow: auto; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border: gray 1px solid; padding: 4px;">
<div style="font-size: 8pt; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;">
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: white; border-style: none; padding: 0px;"><span style="color: #0000ff;">enum</span> Status {</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;">  Not_Available,</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: white; border-style: none; padding: 0px;">  Available_For_Game,</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;">  Available_For_Discussion</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: white; border-style: none; padding: 0px;">}</pre>
</div>
</div>
<p>The string conversion here for the first one would yield Not_Available. This is not desirable in some cases where you don’t want the “_”. A better implementation would be to create attributes to this enum and then extract this.</p>
<div style="font-size: 8pt; margin: 20px 0px 10px; overflow: auto; width: 97.75%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; height: 236px; background-color: #f4f4f4; border: gray 1px solid; padding: 4px;">
<div style="font-size: 8pt; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;">
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: white; border-style: none; padding: 0px;"></pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;">  <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">enum</span> Status {</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: white; border-style: none; padding: 0px;">    [Status(Description = <span style="color: #006080;">"Not Available"</span>)]</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;">    Not_Available = 1,</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: white; border-style: none; padding: 0px;">    [Status(Description = <span style="color: #006080;">"Available For Game"</span>)]</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;">    Available_For_Game = 2,</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: white; border-style: none; padding: 0px;">    [Status(Description = <span style="color: #006080;">"Available For Discussion"</span>)]</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;">    Available_For_Discussion = 3,</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: white; border-style: none; padding: 0px;">  }</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;">  <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span> StatusEnumInfo {</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: white; border-style: none; padding: 0px;">    <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">static</span> StatusAttribute[] edesc;</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;">    <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> String GetDescription(<span style="color: #0000ff;">object</span> e)</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: white; border-style: none; padding: 0px;">    {</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;">      System.Reflection.FieldInfo f = e.GetType().GetField(e.ToString());</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: white; border-style: none; padding: 0px;">      StatusEnumInfo.edesc = f.GetCustomAttributes(<span style="color: #0000ff;">typeof</span>(StatusAttribute), <span style="color: #0000ff;">false</span>) <span style="color: #0000ff;">as</span> StatusAttribute[];</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;">      <span style="color: #0000ff;">if</span> (StatusEnumInfo.edesc != <span style="color: #0000ff;">null</span> &amp;&amp; StatusEnumInfo.edesc.Length == 1)</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: white; border-style: none; padding: 0px;">        <span style="color: #0000ff;">return</span> StatusEnumInfo.edesc[0].Description;</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;">      <span style="color: #0000ff;">else</span></pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: white; border-style: none; padding: 0px;">        <span style="color: #0000ff;">return</span> String.Empty;</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;">    }</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: white; border-style: none; padding: 0px;">    <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">object</span> GetEnumFromDesc(Type t, <span style="color: #0000ff;">string</span> desc)</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;">    {</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: white; border-style: none; padding: 0px;">      Array x = Enum.GetValues(t);</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;">      <span style="color: #0000ff;">foreach</span> (<span style="color: #0000ff;">object</span> o <span style="color: #0000ff;">in</span> x) {</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: white; border-style: none; padding: 0px;">        <span style="color: #0000ff;">if</span> (GetDescription(o).Equals(desc)) {</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;">          <span style="color: #0000ff;">return</span> o;</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: white; border-style: none; padding: 0px;">        }</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;">      } <span style="color: #0000ff;">return</span> String.Empty;</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: white; border-style: none; padding: 0px;">    }</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;">  }</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: white; border-style: none; padding: 0px;">  <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span> StatusAttribute : Attribute {</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;">    <span style="color: #0000ff;">public</span> String Description { get; set; }</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: white; border-style: none; padding: 0px;">  }</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;"></pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: white; border-style: none; padding: 0px;">  <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span> Implemenation {</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;">    <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> Run()</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: white; border-style: none; padding: 0px;">    {</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;">      Status statusEnum = (Status)StatusEnumInfo.GetEnumFromDesc(<span style="color: #0000ff;">typeof</span>(Status), <span style="color: #006080;">"Not Available"</span>);</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: white; border-style: none; padding: 0px;">      String statusString = StatusEnumInfo.GetDescription(Status.Available_For_Discussion);</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4; border-style: none; padding: 0px;">    }</pre>
<pre style="font-size: 8pt; margin: 0em; overflow: visible; width: 100%; color: black; line-height: 12pt; font-family: consolas, 'Courier New', courier, monospace; background-color: white; border-style: none; padding: 0px;">  }</pre>
</div>
</div>
<p>You are of course free to generalize this. Correct me if this is not a correct implementation.</p>
<div class="wlWriterHeaderFooter" style="text-align: right; margin: 0px; padding: 4px 0px 4px 0px;"></div>
]]></content:encoded>
					
					<wfw:commentRss>https://www.gigpeppers.com/enum-attributes/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
	</channel>
</rss>
