Content

C# Category

Add Additional Information to Your Exceptions

19 Jul

+ 0

When Enterprise Library was called Microsoft Application Blocks, if you wanted to log an Exception, you would write (assuming “ex” 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 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:

ExceptionPolicy.HandleException(ex, "General Policy");

where “General Policy” is the name of the Exception Policy in the config file telling the Block what to do with the exception.

  Leave Comment, 0 Comments

Fun with #region

14 May

+ 0

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 allows you to put whatever text you want after #endregion, even if it doesn't match the #region label.

  Leave Comment, 0 Comments

Learning C# over VB.NET

11 May

+ 1

I just finished writing a long '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.

  Leave Comment, 1 Comment

Hiding a Row in ASP.NET

14 Apr

+ 15

Many things that I come across are “No Duh”. 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’t understand is that a Panel tag
renders a table, and as such can’t be used around Table Rows. For instance,
this:

  1 <asp:panel id="test" visible="True" runat="server">
  2    Ewoks aren't mini-wookies.
  3 </asp:panel> 

will render as:

  1 <table id="test" cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td>
  2   Ewoks aren't mini-wookies.
  3 </td></tr></table>

So
that means you can’t do something like:

  Leave Comment, 15 Comments

ReSharper Help and Tutorial

8 Apr

+ 5

I have found that for me, ReSharper wasn'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't easy for me to find and remember all the key combinations. To this day when I can'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 reference card now).

  Leave Comment, 5 Comments

Binding a DropDownList to an Enumeration

18 Aug

+ 0

Ok, well its not really binding to it.

  Leave Comment, 0 Comments

String to Enum

15 Jul

+ 0

I have to do this now and then and each time I don't write this code perfect the first time.

  Leave Comment, 0 Comments