<?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>Scott Elkin &#187; C#</title> <atom:link href="http://scottelkin.com/category/programming/csharp/feed/" rel="self" type="application/rss+xml" /><link>http://scottelkin.com</link> <description>Tech, Love, Life</description> <lastBuildDate>Thu, 07 Apr 2011 23:02:52 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <item><title>Add Additional Information to Your Exceptions</title><link>http://scottelkin.com/programming/aspnet-20/add-additional-information-to-your-exceptions/</link> <comments>http://scottelkin.com/programming/aspnet-20/add-additional-information-to-your-exceptions/#comments</comments> <pubDate>Wed, 19 Jul 2006 07:37:00 +0000</pubDate> <dc:creator>Scott</dc:creator> <category><![CDATA[ASP.NET 2.0]]></category> <category><![CDATA[C#]]></category> <category><![CDATA[Enterprise Library]]></category> <category><![CDATA[Exceptions]]></category> <category><![CDATA[Programming]]></category><guid isPermaLink="false">/archive/2006/07/19/Add-Additional-Information-to-Your-Exceptions.aspx</guid> <description><![CDATA[When Enterprise Library was called Microsoft Application Blocks, if you wanted to log an Exception, you would write (assuming &#8220;ex&#8221; is an Exception): ExceptionManager.Publish(ex) And if you wanted to log some extended properties you could do something like this: NameValueCollection customerInfo = new NameValueCollection(); customerInfo.Add("name","scott"); customerInfo.Add("email","blah@blah.com"); ExceptionManager.Publish(ex,customerInfo); Now that I am upgrading all legacy code [...]No related posts.]]></description> <content:encoded><![CDATA[<p>When Enterprise Library was called Microsoft Application Blocks, if you wanted to log an Exception, you would write (assuming &#8220;ex&#8221; is an Exception):</p><pre><code>ExceptionManager.Publish(ex)</code></pre><p>And if you wanted to log some extended properties you could do something like this:</p><pre><code>NameValueCollection customerInfo = new NameValueCollection();
customerInfo.Add("name","scott");
customerInfo.Add("email","blah@blah.com");
ExceptionManager.Publish(ex,customerInfo);
</code></pre><p>Now that I am upgrading all legacy code to Enterprise Library 2006 for .NET 2.0, I couldn’t find a way to do this since the only way to log an error is:</p><pre><code>ExceptionPolicy.HandleException(ex, "General Policy");
</code></pre><p>where “General Policy” is the name of the Exception Policy in the config file telling the Block what to do with the exception.</p><p>Looking in the config file, I noticed a formatter template with the following at the tail end of the template attribute, “…Extended Properties: {dictionary({key} &#8211; {value} )}&#8221;.  The formatter template is used to format the exception that is about to be logged somewhere.  Looking through the code for where it loops through this Dictionary, I noticed it accessing an IDictionary of <a href="http://msdn2.microsoft.com/en-us/library/system.exception.data.aspx">Exception.Data</a>.  Exception.Data?  Where did that come from?</p><p>Data is a new .NET framework 2.0 property of the Exception class to allow you to add any user-defined information about the exception.  Nothing more to it:  Just a simple name/value dictionary for your enjoyment.  As if you couldn’t figure it out, my new code would look like:</p><pre><code>ex.Data.Add("name","scott");
ex.Data.Add("email","blah@blah.com");
ExceptionPolicy.HandleException(ex, "General Policy");</code></pre><p>And as long as you use the default formatter, it will log this data at the end of the FormattedException field.</p><p>No related posts.</p>]]></content:encoded> <wfw:commentRss>http://scottelkin.com/programming/aspnet-20/add-additional-information-to-your-exceptions/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Fun with #region</title><link>http://scottelkin.com/programming/csharp/fun-with-region/</link> <comments>http://scottelkin.com/programming/csharp/fun-with-region/#comments</comments> <pubDate>Sat, 14 May 2005 00:51:00 +0000</pubDate> <dc:creator>Scott</dc:creator> <category><![CDATA[C#]]></category> <category><![CDATA[Programming]]></category><guid isPermaLink="false">/archive/2005/05/13/Fun-with-_2300_region.aspx</guid> <description><![CDATA[I am not sure if I did this on accident, or my intern did it, but I found this in my code: #region Constructors //code here #endregion Constructors I was not aware you can put a tag after #endregion. Kind of nice to clearly delineate long regions. Not that it really matters, but Visual Studio [...]No related posts.]]></description> <content:encoded><![CDATA[<p>I am not sure if I did this on accident, or my intern did it, but I found this in my code:</p><pre>#region Constructors

//code here

#endregion Constructors
</pre><p>I was not aware you can put a tag after #endregion.  Kind of nice to clearly delineate long regions.  Not that it really matters, but Visual Studio allows you to put whatever text you want after #endregion, even if it doesn&#39;t match the #region label.</p><p>No related posts.</p>]]></content:encoded> <wfw:commentRss>http://scottelkin.com/programming/csharp/fun-with-region/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Learning C# over VB.NET</title><link>http://scottelkin.com/programming/csharp/learning-c-over-vbnet/</link> <comments>http://scottelkin.com/programming/csharp/learning-c-over-vbnet/#comments</comments> <pubDate>Wed, 11 May 2005 23:47:00 +0000</pubDate> <dc:creator>Scott</dc:creator> <category><![CDATA[C#]]></category> <category><![CDATA[Programming]]></category><guid isPermaLink="false">/archive/2005/05/11/Learning-C_2300_-over-VB.NET.aspx</guid> <description><![CDATA[I just finished writing a long &#39;ol email to a friend who wants to do a project in VB.NET since his background is in legacy ASP. Although my points have been illustrated by many over and over, I thought I would post what I wrote in the hopes others can add to my list. I [...]No related posts.]]></description> <content:encoded><![CDATA[<p>I just finished writing a long &#39;ol email to a friend who wants to do a project in VB.NET since his background is in legacy ASP.  Although my points have been illustrated by many over and over, I thought I would post what I wrote in the hopes others can add to my list.</p><ol><li>I realize you feel it will be easier for you, but that is only marginally true.  What takes time is learning the .NET Framework classes (which were all written in C#, BTW), not the language syntax.  For example if you want to get a substring in a string, how would you do it?  I doubt you already know that it is:<pre>//C#string blah = "chad is raicheck";

blah = blah.Substring(0, 15);

&#39;VBDim blah as String = "chad is raicheck"

blah = blah.Substring(0,15)
</pre><p>Either way, you won&#39;t know how to do it off the bat.  Like I said, this is not a VB vs. C# thing.  The code is almost identical.</p></li><li>Since you don&#39;t know either, it is the same learning curve either way.  Believe me, I have had to learn both, and there is MUCH more support from websites, magazines, samples, books, etc with the C# community.  Plus I have done pretty much everything in C# and can help you greatly.</li><li>The code isn&#39;t THAT different once you know the basics.<pre>Private m_user As User 	&#39;VBprivate User m_user;	//C#

&#39;VBPublic ReadOnly Property TotalPosted() As Integer        Get            Return m_totalPosted        End GetEnd Property

//C#public integer TotalPosted{	get	{		return m_totalPosted;	}}
</pre><p>VB is also much more verbose&hellip;look how many more words in VB <img src='http://scottelkin.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> .  And you can make C# even more compact:</p><pre>//C#public integer TotalPosted{	get { 	return m_totalPosted; }}
</pre></li><li>For the last 4 years I have been adding to my code library and it is ALL C#.  That means that even though we are writing our stuff in VB, I will have to spend 3x my time re-writing my website stuff that have already been working and tested.</li><li>I am not going to rewrite my code library of thousands of line of C# code.  .NET allows us to reference C# dlls from VB, so you will still be accessing C# and most likely having to read C# from my code.  In fact, our website solution will have about 3 &#8211; 5 projects in it.  Our website would be in VB, but then there are common functions classes which is already done in C#, the Data Access Classes that is already in C#, other Microsoft&#39;s Data Access Library that everyone uses which Microsoft wrote in C#, Microsoft Enterprise Library&#39;s and Exception Handling all in C# (also written by Microsoft).  So no matter what, if you are debugging, you WILL be tracing through C# code.</li><li>Like I mentioned above, it will take me probably 3x longer to do my job, since I will have to write so much from scratch.  That is the equivalent of paying me 3x my regular hourly wage to do C# <img src='http://scottelkin.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> .</li><li>It actually will be pretty easy to learn either language since you get to read and see all my code working with my comments of what is happening.  I hired a brand new intern who didn&rsquo;t know C# and I HEAVILY commented things and he caught on really fast.</li><li>All my templates that I spent several days writing spits out C# code.  I would have to re-write that for VB.  In the long run it will still save us time, but it is an added expense.</li><li>I said this on the phone, but there are things you just can&#39;t yet do in VB that you can in C#. Examples are this:<pre>//C# this return an object Scott.  This way I can call it by Test.Scott and it returns a "Scott" objectClass Test {	public Scott Scott	{		get		{			return m_scott;		}	}}

&#39;VB - cant do it, must rename the object so they arent the same name.  Now Test.Scott returns an object "ScottObject"Class Test

	Public ReadOnly Property Scott as ScottObject			Get            		Return m_scott        	End Get	End Function

End Class
</pre></li><li>THE BIGGEST REASON:  I use many tools to help with coding such as: GhostDoc to help with documentation, Jetbrains ReSharper for code support which add HUGE productivity gains.  Many of these only work with C#.  To not work with ReSharper is like me telling you to not write code with Intellisense.  It is that crappy.</li><li>There is no XML comments in VB.  This is pretty crappy.  There are ways to go around it, but none are super perfect.</li><li>There are cool things like incrementing shorthand you cant do in VB:<pre>//C#int i = 0

i++;  //adds 1 to i

&#39;VBDim i as Integer = 0

i = i + 1
</pre></li></ol><p>No related posts.</p>]]></content:encoded> <wfw:commentRss>http://scottelkin.com/programming/csharp/learning-c-over-vbnet/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>Hiding a Row in ASP.NET</title><link>http://scottelkin.com/programming/csharp/hiding-a-row-in-aspnet/</link> <comments>http://scottelkin.com/programming/csharp/hiding-a-row-in-aspnet/#comments</comments> <pubDate>Thu, 14 Apr 2005 23:39:00 +0000</pubDate> <dc:creator>Scott</dc:creator> <category><![CDATA[C#]]></category> <category><![CDATA[Programming]]></category><guid isPermaLink="false">/archive/2005/04/14/Hiding-a-Row-in-ASP.NET.aspx</guid> <description><![CDATA[Many things that I come across are &#8220;No Duh&#8221;. This is one of them. I frequently see code from other programmers that incorrectly use Panel for the purpose of hiding content. What they don&#8217;t understand is that a Panel tag renders a table, and as such can&#8217;t be used around Table Rows. For instance, this: [...]No related posts.]]></description> <content:encoded><![CDATA[<p>Many things that I come across are &#8220;No Duh&#8221;. This is one of them.</p><p>I frequently see code from other programmers that incorrectly use Panel for<br /> the purpose of hiding content. What they don&#8217;t understand is that a Panel tag<br /> renders a table, and as such can&#8217;t be used around Table Rows. For instance,<br /> this:</p><pre><code>  1 &lt;asp:panel id="test" visible="True" runat="server"&gt;
  2    Ewoks aren't mini-wookies.
  3 &lt;/asp:panel&gt; </code></pre><p>will render as:</p><pre><code>  1 &lt;table id="test" cellpadding="0" cellspacing="0" border="0" width="100%"&gt;&lt;tr&gt;&lt;td&gt;
  2   Ewoks aren't mini-wookies.
  3 &lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</code></pre><p>So<br /> that means you can&#8217;t do something like:</p><pre><code>  1 &lt;tr&gt;
  2 	&lt;th&gt;name:&lt;/th&gt;
  3 	&lt;td&gt;something...&lt;/td&gt;
  4 &lt;/tr&gt;
  5 &lt;asp:Panel ID="test" Runat="server" Visible="True"&gt;
  6 	&lt;tr&gt;
  7 		&lt;th&gt;date of birth:&lt;/th&gt;
  8 		&lt;td&gt;something...&lt;/td&gt;
  9 	&lt;/tr&gt;
 10 &lt;/asp:Panel&gt;
 11 &lt;tr&gt;
 12 	&lt;th&gt;email:&lt;/th&gt;
 13 	&lt;td&gt;something...&lt;/td&gt;
 14 &lt;/tr&gt;</code></pre><p>To do so will create a table between two rows. The reason this has gone<br /> unnoticed by many developers is that they are developing for Internet Explorer<br /> exclusively, which will forgive some of these mistakes. Firefox shows them clear<br /> as day.</p><p>I was thinking about a solution this morning, wondering if I would have to<br /> create my own Panel control which renders no table, but thought I would try the<br /> obvious first. Could I just do this?:</p><pre><code>  1 &lt;tr&gt;
  2 	&lt;th&gt;name:&lt;/th&gt;
  3 	&lt;td&gt;something...&lt;/td&gt;
  4 &lt;/tr&gt;
  5 &lt;tr id="Tr1" runat="server"&gt;
  6 	&lt;th&gt;date of birth:&lt;/th&gt;
  7 	&lt;td&gt;something...&lt;/td&gt;
  8 &lt;/tr&gt;
  9 &lt;tr&gt;
 10 	&lt;th&gt;email:&lt;/th&gt;
 11 	&lt;td&gt;something...&lt;/td&gt;
 12 &lt;/tr&gt;</code></pre><p>And then use the following in the code behind?:</p><pre><code>  1 protected HtmlControls.HtmlTableRow Tr1;
  2
  3 private void Page_Load(object sender, EventArgs e)
  4 {
  5    Tr1.Visible = false;
  6 }</code></pre><p>Sure enough it hid the row!</p><p>No related posts.</p>]]></content:encoded> <wfw:commentRss>http://scottelkin.com/programming/csharp/hiding-a-row-in-aspnet/feed/</wfw:commentRss> <slash:comments>15</slash:comments> </item> <item><title>ReSharper Help and Tutorial</title><link>http://scottelkin.com/programming/csharp/resharper-help-and-tutorial/</link> <comments>http://scottelkin.com/programming/csharp/resharper-help-and-tutorial/#comments</comments> <pubDate>Fri, 08 Apr 2005 21:03:00 +0000</pubDate> <dc:creator>Scott</dc:creator> <category><![CDATA[C#]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[Resharper]]></category><guid isPermaLink="false">/archive/2005/04/08/ReSharper-Help-and-Tutorial.aspx</guid> <description><![CDATA[I have found that for me, ReSharper wasn&#39;t even close to as great a help until I changed my operating basis regarding how I write code. Many times there are many subtle things you do differently, which just causes pain with ReSharper. It also wasn&#39;t easy for me to find and remember all the key [...]No related posts.]]></description> <content:encoded><![CDATA[<p>I have found that for me, <a href="http://www.jetbrains.com/resharper/" target="_blank" title="http://www.jetbrains.com/resharper/">ReSharper</a> wasn&#39;t even close to as great a help until I changed my operating basis regarding how I write code. Many times there are many subtle things you do differently, which just causes pain with ReSharper. It also wasn&#39;t easy for me to find and remember all the key combinations. To this day when I can&#39;t remember, I just open the Tips it gives during start up and just cycle through them until I find the one I am looking for. (Definately not expeditious since they have a cool PDF <a href="http://www.jetbrains.com/resharper/documentation/1.5_ReferenceCard.pdf" target="_blank" title="http://www.jetbrains.com/resharper/documentation/1.5_ReferenceCard.pdf">reference card</a> now).</p><p>So I thought I would write up a quick tutorial on the functions I use most and give some help to those that may not of discovered them or found them not to be as useful.</p><p><strong>Optimize Usings</strong></p><p>Before:</p><p><img src="http://www.scottelkin.com/images/resharper1.jpg" border="0" alt="" title="http://www.scottelkin.com/images/resharper1.jpg" /></p><p>It highlights in gray any using&#39;s that aren&#39;t being used.</p><p>After:</p><p><img src="http://www.scottelkin.com/images/resharper2.jpg" border="0" alt="" title="http://www.scottelkin.com/images/resharper2.jpg" /></p><p>I love de-cluttering and absolutely hate how I find other peoples code declarations (especially in ASP.NET after the designer adds a bunch of stuff you don&#39;t reference in the code behind).</p><p><strong>Surround With</strong></p><p>This is the problem that had me shaking me head. When I code, a lot of time I don&#39;t know I need a particular statement until after I write the line of code. It would cause me so much lost time deleting and moving code around. So if I have:</p><pre><font size="2" color="#000000">x</font><font size="2"> = 29;</font>
</pre><p>and then I realize I need an &#8220;if&#8221; surrounding my statement, I would start typing the &#8220;if&#8221; and as soon as I hit the enter key after the line, it would insert the {} after my &#8220;if&#8221;, but BEFORE my code, like:</p><pre><font size="2" color="#0000ff">if</font><font size="2"> (</font><font size="2" color="#000000">x</font><font size="2"> == 0){}</font><font size="2" color="#000000">x</font><font size="2"> = 29;</font>
</pre><p>What I really wanted it to do was:</p><pre><font size="2" color="#0000ff">if</font><font size="2"> (</font><font size="2" color="#000000">x</font><font size="2"> == 0){     </font><font size="2" color="#000000">x</font><font size="2"> = 29;}</font>
</pre><p>This is where the &#8220;Surround With&#8221; feature comes in. Highlight your code (in my case x = 29;), Hit Ctrl+Alt+J, and choose &#8220;if&#8221;. You get:</p><pre><font size="2" color="#0000ff">if</font><font size="2"> (){     </font><font size="2" color="#000000">x</font><font size="2"> = 29;}</font>
</pre><p>and then it puts the cursor between the paranthesis to do your &#8220;x == 0&#8243; check.</p><p>And of course, you can also define your own &#8220;Surround with&#8221; macros. I made a few no brainer ones for conversions:</p><p><img src="http://www.scottelkin.com/images/resharper3.jpg" border="0" alt="" title="http://www.scottelkin.com/images/resharper3.jpg" /></p><p>All I do is highlight the &#8220;29&#8243;, hit Ctrl-Alt-J, hit the &#8220;A&#8221; key and:</p><pre><font size="2" color="#000000">x</font><font size="2"> = </font><font size="2" color="#000000">Convert</font><font size="2">.</font><font size="2" color="#000000">ToInt32</font><font size="2">(29);</font>
</pre><p><p>No related posts.</p>]]></content:encoded> <wfw:commentRss>http://scottelkin.com/programming/csharp/resharper-help-and-tutorial/feed/</wfw:commentRss> <slash:comments>5</slash:comments> </item> <item><title>Binding a DropDownList to an Enumeration</title><link>http://scottelkin.com/aspnet/binding-a-dropdownlist-to-an-enumeration/</link> <comments>http://scottelkin.com/aspnet/binding-a-dropdownlist-to-an-enumeration/#comments</comments> <pubDate>Wed, 18 Aug 2004 08:09:00 +0000</pubDate> <dc:creator>Scott</dc:creator> <category><![CDATA[ASP.NET]]></category> <category><![CDATA[C#]]></category> <category><![CDATA[Programming]]></category><guid isPermaLink="false">/archive/2004/08/18/Binding-a-DropDownList-to-an-Enumeration.aspx</guid> <description><![CDATA[Ok, well its not really binding to it. No related posts.No related posts.]]></description> <content:encoded><![CDATA[<p>Ok, well its not really <em>binding</em> to it.</p><p>No related posts.</p>]]></content:encoded> <wfw:commentRss>http://scottelkin.com/aspnet/binding-a-dropdownlist-to-an-enumeration/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>String to Enum</title><link>http://scottelkin.com/aspnet/string-to-enum/</link> <comments>http://scottelkin.com/aspnet/string-to-enum/#comments</comments> <pubDate>Thu, 15 Jul 2004 16:58:00 +0000</pubDate> <dc:creator>Scott</dc:creator> <category><![CDATA[ASP.NET]]></category> <category><![CDATA[C#]]></category> <category><![CDATA[Programming]]></category><guid isPermaLink="false">/archive/2004/07/15/String-to-Enum.aspx</guid> <description><![CDATA[I have to do this now and then and each time I don&#39;t write this code perfect the first time. No related posts.No related posts.]]></description> <content:encoded><![CDATA[<p>I have to do this now and then and each time I don&#39;t write this code perfect the first time.</p><p>No related posts.</p>]]></content:encoded> <wfw:commentRss>http://scottelkin.com/aspnet/string-to-enum/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (enhanced)

Served from: scottelkin.com @ 2012-02-09 10:03:24 -->
