<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Dot Net Technologies -- MS Tech talk and more - Design</title>
    <link>http://www.dotnettechnologies.com/</link>
    <description>Creating Solutions with Microsoft's .Net Technologies</description>
    <language>en-us</language>
    <copyright>© Copyright 2010 </copyright>
    <lastBuildDate>Tue, 10 Aug 2010 05:06:51 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.3.9074.18820</generator>
    <managingEditor>daryl@rubiconcomputing.com</managingEditor>
    <webMaster>daryl@rubiconcomputing.com</webMaster>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=7624b40d-72c0-4e7a-aa80-15e9ddbb0009</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,7624b40d-72c0-4e7a-aa80-15e9ddbb0009.aspx</pingback:target>
      <dc:creator>Daryl</dc:creator>
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,7624b40d-72c0-4e7a-aa80-15e9ddbb0009.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=7624b40d-72c0-4e7a-aa80-15e9ddbb0009</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">Today's tip is more than a tip. It's a
full project which contains a sample of a control I call the MessageCenter. When developing
interactive applications, it's important to provide the user convenient feedback in
a consistent location. In my current application I am working on, there are three
types of messages (which are typical for most applications) -- errors, informational
messages, and warnings. 
<br /><br />
I wanted to make sure each one appeared different enough so the user could quickly
determine which ones needed the most attention. There are a lot of ways I could have
accomplished this, such as a class/collection which maintained the type of message,
and each class has it's own CSS for displaying. However, I opted for a siumpler solution
which is available to every ASP.Net page -- The Validators collection (part of the
page object).<br /><br />
The Validators collection maintains a list of objects which implement the IValidator
interface. This collection is automatically bound to the ValidationSummary control
on the page before (for client-side validation) and after a postback. During a postback
for example, you can add a new error to the Page.Validators collection by calling
the Add method, and supply a class which implements the IValidator interface.<br /><br />
In the sample project, I implemented three classes -- ValidationError, ValidationNotification
and ValidationWarning -- to specify my three different types of messages. Each implements
the IValidator interface essentially the same way. I can use the ErrorMessage property
of the interface to display the message I want to convey to the end user.<br /><br />
In my page base class, I implemented members to easily add these messages to the Page.Validators
collection, as shown below:<br /><br /><pre><span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">public</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">void</span> DisplayError(<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">string</span> message)
{ <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">this</span>.Validators.Add(<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">new</span> ValidationError(message));
} <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">public</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">void</span> DisplayError(<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">string</span> message, <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">params</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">string</span>[]
p) { DisplayError(String.Format(message, p)); } <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">public</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">void</span> DisplayMessage(<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">string</span> message)
{ <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">this</span>.Validators.Add(<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">new</span> NotificationValidator(message));
}</span></pre><br />
 Note in some of the methods, I can pass in a list of parameters, so I can format
the message displayed with a variety of details.   
<br /><br />
The MessageCenter.ascx control is where the work is done. When added to a page, it
provides a ValidationSummary control to handle the clientside validation, and a Repeater
which handles the postback messages. With some work, you could integrate the two,
but that is way beyond what I needed.<br /><br />
During the Page_Load event of the MessageCenter control, I bind the Page.Validators
collection to the Repeater. I also remove these from Page.Validators collection afterwards,
as I don't want them displaying in the ValidationSummary control I use for client
validation.<br /><br /><pre><span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">protected</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">void</span> Page_Load(<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">object</span> sender,
EventArgs e) { rptNotification.DataSource <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">this</span>.Page.Validators;
rptNotification.DataBind(); rptNotification.Visible <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> (<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">this</span>.Page.Validators.Count
!<span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> 0); <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">for</span> (<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">int</span> idx <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> (<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">this</span>.Page.Validators.Count <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">-</span> 1);
idx &gt;= 0; idx--) { IValidator val <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">this</span>.Page.Validators[idx]; <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">this</span>.Page.Validators.Remove(val);
} }</span></pre><br /><br />
During the ItemDataBound event of the repeater, I determine the type of IValidator,
and set the appropriate image to the row of data. I bind the IValidator class ErrorMessage
property to the label inside the repeater row as well, and set the appropriate CSS
class so it displays in the color format I like.<br /><br />
        <pre><span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">protected</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">void</span> rptNotification_ItemDataBound(<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">object</span> sender,
RepeaterItemEventArgs e) { <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">try</span> { <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">if</span> ((e.Item.ItemType
== ListItemType.Item) || ((e.Item.ItemType == ListItemType.AlternatingItem))) { IValidator
val <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> Page.Validators[e.Item.ItemIndex];
Image img <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> (Image)e.Item.FindControl(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"imgNotice"</span>); <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">if</span> (img
!<span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">null</span>)
{ <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">if</span> (val <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">is</span> NotificationValidator)
img.ImageUrl <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span><span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"~/images/info.png"</span>; <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">if</span> (val <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">is</span> ValidationError)
img.ImageUrl <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span><span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"~/images/error.png"</span>; <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">if</span> (val <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">is</span> ValidationWarning)
img.ImageUrl <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span><span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"~/images/warning.png"</span>;
} Label lblInfo <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> (Label)e.Item.FindControl(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"lblDetails"</span>); <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">if</span> (lblInfo
!<span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">null</span>)
{ lblInfo.Text <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> val.ErrorMessage; <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">if</span> (val <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">is</span> NotificationValidator)
lblInfo.CssClass <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span><span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"NotificationItem"</span>; <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">if</span> (val <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">is</span> ValidationError)
lblInfo.CssClass <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span><span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"ErrorItem"</span>; <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">if</span> (val <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">is</span> ValidationWarning)
lblInfo.CssClass <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span><span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"WarningItem"</span>;
} } } <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">catch</span> (Exception
ex) { <span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;">//TODO:
Log the error</span> } } } </span></pre><br />
The end result is a control which sits on top of the page (and is only visible when
there are messages to display) and looks like this:<br /><br /><br /><p></p><img src="http://www.dotnettechnologies.com/content/binary/Example.jpg" border="0" /><a href="http://www.dotnettechnologies.com/content/binary/Notification%5B1%5D.zip">Notification[1].zip
(38.27 KB)</a><br /><br />
UPDATE: Had a bug in the original file, so I updated the project (and cleaned out
all the ancillary junk in it as well) and posted it again.<br /><br /><img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=7624b40d-72c0-4e7a-aa80-15e9ddbb0009" /></body>
      <title>Tip of the Day: Creating a control that displays multiple types of messages using the IValidator interface</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,7624b40d-72c0-4e7a-aa80-15e9ddbb0009.aspx</guid>
      <link>http://www.dotnettechnologies.com/2010/08/10/TipOfTheDayCreatingAControlThatDisplaysMultipleTypesOfMessagesUsingTheIValidatorInterface.aspx</link>
      <pubDate>Tue, 10 Aug 2010 05:06:51 GMT</pubDate>
      <description>Today's tip is more than a tip. It's a full project which contains a sample of a control I call the MessageCenter. When developing interactive applications, it's important to provide the user convenient feedback in a consistent location. In my current application I am working on, there are three types of messages (which are typical for most applications) -- errors, informational messages, and warnings. &lt;br&gt;
&lt;br&gt;
I wanted to make sure each one appeared different enough so the user could quickly
determine which ones needed the most attention. There are a lot of ways I could have
accomplished this, such as a class/collection which maintained the type of message,
and each class has it's own CSS for displaying. However, I opted for a siumpler solution
which is available to every ASP.Net page -- The Validators collection (part of the
page object).&lt;br&gt;
&lt;br&gt;
The Validators collection maintains a list of objects which implement the IValidator
interface. This collection is automatically bound to the ValidationSummary control
on the page before (for client-side validation) and after a postback. During a postback
for example, you can add a new error to the Page.Validators collection by calling
the Add method, and supply a class which implements the IValidator interface.&lt;br&gt;
&lt;br&gt;
In the sample project, I implemented three classes -- ValidationError, ValidationNotification
and ValidationWarning -- to specify my three different types of messages. Each implements
the IValidator interface essentially the same way. I can use the ErrorMessage property
of the interface to display the message I want to convey to the end user.&lt;br&gt;
&lt;br&gt;
In my page base class, I implemented members to easily add these messages to the Page.Validators
collection, as shown below:&lt;br&gt;
&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;public&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;void&lt;/span&gt; DisplayError(&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;string&lt;/span&gt; message)
{ &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;this&lt;/span&gt;.Validators.Add(&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;new&lt;/span&gt; ValidationError(message));
} &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;public&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;void&lt;/span&gt; DisplayError(&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;string&lt;/span&gt; message, &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;params&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;string&lt;/span&gt;[]
p) { DisplayError(String.Format(message, p)); } &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;public&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;void&lt;/span&gt; DisplayMessage(&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;string&lt;/span&gt; message)
{ &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;this&lt;/span&gt;.Validators.Add(&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;new&lt;/span&gt; NotificationValidator(message));
}&lt;/span&gt;&lt;/pre&gt;
&lt;br&gt;
&amp;nbsp;Note in some of the methods, I can pass in a list of parameters, so I can format
the message displayed with a variety of details. &amp;nbsp; 
&lt;br&gt;
&lt;br&gt;
The MessageCenter.ascx control is where the work is done. When added to a page, it
provides a ValidationSummary control to handle the clientside validation, and a Repeater
which handles the postback messages. With some work, you could integrate the two,
but that is way beyond what I needed.&lt;br&gt;
&lt;br&gt;
During the Page_Load event of the MessageCenter control, I bind the Page.Validators
collection to the Repeater. I also remove these from Page.Validators collection afterwards,
as I don't want them displaying in the ValidationSummary control I use for client
validation.&lt;br&gt;
&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;protected&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;void&lt;/span&gt; Page_Load(&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;object&lt;/span&gt; sender,
EventArgs e) { rptNotification.DataSource &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;this&lt;/span&gt;.Page.Validators;
rptNotification.DataBind(); rptNotification.Visible &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; (&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;this&lt;/span&gt;.Page.Validators.Count
!&lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; 0); &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;for&lt;/span&gt; (&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;int&lt;/span&gt; idx &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; (&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;this&lt;/span&gt;.Page.Validators.Count &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;-&lt;/span&gt; 1);
idx &amp;gt;= 0; idx--) { IValidator val &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;this&lt;/span&gt;.Page.Validators[idx]; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;this&lt;/span&gt;.Page.Validators.Remove(val);
} }&lt;/span&gt;&lt;/pre&gt;
&lt;br&gt;
&lt;br&gt;
During the ItemDataBound event of the repeater, I determine the type of IValidator,
and set the appropriate image to the row of data. I bind the IValidator class ErrorMessage
property to the label inside the repeater row as well, and set the appropriate CSS
class so it displays in the color format I like.&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;pre&gt;&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;protected&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;void&lt;/span&gt; rptNotification_ItemDataBound(&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;object&lt;/span&gt; sender,
RepeaterItemEventArgs e) { &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;try&lt;/span&gt; { &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;if&lt;/span&gt; ((e.Item.ItemType
== ListItemType.Item) || ((e.Item.ItemType == ListItemType.AlternatingItem))) { IValidator
val &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; Page.Validators[e.Item.ItemIndex];
Image img &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; (Image)e.Item.FindControl(&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"imgNotice"&lt;/span&gt;); &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;if&lt;/span&gt; (img
!&lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;null&lt;/span&gt;)
{ &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;if&lt;/span&gt; (val &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;is&lt;/span&gt; NotificationValidator)
img.ImageUrl &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; &lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"~/images/info.png"&lt;/span&gt;; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;if&lt;/span&gt; (val &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;is&lt;/span&gt; ValidationError)
img.ImageUrl &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; &lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"~/images/error.png"&lt;/span&gt;; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;if&lt;/span&gt; (val &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;is&lt;/span&gt; ValidationWarning)
img.ImageUrl &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; &lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"~/images/warning.png"&lt;/span&gt;;
} Label lblInfo &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; (Label)e.Item.FindControl(&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"lblDetails"&lt;/span&gt;); &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;if&lt;/span&gt; (lblInfo
!&lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;null&lt;/span&gt;)
{ lblInfo.Text &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; val.ErrorMessage; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;if&lt;/span&gt; (val &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;is&lt;/span&gt; NotificationValidator)
lblInfo.CssClass &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; &lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"NotificationItem"&lt;/span&gt;; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;if&lt;/span&gt; (val &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;is&lt;/span&gt; ValidationError)
lblInfo.CssClass &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; &lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"ErrorItem"&lt;/span&gt;; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;if&lt;/span&gt; (val &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;is&lt;/span&gt; ValidationWarning)
lblInfo.CssClass &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; &lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"WarningItem"&lt;/span&gt;;
} } } &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;catch&lt;/span&gt; (Exception
ex) { &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;//TODO:
Log the error&lt;/span&gt; } } } &lt;/span&gt;&lt;/pre&gt;
&lt;br&gt;
The end result is a control which sits on top of the page (and is only visible when
there are messages to display) and looks like this:&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img src="http://www.dotnettechnologies.com/content/binary/Example.jpg" border="0"&gt;&lt;a href="http://www.dotnettechnologies.com/content/binary/Notification%5B1%5D.zip"&gt;Notification[1].zip
(38.27 KB)&lt;/a&gt;
&lt;br&gt;
&lt;br&gt;
UPDATE: Had a bug in the original file, so I updated the project (and cleaned out
all the ancillary junk in it as well) and posted it again.&lt;br&gt;
&lt;br&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=7624b40d-72c0-4e7a-aa80-15e9ddbb0009" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,7624b40d-72c0-4e7a-aa80-15e9ddbb0009.aspx</comments>
      <category>All Things</category>
      <category>ASP.Net</category>
      <category>CSharp</category>
      <category>Design</category>
      <category>General</category>
      <category>Tips and Tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=1aac1456-13df-443f-b660-27c38fd4eb49</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,1aac1456-13df-443f-b660-27c38fd4eb49.aspx</pingback:target>
      <dc:creator>Daryl</dc:creator>
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,1aac1456-13df-443f-b660-27c38fd4eb49.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=1aac1456-13df-443f-b660-27c38fd4eb49</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">I designed a control to filter data dynamically,
and I wanted to be able to be able to use it to filter either SQL Data (via a DataTable)
or a List&lt;T&gt; of objects. Sorting the DataTable dynamically is easy using the
DataTable, as you can create a DataView and perform case insensitive searches like
this:<br /><br /><pre><span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;">DataView
dvData <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">new</span> DataView(data);
dvData.RowFilter <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> “SomeField=’Test’”; </span></pre>You
can also create widcard searches like this:<pre><span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;">DataView
dvData <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">new</span> DataView(data);
dvData.RowFilter <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> “SomeField
LIKE ’Te%’”; </span></pre>But providing that functionality with List&lt;T&gt; and
LINQ was going to be a challenge.  If you know the properties you want to find
in advance, the syntax is easy using Lambda functions:<br /><pre><span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;">List&lt;MyObject&gt;
objectResults <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> MyList.FindAdd(x
=&gt; x.MyProperty.ToLower() == “Value”);</span></pre>That’s well and good, but in
my filter control, I wanted to be able to specify a property by name for a comparison. 
Something like this:<br /><pre><span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;">List&lt;MyObject&gt;
objectResults <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> MyList.FindAdd(x
=&gt; “MyPropertyName” == “Value”);</span></pre>Unfortunately, that’s not going to
work. I needed something that would dynamically specify the property I want to search.
In a <a href="http://www.dotnettechnologies.com/2009/12/30/TipOfTheDayDynamicallySortingAListCollectionUsingLambdaExpression.aspx" target="_blank">previous
post</a> I described how I could use a defined Lambda Expression to dynamically sort
a list in a similar fashion.<br /><br />
So in my first attempt and doing a lot of searching on Google, I came up with this
method:<br /><br /><pre><span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"> public</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">static</span> IEnumerable&lt;T&gt;
DynamicFilter&lt;T&gt;(<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">this</span> IEnumerable&lt;T&gt;
source, <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">string</span> propertyOrFieldName, <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">string</span> searchValue)
{ Func&lt;T, <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">bool</span>&gt;
predicate <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> CreatePredicate&lt;T&gt;(propertyOrFieldName,
searchValue); <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">return</span> source.Where(predicate);
} <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">static</span> Func&lt;T, <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">bool</span>&gt;
CreatePredicate&lt;T&gt;(<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">string</span> propertyOrFieldName, <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">string</span> searchValue)
{ var arg <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> Expression.Parameter(<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">typeof</span>(T), <span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"arg"</span>);
var body <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> Expression.Equal(Expression.Property(arg,
propertyOrFieldName), Expression.Constant(searchValue)); <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">return</span> Expression.Lambda&lt;Func&lt;T, <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">bool</span>&gt;&gt;(body,
arg).Compile(); } </span></pre>Usage:  
<br /><pre><span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;">List&lt;Employee&gt;
emps <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> Employee.LoadListCollection();
List&lt;Employee&gt; empList <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> emps.DynamicFilter(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"FirstName"</span>, <span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"Angie"</span>).ToList(); </span></pre>This
worked great for a case-sensitive search, but I still didn’t have a way to do a case-insensitve
search or a wildcard search. So after some more searching and more trial-and-error,
I came up with this for a wildcard search:<br /><pre><span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">public</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">static</span> IEnumerable&lt;T&gt;
ContainsString&lt;T&gt;(<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">this</span> IEnumerable&lt;T&gt;
data, <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">string</span> propertyOrFieldName, <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">string</span> searchValue)
{ var param <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> Expression.Parameter(<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">typeof</span>(T), <span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"x"</span>);
var body <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> Expression.Call( <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">typeof</span>(BusinessObjectBase).GetMethod(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"Like"</span>,
BindingFlags.Static <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">|</span> BindingFlags.NonPublic <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">|</span> BindingFlags.Public),
Expression.PropertyOrField(param, propertyOrFieldName), Expression.Constant(searchValue, <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">typeof</span>(<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">string</span>)));
var lambda <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> Expression.Lambda&lt;Func&lt;T, <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">bool</span>&gt;&gt;(body,
param); <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">return</span> data.Where(lambda.Compile());
} </span></pre>A couple things to note here. First, I needed  to add a method
“Like” to my base object (BusinessObjectBase in this case) of the collections I am
searching. It looks like this:<br /><pre><span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"><span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;">///
&lt;summary&gt;</span><span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;">///
comparison operator. Needed for dynamically filtering the objects</span><span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;">///
&lt;/summary&gt;</span><span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;">///
&lt;param name="a"&gt;A.&lt;/param&gt;</span><span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;">///
&lt;param name="b"&gt;The b.&lt;/param&gt;</span><span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;">///
&lt;returns&gt;&lt;/returns&gt;</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">static</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">bool</span> Like(<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">string</span> a, <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">string</span> b)
{ <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">return</span> a.ToLower().Contains(b.ToLower());
} </span></pre>Now I can do a search where I specify the property name, and it returns
and value of that property that contains any part of that string (and it is also case-insensitive).<br /><br /><pre><span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;">List&lt;Employee&gt;
emps <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> Employee.LoadListCollection();
List&lt;Employee&gt; empList <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> emps.ContainsString(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"FirstName"</span>, <span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"An"</span>).ToList(); </span></pre>Then
it occurred to me that I was specifying the name of the static routine in the call.
What would happen if I specified the name of the operator dynamically? Would it work
right? 
<br /><pre><span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;">var
body <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> Expression.Call( <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">typeof</span>(BusinessObjectBase).GetMethod(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"Like"</span>,
BindingFlags.Static <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">|</span> BindingFlags.NonPublic <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">|</span> BindingFlags.Public), 
<br /><font size="2" face="Verdana">Became this:</font><br /><br /><pre><span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;">var
body <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> Expression.Call( <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">typeof</span>(BusinessObjectBase).GetMethod(operatorName,
BindingFlags.Static <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">|</span> BindingFlags.NonPublic <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">|</span> BindingFlags.Public), </span></pre><font size="2" face="Verdana">Now
I could create two static operators (or as many as I might ever need) to provide this
dynamic functionality.<br /><br /><pre><span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">public</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">static</span> IEnumerable&lt;T&gt;
RunOperator&lt;T&gt;(<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">this</span> IEnumerable&lt;T&gt;
data, <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">string</span> operatorName, <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">string</span> propertyOrFieldName, <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">string</span> searchValue)
{ var param <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> Expression.Parameter(<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">typeof</span>(T), <span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"x"</span>);
var body <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> Expression.Call( <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">typeof</span>(BusinessObjectBase).GetMethod(operatorName,
BindingFlags.Static <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">|</span> BindingFlags.NonPublic <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">|</span> BindingFlags.Public),
Expression.PropertyOrField(param, propertyOrFieldName), Expression.Constant(searchValue, <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">typeof</span>(<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">string</span>)));
var lambda <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> Expression.Lambda&lt;Func&lt;T, <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">bool</span>&gt;&gt;(body,
param); <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">return</span> data.Where(lambda.Compile());
} </span></pre>In my BusinessObjectBase class, I added the following methods (Like
for wildcard searches, and Equals for a case-insensitive search):<br /><pre><span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">static</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">bool</span> Like(<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">string</span> a, <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">string</span> b)
{ <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">return</span> a.ToLower().Contains(b.ToLower());
} <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">static</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">bool</span> Equals(<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">string</span> a, <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">string</span> b)
{ <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">return</span> a.ToLower()
== b.ToLower(); } </span></pre>I can call both of these methods like this:<br /><pre><span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">public</span> List&lt;T&gt;
FilterData&lt;T&gt;(List&lt;T&gt; data, <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">bool</span> wildcardSearch)
{ List&lt;T&gt; results <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> data; <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">if</span> (wildcardSearch)
results <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> results.RunOperator(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"Like"</span>,
fi.DataField, fi.FilterValue()).ToList(); <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">else</span>     results <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> results.RunOperator(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"Equals"</span>,
fi.DataField, fi.FilterValue()).ToList();     <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">return</span> results;
} </span></pre>So let’s break it down a little. First, the first parameter of a lambda
expression, which is what we are building here, is the input parameter, or in this
case, the x portion of x =&gt;.<br /><pre><span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;">var
param <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> Expression.Parameter(<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">typeof</span>(T), <span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"x"</span>);</span></pre>Next,
we’re setting up the call which is made to the right of the =&gt; of the Lambda expression.
The code below is saying “grab the method name provided by the operatorName variable,
which can be found in any class which implements the BusinessObjectBase class.<br /><br /><pre><span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">typeof</span>(BusinessObjectBase).GetMethod(operatorName,</span></pre><br />
The result of the expression defined above will be returning a boolean, as defined
here:<br /><pre><span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;">var
lambda <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> Expression.Lambda&lt;Func&lt;T, <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">bool</span>&gt;&gt;(body,
param);</span></pre>Finally, we return the data which evaluates in the lambda expression
as true via this line of code:<br /><br /><pre><span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">return</span> data.Where(lambda.Compile());</span></pre>Note
the delegate lambda expression is compiled into executrable code and produces a delegate
which represents the lambda expression.<br />
Obviously, understanding how to dynamically call methods and compare properties using
LINQ is extremely powerful and has many,many possibilities. I hope this helps someone
else trying to do the same thing!<br /><br /></font></span></pre><p></p><img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=1aac1456-13df-443f-b660-27c38fd4eb49" /></body>
      <title>Tip of the Day: The evolution of dynamic, case insensitive LINQ to Object search</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,1aac1456-13df-443f-b660-27c38fd4eb49.aspx</guid>
      <link>http://www.dotnettechnologies.com/2010/08/09/TipOfTheDayTheEvolutionOfDynamicCaseInsensitiveLINQToObjectSearch.aspx</link>
      <pubDate>Mon, 09 Aug 2010 04:34:12 GMT</pubDate>
      <description>I designed a control to filter data dynamically, and I wanted to be able to be able to use it to filter either SQL Data (via a DataTable) or a List&amp;lt;T&amp;gt; of objects. Sorting the DataTable dynamically is easy using the DataTable, as you can create a DataView and perform case insensitive searches like this:&lt;br&gt;
&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;DataView
dvData &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;new&lt;/span&gt; DataView(data);
dvData.RowFilter &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; “SomeField=’Test’”; &lt;/span&gt;&lt;/pre&gt;You
can also create widcard searches like this:&lt;pre&gt;&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;DataView
dvData &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;new&lt;/span&gt; DataView(data);
dvData.RowFilter &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; “SomeField
LIKE ’Te%’”; &lt;/span&gt;&lt;/pre&gt;But providing that functionality with List&amp;lt;T&amp;gt; and
LINQ was going to be a challenge.&amp;nbsp; If you know the properties you want to find
in advance, the syntax is easy using Lambda functions:&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;List&amp;lt;MyObject&amp;gt;
objectResults &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; MyList.FindAdd(x
=&amp;gt; x.MyProperty.ToLower() == “Value”);&lt;/span&gt;&lt;/pre&gt;That’s well and good, but in
my filter control, I wanted to be able to specify a property by name for a comparison.&amp;nbsp;
Something like this:&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;List&amp;lt;MyObject&amp;gt;
objectResults &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; MyList.FindAdd(x
=&amp;gt; “MyPropertyName” == “Value”);&lt;/span&gt;&lt;/pre&gt;Unfortunately, that’s not going to
work. I needed something that would dynamically specify the property I want to search.
In a &lt;a href="http://www.dotnettechnologies.com/2009/12/30/TipOfTheDayDynamicallySortingAListCollectionUsingLambdaExpression.aspx" target="_blank"&gt;previous
post&lt;/a&gt; I described how I could use a defined Lambda Expression to dynamically sort
a list in a similar fashion.&lt;br&gt;
&lt;br&gt;
So in my first attempt and doing a lot of searching on Google, I came up with this
method:&lt;br&gt;
&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt; public&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;static&lt;/span&gt; IEnumerable&amp;lt;T&amp;gt;
DynamicFilter&amp;lt;T&amp;gt;(&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;this&lt;/span&gt; IEnumerable&amp;lt;T&amp;gt;
source, &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;string&lt;/span&gt; propertyOrFieldName, &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;string&lt;/span&gt; searchValue)
{ Func&amp;lt;T, &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;bool&lt;/span&gt;&amp;gt;
predicate &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; CreatePredicate&amp;lt;T&amp;gt;(propertyOrFieldName,
searchValue); &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;return&lt;/span&gt; source.Where(predicate);
} &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;static&lt;/span&gt; Func&amp;lt;T, &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;bool&lt;/span&gt;&amp;gt;
CreatePredicate&amp;lt;T&amp;gt;(&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;string&lt;/span&gt; propertyOrFieldName, &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;string&lt;/span&gt; searchValue)
{ var arg &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; Expression.Parameter(&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;typeof&lt;/span&gt;(T), &lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"arg"&lt;/span&gt;);
var body &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; Expression.Equal(Expression.Property(arg,
propertyOrFieldName), Expression.Constant(searchValue)); &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;return&lt;/span&gt; Expression.Lambda&amp;lt;Func&amp;lt;T, &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;bool&lt;/span&gt;&amp;gt;&amp;gt;(body,
arg).Compile(); } &lt;/span&gt;&lt;/pre&gt;Usage:&amp;nbsp; 
&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;List&amp;lt;Employee&amp;gt;
emps &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; Employee.LoadListCollection();
List&amp;lt;Employee&amp;gt; empList &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; emps.DynamicFilter(&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"FirstName"&lt;/span&gt;, &lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"Angie"&lt;/span&gt;).ToList(); &lt;/span&gt;&lt;/pre&gt;This
worked great for a case-sensitive search, but I still didn’t have a way to do a case-insensitve
search or a wildcard search. So after some more searching and more trial-and-error,
I came up with this for a wildcard search:&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;public&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;static&lt;/span&gt; IEnumerable&amp;lt;T&amp;gt;
ContainsString&amp;lt;T&amp;gt;(&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;this&lt;/span&gt; IEnumerable&amp;lt;T&amp;gt;
data, &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;string&lt;/span&gt; propertyOrFieldName, &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;string&lt;/span&gt; searchValue)
{ var param &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; Expression.Parameter(&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;typeof&lt;/span&gt;(T), &lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"x"&lt;/span&gt;);
var body &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; Expression.Call( &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;typeof&lt;/span&gt;(BusinessObjectBase).GetMethod(&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"Like"&lt;/span&gt;,
BindingFlags.Static &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;|&lt;/span&gt; BindingFlags.NonPublic &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;|&lt;/span&gt; BindingFlags.Public),
Expression.PropertyOrField(param, propertyOrFieldName), Expression.Constant(searchValue, &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;typeof&lt;/span&gt;(&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;string&lt;/span&gt;)));
var lambda &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; Expression.Lambda&amp;lt;Func&amp;lt;T, &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;bool&lt;/span&gt;&amp;gt;&amp;gt;(body,
param); &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;return&lt;/span&gt; data.Where(lambda.Compile());
} &lt;/span&gt;&lt;/pre&gt;A couple things to note here. First, I needed&amp;nbsp; to add a method
“Like” to my base object (BusinessObjectBase in this case) of the collections I am
searching. It looks like this:&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;///
&amp;lt;summary&amp;gt;&lt;/span&gt; &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;///
comparison operator. Needed for dynamically filtering the objects&lt;/span&gt; &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;///
&amp;lt;/summary&amp;gt;&lt;/span&gt; &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;///
&amp;lt;param name="a"&amp;gt;A.&amp;lt;/param&amp;gt;&lt;/span&gt; &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;///
&amp;lt;param name="b"&amp;gt;The b.&amp;lt;/param&amp;gt;&lt;/span&gt; &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;///
&amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;static&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;bool&lt;/span&gt; Like(&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;string&lt;/span&gt; a, &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;string&lt;/span&gt; b)
{ &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;return&lt;/span&gt; a.ToLower().Contains(b.ToLower());
} &lt;/span&gt;&lt;/pre&gt;Now I can do a search where I specify the property name, and it returns
and value of that property that contains any part of that string (and it is also case-insensitive).&lt;br&gt;
&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;List&amp;lt;Employee&amp;gt;
emps &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; Employee.LoadListCollection();
List&amp;lt;Employee&amp;gt; empList &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; emps.ContainsString(&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"FirstName"&lt;/span&gt;, &lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"An"&lt;/span&gt;).ToList(); &lt;/span&gt;&lt;/pre&gt;Then
it occurred to me that I was specifying the name of the static routine in the call.
What would happen if I specified the name of the operator dynamically? Would it work
right? 
&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;var
body &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; Expression.Call( &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;typeof&lt;/span&gt;(BusinessObjectBase).GetMethod(&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"Like"&lt;/span&gt;,
BindingFlags.Static &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;|&lt;/span&gt; BindingFlags.NonPublic &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;|&lt;/span&gt; BindingFlags.Public), 
&lt;br&gt;
&lt;font size="2" face="Verdana"&gt;Became this:&lt;/font&gt;
&lt;br&gt;
&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;var
body &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; Expression.Call( &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;typeof&lt;/span&gt;(BusinessObjectBase).GetMethod(operatorName,
BindingFlags.Static &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;|&lt;/span&gt; BindingFlags.NonPublic &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;|&lt;/span&gt; BindingFlags.Public), &lt;/span&gt;&lt;/pre&gt;&lt;font size="2" face="Verdana"&gt;Now
I could create two static operators (or as many as I might ever need) to provide this
dynamic functionality.&lt;br&gt;
&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;public&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;static&lt;/span&gt; IEnumerable&amp;lt;T&amp;gt;
RunOperator&amp;lt;T&amp;gt;(&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;this&lt;/span&gt; IEnumerable&amp;lt;T&amp;gt;
data, &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;string&lt;/span&gt; operatorName, &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;string&lt;/span&gt; propertyOrFieldName, &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;string&lt;/span&gt; searchValue)
{ var param &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; Expression.Parameter(&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;typeof&lt;/span&gt;(T), &lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"x"&lt;/span&gt;);
var body &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; Expression.Call( &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;typeof&lt;/span&gt;(BusinessObjectBase).GetMethod(operatorName,
BindingFlags.Static &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;|&lt;/span&gt; BindingFlags.NonPublic &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;|&lt;/span&gt; BindingFlags.Public),
Expression.PropertyOrField(param, propertyOrFieldName), Expression.Constant(searchValue, &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;typeof&lt;/span&gt;(&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;string&lt;/span&gt;)));
var lambda &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; Expression.Lambda&amp;lt;Func&amp;lt;T, &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;bool&lt;/span&gt;&amp;gt;&amp;gt;(body,
param); &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;return&lt;/span&gt; data.Where(lambda.Compile());
} &lt;/span&gt;&lt;/pre&gt;In my BusinessObjectBase class, I added the following methods (Like
for wildcard searches, and Equals for a case-insensitive search):&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;static&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;bool&lt;/span&gt; Like(&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;string&lt;/span&gt; a, &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;string&lt;/span&gt; b)
{ &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;return&lt;/span&gt; a.ToLower().Contains(b.ToLower());
} &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;static&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;bool&lt;/span&gt; Equals(&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;string&lt;/span&gt; a, &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;string&lt;/span&gt; b)
{ &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;return&lt;/span&gt; a.ToLower()
== b.ToLower(); } &lt;/span&gt;&lt;/pre&gt;I can call both of these methods like this:&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;public&lt;/span&gt; List&amp;lt;T&amp;gt;
FilterData&amp;lt;T&amp;gt;(List&amp;lt;T&amp;gt; data, &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;bool&lt;/span&gt; wildcardSearch)
{ List&amp;lt;T&amp;gt; results &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; data; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;if&lt;/span&gt; (wildcardSearch)
results &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; results.RunOperator(&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"Like"&lt;/span&gt;,
fi.DataField, fi.FilterValue()).ToList(); &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;else&lt;/span&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;results &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; results.RunOperator(&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"Equals"&lt;/span&gt;,
fi.DataField, fi.FilterValue()).ToList(); &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;return&lt;/span&gt; results;
} &lt;/span&gt;&lt;/pre&gt;So let’s break it down a little. First, the first parameter of a lambda
expression, which is what we are building here, is the input parameter, or in this
case, the x portion of x =&amp;gt;.&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;var
param &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; Expression.Parameter(&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;typeof&lt;/span&gt;(T), &lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"x"&lt;/span&gt;);&lt;/span&gt;&lt;/pre&gt;Next,
we’re setting up the call which is made to the right of the =&amp;gt; of the Lambda expression.
The code below is saying “grab the method name provided by the operatorName variable,
which can be found in any class which implements the BusinessObjectBase class.&lt;br&gt;
&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;typeof&lt;/span&gt;(BusinessObjectBase).GetMethod(operatorName,&lt;/span&gt;&lt;/pre&gt;
&lt;br&gt;
The result of the expression defined above will be returning a boolean, as defined
here:&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;var
lambda &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; Expression.Lambda&amp;lt;Func&amp;lt;T, &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;bool&lt;/span&gt;&amp;gt;&amp;gt;(body,
param);&lt;/span&gt;&lt;/pre&gt;Finally, we return the data which evaluates in the lambda expression
as true via this line of code:&lt;br&gt;
&lt;br&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;return&lt;/span&gt; data.Where(lambda.Compile());&lt;/span&gt;&lt;/pre&gt;Note
the delegate lambda expression is compiled into executrable code and produces a delegate
which represents the lambda expression.&lt;br&gt;
Obviously, understanding how to dynamically call methods and compare properties using
LINQ is extremely powerful and has many,many possibilities. I hope this helps someone
else trying to do the same thing!&lt;br&gt;
&lt;br&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=1aac1456-13df-443f-b660-27c38fd4eb49" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,1aac1456-13df-443f-b660-27c38fd4eb49.aspx</comments>
      <category>All Things</category>
      <category>ASP.Net</category>
      <category>CSharp</category>
      <category>Design</category>
      <category>General</category>
      <category>Tips and Tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=f32c9c96-4f69-4cb0-8638-85ffbcb0f9ad</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,f32c9c96-4f69-4cb0-8638-85ffbcb0f9ad.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,f32c9c96-4f69-4cb0-8638-85ffbcb0f9ad.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=f32c9c96-4f69-4cb0-8638-85ffbcb0f9ad</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Recently, I posted a <a href="http://www.dotnettechnologies.com/PermaLink,guid,8df6f658-9820-485e-a7f9-1a9a970bd4ce.aspx" target="_blank">script</a> which
would identify all the procedures which did not have appropriate permissions set,
which is great for last minute deployment checks. I realized I needed to explore INFORMATION_SCHEMA
closer as there is a LOT of useful metadata about the database available. Today's
tip is about some of that useful information.
</p>
        <p>
INFORMATION_SCHEMA is a specia schema which contains several views of the database
metadata. Previous to these views, database developers were forced to join on several
sys tables. Many of my earlier scripts for example rely on this method. However, in
SQL Server 2005 system views were provided which made this task significantly easier.
Here's some of the more useful views to look at. Explore them with code like this
and see what they contain.
</p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SELECT</span> * <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">FROM</span> INFORMATION_SCHEMA.COLUMNS</span>
        </p>
        <p>
I have found the following most useful, although in truth I suspect over time I will
have use for all of them.
</p>
        <p>
COLUMNS --&gt; I frequently use this to find what tables a particular column name
is found in
</p>
        <p>
CONSTRAINT_COLUMN_USAGE --&gt; identify what keys (primary, foreign) are defined,
and on what fields
</p>
        <p>
ROUTINES --&gt; allows me to explore procedures and functions using this
view
</p>
        <p>
TABLES --&gt; Get information about the various tables in the database
</p>
        <p>
VIEW_COLUMN_USAGE --&gt; obtain information on the fields the view contains
</p>
        <p>
Here's a good link where you can find more information on the <a href="http://msdn.microsoft.com/en-us/library/ms186778.aspx" target="_blank">INFORMATION_SCHEMA</a>.
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=f32c9c96-4f69-4cb0-8638-85ffbcb0f9ad" />
      </body>
      <title>Tip of the Day: More useful information on INFORMATION_SCHEMA</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,f32c9c96-4f69-4cb0-8638-85ffbcb0f9ad.aspx</guid>
      <link>http://www.dotnettechnologies.com/2010/03/11/TipOfTheDayMoreUsefulInformationOnINFORMATIONSCHEMA.aspx</link>
      <pubDate>Thu, 11 Mar 2010 04:02:00 GMT</pubDate>
      <description>&lt;p&gt;
Recently, I posted a &lt;a href="http://www.dotnettechnologies.com/PermaLink,guid,8df6f658-9820-485e-a7f9-1a9a970bd4ce.aspx" target=_blank&gt;script&lt;/a&gt; which
would identify all the procedures which did not have appropriate permissions set,
which is great for last minute deployment checks. I realized I needed to explore INFORMATION_SCHEMA
closer as there is a LOT of useful metadata about the database available. Today's
tip is about some of that useful information.
&lt;/p&gt;
&lt;p&gt;
INFORMATION_SCHEMA is a specia schema which contains several views of the database
metadata. Previous to these views, database developers were forced to join on several
sys tables. Many of my earlier scripts for example rely on this method. However, in
SQL Server 2005 system views were provided which made this task significantly easier.
Here's some of the more useful views to look at. Explore them with code like this
and see what they contain.
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SELECT&lt;/span&gt; * &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;FROM&lt;/span&gt; INFORMATION_SCHEMA.COLUMNS&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
I have found the following most useful, although in truth I suspect over time I will
have use for all of them.
&lt;/p&gt;
&lt;p&gt;
COLUMNS --&amp;gt; I frequently use this to find what tables a particular column name
is found in
&lt;/p&gt;
&lt;p&gt;
CONSTRAINT_COLUMN_USAGE --&amp;gt; identify what keys (primary, foreign) are defined,
and on what fields
&lt;/p&gt;
&lt;p&gt;
ROUTINES --&amp;gt;&amp;nbsp;allows me to explore&amp;nbsp;procedures and functions using this
view
&lt;/p&gt;
&lt;p&gt;
TABLES --&amp;gt; Get information about the various tables in the database
&lt;/p&gt;
&lt;p&gt;
VIEW_COLUMN_USAGE --&amp;gt; obtain information on the fields the view contains
&lt;/p&gt;
&lt;p&gt;
Here's a good link where you can find more information on the &lt;a href="http://msdn.microsoft.com/en-us/library/ms186778.aspx" target=_blank&gt;INFORMATION_SCHEMA&lt;/a&gt;.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=f32c9c96-4f69-4cb0-8638-85ffbcb0f9ad" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,f32c9c96-4f69-4cb0-8638-85ffbcb0f9ad.aspx</comments>
      <category>All Things</category>
      <category>Design</category>
      <category>General</category>
      <category>SQL Tips</category>
      <category>Tips and Tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=d0d65734-e1ba-458d-9080-eddd8a5d30ed</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,d0d65734-e1ba-458d-9080-eddd8a5d30ed.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,d0d65734-e1ba-458d-9080-eddd8a5d30ed.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=d0d65734-e1ba-458d-9080-eddd8a5d30ed</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
In the past week, I created some CodeSmith templates for my client so we could quickly
generate the business objects for our web site. Since the project will be VS2008,
I decided to bing objects to List&lt;T&gt; collections of objects, so I could start
leveraging LINQ to Objects in the code.
</p>
        <p>
They wanted every field in the GridView sortable, and I always looks for an reusable
way to do things when possible. Since we were going to have many, many grids, this
was a great opportunity to use generics and LINQ to come up with a flexible solution.
</p>
        <p>
In this case, I wanted a way of taking in a field name, and sort direction, and sorting
the collection. It was easy to do using a Lambda expression if I knew in advance all
the field names, such as MyCollection.OrderBy(a =&gt; a.Name) to sort by name. Obviously,
that wasn't going to work. I needed to create a delegate for sorting on the right
field dynamically.
</p>
        <p>
Below is the result of that effort. By using the Lambda.Expression (provided by System.Core.dll),
I was able to dynamically set the Lambda expression to the property I wanted.
Depending on the direction, I used OrderBy or OrderByDescending with the dynamic sort
expression. I created it as an extension method to all List&lt;T&gt; objects for quick
and easy access, which every business object in my solution supports.
</p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
&lt;summary&gt;</span>
            <br />
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
Sorts a list of objects by passing in the parameter and direction.</span>
            <br />
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
Usage: List&lt;MyObject&gt; newList = oldList.SortList("SomeColumn", "SomeDirection");</span>
            <br />
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
Requires System.Core be included in the project.</span>
            <br />
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
&lt;/summary&gt;</span>
            <br />
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
&lt;typeparam name="T"&gt;&lt;/typeparam&gt;</span>
            <br />
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
&lt;param name="list"&gt;The list.&lt;/param&gt;</span>
            <br />
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
&lt;param name="sortColumn"&gt;The sort column.&lt;/param&gt;</span>
            <br />
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
&lt;param name="direction"&gt;The direction.&lt;/param&gt;</span>
            <br />
            <span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">///
&lt;returns&gt;&lt;/returns&gt;</span>
            <br />
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span>
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">static</span> List&lt;T&gt;
SortList&lt;T&gt;(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">this</span> List&lt;T&gt;
list, <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span> sortColumn, <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</span> direction)<br />
{<br />
var param <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> Expression.Parameter(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">typeof</span>(AutoClassParams),
sortColumn);<br />
var sortExpression <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> Expression.Lambda&lt;Func&lt;T, <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">object</span>&gt;&gt;(Expression.Convert(Expression.Property(param,
sortColumn), <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">typeof</span>(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">object</span>)),
param);<br /><br />
List&lt;T&gt; newList <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">null</span>;<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">if</span> (direction.ToUpper()
== <span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"ASC"</span>)<br />
newList <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> list.AsQueryable&lt;T&gt;().OrderBy(sortExpression).ToList&lt;T&gt;();<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">else</span><br />
newList <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</span> list.AsQueryable&lt;T&gt;().OrderByDescending(sortExpression).ToList&lt;T&gt;();<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">return</span> newList;<br />
}</span>
        </p>
        <p>
 
</p>
        <p>
 
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=d0d65734-e1ba-458d-9080-eddd8a5d30ed" />
      </body>
      <title>Tip of the Day: Dynamically sorting a List&lt;T&gt; collection using Lambda.Expression</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,d0d65734-e1ba-458d-9080-eddd8a5d30ed.aspx</guid>
      <link>http://www.dotnettechnologies.com/2009/12/30/TipOfTheDayDynamicallySortingAListCollectionUsingLambdaExpression.aspx</link>
      <pubDate>Wed, 30 Dec 2009 04:58:02 GMT</pubDate>
      <description>&lt;p&gt;
In the past week, I created some CodeSmith templates for my client so we could quickly
generate the business objects for our web site. Since the project will be VS2008,
I decided to bing objects to List&amp;lt;T&amp;gt; collections of objects, so I could start
leveraging LINQ to Objects in the code.
&lt;/p&gt;
&lt;p&gt;
They wanted every field in the GridView sortable, and I always looks for an reusable
way to do things when possible. Since we were going to have many, many grids, this
was a great opportunity to use generics and LINQ to come up with a flexible solution.
&lt;/p&gt;
&lt;p&gt;
In this case, I wanted a way of taking in a field name, and sort direction, and sorting
the collection. It was easy to do using a Lambda expression if I knew in advance all
the field names, such as MyCollection.OrderBy(a =&amp;gt; a.Name) to sort by name. Obviously,
that wasn't going to work. I needed to create a delegate for sorting on the right
field dynamically.
&lt;/p&gt;
&lt;p&gt;
Below is the result of that effort. By using the Lambda.Expression (provided by System.Core.dll),
I was able to dynamically set the Lambda expression to the property&amp;nbsp;I wanted.
Depending on the direction, I used OrderBy or OrderByDescending with the dynamic sort
expression. I created it as an extension method to all List&amp;lt;T&amp;gt; objects for quick
and easy access, which every business object in my solution supports.
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
Sorts a list of objects by passing in the parameter and direction.&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
Usage: List&amp;lt;MyObject&amp;gt; newList = oldList.SortList("SomeColumn", "SomeDirection");&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
Requires System.Core be included in the project.&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;typeparam name="T"&amp;gt;&amp;lt;/typeparam&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;param name="list"&amp;gt;The list.&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;param name="sortColumn"&amp;gt;The sort column.&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;param name="direction"&amp;gt;The direction.&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;static&lt;/span&gt; List&amp;lt;T&amp;gt;
SortList&amp;lt;T&amp;gt;(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;this&lt;/span&gt; List&amp;lt;T&amp;gt;
list, &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt; sortColumn, &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt; direction)&lt;br&gt;
{&lt;br&gt;
var param &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; Expression.Parameter(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;typeof&lt;/span&gt;(AutoClassParams),
sortColumn);&lt;br&gt;
var sortExpression &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; Expression.Lambda&amp;lt;Func&amp;lt;T, &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;object&lt;/span&gt;&amp;gt;&amp;gt;(Expression.Convert(Expression.Property(param,
sortColumn), &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;typeof&lt;/span&gt;(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;object&lt;/span&gt;)),
param);&lt;br&gt;
&lt;br&gt;
List&amp;lt;T&amp;gt; newList &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;null&lt;/span&gt;;&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;if&lt;/span&gt; (direction.ToUpper()
== &lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"ASC"&lt;/span&gt;)&lt;br&gt;
newList &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; list.AsQueryable&amp;lt;T&amp;gt;().OrderBy(sortExpression).ToList&amp;lt;T&amp;gt;();&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;else&lt;/span&gt;
&lt;br&gt;
newList &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; list.AsQueryable&amp;lt;T&amp;gt;().OrderByDescending(sortExpression).ToList&amp;lt;T&amp;gt;();&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;return&lt;/span&gt; newList;&lt;br&gt;
}&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=d0d65734-e1ba-458d-9080-eddd8a5d30ed" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,d0d65734-e1ba-458d-9080-eddd8a5d30ed.aspx</comments>
      <category>All Things</category>
      <category>CSharp</category>
      <category>Design</category>
      <category>General</category>
      <category>Tips and Tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=a0f5b464-8bcd-43d2-a17d-58c4bb7b392b</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,a0f5b464-8bcd-43d2-a17d-58c4bb7b392b.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,a0f5b464-8bcd-43d2-a17d-58c4bb7b392b.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=a0f5b464-8bcd-43d2-a17d-58c4bb7b392b</wfw:commentRss>
      <title>New features of VS2010 which have me smiling (Part 2)</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,a0f5b464-8bcd-43d2-a17d-58c4bb7b392b.aspx</guid>
      <link>http://www.dotnettechnologies.com/2009/11/07/NewFeaturesOfVS2010WhichHaveMeSmilingPart2.aspx</link>
      <pubDate>Sat, 07 Nov 2009 03:45:19 GMT</pubDate>
      <description>&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;Session compression – For out-of-process session
maintenance, the session state is compressed using the &lt;i style="mso-bidi-font-style: normal"&gt;System.IO.Compression.GZipStream&lt;/i&gt; class.
It also looks like it will only do this when CPU cycles are available (but I need
to investigate this further).&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;If that’s
the case, you might want to set up some Performance indicators or alerts when it’s
not being compressed because that might indicate further problems.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;
&lt;o:p&gt;
&lt;font face=Calibri color=#000000 size=3&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;Link: &lt;/font&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: #666666; FONT-FAMILY: 'Tahoma','sans-serif'"&gt;&amp;lt;&lt;a href="http://www.asp.net/learn/whitepapers/aspnet4/default.aspx"&gt;http://www.asp.net/learn/whitepapers/aspnet4/default.aspx&lt;/a&gt;&amp;gt; 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Calibri color=#000000 size=3&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;Multi-Targeting – I’ve mentioned this before,
but it allows you to specify which .Net version you are writing for in the VS2010
IDE. This expands the support that VS2008 has by adaptively changing&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;the
IDE to the targeted environment. The IDE adjusts its Intellisense and compilation
towards the targeted version.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;The whitepaper
indicates ASP.Net, so I need to test and see if it applies to WPF and WinForm as well.
Some features:&lt;/font&gt;
&lt;/p&gt;
&lt;ul style="MARGIN-TOP: 0in" type=disc&gt;
&lt;li class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l3 level1 lfo2"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;Specified in the .config file, defaults to
4.0 when not specified.&lt;/font&gt;
&lt;/li&gt;
&lt;li class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l3 level1 lfo2"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;Compiles the code to the &lt;/font&gt;
&lt;/li&gt;
&lt;li class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l3 level1 lfo2"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;Intellisense adapts to the current version
of the framework selected&lt;/font&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Calibri color=#000000 size=3&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;Link: &lt;/font&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: #666666; FONT-FAMILY: 'Tahoma','sans-serif'"&gt;&amp;lt;&lt;a href="http://www.asp.net/learn/whitepapers/aspnet4/default.aspx"&gt;http://www.asp.net/learn/whitepapers/aspnet4/default.aspx&lt;/a&gt;&amp;gt; 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;Link: &lt;/font&gt;&lt;a href="http://weblogs.asp.net/scottgu/archive/2009/08/27/multi-targeting-support-vs-2010-and-net-4-series.aspx"&gt;&lt;font face=Calibri size=3&gt;http://weblogs.asp.net/scottgu/archive/2009/08/27/multi-targeting-support-vs-2010-and-net-4-series.aspx&lt;/font&gt;&lt;/a&gt;&lt;font face=Calibri color=#000000 size=3&gt; &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Calibri color=#000000 size=3&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;Script Loading – The AJAX library includes
the ability to have better control of script loading in .Net 4.0. It loads the scripts
automatically, and in the order needed. From the whitepaper, here’s the features:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Calibri color=#000000 size=3&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.75in; VERTICAL-ALIGN: middle; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo3; tab-stops: list .5in"&gt;
&lt;font color=#000000&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol; mso-bidi-font-size: 12.0pt"&gt;&lt;span style="mso-list: Ignore"&gt;·&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size=3&gt;&lt;font face=Calibri&gt;Automatically
loads all resources that are required by a script. &lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman','serif'"&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.75in; VERTICAL-ALIGN: middle; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo3; tab-stops: list .5in"&gt;
&lt;font color=#000000&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol; mso-bidi-font-size: 12.0pt"&gt;&lt;span style="mso-list: Ignore"&gt;·&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size=3&gt;&lt;font face=Calibri&gt;Makes
sure that each script is loaded only once. &lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman','serif'"&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.75in; VERTICAL-ALIGN: middle; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo3; tab-stops: list .5in"&gt;
&lt;font color=#000000&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol; mso-bidi-font-size: 12.0pt"&gt;&lt;span style="mso-list: Ignore"&gt;·&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size=3&gt;&lt;font face=Calibri&gt;Improves
performance by loading scripts in parallel and by combining scripts. &lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman','serif'"&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.75in; VERTICAL-ALIGN: middle; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo3; tab-stops: list .5in"&gt;
&lt;font color=#000000&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol; mso-bidi-font-size: 12.0pt"&gt;&lt;span style="mso-list: Ignore"&gt;·&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size=3&gt;&lt;font face=Calibri&gt;Supports
loading scripts only when they are needed (“lazy loading”). &lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman','serif'"&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.75in; VERTICAL-ALIGN: middle; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo3; tab-stops: list .5in"&gt;
&lt;font color=#000000&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol; mso-bidi-font-size: 12.0pt"&gt;&lt;span style="mso-list: Ignore"&gt;·&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size=3&gt;&lt;font face=Calibri&gt;Supports
loading third-party scripts like jQuery and your own scripts.&lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman','serif'"&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt 0.75in; VERTICAL-ALIGN: middle; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo3; tab-stops: list .5in"&gt;
&lt;font color=#000000&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol; mso-bidi-font-size: 11.0pt"&gt;&lt;span style="mso-list: Ignore"&gt;·&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Calibri size=3&gt;Supports
loading scripts from the Microsoft Ajax Content Delivery Network&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Calibri color=#000000 size=3&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;One of the client features is the Sys.require.
When a component and a function is provided, the callback function is called when
the scripts are done loading.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Calibri color=#000000 size=3&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;Link: &lt;/font&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: #666666; FONT-FAMILY: 'Tahoma','sans-serif'"&gt;&amp;lt;&lt;a href="http://www.asp.net/learn/whitepapers/aspnet4/default.aspx"&gt;http://www.asp.net/learn/whitepapers/aspnet4/default.aspx&lt;/a&gt;&amp;gt; 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Calibri color=#000000 size=3&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;jQuery integration – Speaking of jQuery, it’s
now included&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;as part of the ASP.Net Web
forms and the MVC project.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Calibri color=#000000 size=3&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;Link: &lt;/font&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: #666666; FONT-FAMILY: 'Tahoma','sans-serif'"&gt;&amp;lt;&lt;a href="http://www.asp.net/learn/whitepapers/aspnet4/default.aspx"&gt;http://www.asp.net/learn/whitepapers/aspnet4/default.aspx&lt;/a&gt;&amp;gt; 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Calibri color=#000000 size=3&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;ClientID changes – I am mixed about this one,
simply because once In understood how ASP.Net set its clientIDs upon rendering, I
could generate my script accordingly&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;in
my code behind.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;However, it’s been simplified
in VS2010 to allow the user to have control over setting the client IDs. Be forewarned
though, this could open you up to naming issues within container controls as such.
Regardless, I am always supportive of giving the developer the option of more control.
There’s a new property at the configuration file, page and control level called &lt;i style="mso-bidi-font-style: normal"&gt;ClientIDMode&lt;/i&gt; which
has the following settings:&lt;/font&gt;
&lt;/p&gt;
&lt;ul style="MARGIN-TOP: 0in" type=disc&gt;
&lt;li class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l2 level1 lfo4"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;AutoID – mimics the previous version naming
scheme&lt;/font&gt;
&lt;/li&gt;
&lt;li class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l2 level1 lfo4"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;Static – This specifies that the ClientID
value will be the same as the ID without concatenating the IDs of parent naming containers. &lt;/font&gt;
&lt;/li&gt;
&lt;li class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l2 level1 lfo4"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;Predictable – useful for controls which will
be generated in template controls&lt;/font&gt;
&lt;/li&gt;
&lt;li class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l2 level1 lfo4"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;Inherit – take the setting of the parent control
(lots of this in VS2010, which is great, since I have been a champion for UI inheritance
and control-centric programming).&lt;/font&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Calibri color=#000000 size=3&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;Link: &lt;/font&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: #666666; FONT-FAMILY: 'Tahoma','sans-serif'"&gt;&amp;lt;&lt;a href="http://www.asp.net/learn/whitepapers/aspnet4/default.aspx"&gt;http://www.asp.net/learn/whitepapers/aspnet4/default.aspx&lt;/a&gt;&amp;gt; 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Calibri color=#000000 size=3&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Calibri color=#000000 size=3&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;Improved “Add Reference” functionality – Over
the past couple of days, I found myself converting a project from VS2005 to VS2008.
As a result, I found myself needing to change some references as well as I changed
some of the related projects. This change in VS2008 is sort of a “nice to have”. While
it’s not a big win, it’s still nice as it can get painful at times changing the references.
Here are the changes with this:&lt;/font&gt;
&lt;/p&gt;
&lt;ul style="MARGIN-TOP: 0in" type=disc&gt;
&lt;li class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l1 level1 lfo1"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;The .Net and COM tabs are loaded asynchronously&lt;/font&gt;
&lt;/li&gt;
&lt;li class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l1 level1 lfo1"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;Defaults opening to the project tab (I find
myself using this a LOT anyways, but would have preferred this to start at the “Browse”
tab, or better, consider this like a MRU action and remember where I was last time)&lt;/font&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;Link&lt;/font&gt;&lt;span style="FONT-SIZE: 8pt; COLOR: #666666; FONT-FAMILY: 'Tahoma','sans-serif'"&gt;:
&amp;lt;&lt;a href="http://weblogs.asp.net/scottgu/archive/2009/10/29/add-reference-dialog-improvements-vs-2010-and-net-4-0-series.aspx"&gt;http://weblogs.asp.net/scottgu/archive/2009/10/29/add-reference-dialog-improvements-vs-2010-and-net-4-0-series.aspx&lt;/a&gt;&amp;gt; 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Calibri color=#000000 size=3&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font size=3&gt;&lt;font color=#000000&gt;&lt;font face=Calibri&gt;UML Support! Visual Studio 2010
will support the creation of UML diagrams via a modeling project. I like Visio and
all, but I look forward to being able to create UML diagrams right from the same IDE
I develop in. As of now, there’s no code generation support. I do think a clever developer
could possible do some code generation from the saved file via CodeSmith or IDE programming,
so I bet we’ll see something like that soon if Microsoft doesn’t provide it first.
Check out the link below and you can see some of the functionality.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Calibri color=#000000 size=3&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;Link: &lt;/font&gt;&lt;a href="http://weblogs.asp.net/gunnarpeipman/archive/2009/11/04/visual-studio-2010-uml-modeling-projects.aspx"&gt;&lt;font face=Calibri size=3&gt;http://weblogs.asp.net/gunnarpeipman/archive/2009/11/04/visual-studio-2010-uml-modeling-projects.aspx&lt;/font&gt;&lt;/a&gt;&lt;font face=Calibri color=#000000 size=3&gt; &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Calibri color=#000000 size=3&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;Although available in v3.5, VS2010/v4 will
have the chart control integrated into it. In the past, your options were a third-party
control for charting or to use Interop and Excel, or writing your own charting libraries
(gulp!). &lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;The link below lists some details
on this impressive charting library if you’ve never used it.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Calibri color=#000000 size=3&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;Link: &lt;/font&gt;&lt;a href="http://weblogs.asp.net/scottgu/archive/2008/11/24/new-asp-net-charting-control-lt-asp-chart-runat-quot-server-quot-gt.aspx"&gt;&lt;font face=Calibri size=3&gt;http://weblogs.asp.net/scottgu/archive/2008/11/24/new-asp-net-charting-control-lt-asp-chart-runat-quot-server-quot-gt.aspx&lt;/font&gt;&lt;/a&gt;&lt;font face=Calibri color=#000000 size=3&gt; &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Calibri color=#000000 size=3&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;Developers will have more deployment options
Web application &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Calibri color=#000000 size=3&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;Get it here: &lt;/font&gt;&lt;a href="http://msdn.microsoft.com/en-us/vstudio/dd582936.aspx"&gt;&lt;font face=Calibri size=3&gt;http://msdn.microsoft.com/en-us/vstudio/dd582936.aspx&lt;/font&gt;&lt;/a&gt;&lt;font face=Calibri color=#000000 size=3&gt; &lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=a0f5b464-8bcd-43d2-a17d-58c4bb7b392b" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,a0f5b464-8bcd-43d2-a17d-58c4bb7b392b.aspx</comments>
      <category>All Things</category>
      <category>ASP.Net</category>
      <category>CSharp</category>
      <category>Debugging</category>
      <category>Design</category>
      <category>General</category>
      <category>Tips and Tricks</category>
      <category>Tools</category>
      <category>WinForms</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=9c93a3a3-ff3c-4a78-b273-081242375c0d</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,9c93a3a3-ff3c-4a78-b273-081242375c0d.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,9c93a3a3-ff3c-4a78-b273-081242375c0d.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=9c93a3a3-ff3c-4a78-b273-081242375c0d</wfw:commentRss>
      <title>New features of VS2010 which have me smiling (Part 1)</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,9c93a3a3-ff3c-4a78-b273-081242375c0d.aspx</guid>
      <link>http://www.dotnettechnologies.com/2009/10/31/NewFeaturesOfVS2010WhichHaveMeSmilingPart1.aspx</link>
      <pubDate>Sat, 31 Oct 2009 04:22:38 GMT</pubDate>
      <description>&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;As I mentioned before, I historically have
avoided beta software. However, this time I am breaking that rule and really digging
into VS2010 early. Below are a few of the things which have me very excited to see
this release (and with Web Spark, I get it for free! Join now!) This is part one of
a multi-part entry of the things I find really appealing about the upcoming version
of Visual Studio 2010.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;
&lt;o:p&gt;
&lt;font face=Calibri color=#000000 size=3&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font size=3&gt;&lt;font color=#000000&gt;&lt;font face=Calibri&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;IntelliTrace&lt;/b&gt; –
allows you to playback and trace a session to assist with debugging. The major features
are:&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;ul style="MARGIN-TOP: 0in" type=disc&gt;
&lt;li class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l0 level1 lfo1"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;Application Event Recording &lt;/font&gt;
&lt;/li&gt;
&lt;li class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l0 level1 lfo1"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;Playback Debugging (a.k.a Time Travel Debugging) &lt;/font&gt;
&lt;/li&gt;
&lt;li class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l0 level1 lfo1"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;Record and Playback of Manual Test Failures &lt;/font&gt;
&lt;/li&gt;
&lt;li class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l0 level1 lfo1"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;Debugging Build Acceptance Tests &lt;/font&gt;
&lt;/li&gt;
&lt;li class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l0 level1 lfo1"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;Diagnosing Unit Test Defects &lt;/font&gt;
&lt;/li&gt;
&lt;li class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l0 level1 lfo1"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;Debugging Load Test Failures&lt;/font&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Calibri color=#000000 size=3&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;Link: &lt;/font&gt;&lt;a href="http://blogs.msdn.com/habibh/archive/2009/06/02/an-in-depth-look-at-the-historical-debugger-in-visual-studio-2010-part-i.aspx" target=_blank&gt;&lt;font face=Calibri size=3&gt;http://blogs.msdn.com/habibh/archive/2009/06/02/an-in-depth-look-at-the-historical-debugger-in-visual-studio-2010-part-i.aspx&lt;/font&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Calibri color=#000000 size=3&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font size=3&gt;&lt;font color=#000000&gt;&lt;font face=Calibri&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;Auto-Start
applications&lt;/b&gt; – Helps mitigate large startup processes which may run during the
web application “Application_Start” event. Provides a controlled approach for starting
up the application.&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Calibri color=#000000 size=3&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;Link: &lt;/font&gt;&lt;a href="http://weblogs.asp.net/scottgu/archive/2009/09/15/auto-start-asp-net-applications-vs-2010-and-net-4-0-series.aspx" target=_blank&gt;&lt;font face=Calibri size=3&gt;http://weblogs.asp.net/scottgu/archive/2009/09/15/auto-start-asp-net-applications-vs-2010-and-net-4-0-series.aspx&lt;/font&gt;&lt;/a&gt;&lt;font face=Calibri color=#000000 size=3&gt; &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Calibri color=#000000 size=3&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font size=3&gt;&lt;font color=#000000&gt;&lt;font face=Calibri&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;Better
ViewState management&lt;/b&gt; – By default, ViewState is enabled for web controls in past
versions of ASP.Net. In VS2010, ViewState can be disabled by default and onlt enabled
for those that actually need it, and it now supports “inheritance” through the ViewStateMode
property. This allows you to set it to “Inherit” the value from the parent control.&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Calibri color=#000000 size=3&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;Link: &lt;/font&gt;&lt;a href="http://www.asp.net/learn/whitepapers/aspnet4/" target=_blank&gt;&lt;font face=Calibri size=3&gt;http://www.asp.net/learn/whitepapers/aspnet4/&lt;/font&gt;&lt;/a&gt;&lt;font face=Calibri color=#000000 size=3&gt; &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Calibri color=#000000 size=3&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font size=3&gt;&lt;font color=#000000&gt;&lt;font face=Calibri&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;Outut
Caching everywhere &lt;/b&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;-- Now you can
take advantage of caching in applications other than web based, as the cache API is
exposed without using the System.Web.Cache in a WinForm application. There are also
more providers, and the ability to create your own through extensibility.&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Calibri color=#000000 size=3&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;Link: &lt;/font&gt;&lt;a href="http://www.asp.net/learn/whitepapers/aspnet4/" target=_blank&gt;&lt;font face=Calibri size=3&gt;http://www.asp.net/learn/whitepapers/aspnet4/&lt;/font&gt;&lt;/a&gt;&lt;font face=Calibri color=#000000 size=3&gt; &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Calibri color=#000000 size=3&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font size=3&gt;&lt;font color=#000000&gt;&lt;font face=Calibri&gt;&lt;b style="mso-bidi-font-weight: normal"&gt;Reduced
web.config size – &lt;/b&gt;Most of the configuration settings have been moved to the machine.config
file, which greatly simplifies the configuration settings in the web.config file.&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Calibri color=#000000 size=3&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;Link: &lt;/font&gt;&lt;a href="http://www.asp.net/learn/whitepapers/aspnet4/"&gt;&lt;font face=Calibri size=3&gt;http://www.asp.net/learn/whitepapers/aspnet4/&lt;/font&gt;&lt;/a&gt;&lt;font face=Calibri color=#000000 size=3&gt; &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Calibri color=#000000 size=3&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font face=Calibri color=#000000 size=3&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;Get the VS2010 Beta 2 here: &lt;/font&gt;&lt;a href="http://msdn.microsoft.com/en-us/vstudio/dd582936.aspx" target=_blank&gt;&lt;font face=Calibri size=3&gt;http://msdn.microsoft.com/en-us/vstudio/dd582936.aspx&lt;/font&gt;&lt;/a&gt;&lt;font face=Calibri color=#000000 size=3&gt; &lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=9c93a3a3-ff3c-4a78-b273-081242375c0d" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,9c93a3a3-ff3c-4a78-b273-081242375c0d.aspx</comments>
      <category>All Things</category>
      <category>ASP.Net</category>
      <category>CSharp</category>
      <category>Design</category>
      <category>General</category>
      <category>Tips and Tricks</category>
      <category>Web Services</category>
      <category>WinForms</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=98e03a29-d433-4de1-a58a-9d11dd2bd28a</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,98e03a29-d433-4de1-a58a-9d11dd2bd28a.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,98e03a29-d433-4de1-a58a-9d11dd2bd28a.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=98e03a29-d433-4de1-a58a-9d11dd2bd28a</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Once you have data loaded into a DataRow or SqlDataReader, you’d typically do something
like this:
</p>
        <div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">string</span> someValue = (<span style="COLOR: blue">string</span>)drData[<span style="COLOR: #a31515">"MyValue"</span>];
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <font face="Verdana" size="2">In order to place it in the variable, you need to cast
the type correctly (in this example, using the(string)). Also, what happens if “MyValue”
is null?  You’ll need to do an additional check, and then assign the value you
want for the situations where it is null.</font>
          </p>
          <p style="MARGIN: 0px">
            <font face="Verdana" size="2">Today’s tip uses generics to return the correct type.
It also allows you to return a default value if the value is null.</font>
          </p>
          <p style="MARGIN: 0px">
 
</p>
          <div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
            <p style="MARGIN: 0px">
        <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;summary&gt;</span></p>
            <p style="MARGIN: 0px">
        <span style="COLOR: gray">///</span><span style="COLOR: green"> Gets
the data row value.</span></p>
            <p style="MARGIN: 0px">
        <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;/summary&gt;</span></p>
            <p style="MARGIN: 0px">
        <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;typeparam
name="T"&gt;&lt;/typeparam&gt;</span></p>
            <p style="MARGIN: 0px">
        <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;param
name="valueName"&gt;</span><span style="COLOR: green">Name of the value.</span><span style="COLOR: gray">&lt;/param&gt;</span></p>
            <p style="MARGIN: 0px">
        <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;param
name="drData"&gt;</span><span style="COLOR: green">The dr data.</span><span style="COLOR: gray">&lt;/param&gt;</span></p>
            <p style="MARGIN: 0px">
        <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;param
name="defaultValue"&gt;</span><span style="COLOR: green">The default value. Note,
this must be cast to the expected return type. For example, decimal.Parse("0").</span><span style="COLOR: gray">&lt;/param&gt;</span></p>
            <p style="MARGIN: 0px">
        <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;returns&gt;&lt;/returns&gt;</span></p>
            <p style="MARGIN: 0px">
        <span style="COLOR: blue">protected</span> T
GetDataRowValue&lt;T&gt;(<span style="COLOR: blue">string</span> valueName, <span style="COLOR: #2b91af">DataRow</span> drData,
T defaultValue)
</p>
            <p style="MARGIN: 0px">
        {
</p>
            <p style="MARGIN: 0px">
            <span style="COLOR: blue">if</span> (drData[valueName]
== <span style="COLOR: #2b91af">DBNull</span>.Value)
</p>
            <p style="MARGIN: 0px">
                <span style="COLOR: blue">return</span> defaultValue;
</p>
            <p style="MARGIN: 0px">
            <span style="COLOR: blue">else</span></p>
            <p style="MARGIN: 0px">
                <span style="COLOR: blue">return</span> (T)drData[valueName];
</p>
            <p style="MARGIN: 0px">
        }
</p>
            <p style="MARGIN: 0px">
 
</p>
            <p style="MARGIN: 0px">
        <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;summary&gt;</span></p>
            <p style="MARGIN: 0px">
        <span style="COLOR: gray">///</span><span style="COLOR: green"> Gets
the data row value.</span></p>
            <p style="MARGIN: 0px">
        <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;/summary&gt;</span></p>
            <p style="MARGIN: 0px">
        <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;typeparam
name="T"&gt;&lt;/typeparam&gt;</span></p>
            <p style="MARGIN: 0px">
        <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;param
name="valueName"&gt;</span><span style="COLOR: green">Name of the value.</span><span style="COLOR: gray">&lt;/param&gt;</span></p>
            <p style="MARGIN: 0px">
        <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;param
name="drData"&gt;</span><span style="COLOR: green">The dr data.</span><span style="COLOR: gray">&lt;/param&gt;</span></p>
            <p style="MARGIN: 0px">
        <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;param
name="defaultValue"&gt;</span><span style="COLOR: green">The default value. Note,
this must be cast to the expected return type. For example, decimal.Parse("0").</span><span style="COLOR: gray">&lt;/param&gt;</span></p>
            <p style="MARGIN: 0px">
        <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;returns&gt;&lt;/returns&gt;</span></p>
            <p style="MARGIN: 0px">
        <span style="COLOR: blue">protected</span> T
GetDataRowValue&lt;T&gt;(<span style="COLOR: blue">string</span> valueName, <span style="COLOR: #2b91af">SqlDataReader</span> drData,
T defaultValue)
</p>
            <p style="MARGIN: 0px">
        {
</p>
            <p style="MARGIN: 0px">
            <span style="COLOR: blue">if</span> (drData[valueName]
== <span style="COLOR: #2b91af">DBNull</span>.Value)
</p>
            <p style="MARGIN: 0px">
                <span style="COLOR: blue">return</span> defaultValue;
</p>
            <p style="MARGIN: 0px">
            <span style="COLOR: blue">else</span></p>
            <p style="MARGIN: 0px">
                <span style="COLOR: blue">return</span> (T)drData[valueName];
</p>
            <p style="MARGIN: 0px">
        }
</p>
            <p style="MARGIN: 0px">
 
</p>
          </div>
          <!--EndFragment-->
        </div>
        <div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <font face="Verdana" size="2">Here’s
how it’s used. Notice that through the use of generics, one routine can handle multiple
types. </font>
          <p style="MARGIN: 0px">
 
</p>
          <div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
            <p style="MARGIN: 0px">
            <span style="COLOR: blue">int</span> myID
= GetDataRowValue(<span style="COLOR: #a31515">"SomeID"</span>, drData, 0);
</p>
            <p style="MARGIN: 0px">
            <span style="COLOR: #2b91af">DateTime</span> myDate
= GetDataRowValue(<span style="COLOR: #a31515">"SomeDate"</span>, drData, <span style="COLOR: #2b91af">DateTime</span>.Now);
</p>
            <p style="MARGIN: 0px">
            <span style="COLOR: blue">decimal</span> myAmt
= GetDataRowValue(<span style="COLOR: #a31515">"SomeDecimalAmount"</span>, drData, <span style="COLOR: blue">decimal</span>.Parse(<span style="COLOR: #a31515">"0"</span>));
</p>
            <p style="MARGIN: 0px">
            <span style="COLOR: blue">string</span> myString
= GetDataRowValue(<span style="COLOR: #a31515">"SomeString"</span>, drData, <span style="COLOR: #2b91af">String</span>.Empty);
</p>
          </div>
          <p style="MARGIN: 0px">
            <!--EndFragment-->
            <br />
          </p>
        </div>
        <!--EndFragment-->
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=98e03a29-d433-4de1-a58a-9d11dd2bd28a" />
      </body>
      <title>Tip of the Day: Using generics to simplify getting a value from a DataRow or DataReader</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,98e03a29-d433-4de1-a58a-9d11dd2bd28a.aspx</guid>
      <link>http://www.dotnettechnologies.com/2009/10/30/TipOfTheDayUsingGenericsToSimplifyGettingAValueFromADataRowOrDataReader.aspx</link>
      <pubDate>Fri, 30 Oct 2009 04:17:54 GMT</pubDate>
      <description>&lt;p&gt;
Once you have data loaded into a DataRow or SqlDataReader, you’d typically do something
like this:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;string&lt;/span&gt; someValue = (&lt;span style="COLOR: blue"&gt;string&lt;/span&gt;)drData[&lt;span style="COLOR: #a31515"&gt;"MyValue"&lt;/span&gt;];
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;font face=Verdana size=2&gt;In order to place it in the variable, you need to cast the
type correctly (in this example, using the(string)). Also, what happens if “MyValue”
is null?&amp;nbsp; You’ll need to do an additional check, and then assign the value you
want for the situations where it is null.&lt;/font&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;font face=Verdana size=2&gt;Today’s tip uses generics to return the correct type. It
also allows you to return a default value if the value is null.&lt;/font&gt; 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; Gets
the data row value.&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;typeparam
name="T"&amp;gt;&amp;lt;/typeparam&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;param
name="valueName"&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;Name of the value.&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;param
name="drData"&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;The dr data.&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;param
name="defaultValue"&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;The default value. Note,
this must be cast to the expected return type. For example, decimal.Parse("0").&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;protected&lt;/span&gt; T
GetDataRowValue&amp;lt;T&amp;gt;(&lt;span style="COLOR: blue"&gt;string&lt;/span&gt; valueName, &lt;span style="COLOR: #2b91af"&gt;DataRow&lt;/span&gt; drData,
T defaultValue)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (drData[valueName]
== &lt;span style="COLOR: #2b91af"&gt;DBNull&lt;/span&gt;.Value)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; defaultValue;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;else&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; (T)drData[valueName];
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; Gets
the data row value.&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;typeparam
name="T"&amp;gt;&amp;lt;/typeparam&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;param
name="valueName"&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;Name of the value.&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;param
name="drData"&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;The dr data.&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;param
name="defaultValue"&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;The default value. Note,
this must be cast to the expected return type. For example, decimal.Parse("0").&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;protected&lt;/span&gt; T
GetDataRowValue&amp;lt;T&amp;gt;(&lt;span style="COLOR: blue"&gt;string&lt;/span&gt; valueName, &lt;span style="COLOR: #2b91af"&gt;SqlDataReader&lt;/span&gt; drData,
T defaultValue)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (drData[valueName]
== &lt;span style="COLOR: #2b91af"&gt;DBNull&lt;/span&gt;.Value)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; defaultValue;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;else&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; (T)drData[valueName];
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;
&lt;/div&gt;
&lt;div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;&lt;font face=Verdana size=2&gt;Here’s
how it’s used. Notice that through the use of generics, one routine can handle multiple
types. &lt;/font&gt; 
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; myID
= GetDataRowValue(&lt;span style="COLOR: #a31515"&gt;"SomeID"&lt;/span&gt;, drData, 0);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #2b91af"&gt;DateTime&lt;/span&gt; myDate
= GetDataRowValue(&lt;span style="COLOR: #a31515"&gt;"SomeDate"&lt;/span&gt;, drData, &lt;span style="COLOR: #2b91af"&gt;DateTime&lt;/span&gt;.Now);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;decimal&lt;/span&gt; myAmt
= GetDataRowValue(&lt;span style="COLOR: #a31515"&gt;"SomeDecimalAmount"&lt;/span&gt;, drData, &lt;span style="COLOR: blue"&gt;decimal&lt;/span&gt;.Parse(&lt;span style="COLOR: #a31515"&gt;"0"&lt;/span&gt;));
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; myString
= GetDataRowValue(&lt;span style="COLOR: #a31515"&gt;"SomeString"&lt;/span&gt;, drData, &lt;span style="COLOR: #2b91af"&gt;String&lt;/span&gt;.Empty);
&lt;/p&gt;
&lt;/div&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;!--EndFragment--&gt;
&lt;br&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=98e03a29-d433-4de1-a58a-9d11dd2bd28a" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,98e03a29-d433-4de1-a58a-9d11dd2bd28a.aspx</comments>
      <category>All Things</category>
      <category>ASP.Net</category>
      <category>CSharp</category>
      <category>Design</category>
      <category>General</category>
      <category>Tips and Tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=59944df0-d1be-4713-a267-9318e88cf1c1</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,59944df0-d1be-4713-a267-9318e88cf1c1.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,59944df0-d1be-4713-a267-9318e88cf1c1.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=59944df0-d1be-4713-a267-9318e88cf1c1</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
This routine checks the specified minimum and maximum string lengths, and either returns
True/False that it meets those requirements, or could also throw an exception (based
on the throwException parameter value). 
</p>
        <p>
This would also be a good candidate for an extension method. To do so, add a parameter
(in the first position) as “this string”.
</p>
        <div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
        <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;summary&gt;</span></p>
          <p style="MARGIN: 0px">
        <span style="COLOR: gray">///</span><span style="COLOR: green"> Checks
the length of a string to see if it meets the minimum and maximum length</span></p>
          <p style="MARGIN: 0px">
        <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;/summary&gt;</span></p>
          <p style="MARGIN: 0px">
        <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;param
name="checkString"&gt;</span><span style="COLOR: green">string to check</span><span style="COLOR: gray">&lt;/param&gt;</span></p>
          <p style="MARGIN: 0px">
        <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;param
name="minLength"&gt;</span><span style="COLOR: green">minimum string length</span><span style="COLOR: gray">&lt;/param&gt;</span></p>
          <p style="MARGIN: 0px">
        <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;param
name="maxLength"&gt;</span><span style="COLOR: green">maximum string length</span><span style="COLOR: gray">&lt;/param&gt;</span></p>
          <p style="MARGIN: 0px">
        <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;param
name="stringName"&gt;</span><span style="COLOR: green">description of the value to
check</span><span style="COLOR: gray">&lt;/param&gt;</span></p>
          <p style="MARGIN: 0px">
        <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;param
name="throwException"&gt;</span><span style="COLOR: green">T/F to throw an exception
if it exceeds the maximum</span><span style="COLOR: gray">&lt;/param&gt;</span></p>
          <p style="MARGIN: 0px">
        <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;returns&gt;</span><span style="COLOR: green">T/F</span><span style="COLOR: gray">&lt;/returns&gt;</span></p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">public</span><span style="COLOR: blue">static</span><span style="COLOR: blue">bool</span> ValidString(<span style="COLOR: blue">string</span> checkString, <span style="COLOR: blue">int</span> minLength, <span style="COLOR: blue">int</span> maxLength, <span style="COLOR: blue">string</span> stringName, <span style="COLOR: blue">bool</span> throwException)
</p>
          <p style="MARGIN: 0px">
        {
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">if</span> ((checkString.Length
&gt;= minLength) &amp;&amp; (checkString.Length &lt;= maxLength))
</p>
          <p style="MARGIN: 0px">
                <span style="COLOR: blue">return</span><span style="COLOR: blue">true</span>;
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">else</span></p>
          <p style="MARGIN: 0px">
            {
</p>
          <p style="MARGIN: 0px">
                <span style="COLOR: blue">if</span> (checkString.Length
&lt; minLength)
</p>
          <p style="MARGIN: 0px">
                    <span style="COLOR: blue">if</span> (throwException)
</p>
          <p style="MARGIN: 0px">
                   
    <span style="COLOR: blue">throw</span><span style="COLOR: blue">new</span> System.<span style="COLOR: #2b91af">ArgumentOutOfRangeException</span>(<span style="COLOR: #a31515">"The
argument string - "</span> + stringName + <span style="COLOR: #a31515">" was less
than the minimum length."</span>);
</p>
          <p style="MARGIN: 0px">
                    <span style="COLOR: blue">else</span></p>
          <p style="MARGIN: 0px">
                   
    <span style="COLOR: blue">return</span><span style="COLOR: blue">false</span>;
</p>
          <p style="MARGIN: 0px">
                <span style="COLOR: blue">if</span> (checkString.Length
&gt; maxLength)
</p>
          <p style="MARGIN: 0px">
                    <span style="COLOR: blue">if</span> (throwException)
</p>
          <p style="MARGIN: 0px">
                   
    <span style="COLOR: blue">throw</span><span style="COLOR: blue">new</span> System.<span style="COLOR: #2b91af">ArgumentOutOfRangeException</span>(<span style="COLOR: #a31515">"The
length ("</span> + checkString.Length.ToString() + <span style="COLOR: #a31515">")
of argument string - "</span> + stringName + <span style="COLOR: #a31515">" was longer
than the expected length("</span> + maxLength.ToString() + <span style="COLOR: #a31515">")."</span>);
</p>
          <p style="MARGIN: 0px">
                    <span style="COLOR: blue">else</span></p>
          <p style="MARGIN: 0px">
                   
    <span style="COLOR: blue">return</span><span style="COLOR: blue">false</span>;
</p>
          <p style="MARGIN: 0px">
                <span style="COLOR: blue">return</span><span style="COLOR: blue">false</span>;
</p>
          <p style="MARGIN: 0px">
            }
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
        }
</p>
          <p style="MARGIN: 0px">
 
</p>
        </div>
        <!--EndFragment-->
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=59944df0-d1be-4713-a267-9318e88cf1c1" />
      </body>
      <title>Tip of the day: Validate string meets length requirements</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,59944df0-d1be-4713-a267-9318e88cf1c1.aspx</guid>
      <link>http://www.dotnettechnologies.com/2009/10/28/TipOfTheDayValidateStringMeetsLengthRequirements.aspx</link>
      <pubDate>Wed, 28 Oct 2009 04:09:54 GMT</pubDate>
      <description>&lt;p&gt;
This routine checks the specified minimum and maximum string lengths, and either returns
True/False that it meets those requirements, or could also throw an exception (based
on the throwException parameter value). 
&lt;/p&gt;
&lt;p&gt;
This would also be a good candidate for an extension method. To do so, add a parameter
(in the first position) as “this string”.
&lt;/p&gt;
&lt;div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; Checks
the length of a string to see if it meets the minimum and maximum length&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;param
name="checkString"&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;string to check&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;param
name="minLength"&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;minimum string length&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;param
name="maxLength"&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;maximum string length&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;param
name="stringName"&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;description of the value to
check&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;param
name="throwException"&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;T/F to throw an exception
if it exceeds the maximum&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;returns&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;T/F&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/returns&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;static&lt;/span&gt; &lt;span style="COLOR: blue"&gt;bool&lt;/span&gt; ValidString(&lt;span style="COLOR: blue"&gt;string&lt;/span&gt; checkString, &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; minLength, &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; maxLength, &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; stringName, &lt;span style="COLOR: blue"&gt;bool&lt;/span&gt; throwException)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; ((checkString.Length
&amp;gt;= minLength) &amp;amp;&amp;amp; (checkString.Length &amp;lt;= maxLength))
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; &lt;span style="COLOR: blue"&gt;true&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;else&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (checkString.Length
&amp;lt; minLength)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (throwException)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;throw&lt;/span&gt; &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; System.&lt;span style="COLOR: #2b91af"&gt;ArgumentOutOfRangeException&lt;/span&gt;(&lt;span style="COLOR: #a31515"&gt;"The
argument string - "&lt;/span&gt; + stringName + &lt;span style="COLOR: #a31515"&gt;" was less
than the minimum length."&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;else&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; &lt;span style="COLOR: blue"&gt;false&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (checkString.Length
&amp;gt; maxLength)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (throwException)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;throw&lt;/span&gt; &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; System.&lt;span style="COLOR: #2b91af"&gt;ArgumentOutOfRangeException&lt;/span&gt;(&lt;span style="COLOR: #a31515"&gt;"The
length ("&lt;/span&gt; + checkString.Length.ToString() + &lt;span style="COLOR: #a31515"&gt;")
of argument string - "&lt;/span&gt; + stringName + &lt;span style="COLOR: #a31515"&gt;" was longer
than the expected length("&lt;/span&gt; + maxLength.ToString() + &lt;span style="COLOR: #a31515"&gt;")."&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;else&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; &lt;span style="COLOR: blue"&gt;false&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; &lt;span style="COLOR: blue"&gt;false&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=59944df0-d1be-4713-a267-9318e88cf1c1" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,59944df0-d1be-4713-a267-9318e88cf1c1.aspx</comments>
      <category>All Things</category>
      <category>ASP.Net</category>
      <category>CSharp</category>
      <category>Design</category>
      <category>General</category>
      <category>Tips and Tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=11d51691-b09f-4422-aaa5-15a7bf2b628c</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,11d51691-b09f-4422-aaa5-15a7bf2b628c.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,11d51691-b09f-4422-aaa5-15a7bf2b628c.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=11d51691-b09f-4422-aaa5-15a7bf2b628c</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
When starting a project, I always recommend inheriting objects from a base object,
regardless of whether you know you'll need it or not. Usually, they will contain common
functionality like error handling, debugging or other common methods which you'll
use over and over.
</p>
        <p>
In WinForms, however, this can cause a problem if you make the base form an abstract
class (another thing I recommend).  For example, take this simple form:
</p>
        <p>
 
</p>
        <p>
          <img src="http://www.dotnettechnologies.com/content/binary/FormExample.png" border="0" />
        </p>
        <p>
Now let's say I decide to derive this form from an abstract base class, which I will
call BaseForm:
</p>
        <div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: #2b91af">    5</span> <span style="COLOR: blue">using</span> System.Windows.Forms;
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #2b91af">    6</span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #2b91af">    7</span> <span style="COLOR: blue">namespace</span> TestForm
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #2b91af">    8</span> {
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #2b91af">    9</span>     <span style="COLOR: blue">public</span><span style="COLOR: blue">abstract</span><span style="COLOR: blue">class</span><span style="COLOR: #2b91af">BaseForm</span> : <span style="COLOR: #2b91af">Form</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #2b91af">   10</span>     {
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #2b91af">   11</span>         <span style="COLOR: blue">protected</span><span style="COLOR: blue">void</span> SomeCommonMethod()
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #2b91af">   12</span>        
{
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #2b91af">   13</span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #2b91af">   14</span>        
}
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #2b91af">   15</span>     }
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #2b91af">   16</span> }
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <font face="Verdana" size="2">When I go to edit the UI again, I see this, and it scares
the heck out of me (looks scarier in VS2005)....</font>
          </p>
          <p style="MARGIN: 0px">
            <font face="Verdana" size="2">
            </font>
            <img src="http://www.dotnettechnologies.com/content/binary/ErrorPage1.png" border="0" />
          </p>
          <p style="MARGIN: 0px">
            <!--EndFragment-->
          </p>
        </div>
        <p>
What this is telling you is that it can't render an abstract class BaseForm. So while
you are creating the application, you might remove the abstract identifier
from UI related base classes (with a note that they should be inherited from, not
used, as well as a /TODO marker to make sure you mark it as abstract before deployment). 
</p>
        <p>
Doing this will allow you to inherit from a base class while at the same time edit
the UI.
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=11d51691-b09f-4422-aaa5-15a7bf2b628c" />
      </body>
      <title>Tip of the Day: Winform: Displaying the form derived from a base class</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,11d51691-b09f-4422-aaa5-15a7bf2b628c.aspx</guid>
      <link>http://www.dotnettechnologies.com/2009/10/14/TipOfTheDayWinformDisplayingTheFormDerivedFromABaseClass.aspx</link>
      <pubDate>Wed, 14 Oct 2009 05:27:16 GMT</pubDate>
      <description>&lt;p&gt;
When starting a project, I always recommend inheriting objects from a base object,
regardless of whether you know you'll need it or not. Usually, they will contain common
functionality like error handling, debugging or other common methods which you'll
use over and over.
&lt;/p&gt;
&lt;p&gt;
In WinForms, however, this can cause a problem if you make the base form an abstract
class (another thing I recommend).&amp;nbsp; For example, take this simple form:
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://www.dotnettechnologies.com/content/binary/FormExample.png" border=0&gt;
&lt;/p&gt;
&lt;p&gt;
Now let's say I decide to derive this form from an abstract base class, which I will
call BaseForm:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;5&lt;/span&gt;&amp;nbsp;&lt;span style="COLOR: blue"&gt;using&lt;/span&gt; System.Windows.Forms;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;6&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;7&lt;/span&gt;&amp;nbsp;&lt;span style="COLOR: blue"&gt;namespace&lt;/span&gt; TestForm
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;8&lt;/span&gt;&amp;nbsp;{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;9&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;abstract&lt;/span&gt; &lt;span style="COLOR: blue"&gt;class&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;BaseForm&lt;/span&gt; : &lt;span style="COLOR: #2b91af"&gt;Form&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;10&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;11&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;protected&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; SomeCommonMethod()
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;12&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;13&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;14&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;15&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;16&lt;/span&gt;&amp;nbsp;}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;font face=Verdana size=2&gt;When I go to edit the UI again, I see this, and it scares
the heck out of me (looks scarier in VS2005)....&lt;/font&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;font face=Verdana size=2&gt;&lt;/font&gt;&lt;img src="http://www.dotnettechnologies.com/content/binary/ErrorPage1.png" border=0&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;!--EndFragment--&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
What this is telling you is that it can't render an abstract class BaseForm. So while
you are creating the application, you might&amp;nbsp;remove the abstract&amp;nbsp;identifier
from UI related base classes (with a note that they should be inherited from, not
used, as well as a /TODO marker to make sure you mark it as abstract before deployment). 
&lt;/p&gt;
&lt;p&gt;
Doing this will allow you to inherit from a base class while at the same time edit
the UI.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=11d51691-b09f-4422-aaa5-15a7bf2b628c" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,11d51691-b09f-4422-aaa5-15a7bf2b628c.aspx</comments>
      <category>All Things</category>
      <category>C#</category>
      <category>CSharp</category>
      <category>Design</category>
      <category>General</category>
      <category>Tips and Tricks</category>
      <category>Windows</category>
      <category>WinForms</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=a371e8a5-64e8-4e1c-9dd5-cd4a67243da8</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,a371e8a5-64e8-4e1c-9dd5-cd4a67243da8.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,a371e8a5-64e8-4e1c-9dd5-cd4a67243da8.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=a371e8a5-64e8-4e1c-9dd5-cd4a67243da8</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
When using master pages, there are times when you want to access part of the Master
Page (e.g. a public property). One way of doing this is by defining the master page
with the MasterType directive.
</p>
        <p>
&lt;%@ MasterType VirtualPath="~/MyMasterPage.master"%&gt;
</p>
        <p>
By doing this, you can now access the MasterPage as a class Master, and programatically
(and with the benefits of compilation checking) access it.
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=a371e8a5-64e8-4e1c-9dd5-cd4a67243da8" />
      </body>
      <title>Tip of the Day: Directly accessing a Master Page</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,a371e8a5-64e8-4e1c-9dd5-cd4a67243da8.aspx</guid>
      <link>http://www.dotnettechnologies.com/2009/09/29/TipOfTheDayDirectlyAccessingAMasterPage.aspx</link>
      <pubDate>Tue, 29 Sep 2009 04:34:35 GMT</pubDate>
      <description>&lt;p&gt;
When using master pages, there are times when you want to access part of the Master
Page (e.g. a public property). One way of doing this is by defining the master page
with the MasterType directive.
&lt;/p&gt;
&lt;p&gt;
&amp;lt;%@ MasterType VirtualPath="~/MyMasterPage.master"%&amp;gt;
&lt;/p&gt;
&lt;p&gt;
By doing this, you can now access the MasterPage as a class Master, and programatically
(and with the benefits of compilation checking) access it.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=a371e8a5-64e8-4e1c-9dd5-cd4a67243da8" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,a371e8a5-64e8-4e1c-9dd5-cd4a67243da8.aspx</comments>
      <category>All Things</category>
      <category>ASP.Net</category>
      <category>CSharp</category>
      <category>Design</category>
      <category>General</category>
      <category>Tips and Tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=48a3579a-9701-429e-9f5f-55e0faa9f6c3</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,48a3579a-9701-429e-9f5f-55e0faa9f6c3.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,48a3579a-9701-429e-9f5f-55e0faa9f6c3.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=48a3579a-9701-429e-9f5f-55e0faa9f6c3</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
It's time I got back to the interviewing tips as well. So here's an OOP question a
suprising number of candidates miss:
</p>
        <p>
          <strong>Question: </strong>In C#, what's the <em>virtual</em> keywork used for. 
</p>
        <p>
          <strong>Answer: </strong>A method marked virtual has an implementation, but inheriting
objects may override the implementation and provide their own implementation. This
differs from the <em>abstract</em> keyword in that the base class does not have an
implementation, and the deriving class <strong>must</strong> provide an implementation.
</p>
        <p>
This is a key concept to object-oriented programming. If you missed this one, you
can get more information on <a href="http://msdn.microsoft.com/en-us/library/9fkccyh4(VS.80).aspx" target="_blank">Microsoft's
MSDN site</a>.
</p>
        <p>
 
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=48a3579a-9701-429e-9f5f-55e0faa9f6c3" />
      </body>
      <title>Interviewing Question of the Day: Virtual Keyword</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,48a3579a-9701-429e-9f5f-55e0faa9f6c3.aspx</guid>
      <link>http://www.dotnettechnologies.com/2009/09/23/InterviewingQuestionOfTheDayVirtualKeyword.aspx</link>
      <pubDate>Wed, 23 Sep 2009 04:45:06 GMT</pubDate>
      <description>&lt;p&gt;
It's time I got back to the interviewing tips as well. So here's an OOP question a
suprising number of&amp;nbsp;candidates miss:
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Question: &lt;/strong&gt;In C#, what's the &lt;em&gt;virtual&lt;/em&gt; keywork used for. 
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Answer: &lt;/strong&gt;A method marked virtual has an implementation, but inheriting
objects may override the implementation and provide their own implementation. This
differs from the &lt;em&gt;abstract&lt;/em&gt; keyword in that the base class does not have an
implementation, and the deriving class &lt;strong&gt;must&lt;/strong&gt; provide an implementation.
&lt;/p&gt;
&lt;p&gt;
This is a key concept to object-oriented programming. If you missed this one, you
can get more information on &lt;a href="http://msdn.microsoft.com/en-us/library/9fkccyh4(VS.80).aspx" target=_blank&gt;Microsoft's
MSDN site&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=48a3579a-9701-429e-9f5f-55e0faa9f6c3" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,48a3579a-9701-429e-9f5f-55e0faa9f6c3.aspx</comments>
      <category>All Things</category>
      <category>CSharp</category>
      <category>Design</category>
      <category>General</category>
      <category>Tips and Tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=36655dbd-218c-4fcb-b596-e118b6130507</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,36655dbd-218c-4fcb-b596-e118b6130507.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,36655dbd-218c-4fcb-b596-e118b6130507.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=36655dbd-218c-4fcb-b596-e118b6130507</wfw:commentRss>
      <title>Looking into Microsoft Expression -- A design tool</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,36655dbd-218c-4fcb-b596-e118b6130507.aspx</guid>
      <link>http://www.dotnettechnologies.com/2009/09/05/LookingIntoMicrosoftExpressionADesignTool.aspx</link>
      <pubDate>Sat, 05 Sep 2009 15:55:17 GMT</pubDate>
      <description>&lt;p&gt;
As I was looking through &lt;a href="http://www.hanselman.com/blog/ScottHanselmans2009UltimateDeveloperAndPowerUsersToolListForWindows.aspx" target=_blank&gt;Scott
Hanselman's List of Tools for&amp;nbsp;2009&lt;/a&gt;, I saw a reference for &lt;a href="http://www.microsoft.com/expression/" target-?_blank?&gt;Microsoft's
Sketchflow&lt;/a&gt;&amp;nbsp;(part of Microsoft Expression), which allows you to design (among
other things) and work through ideas prior to coding. I am going to check it out this
weekend, and maybe some of the alternate tools he recommended for his post.&amp;nbsp;
I might even have to dust off my Table PC, as it seems like a good combination.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=36655dbd-218c-4fcb-b596-e118b6130507" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,36655dbd-218c-4fcb-b596-e118b6130507.aspx</comments>
      <category>All Things</category>
      <category>CSharp</category>
      <category>Design</category>
      <category>General</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=27255803-b360-4bd0-ba4f-3382811b3ada</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,27255803-b360-4bd0-ba4f-3382811b3ada.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,27255803-b360-4bd0-ba4f-3382811b3ada.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=27255803-b360-4bd0-ba4f-3382811b3ada</wfw:commentRss>
      <title>Tip of the Day: A brief explanation of extension methods</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,27255803-b360-4bd0-ba4f-3382811b3ada.aspx</guid>
      <link>http://www.dotnettechnologies.com/2009/09/04/TipOfTheDayABriefExplanationOfExtensionMethods.aspx</link>
      <pubDate>Fri, 04 Sep 2009 05:10:29 GMT</pubDate>
      <description>&lt;p class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;There’s a very powerful feature in .Net 3.5
called extension methods. In an earlier blog, I used an extension method in my LINQ
to XML to format the date retrieved from an RSS feed. If you’re new to the 3.5 framework,
you may be wondering what the big deal is.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;As a consultant, I have to look at a lot of
old and 3&lt;sup&gt;rd&lt;/sup&gt; party code. There are times when I don’t have access to the
source code, and I need to add some additional functionality to a class. If I can
inherit from the base class, I can just inherit the class and extend it. But what
do I do if the class is sealed? Prior to .et 3.5, my options were limited and certainly
not as object oriented. I’d have to write some type of wrapper of common function
to create the functionality.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;As an example, let’s say I wanted to extend
string with some additional functionality, such as adding in functionality to reverse
a string easily. I create my new class, and try to inherit from the String class,
but I get a compilation error. Let’s look at the definition of the String class in
.Net:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="BACKGROUND: #dddddd; MARGIN: 0in 0in 0pt; VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: normal; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt"&gt;
&lt;span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'; mso-fareast-font-family: 'Times New Roman'"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;[SerializableAttribute]&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="BACKGROUND: #dddddd; MARGIN: 0in 0in 0pt; VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: normal; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt"&gt;
&lt;span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'; mso-fareast-font-family: 'Times New Roman'"&gt;[ComVisibleAttribute(&lt;/span&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-fareast-font-family: 'Times New Roman'"&gt;true&lt;/span&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'; mso-fareast-font-family: 'Times New Roman'"&gt;)]&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="BACKGROUND: #dddddd; MARGIN: 0in 0in 0pt; VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: normal; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt"&gt;
&lt;span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-fareast-font-family: 'Times New Roman'"&gt;public&lt;/span&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'; mso-fareast-font-family: 'Times New Roman'"&gt; sealed &lt;/span&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-fareast-font-family: 'Times New Roman'"&gt;class&lt;/span&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'; mso-fareast-font-family: 'Times New Roman'"&gt; String
: IComparable, 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="BACKGROUND: #dddddd; MARGIN: 0in 0in 0pt; VERTICAL-ALIGN: top; WORD-BREAK: break-all; LINE-HEIGHT: normal; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt"&gt;
&lt;span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'; mso-fareast-font-family: 'Times New Roman'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;ICloneable,
IConvertible, IComparable&amp;lt;&lt;/span&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-fareast-font-family: 'Times New Roman'"&gt;string&lt;/span&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'; mso-fareast-font-family: 'Times New Roman'"&gt;&amp;gt;,
IEnumerable&amp;lt;&lt;/span&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-fareast-font-family: 'Times New Roman'"&gt;char&lt;/span&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 'Courier New'; mso-fareast-font-family: 'Times New Roman'"&gt;&amp;gt;, 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;
&lt;span style="FONT-SIZE: 12pt; COLOR: black; LINE-HEIGHT: 115%; FONT-FAMILY: 'Times New Roman','serif'; mso-fareast-font-family: 'Times New Roman'"&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;IEnumerable,
IEquatable&amp;lt;&lt;/span&gt;&lt;span style="FONT-SIZE: 12pt; COLOR: blue; LINE-HEIGHT: 115%; FONT-FAMILY: 'Times New Roman','serif'; mso-fareast-font-family: 'Times New Roman'"&gt;string&lt;/span&gt;&lt;span style="FONT-SIZE: 12pt; COLOR: black; LINE-HEIGHT: 115%; FONT-FAMILY: 'Times New Roman','serif'; mso-fareast-font-family: 'Times New Roman'"&gt;&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;Because the class is sealed, I can’t inherit
from it. Prior to .Net 3.5, I am going to have to create a function and pass in the
string. By using extension methods, I am no longer restricted by the “sealed” keywords. &lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
Reverses the specified string.&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;param name="s"&amp;gt;The string to reverse.&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;returns&amp;gt;Reversed string&amp;lt;/returns&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;static&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt; Reverse(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;this&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt; s)&lt;br&gt;
{&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;char&lt;/span&gt;[]
arr &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; s.ToCharArray();&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;Array.Reverse(arr);&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;new&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt;(arr);&lt;br&gt;
}&lt;/span&gt;
&lt;/p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt; 
&lt;p class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;
&lt;font face=Calibri size=3&gt;The code above extends any string with a new Reverse function,
which reverses the referenced string. Here’s how it is used:&lt;/font&gt;
&lt;/p&gt;
&lt;font face=Calibri size=3&gt; 
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt; testString &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"MyString"&lt;/span&gt;;&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt; reversedString &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; testString.Reverse();&lt;br&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;
The new reverse function shows up in Intellisense for any string, which helps speed
up coding as well.
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;
So how did this work? It’s all in the definition. First, the class and the function
has to be defined as static. Second, the first parameter must begin with &lt;i style="mso-bidi-font-style: normal"&gt;this&lt;/i&gt; and
is a reference to the type this method extends.
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;
There are some restrictions to static methods. For example, the extension method can
only access public methods of the referenced class. &lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;
Below are some more examples of extending the string class with some additional functionality.
A couple of days ago, I posted some examples of getting values from a DataRow safely.
This would be another great refactor opportunity to extend the DataRow class to provide
this functionality right from the DataRow itself.
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;using&lt;/span&gt; System;&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;using&lt;/span&gt; System.Globalization;&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;using&lt;/span&gt; System.Text.RegularExpressions;&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;using&lt;/span&gt; System.Threading;&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;namespace&lt;/span&gt; Rubicon.Common&lt;br&gt;
{&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;static&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;class&lt;/span&gt; StringExtensions&lt;br&gt;
{&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
Reverses the specified string.&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;param name="s"&amp;gt;The string to reverse.&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;returns&amp;gt;Reversed string&amp;lt;/returns&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;static&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt; Reverse(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;this&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt; s)&lt;br&gt;
{&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;char&lt;/span&gt;[]
arr &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; s.ToCharArray();&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;Array.Reverse(arr);&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;new&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt;(arr);&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
Converts the string to title case.&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;param name="s"&amp;gt;The string to convert.&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;returns&amp;gt;A title case string.&amp;lt;/returns&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;static&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt; ToTitleCase(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;this&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt; s)&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;CultureInfo ci &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; Thread.CurrentThread.CurrentCulture;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;TextInfo ti &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; ci.TextInfo;&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&lt;/span&gt; ti.ToTitleCase(s);&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
Returns true if string is over the specified max length&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;param name="s"&amp;gt;The string to check.&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;param name="maxLength"&amp;gt;max length.&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;static&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;bool&lt;/span&gt; OverMaxLength(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;this&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt; s, &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;int&lt;/span&gt; maxLength)&lt;br&gt;
{&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&lt;/span&gt; (s.Length
&amp;lt;= maxLength);&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
Returns true if string is under the specified min length&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;param name="s"&amp;gt;The string to check.&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;param name="minLength"&amp;gt;min length&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;static&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;bool&lt;/span&gt; UnderMinLength(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;this&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt; s, &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;int&lt;/span&gt; minLength)&lt;br&gt;
{&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&lt;/span&gt; (s.Length
&amp;lt;= minLength);&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
Checks the length of the string to make sure it is within the set bounds.&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;param name="s"&amp;gt;The string to check.&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;param name="minLength"&amp;gt;min length&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;param name="maxLength"&amp;gt;max length&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;static&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;bool&lt;/span&gt; WithinValidLength(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;this&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt; s, &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;int&lt;/span&gt; minLength, &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;int&lt;/span&gt; maxLength)&lt;br&gt;
{&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&lt;/span&gt; ((s.Length
&amp;gt;= minLength) &amp;amp;&amp;amp; (s.Length &amp;lt;= maxLength));&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
Determines whether the string is alpahbetic only.&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;param name="s"&amp;gt;The string to check.&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;returns&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;c&amp;gt;true&amp;lt;/c&amp;gt; if [is alpha only] [the specified
s]; otherwise, &amp;lt;c&amp;gt;false&amp;lt;/c&amp;gt;.&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;/returns&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;static&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;bool&lt;/span&gt; IsAlphaOnly(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;this&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt; s)&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;Regex regPattern &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;new&lt;/span&gt; Regex(&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"[^a-zA-Z]"&lt;/span&gt;);&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&lt;/span&gt; !regPattern.IsMatch(s);&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
Determines whether the string is alphanumeric.&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;param name="s"&amp;gt;The string to check.&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;returns&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;c&amp;gt;true&amp;lt;/c&amp;gt; if [is alpha numeric] [the specified
s]; otherwise, &amp;lt;c&amp;gt;false&amp;lt;/c&amp;gt;.&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;///
&amp;lt;/returns&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;static&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;bool&lt;/span&gt; IsAlphaNumeric(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;this&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;string&lt;/span&gt; s)&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;Regex regPattern &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;=&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;new&lt;/span&gt; Regex(&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"[^a-zA-Z0-9]"&lt;/span&gt;);&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;return&lt;/span&gt; !regPattern.IsMatch(s); 
&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
}&lt;br&gt;
}&lt;/span&gt;
&lt;/p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt; 
&lt;p class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;
&lt;font face=Calibri size=3&gt;Extension methods are a very powerful tool, and enhance
OOP concepts like encapsulation. They will help you organize your code, and extend
the functionality of classes previously you could not modify. I obtained my first
taste of &lt;a href="http://www.amazon.com/Pro-LINQ-Language-Integrated-Windows-Net/dp/1590597893/ref=sr_1_1?ie=UTF8&amp;amp;s=books&amp;amp;qid=1252017727&amp;amp;sr=8-1" target=_blank&gt;Extension
Methods in this book&lt;/a&gt; as I was learning LINQ, and I highly recommend it.&lt;/font&gt;
&lt;br&gt;
&lt;/p&gt;
&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=27255803-b360-4bd0-ba4f-3382811b3ada" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,27255803-b360-4bd0-ba4f-3382811b3ada.aspx</comments>
      <category>All Things</category>
      <category>CSharp</category>
      <category>Design</category>
      <category>General</category>
      <category>Tips and Tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=13f9d0b3-d92b-4787-b147-c379333b39a0</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,13f9d0b3-d92b-4787-b147-c379333b39a0.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,13f9d0b3-d92b-4787-b147-c379333b39a0.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=13f9d0b3-d92b-4787-b147-c379333b39a0</wfw:commentRss>
      <title>Starting new projects.. how to approach it?</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,13f9d0b3-d92b-4787-b147-c379333b39a0.aspx</guid>
      <link>http://www.dotnettechnologies.com/2009/09/03/StartingNewProjectsHowToApproachIt.aspx</link>
      <pubDate>Thu, 03 Sep 2009 19:41:58 GMT</pubDate>
      <description>&lt;p class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;Next week, I’ll be starting a new project,
which is always exciting for me. In this case, it will be a WinForms application,
which I really enjoy working on.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Since
everything is more web-oriented these days, there just aren’t as many WinForms projects.
In fact, I haven’t done one in about two years where I built an application for a
major phone system manufacturer which takes Oracle data/Excel spreadsheets, imports
the data and generates a PDF price list.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;I know a lot of people dread deployment of
WinForm apps, which is one of many reasons web development has taken off. From my
perspective, it’s an even trade because web development has many challenges.. scalability,
security, browser compatibility, etc. Mostly, since WinForm apps are so rare these
days, it’s going to be a fun contract to do something different for a change.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;But that’s not the point of this post. I was
thinking about how I approach a new project (in this case, it’s a re-write of an older
application) and what I do to get it started. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;In this case, it will look something like
this:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoListParagraphCxSpFirst style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l1 level1 lfo1"&gt;
&lt;font color=#000000&gt;&lt;span style="FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3&gt;·&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Calibri size=3&gt;Get
oriented (passwords, system information, high-level project overview)&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoListParagraphCxSpMiddle style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l1 level1 lfo1"&gt;
&lt;font color=#000000&gt;&lt;span style="FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3&gt;·&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Calibri size=3&gt;Get
the environment set up&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoListParagraphCxSpLast style="MARGIN: 0in 0in 10pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l1 level1 lfo1"&gt;
&lt;font color=#000000&gt;&lt;span style="FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3&gt;·&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Calibri size=3&gt;Get
a high level view of what the project entails&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;From there, it’s time to dig in. In this case
it’s a re-write, so one of the many questions I ask will be to find out what was lacking
or has changed since the first application, and what the new desired features are.
Ultimately, this may entail a semi-working prototype. I’ll also want to familiarize
myself with how the old application works. This is important, as most people don’t
like a lot of change unless it really improves the process, so it’s good to understand
how they currently use it, and how they &lt;i style="mso-bidi-font-style: normal"&gt;want&lt;/i&gt; to
use it. You need end user buy-in to be successful, so it’s important that any change
you make will be accepted.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;So now we get to designing and ultimately
coding. It usually involves a few things:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoListParagraphCxSpFirst style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo2"&gt;
&lt;font color=#000000&gt;&lt;span style="FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3&gt;·&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Calibri size=3&gt;Architecting
the application&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoListParagraphCxSpMiddle style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo2"&gt;
&lt;font color=#000000&gt;&lt;span style="FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3&gt;·&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Calibri size=3&gt;Data
Mining/design&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoListParagraphCxSpMiddle style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo2"&gt;
&lt;font color=#000000&gt;&lt;span style="FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3&gt;·&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Calibri size=3&gt;Designing
tests&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoListParagraphCxSpMiddle style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo2"&gt;
&lt;font color=#000000&gt;&lt;span style="FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3&gt;·&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Calibri size=3&gt;Deployment
Strategy&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoListParagraphCxSpMiddle style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo2"&gt;
&lt;font color=#000000&gt;&lt;span style="FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3&gt;·&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Calibri size=3&gt;Post-deployment
support&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoListParagraphCxSpLast style="MARGIN: 0in 0in 10pt 0.5in; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo2"&gt;
&lt;font color=#000000&gt;&lt;span style="FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol"&gt;&lt;span style="mso-list: Ignore"&gt;&lt;font size=3&gt;·&lt;/font&gt;&lt;span style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font face=Calibri size=3&gt;Documentation&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;To architect the application, I need to see
if there are any existing architectures in place. Very rarely am I given free reign
to build the data access layer, but it does happen. A lot of contractors really push
this, or ignore current architectures, but that’s a mistake. I say this because you
need to leave an application which your client can support. If I do change the existing
practices in place, I make sure I know WHY, communicate it and document it. &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;Now come the tools. Some clients won’t allow
you to bring your own software licenses. In that case, I may have to do a CodeSmith
demo to help justify the purchase of the tool. I’ll look for opportunities to generate
code and speed up development. I have had a LOT of push back on that from other contractors
though, in that they feel you are losing billable time by generating all that code,
but I disagree.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;First, as a consultant,
I feel I have a duty to save my client money and time where I can. Second, when you
do quality work and it’s fast, I assure you that you’ll be either getting more projects
or called back. In my 13 years of consulting,&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;almost
every client I have has brought me back for subsequent projects for that exact reason.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;
&lt;font size=3&gt;&lt;font color=#000000&gt;&lt;font face=Calibri&gt;I also bring things like my data
mining queries in my other blog posts which help find what I need to find quickly.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;What tools/techniques do you use?&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;
&lt;o:p&gt;
&lt;font face=Calibri color=#000000 size=3&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=13f9d0b3-d92b-4787-b147-c379333b39a0" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,13f9d0b3-d92b-4787-b147-c379333b39a0.aspx</comments>
      <category>All Things</category>
      <category>CSharp</category>
      <category>Design</category>
      <category>General</category>
      <category>Tips and Tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=28e48f37-06e8-4ef1-9abc-b2a44a34dcdf</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,28e48f37-06e8-4ef1-9abc-b2a44a34dcdf.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,28e48f37-06e8-4ef1-9abc-b2a44a34dcdf.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=28e48f37-06e8-4ef1-9abc-b2a44a34dcdf</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Earlier today, I blogged an interview question about reflection. Earlier this year,
as part of the interviewing process I was tasked to write a simple calculator. There
would only be 2 integer inputs with a single operation. For example, if the invoked
the program, and entered in 1 U 2 (U being the operation for addition), the program
would output 3. 
</p>
        <p>
The assignment also mentioned they would want the possibility to expand the operations
later. Instead of just commenting on it, I decided to implement that into the design.
</p>
        <p>
I won't go into retrieving the data from command prompt, but I will provide the project
at the end and you can see how that is accomplished. I made it robust by accounting
for spaces, etc. As a programming concept, you should always program defensively and
assume the work (and you'll be glad with the results).
</p>
        <p>
First, I created a base class each operand would inherit from, so that each works
similarly. The base class <em>OperationBase</em> looks like this:
</p>
        <div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">using</span> System.Diagnostics;
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">namespace</span> CalcLibrary
</p>
          <p style="MARGIN: 0px">
{
</p>
          <p style="MARGIN: 0px">
    [<span style="COLOR: #2b91af">OperatorIndex</span>(<span style="COLOR: #a31515">""</span>)]
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">abstract</span><span style="COLOR: blue">class</span><span style="COLOR: #2b91af">OperationBase</span></p>
          <p style="MARGIN: 0px">
    {
</p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">private</span><span style="COLOR: blue">int</span> value1;
</p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">private</span><span style="COLOR: blue">int</span> value2;
</p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">private</span><span style="COLOR: blue">string</span> errorInformation
= <span style="COLOR: #2b91af">String</span>.Empty;
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">public</span><span style="COLOR: blue">int</span> Value1
</p>
          <p style="MARGIN: 0px">
        {
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">get</span> { <span style="COLOR: blue">return</span> value1;
}
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">set</span> {
value1 = <span style="COLOR: blue">value</span>; }
</p>
          <p style="MARGIN: 0px">
        }
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">public</span><span style="COLOR: blue">int</span> Value2
</p>
          <p style="MARGIN: 0px">
        {
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">get</span> { <span style="COLOR: blue">return</span> value2;
}
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">set</span> {
value2 = <span style="COLOR: blue">value</span>; }
</p>
          <p style="MARGIN: 0px">
        }
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">public</span><span style="COLOR: blue">string</span> ErrorInformation
</p>
          <p style="MARGIN: 0px">
        {
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">get</span> { <span style="COLOR: blue">return</span> errorInformation;
}
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">private</span><span style="COLOR: blue">set</span> {
errorInformation = <span style="COLOR: blue">value</span>; }
</p>
          <p style="MARGIN: 0px">
        }
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
        <span style="COLOR: green">//NOTE: We may want
to return a string as the division will round every time, but we will keep this as
an int</span></p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">public</span><span style="COLOR: blue">abstract</span><span style="COLOR: blue">int</span> Calculate();
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">protected</span><span style="COLOR: blue">void</span> ErrorHandler(<span style="COLOR: #2b91af">Exception</span> ex)
</p>
          <p style="MARGIN: 0px">
        {
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">try</span></p>
          <p style="MARGIN: 0px">
            {
</p>
          <p style="MARGIN: 0px">
                <span style="COLOR: green">//While
in a production app we would want to hide the internals of an error, in this app we
will show them</span></p>
          <p style="MARGIN: 0px">
                <span style="COLOR: blue">this</span>.ErrorInformation
= <span style="COLOR: #a31515">"An unexpected error occurred ("</span> + <span style="COLOR: blue">new</span><span style="COLOR: #2b91af">StackTrace</span>().GetFrame(2).GetMethod().Name
+ <span style="COLOR: #a31515">")-"</span> + ex.Message;
</p>
          <p style="MARGIN: 0px">
            }
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">catch</span> 
{}
</p>
          <p style="MARGIN: 0px">
        }
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
    }
</p>
          <p style="MARGIN: 0px">
}
</p>
          <p style="MARGIN: 0px">
            <font face="Verdana" size="2">You'll notice this abstract class defines taking two
int inputs (Value1 and Value2), handles the errors, and forces every implementation
to provide a definition of the "Calculate" method. When inheriting from this class, any
operand will be very simple to define -- all it needs to do is determine what to do
for a Calculation, as seen by the addition operand implementation.</font>
          </p>
          <p style="MARGIN: 0px">
            <font face="Verdana" size="2">
            </font> 
</p>
          <font face="Verdana" size="2">
            <div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
              <p style="MARGIN: 0px">
                <span style="COLOR: blue">namespace</span> CalcLibrary
</p>
              <p style="MARGIN: 0px">
{
</p>
              <p style="MARGIN: 0px">
    [<span style="COLOR: #2b91af">OperatorIndex</span>(<span style="COLOR: #a31515">"U"</span>)]
</p>
              <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">class</span><span style="COLOR: #2b91af">AdditionOperand</span> : <span style="COLOR: #2b91af">OperationBase</span></p>
              <p style="MARGIN: 0px">
    {
</p>
              <p style="MARGIN: 0px">
        <span style="COLOR: blue">public</span><span style="COLOR: blue">override</span><span style="COLOR: blue">int</span> Calculate()
</p>
              <p style="MARGIN: 0px">
        {
</p>
              <p style="MARGIN: 0px">
            <span style="COLOR: blue">return</span><span style="COLOR: blue">this</span>.Value1
+ <span style="COLOR: blue">this</span>.Value2;
</p>
              <p style="MARGIN: 0px">
        }
</p>
              <p style="MARGIN: 0px">
    }
</p>
              <p style="MARGIN: 0px">
}
</p>
            </div>
            <!--EndFragment-->
          </font>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <font face="Verdana" size="2">The next task was to determine which operand to use
given the user's input. We could write an "if" statement or a factory method, but
I wanted to make sure if anyone came in to add a new operand, they would not have
to change any code -- just add a new class, inherit from <em>OperationBase</em> and
implement the Calculate() method. To accomplish this task, I decided to use reflection.
By decorating each Operand class with an attribute, I could designate how it reacts
to the inputs. </font>
          </p>
          <p style="MARGIN: 0px">
            <font face="Verdana" size="2">
            </font> 
</p>
          <p style="MARGIN: 0px">
            <font face="Verdana" size="2">First, I needed to define my attribute:</font>
          </p>
          <p style="MARGIN: 0px">
            <font face="Verdana" size="2">
            </font> 
</p>
          <font face="Verdana" size="2">
            <p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New">
              <span style="COLOR: blue">using</span> System;
</p>
            <p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New">
 
</p>
            <p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New">
              <span style="COLOR: blue">namespace</span> CalcLibrary
</p>
            <p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New">
{
</p>
            <p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New">
    [System.<span style="COLOR: #2b91af">AttributeUsage</span>(System.<span style="COLOR: #2b91af">AttributeTargets</span>.Class)]
</p>
            <p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">class</span><span style="COLOR: #2b91af">OperatorIndex</span> :
System.<span style="COLOR: #2b91af">Attribute</span></p>
            <p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New">
    {
</p>
            <p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New">
        <span style="COLOR: blue">public</span><span style="COLOR: blue">string</span> OperatorId
= <span style="COLOR: #2b91af">String</span>.Empty;
</p>
            <p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New">
        <span style="COLOR: blue">public</span> OperatorIndex(<span style="COLOR: blue">string</span> operatorId)
</p>
            <p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New">
        {
</p>
            <p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New">
            OperatorId = operatorId;
</p>
            <p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New">
        }
</p>
            <p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New">
    }
</p>
            <p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New">
}
</p>
            <p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New">
 
</p>
            <p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New">
              <font face="Verdana" size="2">Next, I need to decorate my operands with the appropriate
attribute. Again, I will use the AdditionOperand, which is indicated by the "U" notation.
When I define my class, I decorate it with the attribute letter I want to use to define
that function.</font>
            </p>
            <p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New">
              <font size="2">
              </font>
              <font color="#2b91af" size="2">
                <font color="#2b91af" size="2"> 
</font>
              </font>
            </p>
          </font>
          <font face="Verdana" size="2">
            <div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
              <p style="MARGIN: 0px">
    [<span style="COLOR: #2b91af">OperatorIndex</span>(<span style="COLOR: #a31515">"U"</span>)]
</p>
              <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">class</span><span style="COLOR: #2b91af">AdditionOperand</span> : <span style="COLOR: #2b91af">OperationBase</span></p>
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">
                </span> 
</p>
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">
                  <font face="Verdana" color="#000000" size="2">Now that
I have defined my operations, I need to use them. I created a publically exposed static
class called <em>CalcEngine</em> which loads all the operations, validates the inputs,
and processes the calculations. I created this as a class library so it could be used
with a console application (as it is being called from in the supplied example), a
web application, etc.</font>
                </span>
              </p>
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">
                  <font face="Verdana" color="#000000" size="2">
                  </font>
                </span> 
</p>
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">
                  <font face="Verdana" color="#000000" size="2">In the
constructor, I call a method <em>LoadOperators()</em> which uses LINQ to Reflection
to quickly retrieve all classes of type <em>OperatorBase</em> and have the <em>OperatorIndex</em> defined.
I load the resules into a dictionary object so I can quickly retrieve them for my
calculations. Below is how I load the operators using LINQ to Reflection.</font>
                </span>
              </p>
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">
                  <font face="Verdana" color="#000000" size="2">
                  </font>
                </span> 
</p>
              <span style="COLOR: #2b91af">
                <div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
                  <p style="MARGIN: 0px">
                    <span style="COLOR: blue">private</span>
                    <span style="COLOR: blue">static</span>
                    <span style="COLOR: blue">void</span> LoadOperators()
</p>
                  <p style="MARGIN: 0px">
        {
</p>
                  <p style="MARGIN: 0px">
            <span style="COLOR: green">//Using
LINQ to Reflection, load all classes from the assembly that inherit from our base
Operator type, </span></p>
                  <p style="MARGIN: 0px">
            <span style="COLOR: green">//and
have the attribute set into a dictionary, so we can quickly reference the operator
we want</span></p>
                  <p style="MARGIN: 0px">
            operations =
</p>
                  <p style="MARGIN: 0px">
                (<span style="COLOR: blue">from</span> a <span style="COLOR: blue">in</span><span style="COLOR: #2b91af">AppDomain</span>.CurrentDomain.GetAssemblies()
</p>
                  <p style="MARGIN: 0px">
                <span style="COLOR: blue">from</span> t <span style="COLOR: blue">in</span> a.GetTypes()
</p>
                  <p style="MARGIN: 0px">
                <span style="COLOR: blue">where</span><span style="COLOR: #2b91af">Attribute</span>.IsDefined(t,<span style="COLOR: blue">typeof</span>(<span style="COLOR: #2b91af">OperatorIndex</span>))
</p>
                  <p style="MARGIN: 0px">
                <span style="COLOR: blue">where</span> t.BaseType
== <span style="COLOR: blue">typeof</span>(<span style="COLOR: #2b91af">OperationBase</span>)
</p>
                  <p style="MARGIN: 0px">
                <span style="COLOR: blue">let</span> attribute
= <span style="COLOR: #2b91af">Attribute</span>.GetCustomAttribute(t,<span style="COLOR: blue">typeof</span>(<span style="COLOR: #2b91af">OperatorIndex</span>)) <span style="COLOR: blue">as</span><span style="COLOR: #2b91af">OperatorIndex</span></p>
                  <p style="MARGIN: 0px">
                <span style="COLOR: blue">where</span> attribute.OperatorId
!= <span style="COLOR: #a31515">""</span></p>
                  <p style="MARGIN: 0px">
                <span style="COLOR: blue">select</span></p>
                  <p style="MARGIN: 0px">
                    <span style="COLOR: blue">new</span><span style="COLOR: #2b91af">OperatorDetails</span></p>
                  <p style="MARGIN: 0px">
                   
{
</p>
                  <p style="MARGIN: 0px">
                   
    AssemName = a.GetName().Name,
</p>
                  <p style="MARGIN: 0px">
                   
    ClassName = t.FullName,
</p>
                  <p style="MARGIN: 0px">
                   
    OperatorId = attribute.OperatorId
</p>
                  <p style="MARGIN: 0px">
                   
}).ToDictionary(p =&gt; p.OperatorId,p =&gt; p);
</p>
                  <p style="MARGIN: 0px">
 
</p>
                  <p style="MARGIN: 0px">
        }
</p>
                </div>
                <!--EndFragment-->
              </span>
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">
                  <font face="Verdana" color="#000000" size="2">The main <em>Calculate </em>method
validates the input, retrieves the right operand key from the dictionary, late binds
to the proper <em>OperatorBase</em> class and invokes the <em>Calculate() </em>method,
as seen below.</font>
                </span>
              </p>
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">
                  <font face="Verdana" color="#000000" size="2">
                  </font>
                </span> 
</p>
              <span style="COLOR: #2b91af">
                <font face="Verdana" color="#000000" size="2">
                  <div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
                    <p style="MARGIN: 0px">
                <span style="COLOR: green">//locate
the correct operator from our dictionary</span></p>
                    <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">OperatorDetails</span> operatorInfo
= operations[mathOperator];
</p>
                    <p style="MARGIN: 0px">
 
</p>
                    <p style="MARGIN: 0px">
                <span style="COLOR: green">//dynamically
load the operator class. I chose to do it using reflection so that we wouldn't need
a</span></p>
                    <p style="MARGIN: 0px">
                <span style="COLOR: green">//factory,
which would need to be changed every time a new operator was added.</span></p>
                    <p style="MARGIN: 0px">
                <span style="COLOR: green">//ENHANCEMENT:
you could actually detect other assemblies and load them as well</span></p>
                    <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">Type</span> calcClass
= <span style="COLOR: #2b91af">Type</span>.GetType(operatorInfo.ClassName);
</p>
                    <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">OperationBase</span> calculator
= (<span style="COLOR: #2b91af">OperationBase</span>) <span style="COLOR: #2b91af">Activator</span>.CreateInstance(calcClass);
</p>
                    <p style="MARGIN: 0px">
                calculator.Value1
= value1;
</p>
                    <p style="MARGIN: 0px">
                calculator.Value2
= value2;
</p>
                    <p style="MARGIN: 0px">
                <span style="COLOR: blue">int</span> calculatedResult
= calculator.Calculate();
</p>
                  </div>
                  <!--EndFragment-->
                </font>
              </span>
            </div>
          </font>
        </div>
        <font face="Verdana" size="2">
          <font face="Verdana" size="2">
          </font>
        </font>
        <div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <font face="Verdana" size="2">
            <font face="Verdana" size="2">
            </font>
          </font> 
</div>
        <div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <font face="Verdana" size="2">
            <font face="Verdana" size="2">Using
a console application, it looks like this:</font>
          </font>
        </div>
        <div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <font face="Verdana" size="2">
            <font face="Verdana" size="2">
            </font>
          </font> 
</div>
        <div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <font face="Verdana" size="2">
            <font face="Verdana" size="2">
              <!--EndFragment-->
            </font>
            <!--EndFragment-->
          </font>
        </div>
        <p>
          <img src="http://www.dotnettechnologies.com/content/binary/calc_example.png" border="0" />
        </p>
        <p>
Here's the sample code to look at and play with.. Enjoy!
</p>
        <p>
 
</p>
        <a href="http://www.dotnettechnologies.com/content/binary/SampleProj.zip">SampleProj.zip
(89.4 KB)</a>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=28e48f37-06e8-4ef1-9abc-b2a44a34dcdf" />
      </body>
      <title>How I have used reflection</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,28e48f37-06e8-4ef1-9abc-b2a44a34dcdf.aspx</guid>
      <link>http://www.dotnettechnologies.com/2009/08/25/HowIHaveUsedReflection.aspx</link>
      <pubDate>Tue, 25 Aug 2009 05:12:16 GMT</pubDate>
      <description>&lt;p&gt;
Earlier today, I blogged an interview question about reflection. Earlier this year,
as part of the interviewing process I was tasked to write a simple calculator. There
would only be 2 integer inputs with a single operation. For example, if the invoked
the program, and entered in 1 U 2 (U being the operation for addition), the program
would output 3. 
&lt;/p&gt;
&lt;p&gt;
The assignment also mentioned they would want the possibility to expand the operations
later. Instead of just commenting on it, I decided to implement that into the design.
&lt;/p&gt;
&lt;p&gt;
I won't go into retrieving the data from command prompt, but I will provide the project
at the end and you can see how that is accomplished. I made it robust by accounting
for spaces, etc. As a programming concept, you should always program defensively and
assume the work (and you'll be glad with the results).
&lt;/p&gt;
&lt;p&gt;
First, I created a base class each operand would inherit from, so that each works
similarly. The base class &lt;em&gt;OperationBase&lt;/em&gt; looks like this:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;using&lt;/span&gt; System.Diagnostics;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;namespace&lt;/span&gt; CalcLibrary
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;span style="COLOR: #2b91af"&gt;OperatorIndex&lt;/span&gt;(&lt;span style="COLOR: #a31515"&gt;""&lt;/span&gt;)]
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;abstract&lt;/span&gt; &lt;span style="COLOR: blue"&gt;class&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;OperationBase&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; value1;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; value2;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; errorInformation
= &lt;span style="COLOR: #2b91af"&gt;String&lt;/span&gt;.Empty;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; Value1
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;get&lt;/span&gt; { &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; value1;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;set&lt;/span&gt; {
value1 = &lt;span style="COLOR: blue"&gt;value&lt;/span&gt;; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; Value2
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;get&lt;/span&gt; { &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; value2;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;set&lt;/span&gt; {
value2 = &lt;span style="COLOR: blue"&gt;value&lt;/span&gt;; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; ErrorInformation
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;get&lt;/span&gt; { &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; errorInformation;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: blue"&gt;set&lt;/span&gt; {
errorInformation = &lt;span style="COLOR: blue"&gt;value&lt;/span&gt;; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//NOTE: We may want
to return a string as the division will round every time, but we will keep this as
an int&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;abstract&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; Calculate();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;protected&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; ErrorHandler(&lt;span style="COLOR: #2b91af"&gt;Exception&lt;/span&gt; ex)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;try&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//While
in a production app we would want to hide the internals of an error, in this app we
will show them&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;this&lt;/span&gt;.ErrorInformation
= &lt;span style="COLOR: #a31515"&gt;"An unexpected error occurred ("&lt;/span&gt; + &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;StackTrace&lt;/span&gt;().GetFrame(2).GetMethod().Name
+ &lt;span style="COLOR: #a31515"&gt;")-"&lt;/span&gt; + ex.Message;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;catch&lt;/span&gt;&amp;nbsp;
{}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;font face=Verdana size=2&gt;You'll notice this abstract class defines taking two int
inputs (Value1 and Value2), handles the errors, and forces every implementation to
provide a definition of the "Calculate" method. When inheriting from this class,&amp;nbsp;any
operand will be very simple to define -- all it needs to do is determine what to do
for a Calculation, as seen by the addition operand implementation.&lt;/font&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;font face=Verdana size=2&gt;&lt;/font&gt;&amp;nbsp;
&lt;/p&gt;
&lt;font face=Verdana size=2&gt; 
&lt;div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;namespace&lt;/span&gt; CalcLibrary
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;span style="COLOR: #2b91af"&gt;OperatorIndex&lt;/span&gt;(&lt;span style="COLOR: #a31515"&gt;"U"&lt;/span&gt;)]
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;class&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;AdditionOperand&lt;/span&gt; : &lt;span style="COLOR: #2b91af"&gt;OperationBase&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;override&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; Calculate()
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; &lt;span style="COLOR: blue"&gt;this&lt;/span&gt;.Value1
+ &lt;span style="COLOR: blue"&gt;this&lt;/span&gt;.Value2;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;&lt;/font&gt; 
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;font face=Verdana size=2&gt;The next task was to determine which operand to use given
the user's input. We could write an "if" statement or a factory method, but I wanted
to make sure if anyone came in to add a new operand, they would not have to change
any code -- just add a new class, inherit from &lt;em&gt;OperationBase&lt;/em&gt; and implement
the Calculate() method.&amp;nbsp;To accomplish this task, I decided to use reflection.
By decorating each Operand class with an attribute, I could designate how it reacts
to the inputs. &lt;/font&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;font face=Verdana size=2&gt;&lt;/font&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;font face=Verdana size=2&gt;First, I needed to define my attribute:&lt;/font&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;font face=Verdana size=2&gt;&lt;/font&gt;&amp;nbsp;
&lt;/p&gt;
&lt;font face=Verdana size=2&gt; 
&lt;p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;span style="COLOR: blue"&gt;using&lt;/span&gt; System;
&lt;/p&gt;
&lt;p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;span style="COLOR: blue"&gt;namespace&lt;/span&gt; CalcLibrary
&lt;/p&gt;
&lt;p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New"&gt;
{
&lt;/p&gt;
&lt;p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; [System.&lt;span style="COLOR: #2b91af"&gt;AttributeUsage&lt;/span&gt;(System.&lt;span style="COLOR: #2b91af"&gt;AttributeTargets&lt;/span&gt;.Class)]
&lt;/p&gt;
&lt;p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;class&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;OperatorIndex&lt;/span&gt; :
System.&lt;span style="COLOR: #2b91af"&gt;Attribute&lt;/span&gt;
&lt;/p&gt;
&lt;p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; OperatorId
= &lt;span style="COLOR: #2b91af"&gt;String&lt;/span&gt;.Empty;
&lt;/p&gt;
&lt;p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; OperatorIndex(&lt;span style="COLOR: blue"&gt;string&lt;/span&gt; operatorId)
&lt;/p&gt;
&lt;p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; OperatorId = operatorId;
&lt;/p&gt;
&lt;p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New"&gt;
}
&lt;/p&gt;
&lt;p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;font face=Verdana size=2&gt;Next, I need to decorate my operands with the appropriate
attribute. Again, I will use the AdditionOperand, which is indicated by the "U" notation.
When I define my class, I decorate it with the attribute letter I want to use to define
that function.&lt;/font&gt;
&lt;/p&gt;
&lt;p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;font size=2&gt;&lt;/font&gt;&lt;font color=#2b91af size=2&gt;&lt;font color=#2b91af size=2&gt;&amp;nbsp;
&lt;/p&gt;
&lt;/font&gt;&gt;&lt;font face=Verdana size=2&gt; 
&lt;div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;span style="COLOR: #2b91af"&gt;OperatorIndex&lt;/span&gt;(&lt;span style="COLOR: #a31515"&gt;"U"&lt;/span&gt;)]
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;class&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;AdditionOperand&lt;/span&gt; : &lt;span style="COLOR: #2b91af"&gt;OperationBase&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&lt;font face=Verdana color=#000000 size=2&gt;Now that I have
defined my operations, I need to use them. I created a publically exposed static class
called &lt;em&gt;CalcEngine&lt;/em&gt; which loads all the operations, validates the inputs, and
processes the calculations. I created this as a class library so it could be used
with a console application (as it is being called from in the supplied example), a
web application, etc.&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&lt;font face=Verdana color=#000000 size=2&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&lt;font face=Verdana color=#000000 size=2&gt;In the constructor,
I call a method &lt;em&gt;LoadOperators()&lt;/em&gt; which uses LINQ to Reflection to quickly
retrieve all classes of type &lt;em&gt;OperatorBase&lt;/em&gt; and have the &lt;em&gt;OperatorIndex&lt;/em&gt; defined.
I load the resules into a dictionary object so I can quickly retrieve them for my
calculations. Below is how I load the operators using LINQ to Reflection.&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&lt;font face=Verdana color=#000000 size=2&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;span style="COLOR: #2b91af"&gt; 
&lt;div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: blue"&gt;static&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; LoadOperators()
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//Using
LINQ to Reflection, load all classes from the assembly that inherit from our base
Operator type, &lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//and
have the attribute set into a dictionary, so we can quickly reference the operator
we want&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; operations =
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; (&lt;span style="COLOR: blue"&gt;from&lt;/span&gt; a &lt;span style="COLOR: blue"&gt;in&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;AppDomain&lt;/span&gt;.CurrentDomain.GetAssemblies()
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;from&lt;/span&gt; t &lt;span style="COLOR: blue"&gt;in&lt;/span&gt; a.GetTypes()
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;where&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;Attribute&lt;/span&gt;.IsDefined(t,&lt;span style="COLOR: blue"&gt;typeof&lt;/span&gt;(&lt;span style="COLOR: #2b91af"&gt;OperatorIndex&lt;/span&gt;))
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;where&lt;/span&gt; t.BaseType
== &lt;span style="COLOR: blue"&gt;typeof&lt;/span&gt;(&lt;span style="COLOR: #2b91af"&gt;OperationBase&lt;/span&gt;)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;let&lt;/span&gt; attribute
= &lt;span style="COLOR: #2b91af"&gt;Attribute&lt;/span&gt;.GetCustomAttribute(t,&lt;span style="COLOR: blue"&gt;typeof&lt;/span&gt;(&lt;span style="COLOR: #2b91af"&gt;OperatorIndex&lt;/span&gt;)) &lt;span style="COLOR: blue"&gt;as&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;OperatorIndex&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;where&lt;/span&gt; attribute.OperatorId
!= &lt;span style="COLOR: #a31515"&gt;""&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;select&lt;/span&gt; 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;OperatorDetails&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; AssemName = a.GetName().Name,
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; ClassName = t.FullName,
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; OperatorId = attribute.OperatorId
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
}).ToDictionary(p =&amp;gt; p.OperatorId,p =&amp;gt; p);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;&lt;/span&gt; 
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&lt;font face=Verdana color=#000000 size=2&gt;The main &lt;em&gt;Calculate &lt;/em&gt;method
validates the input, retrieves the right operand key from the dictionary, late binds
to the proper &lt;em&gt;OperatorBase&lt;/em&gt; class and invokes the &lt;em&gt;Calculate() &lt;/em&gt;method,
as seen below.&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&lt;font face=Verdana color=#000000 size=2&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;span style="COLOR: #2b91af"&gt;&lt;font face=Verdana color=#000000 size=2&gt; 
&lt;div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//locate
the correct operator from our dictionary&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #2b91af"&gt;OperatorDetails&lt;/span&gt; operatorInfo
= operations[mathOperator];
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//dynamically
load the operator class. I chose to do it using reflection so that we wouldn't need
a&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//factory,
which would need to be changed every time a new operator was added.&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//ENHANCEMENT:
you could actually detect other assemblies and load them as well&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #2b91af"&gt;Type&lt;/span&gt; calcClass
= &lt;span style="COLOR: #2b91af"&gt;Type&lt;/span&gt;.GetType(operatorInfo.ClassName);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #2b91af"&gt;OperationBase&lt;/span&gt; calculator
= (&lt;span style="COLOR: #2b91af"&gt;OperationBase&lt;/span&gt;) &lt;span style="COLOR: #2b91af"&gt;Activator&lt;/span&gt;.CreateInstance(calcClass);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; calculator.Value1
= value1;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; calculator.Value2
= value2;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; calculatedResult
= calculator.Calculate();
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;&lt;/font&gt;
&lt;/font&gt;&gt;&gt;
&lt;/div&gt;
&lt;font face=Verdana size=2&gt;&lt;font face=Verdana size=2&gt;&lt;/font&gt;&lt;/font&gt;&gt;
&lt;div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;&lt;font face=Verdana size=2&gt;&lt;font face=Verdana size=2&gt;&lt;/font&gt;&lt;/font&gt;&amp;nbsp;
&lt;/div&gt;
&lt;div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;&lt;font face=Verdana size=2&gt;&lt;font face=Verdana size=2&gt;Using
a console application, it looks like this:&lt;/font&gt;&lt;/font&gt;
&lt;/div&gt;
&lt;div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;&lt;font face=Verdana size=2&gt;&lt;font face=Verdana size=2&gt;&lt;/font&gt;&lt;/font&gt;&amp;nbsp;
&lt;/div&gt;
&lt;div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;&lt;font face=Verdana size=2&gt;&lt;font face=Verdana size=2&gt;
&lt;!--EndFragment--&gt;&lt;/font&gt;
&lt;!--EndFragment--&gt;&lt;/font&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;img src="http://www.dotnettechnologies.com/content/binary/calc_example.png" border=0&gt;
&lt;/p&gt;
&lt;p&gt;
Here's the sample code to look at and play with.. Enjoy!
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;a href="http://www.dotnettechnologies.com/content/binary/SampleProj.zip"&gt;SampleProj.zip
(89.4 KB)&lt;/a&gt;&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=28e48f37-06e8-4ef1-9abc-b2a44a34dcdf" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,28e48f37-06e8-4ef1-9abc-b2a44a34dcdf.aspx</comments>
      <category>All Things</category>
      <category>C#</category>
      <category>CSharp</category>
      <category>Design</category>
      <category>Tips and Tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=4a377aac-37cf-4611-9579-20cec1061335</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,4a377aac-37cf-4611-9579-20cec1061335.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,4a377aac-37cf-4611-9579-20cec1061335.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=4a377aac-37cf-4611-9579-20cec1061335</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Today has been an insanely busy day, but I have so much I want to blog about, and
this one won't wait. A few days ago, as I was using some code I found on the net,
I <a href="http://www.dotnettechnologies.com/PermaLink,guid,5428d2b4-f00b-47fc-91a9-6825caa723b6.aspx" target="_blank">commented
here</a> about the over-use of the <em>var</em> keyword.
</p>
        <p>
Seems I am not the only one who has an opinion on the matter. I subscribe to the CodeProject
newsletter, and each issue features a survey. This week, the survey relates to the
opinion of the <em>var</em> type in C#. You can see the <a href="http://www.codeproject.com/script/Surveys/Results.aspx?srvid=950" target="_blank">survey
results here</a>. Make sure you click through to the "optional text answers" for some
funny comments (and a few relevant ones as well).
</p>
        <p>
The interesting thing to note from the survey is that the answers tend to skew towards
the "never use that scenario" range. The two areas where it is most prevalent is with
LINQ, and with anonymous types, which makes total sense. 
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=4a377aac-37cf-4611-9579-20cec1061335" />
      </body>
      <title>Topical: The use of the var keyword revisited</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,4a377aac-37cf-4611-9579-20cec1061335.aspx</guid>
      <link>http://www.dotnettechnologies.com/2009/08/25/TopicalTheUseOfTheVarKeywordRevisited.aspx</link>
      <pubDate>Tue, 25 Aug 2009 04:28:04 GMT</pubDate>
      <description>&lt;p&gt;
Today has been an insanely busy day, but I have so much I want to blog about, and
this one won't wait. A few days ago, as I was using some code I found on the net,
I &lt;a href="http://www.dotnettechnologies.com/PermaLink,guid,5428d2b4-f00b-47fc-91a9-6825caa723b6.aspx" target=_blank&gt;commented
here&lt;/a&gt; about the over-use of the &lt;em&gt;var&lt;/em&gt; keyword.
&lt;/p&gt;
&lt;p&gt;
Seems I am not the only one who has an opinion on the matter. I subscribe to the CodeProject
newsletter, and each issue features a survey. This week, the survey relates to the
opinion of the &lt;em&gt;var&lt;/em&gt; type in C#. You can see the &lt;a href="http://www.codeproject.com/script/Surveys/Results.aspx?srvid=950" target=_blank&gt;survey
results here&lt;/a&gt;. Make sure you click through to the "optional text answers" for some
funny comments (and a few relevant ones as well).
&lt;/p&gt;
&lt;p&gt;
The interesting thing to note from the survey is that the answers tend to skew towards
the "never use that scenario" range. The two areas where it is most prevalent is with
LINQ, and with anonymous types, which makes total sense. 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=4a377aac-37cf-4611-9579-20cec1061335" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,4a377aac-37cf-4611-9579-20cec1061335.aspx</comments>
      <category>All Things</category>
      <category>C#</category>
      <category>CSharp</category>
      <category>Design</category>
      <category>General</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=b94da6c0-6f70-4eee-841d-2d4236253c92</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,b94da6c0-6f70-4eee-841d-2d4236253c92.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,b94da6c0-6f70-4eee-841d-2d4236253c92.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=b94da6c0-6f70-4eee-841d-2d4236253c92</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <strong>Question: </strong>What's reflection, and how have you used it to solve a
problem?
</p>
        <p>
          <strong>Answer: </strong>Reflection is a way to look at assembly metadata and look
in and see what is contained. It also allows you to use late binding and call methods
within those assembles.
</p>
        <p>
For the second part, a simple explanation is all you need to show that you understand
how it is used.
</p>
        <p>
So what if you've enver used reflection? First, shame on you (kidding!). It DOES serve
a very important purpose and allows for some great solutions, especially at an architectural
level. If you've never used it, I recommend immediately trying it out, and you'll
find many, many uses. Here's a <a href="http://www.codeguru.com/csharp/csharp/cs_misc/reflection/article.php/c4257" target="_blank">tutorial</a> I
found that looks decent. That way, when asked this question (and I get this one a
lot) you can answer how you *might* really use it. Honestly, you've probably used
it and didn't realize it if you've added certain attributes to your code.
</p>
        <p>
I have used reflection for everything from identifying certain classes and functions.
For example, for a coding sample, I used LINQ for Reflection and attributes to identify
classes which supported certain calculations. By doing this, I could add more
functions dynamically and the UI would pick it without changing code. Since LINQ for
Reflection is not discussed much, I'll post some about that later.
</p>
        <p>
There are some costs associated with Reflection though. Speed! Late Binding is slower
by it's nature, as well as all the processing looking for methods, so plan and use
wisely!
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=b94da6c0-6f70-4eee-841d-2d4236253c92" />
      </body>
      <title>Tip of the Day: Technical Interview question: What's Reflection?</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,b94da6c0-6f70-4eee-841d-2d4236253c92.aspx</guid>
      <link>http://www.dotnettechnologies.com/2009/08/24/TipOfTheDayTechnicalInterviewQuestionWhatsReflection.aspx</link>
      <pubDate>Mon, 24 Aug 2009 14:27:02 GMT</pubDate>
      <description>&lt;p&gt;
&lt;strong&gt;Question: &lt;/strong&gt;What's reflection, and how have you used it to solve a
problem?
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Answer: &lt;/strong&gt;Reflection is a way to look at assembly metadata and look
in and see what is contained. It also allows you to use late binding and call methods
within those assembles.
&lt;/p&gt;
&lt;p&gt;
For the second part, a simple explanation is all you need to show that you understand
how it is used.
&lt;/p&gt;
&lt;p&gt;
So what if you've enver used reflection? First, shame on you (kidding!). It DOES serve
a very important purpose and allows for some great solutions, especially at an architectural
level. If you've never used it, I recommend immediately trying it out, and you'll
find many, many uses. Here's a &lt;a href="http://www.codeguru.com/csharp/csharp/cs_misc/reflection/article.php/c4257" target=_blank&gt;tutorial&lt;/a&gt; I
found that looks decent. That way, when asked this question (and I get this one a
lot) you can answer how you *might* really use it. Honestly, you've probably used
it and didn't realize it if you've added certain attributes to your code.
&lt;/p&gt;
&lt;p&gt;
I have used reflection for everything from identifying certain classes and functions.
For example, for a coding sample, I used LINQ for Reflection and attributes to identify
classes which supported certain calculations. By doing this,&amp;nbsp;I could add more
functions dynamically and the UI would pick it without changing code. Since LINQ for
Reflection is not discussed much, I'll post some about that later.
&lt;/p&gt;
&lt;p&gt;
There are some costs associated with Reflection though. Speed! Late Binding is slower
by it's nature, as well as all the processing looking for methods, so plan and use
wisely!
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=b94da6c0-6f70-4eee-841d-2d4236253c92" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,b94da6c0-6f70-4eee-841d-2d4236253c92.aspx</comments>
      <category>All Things</category>
      <category>ASP.Net</category>
      <category>C#</category>
      <category>CSharp</category>
      <category>Design</category>
      <category>General</category>
      <category>Tips and Tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=1249a156-8ee0-439c-8a62-e368cd50e004</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,1249a156-8ee0-439c-8a62-e368cd50e004.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,1249a156-8ee0-439c-8a62-e368cd50e004.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=1249a156-8ee0-439c-8a62-e368cd50e004</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
As a full time developer, I search the web... a lot. If you are writing a lot of new
code without at least searching to see what exists, you're either getting paid by
the hour (or line of code), stubborn or a glutton for punishment. Even if I don't
use it, I can get some guidance on what someone else tried, and how it worked out
before I start coding. Granted, it usually requires a lot of refactoring the code
to my standards or needs, but it's a great start.
</p>
        <p>
As I was thinking of things I wanted to put on my site, I realized it would be nice
to share my "favorites"...sort of. If I found something useful, I wanted to be able
to show what it was, how I found it useful and where someone else can find it. In
a way, I am also helping to promote someone else's hard work and improving their search
engine visibility to return the favor of their sharing their work.
</p>
        <p>
Out of this, I came up with an idea for a "Useful Links" section. I wanted to be able
to add links and commentary, and also add it to my <a href="http://www.dotnettechnologies.com/PermaLink,guid,308bd3f2-4d3c-48b6-84f2-1dbe04982eed.aspx" target="_blank">Activity
Aggregator</a> to show help show the content of the site has changed. Later, as I
was using Bing, I got the idea to add some webthumbs to enhance the page graphically,
so the reader would know what the site looked like before going there. I also needed
to add an admin page for creating the useful links (and ultimately maintaining them
-- which is on my TODO list). I'll also leave out the icon creation part, although
I really need to farm out for a new cool looking icon, which is also on my list of
things to do.
</p>
        <p>
I'll skip the admin section, as it's just data entry fields. The process for creating
the entries does change a bit, as I needed to do a few extra steps.
</p>
        <ol>
          <li>
Save the UsefulLink class 
</li>
          <li>
Default the webthumb image to a default "safety" image in case we can't get a webthumb 
</li>
          <li>
Make a request to get a webthumb image of the target site 
</li>
          <li>
Once the image is retrieved, update the UsefulLink record to point to the new webthumb 
</li>
          <li>
Update the Activity Aggregator to show we have a new useful link.</li>
        </ol>
        <p>
Step 3 is where things get tricky. How in all getout do we get webthumb images? There
are <a href="http://www.acasystems.com/en/web-thumb-activex/faq-generate-image-from-html-in-c-sharp.htm" target="_blank">controls </a>out
there you can get, and they are reasonably priced as well. But I decided to keep searching
so I could write this one on my own, as it seems like an interesting challenge.
</p>
        <p>
My next thought was to create my own service to do this. There's plenty of code
out there, but the easiest way to do this would require some WinForms programming.
Don't get me wrong, I LOVE programming WinForms. The problem is I don't want to have
to install it everywhere I am at, as I need a service. I could possibly create a Web
and Windows service to do this as well, but that seemed overly complex. So I did a
search, and I found <a href="http://webthumb.bluga.net/home" target="_blank">this</a>,
which is a service which does it for you. What's even nicer is that they expose a
nice API to use. As of now, the first 100 images a month are free, and after that,
the fees are very reasonable. Even though I doubt I will go over 100 images per month,
I am so impressed I may pay just to keep the service going.
</p>
        <p>
I was also able to find some c# code to make learning the API fast. I did end up changing
it some, but in general it worked very well. You can find it <a href="http://stackoverflow.com/questions/701680/how-do-i-save-a-web-page-to-image-using-c" target="_blank">here</a>.
</p>
        <p>
So when the service returns with my image (I used the medium size), I save it to a
thumbs directory (had to add write permissions to the directory, or I got an obscure GDI+
error), and call a method on my UsefulLink class to update the record with the thumbnail
image. I name the image with the current date and time so that the names will be unique
as well.
</p>
        <p>
Finally, once I have downloaded the image and updated the UsefulLink record, I add
a call to my Activity class which creates an entry for the Activity Aggregator.
As I add more items to throw into the Activity Aggregator, I am considering refactoring
things to do some delegate multicasting for all the updates, or perhaps creating a
factory where you provide class (should be easy since my business objects
share the same base class) or interface, and it knows how to create the activity
record instead of making individual calls. That's on my list down the road. :)
</p>
        <p>
Here's what the Activity Aggrgator looks like, with a special Useful Link icon(<img src="http://www.dotnettechnologies.com/content/binary/useful_link.png" border="0" />):
</p>
        <p>
 
</p>
        <p>
          <img src="http://www.dotnettechnologies.com/content/binary/DevArea_new.png" border="0" />
        </p>
        <p>
And here's what the Useful Link section (which has the webthumbs) looks like. I will
only be showing 10 at a time to save web page real estate. But I also don't want to
lose older links off the page. I am debating now whether to use paging, or just have a
smaller hyperlink-only section below the most recent links. I am leaning towards paging,
as I have a very neat service I want to implement which makes paging and sorting incredibly
fast and easy (more on that someday.. I need to upgrade it to user .Net 3.5 functionality
before I post it).
</p>
        <p>
 
</p>
        <img src="http://www.dotnettechnologies.com/content/binary/UsefulLinks.png" border="0" />
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=1249a156-8ee0-439c-8a62-e368cd50e004" />
      </body>
      <title>Useful Links -- An overview</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,1249a156-8ee0-439c-8a62-e368cd50e004.aspx</guid>
      <link>http://www.dotnettechnologies.com/2009/08/23/UsefulLinksAnOverview.aspx</link>
      <pubDate>Sun, 23 Aug 2009 16:28:00 GMT</pubDate>
      <description>&lt;p&gt;
As a full time developer, I search the web... a lot. If you are writing a lot of new
code without at least searching to see what exists, you're either getting paid by
the hour (or line of code), stubborn or a glutton for punishment. Even if I don't
use it, I can get some guidance on what someone else tried, and how it worked out
before I start coding. Granted, it usually requires a lot of refactoring the code
to my standards or needs, but it's a great start.
&lt;/p&gt;
&lt;p&gt;
As I was thinking of things I wanted to put on my site, I realized it would be nice
to share my "favorites"...sort of. If I found something useful, I wanted to be able
to show what it was, how I found it useful and where someone else can find it. In
a way, I am also helping to promote someone else's hard work and improving their search
engine visibility to return the favor of their sharing their work.
&lt;/p&gt;
&lt;p&gt;
Out of this, I came up with an idea for a "Useful Links" section. I wanted to be able
to add links and commentary, and also add it to my &lt;a href="http://www.dotnettechnologies.com/PermaLink,guid,308bd3f2-4d3c-48b6-84f2-1dbe04982eed.aspx" target=_blank&gt;Activity
Aggregator&lt;/a&gt; to show help show the content of the site has changed. Later, as I
was using Bing, I got the idea to add some webthumbs to enhance the page graphically,
so the reader would know what the site looked like before going there. I also needed
to add an admin page for creating the useful links (and ultimately maintaining them
-- which is on my TODO list). I'll also leave out the icon creation part, although
I really need to farm out for a new cool looking icon, which is also on my list of
things to do.
&lt;/p&gt;
&lt;p&gt;
I'll skip the admin section, as it's just data entry fields. The process for creating
the entries does change a bit, as I needed to do a few extra steps.
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
Save the UsefulLink class 
&lt;li&gt;
Default the webthumb image to a default "safety" image in case we can't get a webthumb 
&lt;li&gt;
Make a request to get a webthumb image of the target site 
&lt;li&gt;
Once the image is retrieved, update the UsefulLink record to point to the new webthumb 
&lt;li&gt;
Update the Activity Aggregator to show we have a new useful link.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
Step 3 is where things get tricky. How in all getout do we get webthumb images? There
are &lt;a href="http://www.acasystems.com/en/web-thumb-activex/faq-generate-image-from-html-in-c-sharp.htm" target=_blank&gt;controls &lt;/a&gt;out
there you can get, and they are reasonably priced as well. But I decided to keep searching
so I could write this one on my own, as it seems like an interesting challenge.
&lt;/p&gt;
&lt;p&gt;
My&amp;nbsp;next thought was to create my own service to do this. There's plenty of code
out there, but the easiest way to do this would require some WinForms programming.
Don't get me wrong, I LOVE programming WinForms. The problem is I don't want to have
to install it everywhere I am at, as I need a service. I could possibly create a Web
and Windows service to do this as well, but that seemed overly complex. So I did a
search, and I found &lt;a href="http://webthumb.bluga.net/home" target=_blank&gt;this&lt;/a&gt;,
which is a service which does it for you. What's even nicer is that they expose a
nice API to use. As of now, the first 100 images a month are free, and after that,
the fees are very reasonable. Even though I doubt I will go over 100 images per month,
I am so impressed I may pay just to keep the service going.
&lt;/p&gt;
&lt;p&gt;
I was also able to find some c# code to make learning the API fast. I did end up changing
it some, but in general it worked very well. You can find it &lt;a href="http://stackoverflow.com/questions/701680/how-do-i-save-a-web-page-to-image-using-c" target=_blank&gt;here&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
So when the service returns with my image (I used the medium size), I save it to a
thumbs directory (had to add write permissions to the directory, or I got an obscure&amp;nbsp;GDI+
error), and call a method on my UsefulLink class to update the record with the thumbnail
image. I name the image with the current date and time so that the names will be unique
as well.
&lt;/p&gt;
&lt;p&gt;
Finally, once I have downloaded the image and updated the UsefulLink record, I add
a call to my Activity class which creates an entry&amp;nbsp;for the Activity Aggregator.
As I add more items to throw into the Activity Aggregator, I am considering refactoring
things to do some delegate multicasting for all the updates, or perhaps creating a
factory where you provide&amp;nbsp;class (should be&amp;nbsp;easy since my business objects
share the same base class)&amp;nbsp;or interface, and it knows how to create the activity
record instead of making individual calls. That's on my list down the road. :)
&lt;/p&gt;
&lt;p&gt;
Here's what the Activity Aggrgator looks like, with a special Useful Link icon(&lt;img src="http://www.dotnettechnologies.com/content/binary/useful_link.png" border=0&gt;):
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://www.dotnettechnologies.com/content/binary/DevArea_new.png" border=0&gt;
&lt;/p&gt;
&lt;p&gt;
And here's what the Useful Link section (which has the webthumbs) looks like. I will
only be showing 10 at a time to save web page real estate. But I also don't want to
lose older links off the page. I am debating now whether to use paging, or just have&amp;nbsp;a
smaller hyperlink-only section below the most recent links. I am leaning towards paging,
as I have a very neat service I want to implement which makes paging and sorting incredibly
fast and easy (more on that someday.. I need to upgrade it to user .Net 3.5 functionality
before I post it).
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;img src="http://www.dotnettechnologies.com/content/binary/UsefulLinks.png" border=0&gt;&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=1249a156-8ee0-439c-8a62-e368cd50e004" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,1249a156-8ee0-439c-8a62-e368cd50e004.aspx</comments>
      <category>All Things</category>
      <category>ASP.Net</category>
      <category>C#</category>
      <category>CSharp</category>
      <category>Design</category>
      <category>General</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=5428d2b4-f00b-47fc-91a9-6825caa723b6</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,5428d2b4-f00b-47fc-91a9-6825caa723b6.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,5428d2b4-f00b-47fc-91a9-6825caa723b6.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=5428d2b4-f00b-47fc-91a9-6825caa723b6</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Today, I was super-dad AND got a lot of coding done, and I managed to get my useful
links controls done for my site <a href="http://www.rubiconcomputing.com/DevArea.aspx" target="_blank">here</a>.
It was actually a complex process to get things like the webthumbs integrated, update
the activity aggregator, create an admin page. The end result needs some cleanup,
but I think for a first run, it came out nice. Tomorrow I will blog on the details
and some code on how I did everything in case someone decides they want something
similar.
</p>
        <p>
Tonight, I am tired. But as I was coding, I came across some code for accessing my
webthumbs, and something struck me. In .Net 3.5, there's a new keyword "var" which
allows for anonymous casting (sort of). When it compiles, the underlying code is cast
to the correct type, and in using the var typed variable, it acts like the cast-type.
It would definitely speed up development if you used it a lot. For those old-school
VB fans, it really reminds me of the variant data type (which it is not). Read more
about it <a href="http://msdn.microsoft.com/en-us/library/bb383973.aspx" target="_blank">here </a>if
you want some details.
</p>
        <p>
However, as with all things, there is a cost. For me, it's readability. In English
anyways, we read left to right. When I see a "var" vast variable, I have to keep reading
to understand the type, then see how it is used. Not too difficult (unless it is coming
out of a function or LINQ query), but it does take a little more time to figure it
out. For example..
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">var</span> doc = <span style="COLOR: blue">new</span><span style="COLOR: #2b91af">XDocument</span>(
</p>
          <p style="MARGIN: 0px">
                <span style="COLOR: blue">new</span><span style="COLOR: #2b91af">XElement</span>(
</p>
        </div>
        <!--EndFragment-->
        <p>
That being said, you can get around using it by declaring the variable to the
expected type when you code it. I have some samples I will post later when I was using
LINQ I forced myself to do this so I would fully understand what was happening in
my LINQ. <a href="http://richarddingwall.name/2008/06/21/csharps-var-keyword-jeff-atwood-gets-it-all-wrong/" target="_blank">Here's</a> someone
else who is taking a similar take on it.
</p>
        <p>
Anyone have any thoughts on that?
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=5428d2b4-f00b-47fc-91a9-6825caa723b6" />
      </body>
      <title>WebThumbs working.. but an aside about VS.Net 2008's var keyword</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,5428d2b4-f00b-47fc-91a9-6825caa723b6.aspx</guid>
      <link>http://www.dotnettechnologies.com/2009/08/23/WebThumbsWorkingButAnAsideAboutVSNet2008sVarKeyword.aspx</link>
      <pubDate>Sun, 23 Aug 2009 06:09:25 GMT</pubDate>
      <description>&lt;p&gt;
Today, I was super-dad AND got a lot of coding done, and I managed to get my useful
links controls done for my site &lt;a href="http://www.rubiconcomputing.com/DevArea.aspx" target=_blank&gt;here&lt;/a&gt;.
It was actually a complex process to get things like the webthumbs integrated, update
the activity aggregator, create an admin page. The end result needs some cleanup,
but I think for a first run, it came out nice. Tomorrow I will blog on the details
and some code on how I did everything in case someone decides they want something
similar.
&lt;/p&gt;
&lt;p&gt;
Tonight, I am tired. But as I was coding, I came across some code for accessing my
webthumbs, and something struck me. In .Net 3.5, there's a new keyword "var" which
allows for anonymous casting (sort of). When it compiles, the underlying code is cast
to the correct type, and in using the var typed variable, it acts like the cast-type.
It would definitely speed up development if you used it a lot. For those old-school
VB fans, it really reminds me of the variant data type (which it is not). Read more
about it &lt;a href="http://msdn.microsoft.com/en-us/library/bb383973.aspx" target=_blank&gt;here &lt;/a&gt;if
you want some details.
&lt;/p&gt;
&lt;p&gt;
However, as with all things, there is a cost. For me, it's readability. In English
anyways, we read left to right. When I see a "var" vast variable, I have to keep reading
to understand the type, then see how it is used. Not too difficult (unless it is coming
out of a function or LINQ query), but it does take a little more time to figure it
out. For example..
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;var&lt;/span&gt; doc = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;XDocument&lt;/span&gt;(
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;XElement&lt;/span&gt;(
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;
&lt;p&gt;
That being said, you can get around using it by&amp;nbsp;declaring the variable to the
expected type when you code it. I have some samples I will post later when I was using
LINQ I forced myself to do this so I would fully understand what was happening in
my LINQ. &lt;a href="http://richarddingwall.name/2008/06/21/csharps-var-keyword-jeff-atwood-gets-it-all-wrong/" target=_blank&gt;Here's&lt;/a&gt; someone
else who is taking a similar take on it.
&lt;/p&gt;
&lt;p&gt;
Anyone have any thoughts on that?
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=5428d2b4-f00b-47fc-91a9-6825caa723b6" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,5428d2b4-f00b-47fc-91a9-6825caa723b6.aspx</comments>
      <category>All Things</category>
      <category>C#</category>
      <category>CSharp</category>
      <category>Design</category>
      <category>General</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=80361cb8-d014-4cc3-b122-202c9f889e92</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,80361cb8-d014-4cc3-b122-202c9f889e92.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,80361cb8-d014-4cc3-b122-202c9f889e92.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=80361cb8-d014-4cc3-b122-202c9f889e92</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
          <font face="Calibri" color="#000000" size="3">Here’s another question which is very
basic, and is mandatory to be able to answer for C# developers: </font>
        </p>
        <p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
          <font size="3">
            <font color="#000000">
              <font face="Calibri">
                <b>Question</b>: What are
the various access modifiers in C#?</font>
            </font>
          </font>
        </p>
        <p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
          <font size="3">
            <font color="#000000">
              <font face="Calibri">
                <b>
                </b>
              </font>
            </font>
          </font> 
</p>
        <p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
          <font size="3">
            <font color="#000000">
              <font face="Calibri">
                <b>Answer: </b>public, private,
protected, internal, protected internal</font>
            </font>
          </font>
        </p>
        <p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
          <font face="Calibri" color="#000000" size="3">Depending on how the person answers
the question (e.g. if it’s obviously an easy question for them, I move on), I may
follow up with “So what does the protected keyword mean?”</font>
        </p>
        <p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
          <font face="Calibri" color="#000000" size="3">So here’s the answers to each… you absolutely
need to know what each of these are!</font>
        </p>
        <p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
          <font size="3">
            <font color="#000000">
              <font face="Calibri">
                <b>Public</b> – accessible
to anything </font>
            </font>
          </font>
        </p>
        <p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
          <font size="3">
            <font color="#000000">
              <font face="Calibri">
                <b>Private</b> – can only
be access by code in the same class or struct</font>
            </font>
          </font>
        </p>
        <p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
          <font size="3">
            <font color="#000000">
              <font face="Calibri">
                <b>Internal</b> – accessible
only within the same assembly</font>
            </font>
          </font>
        </p>
        <p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
          <font size="3">
            <font color="#000000">
              <font face="Calibri">
                <b>Protected</b> – accessible
in the same class, or in a derived class</font>
            </font>
          </font>
        </p>
        <p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
          <font face="Calibri" color="#000000" size="3">
          </font> 
</p>
        <p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
          <font face="Calibri" color="#000000" size="3">Go here for some more info if needed:  </font>
          <a href="http://msdn.microsoft.com/en-us/library/ms173121.aspx" target="_blank">
            <font face="Calibri" size="3">http://msdn.microsoft.com/en-us/library/ms173121.aspx</font>
          </a>
          <font face="Calibri" color="#000000" size="3">
          </font>
        </p>
        <p>
        </p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=80361cb8-d014-4cc3-b122-202c9f889e92" />
      </body>
      <title>Tip of the Day: Interview Questions- Access modifiers in C#         </title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,80361cb8-d014-4cc3-b122-202c9f889e92.aspx</guid>
      <link>http://www.dotnettechnologies.com/2009/08/21/TipOfTheDayInterviewQuestionsAccessModifiersInC.aspx</link>
      <pubDate>Fri, 21 Aug 2009 04:06:04 GMT</pubDate>
      <description>&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;Here’s another question which is very basic,
and is mandatory to be able to answer for C# developers: &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font size=3&gt;&lt;font color=#000000&gt;&lt;font face=Calibri&gt;&lt;b&gt;Question&lt;/b&gt;: What are the
various access modifiers in C#?&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font size=3&gt;&lt;font color=#000000&gt;&lt;font face=Calibri&gt;&lt;b&gt;&lt;/b&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font size=3&gt;&lt;font color=#000000&gt;&lt;font face=Calibri&gt;&lt;b&gt;Answer: &lt;/b&gt;public, private,
protected, internal, protected internal&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;Depending on how the person answers the question
(e.g. if it’s obviously an easy question for them, I move on), I may follow up with
“So what does the protected keyword mean?”&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;So here’s the answers to each… you absolutely
need to know what each of these are!&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font size=3&gt;&lt;font color=#000000&gt;&lt;font face=Calibri&gt;&lt;b&gt;Public&lt;/b&gt; – accessible to
anything &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font size=3&gt;&lt;font color=#000000&gt;&lt;font face=Calibri&gt;&lt;b&gt;Private&lt;/b&gt; – can only be access
by code in the same class or struct&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font size=3&gt;&lt;font color=#000000&gt;&lt;font face=Calibri&gt;&lt;b&gt;Internal&lt;/b&gt; – accessible only
within the same assembly&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font size=3&gt;&lt;font color=#000000&gt;&lt;font face=Calibri&gt;&lt;b&gt;Protected&lt;/b&gt; – accessible
in the same class, or in a derived class&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;&lt;/font&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;Go here for some more info if needed:&amp;nbsp; &lt;/font&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms173121.aspx" target=_blank&gt;&lt;font face=Calibri size=3&gt;http://msdn.microsoft.com/en-us/library/ms173121.aspx&lt;/font&gt;&lt;/a&gt;&lt;font face=Calibri color=#000000 size=3&gt; &lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=80361cb8-d014-4cc3-b122-202c9f889e92" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,80361cb8-d014-4cc3-b122-202c9f889e92.aspx</comments>
      <category>All Things</category>
      <category>C#</category>
      <category>Design</category>
      <category>General</category>
      <category>Tips and Tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=9ce8b8f1-1639-45fd-819b-7ce942362179</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,9ce8b8f1-1639-45fd-819b-7ce942362179.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,9ce8b8f1-1639-45fd-819b-7ce942362179.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=9ce8b8f1-1639-45fd-819b-7ce942362179</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I've been doing technical interviews for about 5 years now for .Net, and hired a lot
of developers in that time. As a result, I have become proficient at quickly assessing
a level of technical expertise as well as how a developer may fit within an organization.
I will blog another time about what characteristics I look for in a candidate,
but for now, I will go through some of the technical questions I ask, answer them,
and explain why I ask the question.
</p>
        <p>
          <strong>Question:</strong> What's the difference between an abstract class and an
interface
</p>
        <p>
          <strong>Answer: </strong>They have some similarities in that they both define abstract
members which have to be implemented. An interface is really just a contract where
you are stating "if I implement this interface, I will implement these methods". However,
an abstract class <em>can</em> have an implementation, where an interface cannot.
An abstract class can also have constructors and field data. 
</p>
        <p>
One advantage of an interface is that you can implement more than one interface per
class, but you can only inherit from one class.
</p>
        <p>
Note there's a lot more you could talk about with them both (and you don't want to
overtalk any question), but the above will demonstrate you have a good knowledge of
OOP design, which is what I was looking for. It's surprising how many developers
cannot get this question right.
</p>
        <p>
To learn more, here's a <a href="http://www.codeproject.com/KB/cs/abstractsvsinterfaces.aspx" target="_blank">good
article </a>which discusses them in more detail (more than you'd need to answer the
question for sure, but good knowledge to have!)
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=9ce8b8f1-1639-45fd-819b-7ce942362179" />
      </body>
      <title>Tip of the Day: Technical Interview question: The difference between a abstract class and an interface</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,9ce8b8f1-1639-45fd-819b-7ce942362179.aspx</guid>
      <link>http://www.dotnettechnologies.com/2009/08/18/TipOfTheDayTechnicalInterviewQuestionTheDifferenceBetweenAAbstractClassAndAnInterface.aspx</link>
      <pubDate>Tue, 18 Aug 2009 15:02:10 GMT</pubDate>
      <description>&lt;p&gt;
I've been doing technical interviews for about 5 years now for .Net, and hired a lot
of developers in that time. As a result, I have become proficient at quickly assessing
a level of technical expertise as well as how a developer may fit within an organization.
I will blog another time about&amp;nbsp;what characteristics I look for in a candidate,
but for now, I will go through some of the technical questions I ask, answer them,
and explain why I ask the question.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Question:&lt;/strong&gt; What's the difference between an abstract class and an
interface
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Answer: &lt;/strong&gt;They have some similarities in that they both define abstract
members which have to be implemented. An interface is really just a contract where
you are stating "if I implement this interface, I will implement these methods". However,
an abstract class &lt;em&gt;can&lt;/em&gt; have an implementation, where an interface cannot.
An abstract class can also have constructors and field data. 
&lt;/p&gt;
&lt;p&gt;
One advantage of an interface is that you can implement more than one interface per
class, but you can only inherit from one class.
&lt;/p&gt;
&lt;p&gt;
Note there's a lot more you could talk about with them both (and you don't want to
overtalk any question), but the above will demonstrate you have a good knowledge of
OOP design, which is what I was looking for. It's&amp;nbsp;surprising how many developers
cannot get this question right.
&lt;/p&gt;
&lt;p&gt;
To learn more, here's a &lt;a href="http://www.codeproject.com/KB/cs/abstractsvsinterfaces.aspx" target=_blank&gt;good
article &lt;/a&gt;which discusses them in more detail (more than you'd need to answer the
question for sure, but good knowledge to have!)
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=9ce8b8f1-1639-45fd-819b-7ce942362179" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,9ce8b8f1-1639-45fd-819b-7ce942362179.aspx</comments>
      <category>All Things</category>
      <category>Design</category>
      <category>General</category>
      <category>Tips and Tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=bc6f5c00-7429-4ae3-911d-121870d05fe8</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,bc6f5c00-7429-4ae3-911d-121870d05fe8.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,bc6f5c00-7429-4ae3-911d-121870d05fe8.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=bc6f5c00-7429-4ae3-911d-121870d05fe8</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
As developers, we tend to get stuck in development boxes. By that, a lot of times
you're so busy heads down, things change around you and you don't get a chance to
do different things unless a problem comes up and you research the solution to it. 
</p>
        <p>
As new developers, the amount of information available can seem overwhelming. When
do I use a web service? What are Design Patterns? What's the recommended way to.....
you get the idea.
</p>
        <p>
Fortunately, there's a guide on CodePlex which present high level concepts and recommendations
for architects and would-be architects. It's a great reference, and best of all, it's
free! If you have not downloaded it, I highly recommend you rush <a href="http://www.codeplex.com/AppArchGuide/Release/ProjectReleases.aspx?ReleaseId=20586" target="_blank">here</a> and
get it.
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=bc6f5c00-7429-4ae3-911d-121870d05fe8" />
      </body>
      <title>Tip of the Day: Get the Application Architecture guidelines!</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,bc6f5c00-7429-4ae3-911d-121870d05fe8.aspx</guid>
      <link>http://www.dotnettechnologies.com/2009/08/17/TipOfTheDayGetTheApplicationArchitectureGuidelines.aspx</link>
      <pubDate>Mon, 17 Aug 2009 00:21:50 GMT</pubDate>
      <description>&lt;p&gt;
As developers, we tend to get stuck in development boxes. By that, a lot of times
you're so busy heads down, things change around you and you don't get a chance to
do different things unless a problem comes up and you research the solution to it. 
&lt;/p&gt;
&lt;p&gt;
As new developers, the amount of information available can seem overwhelming. When
do I use a web service? What are Design Patterns? What's the recommended way to.....
you get the idea.
&lt;/p&gt;
&lt;p&gt;
Fortunately, there's a guide on CodePlex which present high level concepts and recommendations
for architects and would-be architects. It's a great reference, and best of all, it's
free! If you have not downloaded it, I highly recommend you rush &lt;a href="http://www.codeplex.com/AppArchGuide/Release/ProjectReleases.aspx?ReleaseId=20586" target=_blank&gt;here&lt;/a&gt; and
get it.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=bc6f5c00-7429-4ae3-911d-121870d05fe8" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,bc6f5c00-7429-4ae3-911d-121870d05fe8.aspx</comments>
      <category>All Things</category>
      <category>Design</category>
      <category>General</category>
      <category>Tips and Tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=308bd3f2-4d3c-48b6-84f2-1dbe04982eed</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,308bd3f2-4d3c-48b6-84f2-1dbe04982eed.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,308bd3f2-4d3c-48b6-84f2-1dbe04982eed.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=308bd3f2-4d3c-48b6-84f2-1dbe04982eed</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I have to get some landscape rock put out before my home owner's association has a
cow, but I decided to do some more work on my activity aggregator. Today, I decided
to integrate my blog feed into it, so when I post here, it will automatically update
this activity on my home page (and soon to be in my developer's area).
</p>
        <p>
Here's what the end result looks (for now).
</p>
        <p>
          <img src="http://www.dotnettechnologies.com/content/binary/DevArea.png" border="0" />
        </p>
        <p>
Doing it was fairly easy with the design I implemented in my last <a href="http://www.dotnettechnologies.com/PermaLink,guid,058b6bdb-5cc4-470d-a4ff-3f7452a4a7b1.aspx" target="_blank">post</a>.
My BlogFeed class inherits the BaseFeed class, which means I need to implement the
ParseFeed() method. Since the RSS feed from my blog is XML, I was easily able to adapt the
same code from my TwitterFeed class to work for this RSS feed (which should actually
work for any RSS feed I pass in).
</p>
        <p>
I also created another Extension method (for practice) to convert the RSS feed date
time to a C# DateTime object. I will post that code as "Tip of the Day" but I have
to give Dan Wahlin <a href="http://weblogs.asp.net/dwahlin/archive/2006/09/28/Creating-an-ASP.NET-RSS-Blog-Roller.aspx" target="_blank">credit</a> for
it, as I adapted some sample code he provided.
</p>
        <p>
Here's how the RSS feed (aka BlogFeed) uses LINQ to XML for creating my activity object.
</p>
        <div style="FONT-SIZE: 7pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <span style="COLOR: #2b91af">
            <div style="FONT-SIZE: 7pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
              <p style="MARGIN: 0px">
    <span style="COLOR: blue">internal</span><span style="COLOR: blue">class</span><span style="COLOR: #2b91af">BlogFeed</span> : <span style="COLOR: #2b91af">BaseFeed</span></p>
              <p style="MARGIN: 0px">
    {
</p>
              <p style="MARGIN: 0px">
 
</p>
              <p style="MARGIN: 0px">
        <span style="COLOR: blue">public</span><span style="COLOR: blue">override</span><span style="COLOR: blue">int</span> ParseFeed(<span style="COLOR: #2b91af">XDocument</span> doc)
</p>
              <p style="MARGIN: 0px">
        {
</p>
              <p style="MARGIN: 0px">
            <span style="COLOR: blue">try</span></p>
              <p style="MARGIN: 0px">
            {
</p>
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">ReturnCode</span> code
= <span style="COLOR: #2b91af">ReturnCode</span>.Success;
</p>
              <p style="MARGIN: 0px">
                <span style="COLOR: blue">if</span> (doc
!= <span style="COLOR: blue">null</span>)
</p>
              <p style="MARGIN: 0px">
                {
</p>
              <p style="MARGIN: 0px">
                    <span style="COLOR: blue">var</span> activityList
= <span style="COLOR: blue">from</span> e <span style="COLOR: blue">in</span> doc.Descendants(<span style="COLOR: #a31515">"item"</span>)
</p>
              <p style="MARGIN: 0px">
                   
                   <span style="COLOR: blue">select</span><span style="COLOR: blue">new</span> RubiconPortal.BusinessObjects.<span style="COLOR: #2b91af">Activity</span></p>
              <p style="MARGIN: 0px">
                   
                  
{
</p>
              <p style="MARGIN: 0px">
                   
                   
   ActivityTypeID = <span style="COLOR: #2b91af">ActivityTypes</span>.Blog.Code,
</p>
              <p style="MARGIN: 0px">
                   
                   
   ActivityDate = e.Element(<span style="COLOR: #a31515">"pubDate"</span>).Value.RSSDateTime().ToShortDateString()
+ <span style="COLOR: #a31515">" "</span> + e.Element(<span style="COLOR: #a31515">"pubDate"</span>).Value.RSSDateTime().ToShortDateString(),
</p>
              <p style="MARGIN: 0px">
                   
                   
   ActivitySummary = <span style="COLOR: #2b91af">HttpUtility</span>.HtmlDecode(e.Element(<span style="COLOR: #a31515">"title"</span>).Value),
</p>
              <p style="MARGIN: 0px">
                   
                   
   ActivityDetailsURL = e.Element(<span style="COLOR: #a31515">"link"</span>).Value
</p>
              <p style="MARGIN: 0px">
                   
                  
};
</p>
              <p style="MARGIN: 0px">
 
</p>
              <p style="MARGIN: 0px">
                    <span style="COLOR: blue">foreach</span> (<span style="COLOR: #2b91af">Activity</span> item <span style="COLOR: blue">in</span> activityList)
</p>
              <p style="MARGIN: 0px">
                   
{
</p>
              <p style="MARGIN: 0px">
                   
    <span style="COLOR: green">//We need to check and see if the item
exists</span></p>
              <p style="MARGIN: 0px">
                   
    <span style="COLOR: blue">if</span> (!<span style="COLOR: #2b91af">Activity</span>.CheckEntryExists(item.ActivityTypeID,
item.ActivityDetailsURL))
</p>
              <p style="MARGIN: 0px">
                   
    {
</p>
              <p style="MARGIN: 0px">
                   
        <span style="COLOR: blue">int</span> results
= item.Save();
</p>
              <p style="MARGIN: 0px">
                   
        <span style="COLOR: blue">if</span> (results
!= <span style="COLOR: #2b91af">ReturnCode</span>.Success.Code)
</p>
              <p style="MARGIN: 0px">
                   
            code = <span style="COLOR: #2b91af">ReturnCode</span>.Failure;
</p>
              <p style="MARGIN: 0px">
                   
    }
</p>
              <p style="MARGIN: 0px">
                   
    <span style="COLOR: blue">else</span></p>
              <p style="MARGIN: 0px">
                   
        <span style="COLOR: blue">return</span> code.Code;   <span style="COLOR: green">//we
can break once we hit one we've already logged (for performance reasons</span></p>
              <p style="MARGIN: 0px">
 
</p>
              <p style="MARGIN: 0px">
 
</p>
              <p style="MARGIN: 0px">
                   
}
</p>
              <p style="MARGIN: 0px">
 
</p>
              <p style="MARGIN: 0px">
 
</p>
              <p style="MARGIN: 0px">
                }
</p>
              <p style="MARGIN: 0px">
                <span style="COLOR: blue">return</span> code.Code;
</p>
              <p style="MARGIN: 0px">
            }
</p>
              <p style="MARGIN: 0px">
            <span style="COLOR: blue">catch</span> (<span style="COLOR: #2b91af">Exception</span> ex)
</p>
              <p style="MARGIN: 0px">
            {
</p>
              <p style="MARGIN: 0px">
                ErrorHandler(ex, <span style="COLOR: #a31515">"An
unexpected error occurred in TwitterFeed.ParseFeed() - "</span> + ex.Message);
</p>
              <p style="MARGIN: 0px">
                <span style="COLOR: blue">return</span><span style="COLOR: #2b91af">ReturnCode</span>.Failure.Code;
</p>
              <p style="MARGIN: 0px">
            }
</p>
              <p style="MARGIN: 0px">
        }
</p>
              <p style="MARGIN: 0px">
    }
</p>
              <p style="MARGIN: 0px">
 
</p>
            </div>
            <!--EndFragment-->
            <p style="MARGIN: 0px">
              <!--EndFragment-->
            </p>
          </span>
          <font face="Verdana" size="2">My next step will be to integrate some AJAX
so when the user hovers over the link, they can see things like the date, more of
the topic, etc. I also need to integrate my "Useful Links" dicussion as well.</font>
        </div>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=308bd3f2-4d3c-48b6-84f2-1dbe04982eed" />
      </body>
      <title>Logging Blog Activity to my Activity Aggregator</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,308bd3f2-4d3c-48b6-84f2-1dbe04982eed.aspx</guid>
      <link>http://www.dotnettechnologies.com/2009/08/15/LoggingBlogActivityToMyActivityAggregator.aspx</link>
      <pubDate>Sat, 15 Aug 2009 20:13:22 GMT</pubDate>
      <description>&lt;p&gt;
I have to get some landscape rock put out before my home owner's association has a
cow, but I decided to do some more work on my activity aggregator. Today, I decided
to integrate my blog feed into it, so when I post here, it will automatically update
this activity on my home page (and soon to be in my developer's area).
&lt;/p&gt;
&lt;p&gt;
Here's what the end result looks (for now).
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://www.dotnettechnologies.com/content/binary/DevArea.png" border=0&gt;
&lt;/p&gt;
&lt;p&gt;
Doing it was fairly easy with the design I implemented in my last &lt;a href="http://www.dotnettechnologies.com/PermaLink,guid,058b6bdb-5cc4-470d-a4ff-3f7452a4a7b1.aspx" target=_blank&gt;post&lt;/a&gt;.
My BlogFeed class inherits the BaseFeed class, which means I need to implement the
ParseFeed() method. Since the RSS feed from my blog is XML, I was easily able to adapt&amp;nbsp;the
same code from my TwitterFeed class to work for this RSS feed (which should actually
work for any RSS feed I pass in).
&lt;/p&gt;
&lt;p&gt;
I also created another Extension method (for practice) to convert the RSS feed date
time to a C# DateTime object. I will post that code as "Tip of the Day" but I have
to give Dan Wahlin &lt;a href="http://weblogs.asp.net/dwahlin/archive/2006/09/28/Creating-an-ASP.NET-RSS-Blog-Roller.aspx" target=_blank&gt;credit&lt;/a&gt; for
it, as I adapted some sample code he provided.
&lt;/p&gt;
&lt;p&gt;
Here's how the RSS feed (aka BlogFeed) uses LINQ to XML for creating my activity object.
&lt;/p&gt;
&lt;div style="FONT-SIZE: 7pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;&lt;span style="COLOR: #2b91af"&gt; 
&lt;div style="FONT-SIZE: 7pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;internal&lt;/span&gt; &lt;span style="COLOR: blue"&gt;class&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;BlogFeed&lt;/span&gt; : &lt;span style="COLOR: #2b91af"&gt;BaseFeed&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;override&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; ParseFeed(&lt;span style="COLOR: #2b91af"&gt;XDocument&lt;/span&gt; doc)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;try&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #2b91af"&gt;ReturnCode&lt;/span&gt; code
= &lt;span style="COLOR: #2b91af"&gt;ReturnCode&lt;/span&gt;.Success;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (doc
!= &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;var&lt;/span&gt; activityList
= &lt;span style="COLOR: blue"&gt;from&lt;/span&gt; e &lt;span style="COLOR: blue"&gt;in&lt;/span&gt; doc.Descendants(&lt;span style="COLOR: #a31515"&gt;"item"&lt;/span&gt;)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;select&lt;/span&gt; &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; RubiconPortal.BusinessObjects.&lt;span style="COLOR: #2b91af"&gt;Activity&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp; ActivityTypeID = &lt;span style="COLOR: #2b91af"&gt;ActivityTypes&lt;/span&gt;.Blog.Code,
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp; ActivityDate = e.Element(&lt;span style="COLOR: #a31515"&gt;"pubDate"&lt;/span&gt;).Value.RSSDateTime().ToShortDateString()
+ &lt;span style="COLOR: #a31515"&gt;" "&lt;/span&gt; + e.Element(&lt;span style="COLOR: #a31515"&gt;"pubDate"&lt;/span&gt;).Value.RSSDateTime().ToShortDateString(),
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp; ActivitySummary = &lt;span style="COLOR: #2b91af"&gt;HttpUtility&lt;/span&gt;.HtmlDecode(e.Element(&lt;span style="COLOR: #a31515"&gt;"title"&lt;/span&gt;).Value),
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp; ActivityDetailsURL = e.Element(&lt;span style="COLOR: #a31515"&gt;"link"&lt;/span&gt;).Value
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;
};
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;foreach&lt;/span&gt; (&lt;span style="COLOR: #2b91af"&gt;Activity&lt;/span&gt; item &lt;span style="COLOR: blue"&gt;in&lt;/span&gt; activityList)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//We need to check and see if the item
exists&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (!&lt;span style="COLOR: #2b91af"&gt;Activity&lt;/span&gt;.CheckEntryExists(item.ActivityTypeID,
item.ActivityDetailsURL))
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; results
= item.Save();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (results
!= &lt;span style="COLOR: #2b91af"&gt;ReturnCode&lt;/span&gt;.Success.Code)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; code = &lt;span style="COLOR: #2b91af"&gt;ReturnCode&lt;/span&gt;.Failure;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;else&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; code.Code;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//we
can break once we hit one we've already logged (for performance reasons&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; code.Code;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;catch&lt;/span&gt; (&lt;span style="COLOR: #2b91af"&gt;Exception&lt;/span&gt; ex)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ErrorHandler(ex, &lt;span style="COLOR: #a31515"&gt;"An
unexpected error occurred in TwitterFeed.ParseFeed() - "&lt;/span&gt; + ex.Message);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;ReturnCode&lt;/span&gt;.Failure.Code;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;!--EndFragment--&gt;
&lt;/span&gt;&lt;font face=Verdana size=2&gt;My next step will be to integrate some AJAX so when
the user hovers over the link, they can see things like the date, more of the topic,
etc. I also need to integrate my "Useful Links" dicussion as well.&lt;/font&gt;&gt;
&lt;/div&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=308bd3f2-4d3c-48b6-84f2-1dbe04982eed" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,308bd3f2-4d3c-48b6-84f2-1dbe04982eed.aspx</comments>
      <category>All Things</category>
      <category>ASP.Net</category>
      <category>C#</category>
      <category>CSharp</category>
      <category>Design</category>
      <category>General</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=058b6bdb-5cc4-470d-a4ff-3f7452a4a7b1</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,058b6bdb-5cc4-470d-a4ff-3f7452a4a7b1.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,058b6bdb-5cc4-470d-a4ff-3f7452a4a7b1.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=058b6bdb-5cc4-470d-a4ff-3f7452a4a7b1</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Tonight was a very enjoyable night of coding. I created the first phase of my "activity
aggregator". I actually had a more clever name for it, but being tired, it slips my
mind right now.
</p>
        <p>
Currently, I post several places.. short updates for on Twitter. Longer discussions
end up on here, my blog. I have some other sources I plan on integrating over time,
such as links I found useful (similar to Digg, but also where I can place why I found
it useful). That means growth, and when it comes to design, it's best to design change
into it up front.
</p>
        <p>
The first thing I needed to do was create my table and business object to collect
these activities. In my table, I store ActivityDate, what type of activity it was
(foreign key to another table -- ActivityType), a brief summary of the activity text,
and finally the url someone interested could click on to get more information. The
internal members of my activity class look like this:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: #2b91af">   15</span> <span style="COLOR: blue">   
    #region</span> Private Members
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #2b91af">   16</span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #2b91af">   17</span>         <span style="COLOR: blue">private</span><span style="COLOR: blue">int</span> activityID;
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #2b91af">   18</span>         <span style="COLOR: blue">private</span><span style="COLOR: blue">int</span> activityTypeID;
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #2b91af">   19</span>         <span style="COLOR: blue">private</span><span style="COLOR: blue">string</span> activityDate;
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #2b91af">   20</span>         <span style="COLOR: blue">private</span><span style="COLOR: blue">string</span> activitySummary;
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #2b91af">   21</span>         <span style="COLOR: blue">private</span><span style="COLOR: blue">string</span> activityDetailsURL;
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #2b91af">   22</span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #2b91af">   23</span> <span style="COLOR: blue">   
    #endregion</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">
            </span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">
              <font face="Verdana" color="#000000">Each private member
has a publically exposed property.</font>
            </span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">
              <font face="Verdana" color="#000000">
              </font>
            </span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">
              <font face="Verdana" color="#000000">Most of my activities
will have XML feeds, such as the RSS feed of my blog, and the Twitter API. Therefore,
I enforce a similar implementation by creating an abstract base class, called BaseFeed,
which looks like this:</font>
            </span>
          </p>
          <span style="COLOR: blue">
            <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">    1</span> <span style="COLOR: blue">using</span> System.Xml.Linq;
</p>
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">    2</span> <span style="COLOR: blue">using</span> RubiconPortal.Common;
</p>
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">    3</span> 
</p>
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">    4</span> <span style="COLOR: blue">namespace</span> RubiconPortal.BusinessObjects
</p>
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">    5</span> {
</p>
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">    6</span>     <span style="COLOR: blue">internal</span><span style="COLOR: blue">abstract</span><span style="COLOR: blue">class</span><span style="COLOR: #2b91af">BaseFeed</span> :
BaseClass
</p>
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">    7</span>    
{
</p>
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">    8</span> 
</p>
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">    9</span>    
    <span style="COLOR: blue">public</span><span style="COLOR: blue">abstract</span><span style="COLOR: blue">int</span> ParseFeed(XDocument
doc);
</p>
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">   10</span> 
</p>
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">   11</span>     }
</p>
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">   12</span> }
</p>
            </div>
            <!--EndFragment-->
          </span>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">
              <font face="Verdana" color="#000000">
              </font>
            </span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">
              <font face="Verdana" color="#000000">So now I have a "contract"
that I need to use to have a similar method for any activity I want to log. I could
have used an interface for this, since there's no true implentation here, and I may
refactor it later to do so, but I do have some ideas where I may want to provide some
implementation, so that's why I chose an abstract class.</font>
            </span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">
              <font face="Verdana" color="#000000">
              </font>
            </span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">
              <font face="Verdana" color="#000000">So the first item I
wanted to do was implement capturing my <a href="http://twitter.com/RubiconComp" target="_blank">Twitter
posts</a> in this activity, since I currently don't have a way to capture and post
them on my site. I will add the rest of the activities later. In a previous post,
I described how I took the Yedda Twitter API and modified it to return XDocuments,
and here's another chance to take advantage of that change with LINQ.</font>
            </span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">
              <font face="Verdana" color="#000000">
              </font>
            </span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">
              <font face="Verdana" color="#000000">When I post to my Twitter
feed, I want to make sure my home page automatically reflects this activity. So I
implement a TwitterFeed object, which implements the BaseFeed method ParseFeed. Using
LINQ to XML, I pull out the pieces of the response I want, and populate the public
properties of my Activities class, then save my activity. Here's what my TwitterFeed
class looks like:</font>
            </span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">
              <font face="Verdana" color="#000000">
              </font>
            </span> 
</p>
          <span style="COLOR: blue">
            <font face="Verdana" color="#000000">
              <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">    1</span> <span style="COLOR: blue">using</span> System;
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">    2</span> <span style="COLOR: blue">using</span> System.Linq;
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">    3</span> <span style="COLOR: blue">using</span> System.Web;
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">    4</span> <span style="COLOR: blue">using</span> System.Xml.Linq;
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">    5</span> <span style="COLOR: blue">using</span> Rubicon.Common;
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">    6</span> <span style="COLOR: blue">using</span> RubiconPortal.Common;
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">    7</span> 
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">    8</span> <span style="COLOR: blue">namespace</span> RubiconPortal.BusinessObjects
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">    9</span> {
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   10</span>     <span style="COLOR: blue">internal</span><span style="COLOR: blue">class</span><span style="COLOR: #2b91af">TwitterFeed</span> :
BaseFeed
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   11</span>     {
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   12</span>         <span style="COLOR: blue">public</span><span style="COLOR: blue">override</span><span style="COLOR: blue">int</span> ParseFeed(XDocument
doc)
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   13</span>        
{
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   14</span>        
    <span style="COLOR: blue">try</span></p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   15</span>        
    {
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   16</span>        
        <span style="COLOR: blue">if</span> (doc != <span style="COLOR: blue">null</span>)
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   17</span>        
        {
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   18</span>        
            <span style="COLOR: blue">var</span> activityList
= <span style="COLOR: blue">from</span> e <span style="COLOR: blue">in</span> doc.Descendants(<span style="COLOR: #a31515">"status"</span>)
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   19</span>        
                   
           <span style="COLOR: blue">select</span><span style="COLOR: blue">new</span> RubiconPortal.BusinessObjects.Activity
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   20</span>        
                   
           {
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   21</span>        
                   
               ActivityTypeID
= ActivityTypes.Twitter.Code,
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   22</span>        
                   
               ActivityDate
= (e.Element(<span style="COLOR: #a31515">"created_at"</span>).Value.ParseDateTime()).ToShortDateString()
+ <span style="COLOR: #a31515">" "</span> + (e.Element(<span style="COLOR: #a31515">"created_at"</span>).Value.ParseDateTime()).ToShortTimeString(),
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   23</span>        
                   
               ActivitySummary
= HttpUtility.HtmlDecode(e.Element(<span style="COLOR: #a31515">"text"</span>).Value),
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   24</span>        
                   
               ActivityDetailsURL
= <span style="COLOR: #a31515">"http://twitter.com/"</span> + e.Element(<span style="COLOR: #a31515">"user"</span>).Element(<span style="COLOR: #a31515">"screen_name"</span>).Value
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   25</span>        
                   
           };
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   26</span> 
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   27</span>        
            <span style="COLOR: blue">foreach</span> (RubiconPortal.BusinessObjects.Activity
item <span style="COLOR: blue">in</span> activityList)
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   28</span>        
            {
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   29</span>        
                item.Save();
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   30</span>        
            }
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   31</span>        
        }
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   32</span> 
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   33</span>        
        <span style="COLOR: blue">return</span> ReturnCode.Success.Code;
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   34</span>        
    }
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   35</span>        
    <span style="COLOR: blue">catch</span> (<span style="COLOR: #2b91af">Exception</span> ex)
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   36</span>        
    {
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   37</span>        
        ErrorHandler(ex, <span style="COLOR: #a31515">"An
unexpected error occurred in TwitterFeed.ParseFeed() - "</span> + ex.Message);
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   38</span>        
        <span style="COLOR: blue">return</span> ReturnCode.Failure.Code;
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   39</span>        
    } 
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   40</span>        
}
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   41</span> 
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   42</span>     }
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   43</span> 
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   44</span> }
</p>
              </div>
              <!--EndFragment-->
            </font>
          </span>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">
              <font face="Verdana" color="#000000">
              </font>
            </span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">
              <font face="Verdana" color="#000000">Within the ParseFeed
method I am using LINQ to XML to populate my business object calling the save()
method to write it to the database. As you can see, using LINQ to XML can be
a lot simpler than using XML/XPath. Once in the database, I can query it in my user
control, and display it on my home page <a href="http://www.rubiconcomputing.com/" target="_blank">here</a>.</font>
            </span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">
              <font face="Verdana" color="#000000">
              </font>
            </span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">
              <font face="Verdana" color="#000000">Now, when I make my
Twitter post, all I need to do is take the XDocument the Twitter API returns, and
pass it into the ParseFeed method, which looks like this...</font>
            </span>
          </p>
          <span style="COLOR: blue">
            <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">   35</span>        
            <span style="COLOR: green">//Post
my tweet to Twitter</span></p>
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">   36</span>        
            TwitterAPI twit = <span style="COLOR: blue">new</span> TwitterAPI();
</p>
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">   37</span>        
            XDocument doc = twit.UpdateAsXML(Settings.TwitterUserName(),
Settings.TwitterPassword(), txtPost.Text);
</p>
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">   38</span> 
</p>
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">   39</span>        
            <span style="COLOR: green">//Save
it to the activity table for displaying the activity</span></p>
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">   40</span>        
            TwitterFeed feed = <span style="COLOR: blue">new</span> TwitterFeed();
</p>
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">   41</span>        
            feed.ParseFeed(doc);
</p>
            </div>
            <!--EndFragment-->
          </span>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">
              <font face="Verdana" color="#000000">
              </font>
            </span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">
              <font face="Verdana" color="#000000">Simple and neat! Now
when I implement it for my blog, it will be just as quick and easy!</font>
            </span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">
              <font face="Verdana" color="#000000">
              </font>
            </span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">
              <font face="Verdana" color="#000000">Props go out to this <a href="http://blogs.msdn.com/bursteg/archive/2009/05/29/twitter-api-from-c-getting-a-user-s-time-line.aspx" target="_blank">post </a>I
snagged an extension method for formatting the Twitter posting date to something a
human can use (and my C# class can use to manipulate and save!)</font>
            </span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">
              <font face="Verdana" color="#000000">
              </font>
            </span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">
              <font face="Verdana" color="#000000">
              </font>
            </span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">
              <font face="Verdana" color="#000000">
              </font>
            </span> 
</p>
        </div>
        <!--EndFragment-->
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=058b6bdb-5cc4-470d-a4ff-3f7452a4a7b1" />
      </body>
      <title>Creating my activity aggregator</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,058b6bdb-5cc4-470d-a4ff-3f7452a4a7b1.aspx</guid>
      <link>http://www.dotnettechnologies.com/2009/08/14/CreatingMyActivityAggregator.aspx</link>
      <pubDate>Fri, 14 Aug 2009 06:40:31 GMT</pubDate>
      <description>&lt;p&gt;
Tonight was a very enjoyable night of coding. I created the first phase of my "activity
aggregator". I actually had a more clever name for it, but being tired, it slips my
mind right now.
&lt;/p&gt;
&lt;p&gt;
Currently, I post several places.. short updates for on Twitter. Longer discussions
end up on here, my blog. I have some other sources I plan on integrating over time,
such as links I found useful (similar to Digg, but also where I can place why I found
it useful). That means growth, and when it comes to design, it's best to design change
into it up front.
&lt;/p&gt;
&lt;p&gt;
The first thing I needed to do was create my table and business object to collect
these activities. In my table, I store ActivityDate, what type of activity it was
(foreign key to another table -- ActivityType), a brief summary of the activity text,
and finally the url someone interested could click on to get more information. The
internal members of my activity class look like this:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;15&lt;/span&gt;&amp;nbsp;&lt;span style="COLOR: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; #region&lt;/span&gt; Private Members
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;16&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;17&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; activityID;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;18&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; activityTypeID;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;19&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; activityDate;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;20&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; activitySummary;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;21&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; activityDetailsURL;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;22&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;23&lt;/span&gt;&amp;nbsp;&lt;span style="COLOR: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; #endregion&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face=Verdana color=#000000&gt;Each private member has
a publically exposed property.&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face=Verdana color=#000000&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face=Verdana color=#000000&gt;Most of my activities will
have XML feeds, such as the RSS feed of my blog, and the Twitter API. Therefore, I
enforce a similar implementation by creating an abstract base class, called BaseFeed,
which looks like this:&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;span style="COLOR: blue"&gt; 
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;1&lt;/span&gt;&amp;nbsp;&lt;span style="COLOR: blue"&gt;using&lt;/span&gt; System.Xml.Linq;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2&lt;/span&gt;&amp;nbsp;&lt;span style="COLOR: blue"&gt;using&lt;/span&gt; RubiconPortal.Common;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;3&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;4&lt;/span&gt;&amp;nbsp;&lt;span style="COLOR: blue"&gt;namespace&lt;/span&gt; RubiconPortal.BusinessObjects
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;5&lt;/span&gt;&amp;nbsp;{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;6&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;internal&lt;/span&gt; &lt;span style="COLOR: blue"&gt;abstract&lt;/span&gt; &lt;span style="COLOR: blue"&gt;class&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;BaseFeed&lt;/span&gt; :
BaseClass
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;7&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;8&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;9&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;abstract&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; ParseFeed(XDocument
doc);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;10&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;11&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;12&lt;/span&gt;&amp;nbsp;}
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;&lt;/span&gt; 
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face=Verdana color=#000000&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face=Verdana color=#000000&gt;So now I have a "contract"
that I need to use to have a similar method for any activity I want to log. I could
have used an interface for this, since there's no true implentation here, and I may
refactor it later to do so, but I do have some ideas where I may want to provide some
implementation, so that's why I chose an abstract class.&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face=Verdana color=#000000&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face=Verdana color=#000000&gt;So the first item I wanted
to do was implement capturing my &lt;a href="http://twitter.com/RubiconComp" target=_blank&gt;Twitter
posts&lt;/a&gt; in this activity, since I currently don't have a way to capture and post
them on my site. I will add the rest of the activities later. In a previous post,
I described how I took the Yedda Twitter API and modified it to return XDocuments,
and here's another chance to take advantage of that change with LINQ.&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face=Verdana color=#000000&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face=Verdana color=#000000&gt;When I post to my Twitter
feed, I want to make sure my home page automatically reflects this activity. So I
implement a TwitterFeed object, which implements the BaseFeed method ParseFeed. Using
LINQ to XML, I pull out the pieces of the response I want, and populate the public
properties of my Activities class, then save my activity. Here's what my TwitterFeed
class looks like:&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face=Verdana color=#000000&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face=Verdana color=#000000&gt; 
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;1&lt;/span&gt;&amp;nbsp;&lt;span style="COLOR: blue"&gt;using&lt;/span&gt; System;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2&lt;/span&gt;&amp;nbsp;&lt;span style="COLOR: blue"&gt;using&lt;/span&gt; System.Linq;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;3&lt;/span&gt;&amp;nbsp;&lt;span style="COLOR: blue"&gt;using&lt;/span&gt; System.Web;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;4&lt;/span&gt;&amp;nbsp;&lt;span style="COLOR: blue"&gt;using&lt;/span&gt; System.Xml.Linq;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;5&lt;/span&gt;&amp;nbsp;&lt;span style="COLOR: blue"&gt;using&lt;/span&gt; Rubicon.Common;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;6&lt;/span&gt;&amp;nbsp;&lt;span style="COLOR: blue"&gt;using&lt;/span&gt; RubiconPortal.Common;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;7&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;8&lt;/span&gt;&amp;nbsp;&lt;span style="COLOR: blue"&gt;namespace&lt;/span&gt; RubiconPortal.BusinessObjects
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;9&lt;/span&gt;&amp;nbsp;{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;10&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;internal&lt;/span&gt; &lt;span style="COLOR: blue"&gt;class&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;TwitterFeed&lt;/span&gt; :
BaseFeed
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;11&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;12&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;override&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; ParseFeed(XDocument
doc)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;13&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;14&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;try&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;15&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;16&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (doc != &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;17&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;18&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;var&lt;/span&gt; activityList
= &lt;span style="COLOR: blue"&gt;from&lt;/span&gt; e &lt;span style="COLOR: blue"&gt;in&lt;/span&gt; doc.Descendants(&lt;span style="COLOR: #a31515"&gt;"status"&lt;/span&gt;)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;19&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;select&lt;/span&gt; &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; RubiconPortal.BusinessObjects.Activity
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;20&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;21&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; ActivityTypeID
= ActivityTypes.Twitter.Code,
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;22&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; ActivityDate
= (e.Element(&lt;span style="COLOR: #a31515"&gt;"created_at"&lt;/span&gt;).Value.ParseDateTime()).ToShortDateString()
+ &lt;span style="COLOR: #a31515"&gt;" "&lt;/span&gt; + (e.Element(&lt;span style="COLOR: #a31515"&gt;"created_at"&lt;/span&gt;).Value.ParseDateTime()).ToShortTimeString(),
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;23&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; ActivitySummary
= HttpUtility.HtmlDecode(e.Element(&lt;span style="COLOR: #a31515"&gt;"text"&lt;/span&gt;).Value),
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;24&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; ActivityDetailsURL
= &lt;span style="COLOR: #a31515"&gt;"http://twitter.com/"&lt;/span&gt; + e.Element(&lt;span style="COLOR: #a31515"&gt;"user"&lt;/span&gt;).Element(&lt;span style="COLOR: #a31515"&gt;"screen_name"&lt;/span&gt;).Value
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;25&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; };
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;26&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;27&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;foreach&lt;/span&gt; (RubiconPortal.BusinessObjects.Activity
item &lt;span style="COLOR: blue"&gt;in&lt;/span&gt; activityList)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;28&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;29&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; item.Save();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;30&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;31&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;32&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;33&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; ReturnCode.Success.Code;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;34&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;35&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;catch&lt;/span&gt; (&lt;span style="COLOR: #2b91af"&gt;Exception&lt;/span&gt; ex)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;36&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;37&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ErrorHandler(ex, &lt;span style="COLOR: #a31515"&gt;"An
unexpected error occurred in TwitterFeed.ParseFeed() - "&lt;/span&gt; + ex.Message);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;38&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; ReturnCode.Failure.Code;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;39&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; } 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;40&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;41&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;42&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;43&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;44&lt;/span&gt;&amp;nbsp;}
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;&lt;/font&gt;&lt;/span&gt; 
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face=Verdana color=#000000&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face=Verdana color=#000000&gt;Within&amp;nbsp;the ParseFeed
method I am&amp;nbsp;using LINQ to XML to populate my business object calling the save()
method&amp;nbsp;to write it to the database. As you can see, using LINQ to XML can be
a lot simpler than using XML/XPath. Once in the database, I can query it in my user
control, and display it on my home page &lt;a href="http://www.rubiconcomputing.com/" target=_blank&gt;here&lt;/a&gt;.&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face=Verdana color=#000000&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face=Verdana color=#000000&gt;Now, when I make my Twitter
post, all I need to do is take the XDocument the Twitter API returns, and pass it
into the ParseFeed method, which looks like this...&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;span style="COLOR: blue"&gt; 
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;35&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//Post
my tweet to Twitter&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;36&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; TwitterAPI twit = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; TwitterAPI();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;37&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; XDocument doc = twit.UpdateAsXML(Settings.TwitterUserName(),
Settings.TwitterPassword(), txtPost.Text);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;38&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;39&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//Save
it to the activity table for displaying the activity&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;40&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; TwitterFeed feed = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; TwitterFeed();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;41&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; feed.ParseFeed(doc);
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;&lt;/span&gt; 
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face=Verdana color=#000000&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face=Verdana color=#000000&gt;Simple and neat! Now when
I implement it for my blog, it will be just as quick and easy!&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face=Verdana color=#000000&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face=Verdana color=#000000&gt;Props go out to this &lt;a href="http://blogs.msdn.com/bursteg/archive/2009/05/29/twitter-api-from-c-getting-a-user-s-time-line.aspx" target=_blank&gt;post &lt;/a&gt;I
snagged an extension method for formatting the Twitter posting date to something a
human can use (and my C# class can use to manipulate and save!)&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face=Verdana color=#000000&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face=Verdana color=#000000&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face=Verdana color=#000000&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=058b6bdb-5cc4-470d-a4ff-3f7452a4a7b1" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,058b6bdb-5cc4-470d-a4ff-3f7452a4a7b1.aspx</comments>
      <category>All Things</category>
      <category>ASP.Net</category>
      <category>C#</category>
      <category>CSharp</category>
      <category>Design</category>
      <category>Tips and Tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=c0cbc280-544f-45b1-943c-3715fb32920c</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,c0cbc280-544f-45b1-943c-3715fb32920c.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,c0cbc280-544f-45b1-943c-3715fb32920c.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=c0cbc280-544f-45b1-943c-3715fb32920c</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Tonight was a short night of development, as my folks were in town as my dad needed
to go to the doctor. I did get some database work done, and my business objects done.
I use a hybrid of Rockford Lhotka's CSLA. I don't need all the functionality (such
as layers of undo) so I trimmed them back the amount of functionality I needed and
created CodeSmith templates to generate my classes. Let me just say I can code really
fast now. :) If you haven't taken a look at Lhotka's Business Objects book, I highly
recommend taking a look at them. I began using his concepts in VB, and they have proven
very reliable and scalable.
</p>
        <p>
QDJ: Do you use ORM's, and if so, what flavor do you like?
</p>
        <p>
I have to admit, I am not the biggest fan of the various ORMs I have tried. They do
serve a purpose though, but I have found most inflexible. I am currently using nHibernate,
and while they make themselves readily available to code generation, so far, it seems
like a lot of code. See my previous comments about another ORM I tried. My brother
uses it, and seems to be happy with it. I just thought the learning curve was very
steep, and the documentation was very lacking. I took a beating for that opinion.
:)
</p>
        <p>
So tonight, I want to post a couple of links I used today. Soon there will be a control
for this on the <a href="http://www.rubiconcomputing.com/" target="_blank">Rubicon
Computing</a> site, but until then, I will post them here.
</p>
        <p>
First, I referred to this before, but here's a site with a lot of good links to various
"cheat sheets". Some are really good and useful. You can find those <a href="http://john-sheehan.com/blog/net-cheat-sheets/" target="_blank">here</a>.
</p>
        <p>
Next, I found some neat add-ins for Visual Studio 2008. The first is the <a href="http://visualstudiogallery.msdn.microsoft.com/en-us/bea9ed59-8857-4032-9666-9af1c1a33969" target="_blank">Source
Code Power Toy</a>. It outlines your code in a treeview, which makes navigating your
code, especially in complex classes, very easy. Best of all, it's free! It's available
for VS2005 as well.
</p>
        <p>
I also installed the <a href="http://code.msdn.microsoft.com/PowerCommands" target="_blank">Power
Commands</a> for the VS 2008 IDE. It has some useful right-click functionality, such
as opening a command prompt, and opening the containing folder, and that's just a
small glimpse of what it can do. It seems to be well documented, and I look forward
to exploring all it's functionality. And best thing, this one is free too.
</p>
        <p>
I'll probably post some useful CodeSmith templates I created. I love <a href="http://www.codesmithtools.com/" target="_blank">CodeSmith</a>,
but sometimes it's tough to find out exactly how to do things, so I will spare the
world the trial-and-error where I can. In the current project I am working on, our
team saved 1,100+ hours, and over $50,000 dollars last month alone by generating nHibernate
code from the templates we created. Yeah, I earned my rate last month for sure. :)
</p>
        <p>
 
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=c0cbc280-544f-45b1-943c-3715fb32920c" />
      </body>
      <title>Some neat things I found today...</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,c0cbc280-544f-45b1-943c-3715fb32920c.aspx</guid>
      <link>http://www.dotnettechnologies.com/2009/08/12/SomeNeatThingsIFoundToday.aspx</link>
      <pubDate>Wed, 12 Aug 2009 05:31:11 GMT</pubDate>
      <description>&lt;p&gt;
Tonight was a short night of development, as my folks were in town as my dad needed
to go to the doctor. I did get some database work done, and my business objects done.
I use a hybrid of Rockford Lhotka's CSLA. I don't need all the functionality (such
as layers of undo) so I trimmed them back the amount of functionality I needed and
created CodeSmith templates to generate my classes. Let me just say I can code really
fast now. :) If you haven't taken a look at Lhotka's Business Objects book, I highly
recommend taking a look at them. I began using his concepts in VB, and they have proven
very reliable and scalable.
&lt;/p&gt;
&lt;p&gt;
QDJ: Do you use ORM's, and if so, what flavor do you like?
&lt;/p&gt;
&lt;p&gt;
I have to admit, I am not the biggest fan of the various ORMs I have tried. They do
serve a purpose though, but I have found most inflexible. I am currently using nHibernate,
and while they make themselves readily available to code generation, so far, it seems
like a lot of code. See my previous comments about another ORM I tried. My brother
uses it, and seems to be happy with it. I just thought the learning curve was very
steep, and the documentation was very lacking. I took a beating for that opinion.
:)
&lt;/p&gt;
&lt;p&gt;
So tonight, I want to post a couple of links I used today. Soon there will be a control
for this on the&amp;nbsp;&lt;a href="http://www.rubiconcomputing.com/" target=_blank&gt;Rubicon
Computing&lt;/a&gt;&amp;nbsp;site, but until then, I will post them here.
&lt;/p&gt;
&lt;p&gt;
First, I referred to this before, but here's a site with a lot of good links to various
"cheat sheets". Some are really good and useful. You can find those &lt;a href="http://john-sheehan.com/blog/net-cheat-sheets/" target=_blank&gt;here&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
Next, I found some neat add-ins for Visual Studio 2008. The first is the &lt;a href="http://visualstudiogallery.msdn.microsoft.com/en-us/bea9ed59-8857-4032-9666-9af1c1a33969" target=_blank&gt;Source
Code Power Toy&lt;/a&gt;. It outlines your code in a treeview, which makes navigating your
code, especially in complex classes, very easy. Best of all, it's free! It's available
for VS2005 as well.
&lt;/p&gt;
&lt;p&gt;
I also installed the &lt;a href="http://code.msdn.microsoft.com/PowerCommands" target=_blank&gt;Power
Commands&lt;/a&gt; for the VS 2008 IDE. It has some useful right-click functionality, such
as opening a command prompt, and opening the containing folder, and that's just a
small glimpse of what it can do.&amp;nbsp;It seems to be well documented, and I look forward
to exploring all it's functionality. And best thing, this one is free too.
&lt;/p&gt;
&lt;p&gt;
I'll probably post some useful CodeSmith templates I created. I love &lt;a href="http://www.codesmithtools.com/" target=_blank&gt;CodeSmith&lt;/a&gt;,
but sometimes it's tough to find out exactly how to do things, so I will spare the
world the trial-and-error where I can. In the current project I am working on, our
team saved 1,100+ hours, and over $50,000 dollars last month alone by generating nHibernate
code from the templates we created. Yeah, I earned my rate last month for sure. :)
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=c0cbc280-544f-45b1-943c-3715fb32920c" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,c0cbc280-544f-45b1-943c-3715fb32920c.aspx</comments>
      <category>All Things</category>
      <category>ASP.Net</category>
      <category>C#</category>
      <category>CSharp</category>
      <category>Design</category>
      <category>General</category>
      <category>Tips and Tricks</category>
      <category>Tools</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=de920c29-c8b9-40e4-bb75-cb7daa2af822</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,de920c29-c8b9-40e4-bb75-cb7daa2af822.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,de920c29-c8b9-40e4-bb75-cb7daa2af822.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=de920c29-c8b9-40e4-bb75-cb7daa2af822</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Tonight I didn't get as much time to work on the site as I would have liked, so I
focused on getting the admin pages up on the production server so I could do some
"behind-the-scenes" work remotely. This required some security, which I started last
night, but the data migration for that was a bit more daunting, so I needed to finish
it tonight. While the authentication providers and controls do handle a LOT, it has
an interesting learning-curve, and deployment can be a challenge as well. All-in-all,
it sure beats writing all that code by myself. 
</p>
        <p>
I tried to use a lot of caching and cached settings to help improve the performance
on certain pages, especially my client list. On my admin pages, I made sure to create
a means to reset that cache without having to do a complete server reset. Actually,
the same approach I took would work well for high availability sites, as the method
I used to complete this would not require a server reset to re-load systems. When
I was int he banking industry, high-availability was a huge issue, and simple config
changes meant waiting for a scheduled system outage or worse, an emergency outage.
When I redesigned that site, that was one of the top priorities I had.
</p>
        <p>
It occurred to me how much time it takes to set up the infrastructure of a site: master
pages, common libraries, configuration files, CSS, etc. Once those are done, if done
properly, the rest of the site should go fast. One thing I have found to speed that
up was the use of Visual Studio Project Templates. Combined with code generation like
CodeSmith, you can really generate web sites extremely fast, and get on to coding
the "fun" items. I will write about both of those in the future (CodeSmith and Project
Templates) once the site is stabilized.
</p>
        <p>
Tomorrow night may not have a lot of development, as my parents will be in town. Later
this week, I will be coding my next control: the activity feed. When posts and feeds
are made or read, this control will snag it, and place a brief "teaser" on the home
page.
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=de920c29-c8b9-40e4-bb75-cb7daa2af822" />
      </body>
      <title>As we march across the Rubicon, we have Admin pages!</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,de920c29-c8b9-40e4-bb75-cb7daa2af822.aspx</guid>
      <link>http://www.dotnettechnologies.com/2009/08/11/AsWeMarchAcrossTheRubiconWeHaveAdminPages.aspx</link>
      <pubDate>Tue, 11 Aug 2009 05:05:59 GMT</pubDate>
      <description>&lt;p&gt;
Tonight I didn't get as much time to work on the site as I would have liked, so I
focused on getting the admin pages up on the production server so I could do some
"behind-the-scenes" work remotely. This required some security, which I started last
night, but the data migration for that was a bit more daunting, so I needed to finish
it tonight. While the authentication providers and controls do handle a LOT, it has
an interesting learning-curve, and deployment can be a challenge as well. All-in-all,
it sure beats writing all that code by myself. 
&lt;/p&gt;
&lt;p&gt;
I tried to use a lot of caching and cached settings to help improve the performance
on certain pages, especially my client list. On my admin pages, I made sure to create
a means to reset that cache without having to do a complete server reset. Actually,
the same approach I took would work well for high availability sites, as the method
I used to complete this would not require a server reset to re-load systems. When
I was int he banking industry, high-availability was a huge issue, and simple config
changes meant waiting for a scheduled system outage or worse, an emergency outage.
When I redesigned that site, that was one of the top priorities I had.
&lt;/p&gt;
&lt;p&gt;
It occurred to me how much time it takes to set up the infrastructure of a site: master
pages, common libraries, configuration files, CSS, etc. Once those are done, if done
properly, the rest of the site should go fast. One thing I have found to speed that
up was the use of Visual Studio Project Templates. Combined with code generation like
CodeSmith, you can really generate web sites extremely fast, and get on to coding
the "fun" items. I will write about both of those in the future (CodeSmith and Project
Templates) once the site is stabilized.
&lt;/p&gt;
&lt;p&gt;
Tomorrow night may not have a lot of development, as my parents will be in town. Later
this week, I will be coding my next control: the activity feed. When posts and feeds
are made or read, this control will snag it, and place a brief "teaser" on the home
page.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=de920c29-c8b9-40e4-bb75-cb7daa2af822" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,de920c29-c8b9-40e4-bb75-cb7daa2af822.aspx</comments>
      <category>All Things</category>
      <category>ASP.Net</category>
      <category>C#</category>
      <category>CSharp</category>
      <category>Design</category>
      <category>General</category>
      <category>Tips and Tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=031d112b-9b09-493a-bf48-8f168ce1018c</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,031d112b-9b09-493a-bf48-8f168ce1018c.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,031d112b-9b09-493a-bf48-8f168ce1018c.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=031d112b-9b09-493a-bf48-8f168ce1018c</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I finally managed to get my client list online today. From a technological standpoint,
it was pretty straight forward. I store the information in the database, and use my
CodeSmith templates to create a class for extracting the data, and then use a Repeater
to present the information in a table format. I still need to make some changes to
it, but all in all, it works well. Since the data won't be changing often, I did cache
the data to make it come back faster. 
</p>
        <p>
I started working on security for my Administration pages. I need to get that set
up before I can activate the admin pages, but I have run into some issues getting
it all configured. I ran into this once before with the ASP.Net forms authentication
security provider, but this time is a little different, as I only want to secure one
folder. Certainly not too difficult to do, but not as easy as I would have hoped either.
</p>
        <p>
Once I get the security and login page worked out, I'll begin working on my "links"
page. The idea here is that when I blog, or post to twitter, or a few other ideas
I have, it will update the dark blue control on the home page with a summary and hopefully
someone will click through to get the rest of the details. This should be fairly straightforward
to do. Since most of the services respond in XML, I'll just use a factory method to
instantiate the proper object, which will know exactly what information I want to
extract from the XML feed. As I add more items I want to track, I will simply have
to implement the same interface and it will plug right in to my "updater". For the
items which return XML (e.g. RSS or Twitter), I will use LINQ for XML to grab just
want I want and populate the data right into my classes.
</p>
        <p>
Which brings up a point...
</p>
        <p>
I could probably do this almost as easy with XPath. When does it make sense to move
to the more "sexier" technology as opposed something proven and works well? For example,
a lot of times, when a new technology is rolled out, it tends to be buggy and some
of them historically have not performed well (e.g. early XML for those who have been
around a while). All things equal, when does it make sense? Just a rhetorical question,
but one I got hit with recently.
</p>
        <p>
I was in a technical interview for a job I wasn't planning on taking (drive was too
far -- the company I was representing knew this as well, they just wanted me to be
on their radar for the future). I was asked about a particular implementation of the
new List object. Honestly, I know how to use the List object, and he was asking about
some of the internals I really hadn't needed to know. 
</p>
        <p>
If I was having performance issues, I would want to know, and then I would look into
it further. In this case, I was able to provide at least 4 other reasonable implementations
based on the criteria I was given, yet, I still couldn't get the "sexy" answer he
was looking for. At what point does it really matter? For my part, I didn't like NOT
knowing, and I did look it up when I left, but in the big picture, when does it become
relevant? In my book, the practical solution to a relevant problem always supercedes
technical "sexiness". 
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=031d112b-9b09-493a-bf48-8f168ce1018c" />
      </body>
      <title>More progress on my site -- Client List!</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,031d112b-9b09-493a-bf48-8f168ce1018c.aspx</guid>
      <link>http://www.dotnettechnologies.com/2009/08/10/MoreProgressOnMySiteClientList.aspx</link>
      <pubDate>Mon, 10 Aug 2009 04:58:40 GMT</pubDate>
      <description>&lt;p&gt;
I finally managed to get my client list online today. From a technological standpoint,
it was pretty straight forward. I store the information in the database, and use my
CodeSmith templates to create a class for extracting the data, and then use a Repeater
to present the information in a table format. I still need to make some changes to
it, but all in all, it works well. Since the data won't be changing often, I did cache
the data to make it come back faster. 
&lt;/p&gt;
&lt;p&gt;
I started working on security for my Administration pages. I need to get that set
up before I can activate the admin pages, but I have run into some issues getting
it all configured. I ran into this once before with the ASP.Net forms authentication
security provider, but this time is a little different, as I only want to secure one
folder. Certainly not too difficult to do, but not as easy as I would have hoped either.
&lt;/p&gt;
&lt;p&gt;
Once I get the security and login page worked out, I'll begin working on my "links"
page. The idea here is that when I blog, or post to twitter, or a few other ideas
I have, it will update the dark blue control on the home page with a summary and hopefully
someone will click through to get the rest of the details. This should be fairly straightforward
to do. Since most of the services respond in XML, I'll just use a factory method to
instantiate the proper object, which will know exactly what information I want to
extract from the XML feed. As I add more items I want to track, I will simply have
to implement the same interface and it will plug right in to my "updater". For the
items which return XML (e.g. RSS or Twitter), I will use LINQ for XML to grab just
want I want and populate the data right into my classes.
&lt;/p&gt;
&lt;p&gt;
Which brings up a point...
&lt;/p&gt;
&lt;p&gt;
I could probably do this almost as easy with XPath. When does it make sense to move
to the more "sexier" technology as opposed something proven and works well? For example,
a lot of times, when a new technology is rolled out, it tends to be buggy and some
of them historically have not performed well (e.g. early XML for those who have been
around a while). All things equal, when does it make sense? Just a rhetorical question,
but one I got hit with recently.
&lt;/p&gt;
&lt;p&gt;
I was in a technical interview for a job I wasn't planning on taking (drive was too
far -- the company I was representing knew this as well, they just wanted me to be
on their radar for the future). I was asked about a particular implementation of the
new List object. Honestly, I know how to use the List object, and he was asking about
some of the internals I really hadn't needed to know. 
&lt;/p&gt;
&lt;p&gt;
If I was having performance issues, I would want to know, and then I would look into
it further. In this case, I was able to provide at least 4 other reasonable implementations
based on the criteria I was given, yet, I still couldn't get the "sexy" answer he
was looking for. At what point does it really matter? For my part, I didn't like NOT
knowing, and I did look it up when I left, but in the big picture, when does it become
relevant? In my book, the practical solution to a relevant problem always supercedes
technical "sexiness". 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=031d112b-9b09-493a-bf48-8f168ce1018c" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,031d112b-9b09-493a-bf48-8f168ce1018c.aspx</comments>
      <category>All Things</category>
      <category>ASP.Net</category>
      <category>C#</category>
      <category>CSharp</category>
      <category>Design</category>
      <category>General</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=71a6f346-d8d1-4b6d-ba7e-731960fe2e46</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,71a6f346-d8d1-4b6d-ba7e-731960fe2e46.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,71a6f346-d8d1-4b6d-ba7e-731960fe2e46.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=71a6f346-d8d1-4b6d-ba7e-731960fe2e46</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I finally got around to updating my resume, and I pasted it temporarily on my
home page at <a href="http://www.rubiconcomputing.com/" target="_blank">Rubicon Computing
Solutions</a>. That's my company, and it's been a great run of 13 years.  I say
temporarily simply because it will better positioned later, but I realized I really
should have it on there so it gets picked up by some search engines, recruiters and
in general people looking for .Net development in the Phoenix area.
</p>
        <p>
I am in some talks with some other very senior developers I have had the pleasure
of working with over the past couple of years about banding our talent together. I've
tried that before, but these developers have been on their own for a long time, so
we have a very similar background and strong work ethic to build upon. I have always
struggled in the past with partnering up with other developers, as I have very high
expectations of any project I work on. In fact, this is why I have had trouble hiring
help, as my standards of quality aren't met by most developers without substantial
coaching. These developers already have that skill, along with maturity and experience,
which makes this a very exciting opportunity. Interesting how this economy drags some
people down, yet others, like myself see it as an opportunity.
</p>
        <p>
One of the limiting factors I have always had was that I was limited on the size of
projects I could take alone. This changes that dynamic dramatically.
</p>
        <p>
So if you're looking for some quality application development (web or windows), I
specialize in quality service and coding in a Microsoft environment. I can work alone,
with a team, or build and lead teams. You can find more details about those skills <a href="http://www.rubiconcomputing.com/resume/resume.html" target="_blank">here</a>.
Thanks!
</p>
        <p>
 
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=71a6f346-d8d1-4b6d-ba7e-731960fe2e46" />
      </body>
      <title>A not-so-shameless plug</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,71a6f346-d8d1-4b6d-ba7e-731960fe2e46.aspx</guid>
      <link>http://www.dotnettechnologies.com/2009/08/07/ANotsoshamelessPlug.aspx</link>
      <pubDate>Fri, 07 Aug 2009 05:02:11 GMT</pubDate>
      <description>&lt;p&gt;
I finally got around&amp;nbsp;to updating my resume, and I pasted it temporarily on my
home page at &lt;a href="http://www.rubiconcomputing.com/" target=_blank&gt;Rubicon Computing
Solutions&lt;/a&gt;. That's my company, and it's been a great run of 13 years.&amp;nbsp; I say
temporarily simply because it will better positioned later, but I realized I really
should have it on there so it gets picked up by some search engines, recruiters and
in general people looking for .Net development in the Phoenix area.
&lt;/p&gt;
&lt;p&gt;
I am in some talks with some other very senior developers I have had the pleasure
of working with over the past couple of years about banding our talent together. I've
tried that before, but these developers have been on their own for a long time, so
we have a very similar background and strong work ethic to build upon. I have always
struggled in the past with partnering up with other developers, as I have very high
expectations of any project I work on. In fact, this is why I have had trouble hiring
help, as my standards of quality aren't met by most developers without substantial
coaching. These developers already have that skill, along with maturity and experience,
which makes this a very exciting opportunity. Interesting how this economy drags some
people down, yet others, like myself see it as an opportunity.
&lt;/p&gt;
&lt;p&gt;
One of the limiting factors I have always had was that I was limited on the size of
projects I could take alone. This changes that dynamic dramatically.
&lt;/p&gt;
&lt;p&gt;
So if you're looking for some quality application development (web or windows), I
specialize in quality service and coding in a Microsoft environment. I can work alone,
with a team, or build and lead teams. You can find more details about those skills &lt;a href="http://www.rubiconcomputing.com/resume/resume.html" target=_blank&gt;here&lt;/a&gt;.
Thanks!
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=71a6f346-d8d1-4b6d-ba7e-731960fe2e46" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,71a6f346-d8d1-4b6d-ba7e-731960fe2e46.aspx</comments>
      <category>All Things</category>
      <category>ASP.Net</category>
      <category>C#</category>
      <category>CSharp</category>
      <category>Design</category>
      <category>General</category>
      <category>Tips and Tricks</category>
      <category>Web Services</category>
      <category>Windows</category>
      <category>WinForms</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=93b87350-9e5d-45df-b06e-3ac75edeb809</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,93b87350-9e5d-45df-b06e-3ac75edeb809.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,93b87350-9e5d-45df-b06e-3ac75edeb809.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=93b87350-9e5d-45df-b06e-3ac75edeb809</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Tonight's coding session went by WAY too fast. I integrated <a href="http://devblog.yedda.com/index.php/twitter-c-library/" target="_blank">Yedda's
Twitter API</a> into my admin pages so I could post directly without having to use
another client or browse to Twitter to do it. The next step will be to read my blog
feed and Tweet automatically about the topic. That's for another night though, as
tomorrow night is poker night, and yes, I still play. :)
</p>
        <p>
One change I made to the Yedda library (ok, two.. I ran into an issue with an error
code 471 being returned, but a quick Google search fixed that (sometimes I how effeciently
we coded before Google). I wanted to use LINQ to XML to parse out my response code.
So Instead of returning the XML Document, I convert it to an XDocument using the Parse
method, and return that, like this:
</p>
        <font color="#0000ff" size="2">
          <font color="#0000ff" size="2">
            <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
              <p style="MARGIN: 0px">
                <span style="COLOR: blue">         public</span>
                <span style="COLOR: #2b91af">XDocument</span> UpdateAsXML(<span style="COLOR: blue">string</span> userName, <span style="COLOR: blue">string</span> password, <span style="COLOR: blue">string</span> text)
</p>
              <p style="MARGIN: 0px">
        {
</p>
              <p style="MARGIN: 0px">
            <span style="COLOR: blue">string</span> output
= Update(userName, password, text, <span style="COLOR: #2b91af">OutputFormatType</span>.XML);
</p>
              <p style="MARGIN: 0px">
            <span style="COLOR: blue">if</span> (!<span style="COLOR: blue">string</span>.IsNullOrEmpty(output))
</p>
              <p style="MARGIN: 0px">
            {
</p>
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">XDocument</span> xmlDocument
= <span style="COLOR: blue">new</span><span style="COLOR: #2b91af">XDocument</span>();
</p>
              <p style="MARGIN: 0px">
                xmlDocument
= <span style="COLOR: #2b91af">XDocument</span>.Parse(output);
</p>
              <p style="MARGIN: 0px">
 
</p>
              <p style="MARGIN: 0px">
                <span style="COLOR: blue">return</span> xmlDocument;
</p>
              <p style="MARGIN: 0px">
            }
</p>
              <p style="MARGIN: 0px">
 
</p>
              <p style="MARGIN: 0px">
            <span style="COLOR: blue">return</span><span style="COLOR: blue">null</span>;
</p>
              <p style="MARGIN: 0px">
        }
</p>
            </div>
            <!--EndFragment-->
          </font>
        </font>
        <font size="2">
          <p>
Next, if I want to grab the status from of the post to Twitter, I can use LINQ as
follows (in this case, I want the id so I can see if it was successful):
</p>
          <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
            <p style="MARGIN: 0px">
              <span style="COLOR: #2b91af">TwitterAPI</span> twit = <span style="COLOR: blue">new</span><span style="COLOR: #2b91af">TwitterAPI</span>();
</p>
            <p style="MARGIN: 0px">
                    <span style="COLOR: #2b91af">XDocument</span> doc
= twit.UpdateAsXML(<span style="COLOR: #2b91af">Settings</span>.TwitterUserName(), <span style="COLOR: #2b91af">Settings</span>.TwitterPassword(),
txtPost.Text);
</p>
            <p style="MARGIN: 0px">
 
</p>
            <p style="MARGIN: 0px">
                    <span style="COLOR: blue">var</span> status
= <span style="COLOR: blue">from</span> s <span style="COLOR: blue">in</span> doc.Descendants(<span style="COLOR: #a31515">"status"</span>)
</p>
            <p style="MARGIN: 0px">
                   
             <span style="COLOR: blue">select</span> (<span style="COLOR: blue">string</span>)s.Element(<span style="COLOR: #a31515">"id"</span>);
</p>
            <p style="MARGIN: 0px">
 
</p>
            <p style="MARGIN: 0px">
                    <span style="COLOR: blue">bool</span> found
= <span style="COLOR: blue">false</span>;
</p>
            <p style="MARGIN: 0px">
                    <span style="COLOR: blue">foreach</span> (<span style="COLOR: blue">string</span> id <span style="COLOR: blue">in</span> status)
</p>
            <p style="MARGIN: 0px">
                   
    found = <span style="COLOR: blue">true</span>;
</p>
          </div>
          <!--EndFragment-->
          <p>
I am sure there is a better way to determine if it was successful, but this will work
for now, as there are other things I want to do with the response as well. Since this
worked so well, I plan on converting all the XML calls to XDocuments so I can use
LINQ to work with the response.
</p>
          <p>
That's it for today!
</p>
        </font>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=93b87350-9e5d-45df-b06e-3ac75edeb809" />
      </body>
      <title>Yedda library, Twitter Responses and LINQ to XML</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,93b87350-9e5d-45df-b06e-3ac75edeb809.aspx</guid>
      <link>http://www.dotnettechnologies.com/2009/08/05/YeddaLibraryTwitterResponsesAndLINQToXML.aspx</link>
      <pubDate>Wed, 05 Aug 2009 05:34:05 GMT</pubDate>
      <description>&lt;p&gt;
Tonight's coding session went by WAY too fast. I integrated &lt;a href="http://devblog.yedda.com/index.php/twitter-c-library/" target=_blank&gt;Yedda's
Twitter API&lt;/a&gt; into my admin pages so I could post directly without having to use
another client or browse to Twitter to do it. The next step will be to read my blog
feed and Tweet automatically about the topic. That's for another night though, as
tomorrow night is poker night, and yes, I still play. :)
&lt;/p&gt;
&lt;p&gt;
One change I made to the Yedda library (ok, two.. I ran into an issue with an error
code 471 being returned, but a quick Google search fixed that (sometimes I how effeciently
we coded before Google). I wanted to use LINQ to XML to parse out my response code.
So Instead of returning the XML Document, I convert it to an XDocument using the Parse
method, and return that, like this:
&lt;/p&gt;
&lt;font color=#0000ff size=2&gt;&lt;font color=#0000ff size=2&gt; 
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;XDocument&lt;/span&gt; UpdateAsXML(&lt;span style="COLOR: blue"&gt;string&lt;/span&gt; userName, &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; password, &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; text)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; output
= Update(userName, password, text, &lt;span style="COLOR: #2b91af"&gt;OutputFormatType&lt;/span&gt;.XML);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (!&lt;span style="COLOR: blue"&gt;string&lt;/span&gt;.IsNullOrEmpty(output))
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #2b91af"&gt;XDocument&lt;/span&gt; xmlDocument
= &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;XDocument&lt;/span&gt;();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; xmlDocument
= &lt;span style="COLOR: #2b91af"&gt;XDocument&lt;/span&gt;.Parse(output);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; xmlDocument;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size=2&gt; 
&lt;p&gt;
Next, if I want to grab the status from of the post to Twitter, I can use LINQ as
follows (in this case, I want the id so I can see if it was successful):
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;TwitterAPI&lt;/span&gt; twit = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;TwitterAPI&lt;/span&gt;();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #2b91af"&gt;XDocument&lt;/span&gt; doc
= twit.UpdateAsXML(&lt;span style="COLOR: #2b91af"&gt;Settings&lt;/span&gt;.TwitterUserName(), &lt;span style="COLOR: #2b91af"&gt;Settings&lt;/span&gt;.TwitterPassword(),
txtPost.Text);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;var&lt;/span&gt; status
= &lt;span style="COLOR: blue"&gt;from&lt;/span&gt; s &lt;span style="COLOR: blue"&gt;in&lt;/span&gt; doc.Descendants(&lt;span style="COLOR: #a31515"&gt;"status"&lt;/span&gt;)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;select&lt;/span&gt; (&lt;span style="COLOR: blue"&gt;string&lt;/span&gt;)s.Element(&lt;span style="COLOR: #a31515"&gt;"id"&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;bool&lt;/span&gt; found
= &lt;span style="COLOR: blue"&gt;false&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;foreach&lt;/span&gt; (&lt;span style="COLOR: blue"&gt;string&lt;/span&gt; id &lt;span style="COLOR: blue"&gt;in&lt;/span&gt; status)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; found = &lt;span style="COLOR: blue"&gt;true&lt;/span&gt;;
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;
&lt;p&gt;
I am sure there is a better way to determine if it was successful, but this will work
for now, as there are other things I want to do with the response as well. Since this
worked so well, I plan on converting all the XML calls to XDocuments so I can use
LINQ to work with the response.
&lt;/p&gt;
&lt;p&gt;
That's it for today!
&lt;/p&gt;
&lt;/font&gt;&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=93b87350-9e5d-45df-b06e-3ac75edeb809" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,93b87350-9e5d-45df-b06e-3ac75edeb809.aspx</comments>
      <category>All Things</category>
      <category>ASP.Net</category>
      <category>C#</category>
      <category>CSharp</category>
      <category>Design</category>
      <category>General</category>
      <category>Tips and Tricks</category>
    </item>
    <item xml:lang="en-US">
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=42b37674-1b23-41ec-b6af-d7a24f8fe980</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,42b37674-1b23-41ec-b6af-d7a24f8fe980.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,42b37674-1b23-41ec-b6af-d7a24f8fe980.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=42b37674-1b23-41ec-b6af-d7a24f8fe980</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Today has been a very productive day in general for my .Net development. I came up
with a few ideas of integrating Twitter with the site, as well as some longer range
plans for using trending APIs for a concept I will tentatively call sociolytics<sup>®</sup> (I
would have preferred socialytics<sup>®</sup>, but the name was taken, so I will coin
both and trademark them both). :) 
</p>
        <p>
So today's topic will encompass some of the design considerations. First, I needed
to create an admin page to allow me "behind the scenes" access to posting and functionality.
I made sure to create the page it its own subdirectory to simplify access control
to those pages. I created a separate master page for this section, as I might need
more real estate for the controls which will reside on this page. Which brings up
another topicI will bring up at some point --&gt; control oriented encapsulation.
</p>
        <p>
One of the controls was to allow me to post to Twitter directly from the page. I debated
a couple ways to do this.. limit my control to 140 characters, or allow more, and
do multiple posts. I opted one post per submit, as I want to make sure my posts are
complete. I wil add a link to create "tiny URLs" via a web service next, to aid in
quickly creating short links for things I want to tweet. I picked up a nice article
on that over at <a href="http://www.codeproject.com/KB/aspnet/ZetaTinyUrl.aspx" target="_blank">CodeProject</a>.
</p>
        <p>
But the topic of this post relates to a cool feature in the Visual Studio 2008 IDE.
Maybe this has been there all along, and I didn't notice it, but today I did. I needed
to create a control which allows me to quickly encrypt values. For example, until
I get OAuth implemented, I want to hide my Twitter credentials. However, when I post
this functionality, I really don't want the world playing with this functionality
if they manage to hit this page.
</p>
        <p>
So enter the conditional compilation. I wrap the calls in the following code, and
when I compile for release, it's not included. What's nice is that the IDE even reflects
the code won't be available when compiling in Release mode. Pretty nifty!!
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">            try</span>
          </p>
          <p style="MARGIN: 0px">
            {
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">#if</span> DEBUG
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: gray">           
    if (txtValue.Text.Trim().Length &gt; 0)</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: gray">           
    {</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: gray">           
        lblResult.Text = Settings.EncryptString(txtValue.Text);</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: gray">           
    }</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: gray">           
    else</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: gray">           
        lblResult.Text = String.Empty;</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">#endif</span>
          </p>
          <p style="MARGIN: 0px">
            }
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">catch</span> (<span style="COLOR: #2b91af">Exception</span> ex)
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
BTW, thanks to <a href="http://www.jtleigh.com/people/colin/software/CopySourceAsHtml/" target="_blank">CopySourceAsHTML</a> for
making posting snippets so easy!
</p>
          <p style="MARGIN: 0px">
 
</p>
        </div>
        <!--EndFragment-->
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=42b37674-1b23-41ec-b6af-d7a24f8fe980" />
      </body>
      <title>Conditional Compilation and the VS2008 IDE</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,42b37674-1b23-41ec-b6af-d7a24f8fe980.aspx</guid>
      <link>http://www.dotnettechnologies.com/2009/08/04/ConditionalCompilationAndTheVS2008IDE.aspx</link>
      <pubDate>Tue, 04 Aug 2009 05:15:10 GMT</pubDate>
      <description>&lt;p&gt;
Today has been a very productive day in general for my .Net development. I came up
with a few ideas of integrating Twitter with the site, as well as some longer range
plans for using trending APIs for a concept I will tentatively call sociolytics&lt;sup&gt;®&lt;/sup&gt; (I
would have preferred socialytics&lt;sup&gt;®&lt;/sup&gt;, but the name was taken, so I will coin
both and trademark them both). :) 
&lt;/p&gt;
&lt;p&gt;
So today's topic will encompass some of the design considerations. First, I needed
to create an admin page to allow me "behind the scenes" access to posting and functionality.
I made sure to create the page it its own subdirectory to simplify access control
to those pages. I created a separate master page for this section, as I might need
more real estate for the controls which will reside on this page. Which brings up
another topicI will bring up at some point --&amp;gt; control oriented encapsulation.
&lt;/p&gt;
&lt;p&gt;
One of the controls was to allow me to post to Twitter directly from the page. I debated
a couple ways to do this.. limit my control to 140 characters, or allow more, and
do multiple posts. I opted one post per submit, as I want to make sure my posts are
complete. I wil add a link to create "tiny URLs" via a web service next, to aid in
quickly creating short links for things I want to tweet. I picked up a nice article
on that over at &lt;a href="http://www.codeproject.com/KB/aspnet/ZetaTinyUrl.aspx" target=_blank&gt;CodeProject&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
But the topic of this post relates to a cool feature in the Visual Studio 2008 IDE.
Maybe this has been there all along, and I didn't notice it, but today I did. I needed
to create a control which allows me to quickly encrypt values. For example, until
I get OAuth implemented, I want to hide my Twitter credentials. However, when I post
this functionality, I really don't want the world playing with this functionality
if they manage to hit this page.
&lt;/p&gt;
&lt;p&gt;
So enter the conditional compilation. I wrap the calls in the following code, and
when I compile for release, it's not included. What's nice is that the IDE even reflects
the code won't be available when compiling in Release mode. Pretty nifty!!
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;try&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;#if&lt;/span&gt; DEBUG
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: gray"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; if (txtValue.Text.Trim().Length &amp;gt; 0)&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: gray"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: gray"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; lblResult.Text = Settings.EncryptString(txtValue.Text);&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: gray"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: gray"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; else&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: gray"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; lblResult.Text = String.Empty;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;#endif&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;catch&lt;/span&gt; (&lt;span style="COLOR: #2b91af"&gt;Exception&lt;/span&gt; ex)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
BTW, thanks to &lt;a href="http://www.jtleigh.com/people/colin/software/CopySourceAsHtml/" target=_blank&gt;CopySourceAsHTML&lt;/a&gt; for
making posting snippets so easy!
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=42b37674-1b23-41ec-b6af-d7a24f8fe980" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,42b37674-1b23-41ec-b6af-d7a24f8fe980.aspx</comments>
      <category>All Things</category>
      <category>ASP.Net</category>
      <category>CSharp</category>
      <category>Design</category>
      <category>General</category>
      <category>Tips and Tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=8e641840-54a8-4e88-ada1-e98f308e611f</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,8e641840-54a8-4e88-ada1-e98f308e611f.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,8e641840-54a8-4e88-ada1-e98f308e611f.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=8e641840-54a8-4e88-ada1-e98f308e611f</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
As the main site is developed, I'll detail what decisions I used to create the
site, then a high level overview of how I designed it. Just a warning though, some
of the decisions will seem very arbitrary, as they were. I made them simply because
working on your own site gives you a luxury of trying things you normally can't do
with a client. In my case, a lot of my decisions will be over-engineered, because
I may want to re-use them later.
</p>
        <p>
Of course, the first thing I had to come up with was an overall site layout. I won't
go into that here, as one thing I will never profess to be is a layout guru. I got
a decent design, and I set them up as a master page so the rest of the site development
will go easy. I used VS2008 and C#, and began implementing AJAX where it made sense.
For example, there's a control which updates the current time every 30 seconds or
so, so I could use the update panel and timer control.
</p>
        <p>
The first real functionality I wanted to add was a link to this blog. So I created
a user control, and placed it on the front page. However, I do plan on posting a lot
more here, so I knew it wouldn't be feasible to show every post, so I decided to limit
it to the latest three posts. I wanted to display the title, the date and the first
bit of the post to hopefully catch a reader's attention.
</p>
        <p>
But reading from a feed from sites at two different hosting providers can be tricky.
Not from a security standpoint, as RSS feeds are open, but more from a performance
standpoint. Anyone coming to my portal site should be able to see the latest posts,
and quickly. The fastest way of doing this would be to create a Windows service which
periodically reads the feed, and stores the information in a database. However, I
am not sure I would be able to install a Windows service on my service provider's
server. So......
</p>
        <p>
What<em>  </em>I <em>can</em> do however is read the feed, and place it in cache.
Periodically, I can expire the cache and re-load it, and unless you are the unlucky
soul to have to wait while it loads, the majority of the users will have a quick response.
For that poor soul who waits while cache is refreshed, I used Ajax and the UpdateProgress
control to provide some visual feedback that the page is doing something.
</p>
        <p>
The rest was pretty straightforward. I either request the XML from the RSS feed (or
cache), and use XSLT to display it. It's been a while since I have used XSLT, but
there is a lot of potential there, I expect I will be using a lot more of it in future
controls. I created the class generically so that I could pull any RSS feed
I wanted from it as well.
</p>
        <p>
One great use I found for XSLT was on a high-availability web site which sent a lot
of emails. We wanted to be able to change the email format frequently without bringing
the site down. Using XSLT, we could change the email template files any time to create
very nice HTML based email messages. I read a great article recently about calling
C# functions in your XSLT templates using extension methods, which I plan to use extensively,
as C# is my main domain. Maybe I will use them... I say that as I really would like
to improve my XSLT skills, as I think the technology is highy underused in the .Net
world.
</p>
        <p>
So now I am playing with Twitter feeds and getting the rest of the site content set
up. I also used the AJAX popup control to help prevent any 404 errors as I complete
the functionality. If you've been putting off using the AJAX Control Toolkit for some
reason.. STOP! The amount of functionality these controls offer is amazing, and you
can't beat the price.
</p>
        <p>
That's it for now! If you want more details on how I accomplished this or some sample
code, just send me a comment. Upcoming posts will address the development of the rest
of the site, along with some major wins recently using CodeSmith.
</p>
        <p>
 
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=8e641840-54a8-4e88-ada1-e98f308e611f" />
      </body>
      <title>First Control -- RSS Feed</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,8e641840-54a8-4e88-ada1-e98f308e611f.aspx</guid>
      <link>http://www.dotnettechnologies.com/2009/08/02/FirstControlRSSFeed.aspx</link>
      <pubDate>Sun, 02 Aug 2009 14:54:16 GMT</pubDate>
      <description>&lt;p&gt;
As the main site is developed, I'll detail what&amp;nbsp;decisions I used to create the
site, then a high level overview of how I designed it. Just a warning though, some
of the decisions will seem very arbitrary, as they were. I made them simply because
working on your own site gives you a luxury of trying things you normally can't do
with a client. In my case, a lot of my decisions will be over-engineered, because
I may want to re-use them later.
&lt;/p&gt;
&lt;p&gt;
Of course, the first thing I had to come up with was an overall site layout. I won't
go into that here, as one thing I will never profess to be is a layout guru. I got
a decent design, and I set them up as a master page so the rest of the site development
will go easy. I used VS2008 and C#, and began implementing AJAX where it made sense.
For example, there's a control which updates the current time every 30 seconds or
so, so I could use the update panel and timer control.
&lt;/p&gt;
&lt;p&gt;
The first real functionality I wanted to add was a link to this blog. So I created
a user control, and placed it on the front page. However, I do plan on posting a lot
more here, so I knew it wouldn't be feasible to show every post, so I decided to limit
it to the latest three posts. I wanted to display the title, the date and the first
bit of the post to hopefully catch a reader's attention.
&lt;/p&gt;
&lt;p&gt;
But reading from a feed from sites at two different hosting providers can be tricky.
Not from a security standpoint, as RSS feeds are open, but more from a performance
standpoint. Anyone coming to my portal site should be able to see the latest posts,
and quickly. The fastest way of doing this would be to create a Windows service which
periodically reads the feed, and stores the information in a database. However, I
am not sure I would be able to install a Windows service on my service provider's
server. So......
&lt;/p&gt;
&lt;p&gt;
What&lt;em&gt;&amp;nbsp; &lt;/em&gt;I &lt;em&gt;can&lt;/em&gt; do however is read the feed, and place it in cache.
Periodically, I can expire the cache and re-load it, and unless you are the unlucky
soul to have to wait while it loads, the majority of the users will have a quick response.
For that poor soul who waits while cache is refreshed, I used Ajax and the UpdateProgress
control to provide some visual feedback that the page is doing something.
&lt;/p&gt;
&lt;p&gt;
The rest was pretty straightforward. I either request the XML from the RSS feed (or
cache), and use XSLT to display it. It's been a while since I have used XSLT, but
there is a lot of potential there, I expect I will be using a lot more of it in future
controls. I created the class&amp;nbsp;generically so&amp;nbsp;that I could pull any RSS feed
I wanted from it as well.
&lt;/p&gt;
&lt;p&gt;
One great use I found for XSLT was on a high-availability web site which sent a lot
of emails. We wanted to be able to change the email format frequently without bringing
the site down. Using XSLT, we could change the email template files any time to create
very nice HTML based email messages. I read a great article recently about calling
C# functions in your XSLT templates using extension methods, which I plan to use extensively,
as C# is my main domain. Maybe I will use them... I say that as I really would like
to improve my XSLT skills, as I think the technology is highy underused in the .Net
world.
&lt;/p&gt;
&lt;p&gt;
So now I am playing with Twitter feeds and getting the rest of the site content set
up. I also used the AJAX popup control to help prevent any 404 errors as I complete
the functionality. If you've been putting off using the AJAX Control Toolkit for some
reason.. STOP! The amount of functionality these controls offer is amazing, and you
can't beat the price.
&lt;/p&gt;
&lt;p&gt;
That's it for now! If you want more details on how I accomplished this or some sample
code, just send me a comment. Upcoming posts will address the development of the rest
of the site, along with some major wins recently using CodeSmith.
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=8e641840-54a8-4e88-ada1-e98f308e611f" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,8e641840-54a8-4e88-ada1-e98f308e611f.aspx</comments>
      <category>All Things</category>
      <category>ASP.Net</category>
      <category>C#</category>
      <category>Design</category>
      <category>General</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=e889b6b0-390d-4c5a-a94c-1702a2d7d8e5</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,e889b6b0-390d-4c5a-a94c-1702a2d7d8e5.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,e889b6b0-390d-4c5a-a94c-1702a2d7d8e5.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=e889b6b0-390d-4c5a-a94c-1702a2d7d8e5</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
There's a pretty useful feature (IMHO) in the .Net 2.0 Exception object which
I hadn't noticed before. The Exception object contains a new Data interface, which
is essentially an IDictionary for applying additional values to the exception object.
I am currently using it with my integration of the new VS2005 Enterprise Library into
our framework. 
</p>
        <p>
I want to log exceptions to a database, but I have found it useful in the past to
have an Error #. In the old days (VB 6, for example) I could usually look at the error
number of an application and tell exactly what the problem was. When .Net came into
being, we lost the error number, and there was no easy way to get around it. You could
roll your own exception classes of course and add these properties, but this is only
a limited solution because other exception handlers wouldn't be capable of handling
the additional features by default.
</p>
        <p>
Now this feature is going to allow me to take advantage of error numbers by classifying
each exception type, and appending an error number to the exception object. I can
use this information in my database to classify and group errors by type to identify
weak areas in an application as well. Not Earth shattering, but still a useful feature
full of all kinds of possibilities.
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=e889b6b0-390d-4c5a-a94c-1702a2d7d8e5" />
      </body>
      <title>New feature in .Net 2.0 Exception object</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,e889b6b0-390d-4c5a-a94c-1702a2d7d8e5.aspx</guid>
      <link>http://www.dotnettechnologies.com/2006/06/13/NewFeatureInNet20ExceptionObject.aspx</link>
      <pubDate>Tue, 13 Jun 2006 15:42:38 GMT</pubDate>
      <description>&lt;p&gt;
There's a pretty useful feature (IMHO)&amp;nbsp;in the .Net 2.0 Exception object which
I hadn't noticed before. The Exception object contains a new Data interface, which
is essentially an IDictionary for applying additional values to the exception object.
I am currently using it with my integration of the new VS2005 Enterprise Library into
our framework. 
&lt;/p&gt;
&lt;p&gt;
I want to log exceptions to a database, but I have found it useful in the past to
have an Error #. In the old days (VB 6, for example) I could usually look at the error
number of an application and tell exactly what the problem was. When .Net came into
being, we lost the error number, and there was no easy way to get around it. You could
roll your own exception classes of course and add these properties, but this is only
a limited solution because other exception handlers wouldn't be capable of handling
the additional features by default.
&lt;/p&gt;
&lt;p&gt;
Now this feature is going to allow me to take advantage of error numbers by classifying
each exception type, and appending an error number to the exception object. I can
use this information in my database to classify and group errors by type to identify
weak areas in an application as well. Not Earth shattering, but still a useful feature
full of all kinds of possibilities.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=e889b6b0-390d-4c5a-a94c-1702a2d7d8e5" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,e889b6b0-390d-4c5a-a94c-1702a2d7d8e5.aspx</comments>
      <category>All Things</category>
      <category>CSharp</category>
      <category>Debugging</category>
      <category>Design</category>
      <category>General</category>
      <category>Tips and Tricks</category>
      <category>VB.Net</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=e71c0a9e-e77d-4544-8698-d2c8674e7435</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,e71c0a9e-e77d-4544-8698-d2c8674e7435.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,e71c0a9e-e77d-4544-8698-d2c8674e7435.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=e71c0a9e-e77d-4544-8698-d2c8674e7435</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
So it has been hit or miss posting here, but I am trying to correct it by bringing
on some additional help. I set up a new blog, <a href="http://www.developernation.net">developernation.net</a>,
and begun getting some content on there. Likely I'll crosspost on here too (my content
anyways) but likely most new entries are going to be there first. I figured if I could
get someone else on there helping doing some content, it will have more regular posts.
This blog will continue, just a lag a few days on the content of theother site, and
contain more personal observations.
</p>
        <p>
So swing on by and pop in. I've started off with a bang, and I am in the process of
posting a web service design I created and tested which handles paging and sorting
of data on the server, which my initial tests have shown to be highly efficient. I
am walking through the entire design, and by the end of the weekend I hope to have
the series done and the code posted. If not, you can wait a few days and I will post
it all here as well. 
</p>
        <p>
Thanks!
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=e71c0a9e-e77d-4544-8698-d2c8674e7435" />
      </body>
      <title>A change of directions...</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,e71c0a9e-e77d-4544-8698-d2c8674e7435.aspx</guid>
      <link>http://www.dotnettechnologies.com/2006/04/28/AChangeOfDirections.aspx</link>
      <pubDate>Fri, 28 Apr 2006 15:38:06 GMT</pubDate>
      <description>&lt;p&gt;
So it has been hit or miss posting here, but I am trying to correct it by bringing
on some additional help. I set up a new blog, &lt;a href="http://www.developernation.net"&gt;developernation.net&lt;/a&gt;,
and begun getting some content on there. Likely I'll crosspost on here too (my content
anyways) but likely most new entries are going to be there first. I figured if I could
get someone else on there helping doing some content, it will have more regular posts.
This blog will continue, just a lag a few days on the content of theother site, and
contain more personal observations.
&lt;/p&gt;
&lt;p&gt;
So swing on by and pop in. I've started off with a bang, and I am in the process of
posting a web service design I created and tested which handles paging and sorting
of data on the server, which my initial tests have shown to be highly efficient. I
am walking through the entire design, and by the end of the weekend I hope to have
the series done and the code posted. If not, you can wait a few days and I will post
it all here as well. 
&lt;/p&gt;
&lt;p&gt;
Thanks!
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=e71c0a9e-e77d-4544-8698-d2c8674e7435" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,e71c0a9e-e77d-4544-8698-d2c8674e7435.aspx</comments>
      <category>All Things</category>
      <category>ASP.Net</category>
      <category>C#</category>
      <category>CSharp</category>
      <category>Debugging</category>
      <category>Design</category>
      <category>General</category>
      <category>SQL Tips</category>
      <category>Tips and Tricks</category>
      <category>Tools</category>
      <category>VB.Net</category>
      <category>Web Services</category>
      <category>Windows</category>
      <category>WinForms</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=5876a92e-efe9-4698-ab08-cf57d4ed2112</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,5876a92e-efe9-4698-ab08-cf57d4ed2112.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,5876a92e-efe9-4698-ab08-cf57d4ed2112.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=5876a92e-efe9-4698-ab08-cf57d4ed2112</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <font face="Lucida Sans Typewriter" color="#000000">A year ago, I completed my MCSD
for .Net. One of the attractive<br />
benefits of this certification (as well as the MCDBA) was a $500<br />
discount on a one-year MSDN Universal subscription during the first<br />
year of certification.<br /><br />
Although the MCSD benefits page still lists this benefit<br />
(</font>
          <a href="http://www.microsoft.com/learning/mcp/mcsd/benefits.asp" target="_blank">
            <font face="Lucida Sans Typewriter" color="#9136ad">http://www.microsoft.com/learning/mcp/mcsd/benefits.asp</font>
          </a>
          <font face="Lucida Sans Typewriter" color="#000000">),
they<br />
quietly removed it as of April 2005. The text on the page still<br />
states the following:<br />
Rebates or discounts on a one-year subscription to MSDN during the<br />
first year of certification.<br /><br />
If you call or write to get the certificate as I did, you'll get the<br />
terse response it's no longer available, and they just haven't<br />
updated the site. I figured I would help them get the word out since<br />
they didn't deem it important enough to change on their site or<br />
announce. It would be a shame if anyone expected this benefit based<br />
on the MS web site information.</font>
        </p>
        <p>
-------------------------------------------------------------------------
</p>
        <p>
Above is what I posted to our local .Net community group on Yahoo. Now I am going
to add some personal comments. Once again, MS has dropped the ball in supporting the
developer community. Earlier this year, MS announced the MSDN Universal would not
include the new .Net Team Development system (or some name like that -- I am too lazy
to go look it up). Fortunately, enough of an uproar went out that they reversed that
decision. Their waning support of VB also caused a petition/uproar. Likely, since
the MCSD/MCDBA community is a lot smaller, there isn't likely to be a huge outcry
on this issue.
</p>
        <p>
This is a HUGE mistake on MS's behalf. Someone that is likely to spend the extra time
and money to get certifications are the ones MS should really cater to. There's always
been a criticism that the certifications are worthless, and that benefit alone
made it real easy to justify spending the money on books, training materials and exam
costs for achieving the certification. I won't argue the merits of the certifications
here, but I have a lot of them -- MCP, MCDBA, MCSD for VB, MCSD for .Net (C#), and
MCAD. Will I continue? I may have to given I am an Independent Contractor and it helps
to get me in the door. Will I recommend it to someone not in my position? Not likely.
</p>
        <p>
Don't get me wrong, the MSDN Universal is still a great deal. My disgust over this
situation is that the benefit is <strong>still</strong> listed, as well as no announcement
in April 2005 when they made this decision (or if they did, I sure didn't see it).
I have been one of the most stalwart supporters of Microsoft over the years,
and I have personally been involved in projects which have generated millions in
licensing revenues for Microsoft in the last 10 years. The past 1.5 years I have watched
MS anger the core base of developers.
</p>
        <p>
I think this is indicative of the internal problems at MS, and why Google is going
to be a viable competitor to MS. In a paraphrase of the words of Stephen King, and
the Dark Tower series, MS has forgotten the face of their father. One of the reasons
MS dominated the market over Apple was that MS supported developers way beyond the
norm. In the name of profit, I think we are seeing this slowly change.<br /></p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=5876a92e-efe9-4698-ab08-cf57d4ed2112" />
      </body>
      <title>MSDN Universal Discount for MCSD/MCDBA </title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,5876a92e-efe9-4698-ab08-cf57d4ed2112.aspx</guid>
      <link>http://www.dotnettechnologies.com/2005/10/07/MSDNUniversalDiscountForMCSDMCDBA.aspx</link>
      <pubDate>Fri, 07 Oct 2005 15:57:27 GMT</pubDate>
      <description>&lt;p&gt;
&lt;font face="Lucida Sans Typewriter" color=#000000&gt;A year ago, I completed my MCSD
for .Net. One of the attractive&lt;br&gt;
benefits of this certification (as well as the MCDBA) was a $500&lt;br&gt;
discount on a one-year MSDN Universal subscription during the first&lt;br&gt;
year of certification.&lt;br&gt;
&lt;br&gt;
Although the MCSD benefits page still lists this benefit&lt;br&gt;
(&lt;/font&gt;&lt;a href="http://www.microsoft.com/learning/mcp/mcsd/benefits.asp" target=_blank&gt;&lt;font face="Lucida Sans Typewriter" color=#9136ad&gt;http://www.microsoft.com/learning/mcp/mcsd/benefits.asp&lt;/font&gt;&lt;/a&gt;&lt;font face="Lucida Sans Typewriter" color=#000000&gt;),
they&lt;br&gt;
quietly removed it as of April 2005. The text on the page still&lt;br&gt;
states the following:&lt;br&gt;
Rebates or discounts on a one-year subscription to MSDN during the&lt;br&gt;
first year of certification.&lt;br&gt;
&lt;br&gt;
If you call or write to get the certificate as I did, you'll get the&lt;br&gt;
terse response it's no longer available, and they just haven't&lt;br&gt;
updated the site. I figured I would help them get the word out since&lt;br&gt;
they didn't deem it important enough to change on their site or&lt;br&gt;
announce. It would be a shame if anyone expected this benefit based&lt;br&gt;
on the MS web site information.&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
-------------------------------------------------------------------------
&lt;/p&gt;
&lt;p&gt;
Above is what I posted to our local .Net community group on Yahoo. Now I am going
to add some personal comments. Once again, MS has dropped the ball in supporting the
developer community. Earlier this year, MS announced the MSDN Universal would not
include the new .Net Team Development system (or some name like that -- I am too lazy
to go look it up). Fortunately, enough of an uproar went out that they reversed that
decision. Their waning support of VB also caused a petition/uproar. Likely, since
the MCSD/MCDBA&amp;nbsp;community is a lot smaller, there isn't likely to be a huge outcry
on this issue.
&lt;/p&gt;
&lt;p&gt;
This is a HUGE mistake on MS's behalf. Someone that is likely to spend the extra time
and money to get certifications are the ones MS should really cater to. There's always
been a criticism that the certifications are worthless, and that benefit&amp;nbsp;alone
made it real easy to justify spending the money on books, training materials and exam
costs for achieving the certification. I won't argue the merits of the certifications
here, but I have a lot of them -- MCP, MCDBA, MCSD for VB, MCSD for .Net (C#), and
MCAD. Will I continue? I may have to given I am an Independent Contractor and it helps
to get me in the door. Will I recommend it to someone not in my position? Not likely.
&lt;/p&gt;
&lt;p&gt;
Don't get me wrong, the MSDN Universal is still a great deal. My disgust over this
situation is that the benefit is &lt;strong&gt;still&lt;/strong&gt; listed, as well as no announcement
in April 2005 when they made this decision (or if they did, I sure didn't see it).
I have&amp;nbsp;been one of the most stalwart supporters of Microsoft over the years,
and I have personally been involved in projects which have generated millions&amp;nbsp;in
licensing revenues for Microsoft in the last 10 years. The past 1.5 years I have watched
MS anger the core base of developers.
&lt;/p&gt;
&lt;p&gt;
I think this is indicative of the internal problems at MS, and why Google is going
to be a viable competitor to MS. In a paraphrase of the words of Stephen King, and
the Dark Tower series, MS has forgotten the face of their father. One of the reasons
MS dominated the market over Apple was that MS supported developers way beyond the
norm. In the name of profit, I think we are seeing this slowly change.&lt;br&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=5876a92e-efe9-4698-ab08-cf57d4ed2112" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,5876a92e-efe9-4698-ab08-cf57d4ed2112.aspx</comments>
      <category>All Things</category>
      <category>ASP.Net</category>
      <category>C#</category>
      <category>CSharp</category>
      <category>Design</category>
      <category>General</category>
      <category>Tips and Tricks</category>
      <category>Tools</category>
      <category>VB.Net</category>
      <category>Windows</category>
      <category>WinForms</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=303d10f5-f6ad-43aa-b22c-35d4768481da</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,303d10f5-f6ad-43aa-b22c-35d4768481da.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,303d10f5-f6ad-43aa-b22c-35d4768481da.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=303d10f5-f6ad-43aa-b22c-35d4768481da</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
OK, time for a little fairness in the world. When I wrote my blog entry on Monday,
I was certainly frustrated with LLBLGen. Franz Bouma has responded to my comments
about LLBLGen (little did I know I had such illustrious visitors!). So in fairness,
I want to make sure anyone out there reading my blog sees those comments so they can
see both sides of the review and form opinions on more than just my emotional outbursts,
and my semi-apology for blogging while frustrated. :)
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=303d10f5-f6ad-43aa-b22c-35d4768481da" />
      </body>
      <title>See the LLBLGen comments from July 18th...</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,303d10f5-f6ad-43aa-b22c-35d4768481da.aspx</guid>
      <link>http://www.dotnettechnologies.com/2005/07/20/SeeTheLLBLGenCommentsFromJuly18th.aspx</link>
      <pubDate>Wed, 20 Jul 2005 20:31:12 GMT</pubDate>
      <description>&lt;p&gt;
OK, time for a little fairness in the world. When I wrote my blog entry on Monday,
I was certainly frustrated with LLBLGen. Franz Bouma has responded to my comments
about LLBLGen (little did I know I had such illustrious visitors!). So in fairness,
I want to make sure anyone out there reading my blog sees those comments so they can
see both sides of the review and form opinions on more than just my emotional outbursts,
and my semi-apology for blogging while frustrated. :)
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=303d10f5-f6ad-43aa-b22c-35d4768481da" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,303d10f5-f6ad-43aa-b22c-35d4768481da.aspx</comments>
      <category>All Things</category>
      <category>ASP.Net</category>
      <category>CSharp</category>
      <category>Design</category>
      <category>General</category>
      <category>Tools</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=9884adf4-7314-4f4e-a5d5-e2855a819af8</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,9884adf4-7314-4f4e-a5d5-e2855a819af8.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,9884adf4-7314-4f4e-a5d5-e2855a819af8.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=9884adf4-7314-4f4e-a5d5-e2855a819af8</wfw:commentRss>
      <slash:comments>5</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I have tons I need to blog about but no time to do it, as once again I am up to my
head in projects. So this entry is going to be to vent....
</p>
        <p>
One of my current clients is requiring me to use a product called LLBLGen Pro (see
it at <a href="http://www.llblgen.com/" target="_blank">http://www.llblgen.com</a>).
I am certain it's a powerful product, and while it generates enough code to make a
COBOL program to look efficient, it seems to perform OK, although my gut tells me
this thing would be a pig in a high-demand environment. But here's my gripe -- the
documentation is <em>horrendous</em>. I have spent at least 50 hours trying to get
this thing to generate code effectively as well as consistantly. And even then, I
don't understand a tenth of what's generated. I understand enough to make minor changes,
and after a lot of wrestling, I can finally get it to generate code. OK, 50 hours
may not seem like a lot to learn a new paradigm which might reap a lot of benefits
later, but let me tell you what that 50 hours (billable to my client, I might add,
since I begged them after 10 hours to scrap it) bought you. I managed to add 2 fields
to a table, and add two tables. The two new table still don't work right. 
</p>
        <p>
Let's put that into perspective. First, I code lightning fast. Not spaghetti code
mind you, but robust code which typically is right the first time. In that 50 hours,
I could have re-written a good chunk of the app, and believe me, it needs it. Fortunately,
I did my consultant's duty to bring that point up. It would have taken me three hours
tops to make the changes which we are looking at 50 hours and still not working.  
</p>
        <p>
Second, the code is difficult to read at best. The project has fallen behind because
of the insistance we use this tool, so they brought on two other developers. Guess
what, they are having the same problems. They have spent two solid days now, and not
one line of code written. Using standard objects, any developer with experience in
.Net can peruse the object model quickly and begin coding. Not with this tool!
</p>
        <p>
You can't compare CodeSmith, which I have praised before, with LLBLGen. LLBLGen is
far more sophisticated, unfortunately to the point of being unusable. I know there
are a few people who swear by it, and that's great, but I get paid to come in and
make a difference fast, and LLBLGen has proven to be more an expensive hindrance than
a solution.
</p>
        <p>
OK, that's the end of the vent. I have been deploying some web services for another
client, and once we have everything debugged, I have a ton of tips related to web
services and deployment which I promise will save a ton of hours to other developers
entering into this domain. Until then!
</p>
        <p>
 
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=9884adf4-7314-4f4e-a5d5-e2855a819af8" />
      </body>
      <title>When code generation goes bad....</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,9884adf4-7314-4f4e-a5d5-e2855a819af8.aspx</guid>
      <link>http://www.dotnettechnologies.com/2005/07/19/WhenCodeGenerationGoesBad.aspx</link>
      <pubDate>Tue, 19 Jul 2005 04:49:51 GMT</pubDate>
      <description>&lt;p&gt;
I have tons I need to blog about but no time to do it, as once again I am up to my
head in projects. So this entry is going to be to vent....
&lt;/p&gt;
&lt;p&gt;
One of my current clients is requiring me to use a product called LLBLGen Pro (see
it at &lt;a href="http://www.llblgen.com/" target=_blank&gt;http://www.llblgen.com&lt;/a&gt;).
I am certain it's a powerful product, and while it generates enough code to make a
COBOL program to look efficient, it seems to perform OK, although my gut tells me
this thing would be a pig in a high-demand environment. But here's my gripe -- the
documentation is &lt;em&gt;horrendous&lt;/em&gt;. I have spent at least 50 hours trying to get
this thing to generate code effectively as well as consistantly. And even then, I
don't understand a tenth of what's generated. I understand enough to make minor changes,
and after a lot of wrestling, I can finally get it to generate code. OK, 50 hours
may not seem like a lot to learn a new paradigm which might reap a lot of benefits
later, but let me tell you what that 50 hours (billable to my client, I might add,
since I begged them after 10 hours to scrap it) bought you. I managed to add 2 fields
to a table, and add two tables. The two new table still don't work right. 
&lt;/p&gt;
&lt;p&gt;
Let's put that into perspective. First, I code lightning fast. Not spaghetti code
mind you, but robust code which typically is right the first time. In that 50 hours,
I could have re-written a good chunk of the app, and believe me, it needs it. Fortunately,
I did my consultant's duty to bring that point up.&amp;nbsp;It would have taken me three&amp;nbsp;hours
tops to make the changes which we are looking at 50 hours and still not working.&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
Second, the code is difficult to read at best. The project has fallen behind because
of the insistance we use this tool, so they brought on two other developers. Guess
what, they are having the same problems. They have spent two solid days now, and not
one line of code written. Using standard objects, any developer with experience in
.Net can peruse the object model quickly and begin coding. Not with this tool!
&lt;/p&gt;
&lt;p&gt;
You can't compare CodeSmith, which I have praised before, with LLBLGen. LLBLGen is
far more sophisticated, unfortunately to the point of being unusable. I know there
are a few people who swear by it, and that's great, but I get paid to come in and
make a difference fast, and LLBLGen has proven to be more an expensive hindrance than
a solution.
&lt;/p&gt;
&lt;p&gt;
OK, that's the end of the vent. I have been deploying some web services for another
client, and once we have everything debugged, I have a ton of tips related to web
services and deployment which I promise will save a ton of hours to other developers
entering into this domain. Until then!
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=9884adf4-7314-4f4e-a5d5-e2855a819af8" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,9884adf4-7314-4f4e-a5d5-e2855a819af8.aspx</comments>
      <category>All Things</category>
      <category>ASP.Net</category>
      <category>Design</category>
      <category>General</category>
      <category>Tools</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=faefbcf2-c211-4893-820b-0aaab66e31be</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,faefbcf2-c211-4893-820b-0aaab66e31be.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,faefbcf2-c211-4893-820b-0aaab66e31be.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=faefbcf2-c211-4893-820b-0aaab66e31be</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Extremes in anything (IMHO) are typically not good. Extreme temperatures, religeons,
attitudes -- you name it, likely there is a downside. In programming, it's no different.
Now, while not a big fan of Extreme Programming, there's a couple of extremes from
it that bother me. One is that you shouldn't include documentation. The other, which
I suspect  was someone's personal preference, was not to use the “Region”
directives in C# (or I guess VB.Net either). Here's a little history...
</p>
        <p>
This guy was a former Java programmer working for a large chip manufacturer. He was
supposed to be a XP guru, so he was transferred to the local site to help a team in
it's transition to the XP methodology. 
</p>
        <p>
Strike 1 -- he knew the methodology well, but he was by no means an expert in the
language of the group. Why was this a strike? I guess technological bias in that his
preferences to his other language directed him to want to make the .Net environment
the same as a java environment. 
</p>
        <p>
Strike 2 -- It was his way or the highway. The environment was such that one or two
developers had 95% of the say on development decisions. Part of the reason for this
is that wacky trend in which everyone is ranked from best to worst in terms of raises,
options and promotion (for more info what I am talking about, read this article, which
is the same process -- <a href="http://www.sqlservercentral.com/newsletter/view_newsletter.asp?dt=5/26/2005" target="_blank">Saying
Goodbye</a>). No one would ever argue with the two for fear of getting a bad ranking
for being considered a troublemaker.
</p>
        <p>
Regardless, I digress, but I do think it's important to understand why sometimes these
extremes come about in an environment. I was a contractor brought on to bring some
quick wins for a project, and it was my first (and likely last) venture into the XP
methodology. They needed code, and they needed it fast. 
</p>
        <p>
One problem I addressed was the lack of uniformity on the project. We had three developers,
which meant three different styles of programming. Even with XP, that meant one of
us was alone, and the other two would spend the pair time arguning over which style
was a standard and best (even though standards existed -- they were just never used
because of informal rules imposed by the 2 'chiefs'). I decided to create a template
which would standardize (and speed up) our development. I organized the code within
the controls into regions, and deployed them onto our machines with anticipation I
easily saved our team15-20 minutes each time we created a new control.
</p>
        <p>
Alas, it was scrapped instantly. Why? Well, it seems in my templates, I placed the
code into logical “regions” -- e.g. Public Properties, Public Methods,
Private Methods, etc. I was “informed” (even though I had been using regions
for a couple of months now) that regions were not allowed, because all they did was
hide bad code. WHAT???!! Well, I liked the contract, and knew the results if I stood
up to them, so I bit my tongue and moved on. It has bothered me ever since, but I
never took the time to formulate an argument as to why regions are actually a good
idea. 
</p>
        <p>
Why bring this up today after a year has passed? Well, I was coding something, and
the constructor was hidden by a region. I was thinking “Hmm, if we just left
the constructors out of regions, it would be easy to read, because the regions would
hide the internal implementations I don't care about, yet at a glance I can see how
to instantiate the object” (hmm, I think they call that encapsulation) and use
it. Now that right there justifies the use of regions alone.... I can actually think
of a lot of reasons to use regions, and I do it religeously where my client has no
opition about it. 
</p>
        <p>
Just a flashback from the past.... anyone got a counter opinion? Regardless, it just
goes to show extreme anything typically isn't a good thing in my mind. You have to
be flexible in your approach to life if you plan on growing...
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=faefbcf2-c211-4893-820b-0aaab66e31be" />
      </body>
      <title>It just occurred to me...why extremes are bad in programming</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,faefbcf2-c211-4893-820b-0aaab66e31be.aspx</guid>
      <link>http://www.dotnettechnologies.com/2005/05/27/ItJustOccurredToMewhyExtremesAreBadInProgramming.aspx</link>
      <pubDate>Fri, 27 May 2005 17:28:46 GMT</pubDate>
      <description>&lt;p&gt;
Extremes in anything (IMHO) are typically not good. Extreme temperatures, religeons,
attitudes -- you name it, likely there is a downside. In programming, it's no different.
Now, while not a big fan of Extreme Programming, there's a couple of extremes from
it that bother me. One is that you shouldn't include documentation. The other, which
I suspect&amp;nbsp; was someone's personal preference, was not to use the &amp;#8220;Region&amp;#8221;
directives in C# (or I guess VB.Net either). Here's a little history...
&lt;/p&gt;
&lt;p&gt;
This guy was a former Java programmer working for a large chip manufacturer. He was
supposed to be a XP guru, so he was transferred to the local site to help a team in
it's transition to the XP methodology. 
&lt;/p&gt;
&lt;p&gt;
Strike 1 -- he knew the methodology well, but he was by no means an expert in the
language of the group. Why was this a strike? I guess technological bias in that his
preferences to his other language directed him to want to make the .Net environment
the same as a java environment. 
&lt;/p&gt;
&lt;p&gt;
Strike 2 -- It was his way or the highway. The environment was such that one or two
developers had 95% of the say on development decisions. Part of the reason for this
is that wacky trend in which everyone is ranked from best to worst in terms of raises,
options and promotion (for more info what I am talking about, read this article, which
is the same process -- &lt;a href="http://www.sqlservercentral.com/newsletter/view_newsletter.asp?dt=5/26/2005" target=_blank&gt;Saying
Goodbye&lt;/a&gt;). No one would ever argue with the two for fear of getting a bad ranking
for being considered a troublemaker.
&lt;/p&gt;
&lt;p&gt;
Regardless, I digress, but I do think it's important to understand why sometimes these
extremes come about in an environment. I was a contractor brought on to bring some
quick wins for a project, and it was my first (and likely last) venture into the XP
methodology. They needed code, and they needed it fast. 
&lt;/p&gt;
&lt;p&gt;
One problem I addressed was the lack of uniformity on the project. We had three developers,
which meant three different styles of programming. Even with XP, that meant one of
us was alone, and the other two would spend the pair time arguning over which style
was a standard and best (even though standards existed -- they were just never used
because of informal rules imposed by the 2 'chiefs'). I decided to create a template
which would standardize (and speed up) our development. I organized the code within
the controls into regions, and deployed them onto our machines with anticipation I
easily saved our team15-20 minutes each time we created a new control.
&lt;/p&gt;
&lt;p&gt;
Alas, it was scrapped instantly. Why? Well, it seems in my templates, I placed the
code into logical &amp;#8220;regions&amp;#8221; -- e.g. Public Properties, Public Methods,
Private Methods, etc. I was &amp;#8220;informed&amp;#8221; (even though I had been using regions
for a couple of months now) that regions were not allowed, because all they did was
hide bad code. WHAT???!! Well, I liked the contract, and knew the results if I stood
up to them, so I bit my tongue and moved on. It has bothered me ever since, but I
never took the time to formulate an argument as to why regions are actually a good
idea. 
&lt;/p&gt;
&lt;p&gt;
Why bring this up today after a year has passed? Well, I was coding something, and
the constructor was hidden by a region. I was thinking &amp;#8220;Hmm, if we just left
the constructors out of regions, it would be easy to read, because the regions would
hide the internal implementations I don't care about, yet at a glance I can see how
to instantiate the object&amp;#8221; (hmm, I think they call that encapsulation) and use
it. Now that right there justifies the use of regions alone.... I can actually think
of a lot of reasons to use regions, and I do it religeously where my client has no
opition about it. 
&lt;/p&gt;
&lt;p&gt;
Just a flashback from the past.... anyone got a counter opinion? Regardless, it just
goes to show extreme anything typically isn't a good thing in my mind. You have to
be flexible in your approach to life if you plan on growing...
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=faefbcf2-c211-4893-820b-0aaab66e31be" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,faefbcf2-c211-4893-820b-0aaab66e31be.aspx</comments>
      <category>All Things</category>
      <category>C#</category>
      <category>CSharp</category>
      <category>Design</category>
      <category>General</category>
      <category>Tips and Tricks</category>
      <category>VB.Net</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=d98820c4-cb7c-4348-8d80-b59c6d514d01</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,d98820c4-cb7c-4348-8d80-b59c6d514d01.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,d98820c4-cb7c-4348-8d80-b59c6d514d01.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=d98820c4-cb7c-4348-8d80-b59c6d514d01</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Tentatively, my current project is set to end in October. No big deal there, as I
have had absolutely no bench days in the past 10 years as an Independent Contractor.
In fact, during most of those 10 years I have been working 55-80+ hours per week and
having a great time doing it. I don't do the book thing or magazine article thing
because quite frankly, I don't have time because I am busy doing billable work which
pays a lot more. I havn't needed self-promotion thing either because almost all my
business comes from referrals from current or past customers.
</p>
        <p>
Then along come kids, and dang if you don't suddenly want to spend more time at home
and improve their quality of life (and mine). My current project wants to bring me
on full time, and we've had some preliminary discussions on it, and I am willing to
take the pay cut in my pay for one simple thing: I want to work remotely
and raise my kids in the country. Their attitude is like mine, which is that should
be fine since I have a strong work ethic and can get things done, what does it matter
where I work as long as I have a phone and internet connection. However, there are
data security concerns and management concerns which would need to be overcome. 
</p>
        <p>
I have plenty of time, since barring disaster, the contract won't be over until
October sometime. But I figure I will start self-promoting just in case someone from
a company who doesn't mind remote employees stumbles on this blog. Towards October,
I will go full bore trying to close something out, and in the meantime I plan on blogging
much more so I can display what talents I can bring to the table. 
</p>
        <p>
If any companies out there that come up on this, and want a great employee (C#/VB
developer with lots of SQL Server and architect/designer/coding and full-life cycle
development) that brings a lot of experience, a great professional attitude and
presence as well as the ability to code like the wind (and good code at that..), then
drop me a line and let's talk. 
</p>
        <p>
Here's a <a href="http://www.rubiconcomputing.com/resume/resume.html" target="_blank">resume </a>just
in case.. 
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=d98820c4-cb7c-4348-8d80-b59c6d514d01" />
      </body>
      <title>Self Promotion</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,d98820c4-cb7c-4348-8d80-b59c6d514d01.aspx</guid>
      <link>http://www.dotnettechnologies.com/2005/05/26/SelfPromotion.aspx</link>
      <pubDate>Thu, 26 May 2005 23:33:35 GMT</pubDate>
      <description>&lt;p&gt;
Tentatively, my current project is set to end in October. No big deal there, as I
have had absolutely no bench days in the past 10 years as an Independent Contractor.
In fact, during most of those 10 years I have been working 55-80+ hours per week and
having a great time doing it. I don't do the book thing or magazine article thing
because quite frankly, I don't have time because I am busy doing billable work which
pays a lot more. I havn't needed self-promotion thing either because almost all my
business comes from referrals from current or past customers.
&lt;/p&gt;
&lt;p&gt;
Then along come kids, and dang if you don't suddenly want to spend more time at home
and improve their quality of life (and mine). My current project wants to bring me
on full time, and we've had some preliminary discussions on it, and I am willing to
take&amp;nbsp;the pay&amp;nbsp;cut in my pay for one simple thing: I want to work remotely
and raise my kids in the country. Their attitude is like mine, which is that should
be fine since I have a strong work ethic and can get things done, what does it matter
where I work as long as I have a phone and internet connection. However, there are
data security concerns and management concerns which would need to be overcome. 
&lt;/p&gt;
&lt;p&gt;
I&amp;nbsp;have plenty of time, since barring disaster, the contract won't be over until
October sometime. But I figure I will start self-promoting just in case someone from
a company who doesn't mind remote employees stumbles on this blog. Towards October,
I will go full bore trying to close something out, and in the meantime I plan on blogging
much more so I can display what talents I can bring to the table. 
&lt;/p&gt;
&lt;p&gt;
If any companies out there that come up on this, and want a great employee (C#/VB
developer with lots of SQL Server and architect/designer/coding and full-life cycle
development)&amp;nbsp;that brings a lot of experience, a great professional attitude and
presence as well as the ability to code like the wind (and good code at that..), then
drop me a line and let's talk. 
&lt;/p&gt;
&lt;p&gt;
Here's a &lt;a href="http://www.rubiconcomputing.com/resume/resume.html" target=_blank&gt;resume &lt;/a&gt;just
in case.. 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=d98820c4-cb7c-4348-8d80-b59c6d514d01" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,d98820c4-cb7c-4348-8d80-b59c6d514d01.aspx</comments>
      <category>All Things</category>
      <category>ASP.Net</category>
      <category>C#</category>
      <category>CSharp</category>
      <category>Design</category>
      <category>General</category>
      <category>SQL Tips</category>
      <category>Tips and Tricks</category>
      <category>Tools</category>
      <category>VB.Net</category>
      <category>Windows</category>
      <category>WinForms</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=9371af86-0405-4beb-bd2e-b0b1f0884ae1</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,9371af86-0405-4beb-bd2e-b0b1f0884ae1.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,9371af86-0405-4beb-bd2e-b0b1f0884ae1.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=9371af86-0405-4beb-bd2e-b0b1f0884ae1</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I bought CodeSmith back in v2, but I was so busy I never got a chance to do more than
play around with it. So now v3 is released, and I was looking at the improvements
(like Intellisense) and decided I would take a look at it again. Boy, was I glad I
did..
</p>
        <p>
Don't get me wrong, I wasn't putting it off because I think code generation and templates
are bad. In fact, quite the opposite. When I first started my business, I had a few
people working with me part-time, and then finally full time as the business grew.
What I found was that in the end, I apparently hold my coding standards to a higher
value than others and I would end up coding 90% of the application myself. I realized
quickly there were a few huge advantages to automated code generation. Here's a few:
</p>
        <ul>
          <li>
Fewer errors (as long as you fix the templates as errors are encountered)</li>
          <li>
One developer can do the work of 4-5 once you get a good architecture set up</li>
          <li>
Standards enforcement is a no-brainer when you are all working off the same templates</li>
          <li>
You can spend more time on UI usability and data structure because 90% of the infrastructure
stuff is done automatically</li>
          <li>
Changes are easy. Change the structure and regenerate the code, and you are off again.</li>
        </ul>
        <p>
I could go on and on about it. I had written a series of VB6 addins which I used based
off Rocky Lhotka's BusinessObjects book for VB5. In hours I could generate almost
all of my middle and data tier code. A tweak here and there, and I was doing the fun
stuff like UI coding. 
</p>
        <p>
Along comes .Net, and my addins were irrelevant. I created a couple of quick and dirty
addins, but I was so busy heads-down coding, I didn't have time to create new templates
to reflect the impact of .Net. I did create some common libraries of functions which
got me through a good chunk of redundant coding, so that was going to have to do the
job for the time.  I had always intended on going back and re-coding some new
templates, but it never happened. 
</p>
        <p>
I am currently working on a project and we are horribly understaffed, and there's
no relief in sight. There are some huge deadlines coming up, and it's time to make
the rubber hit the road. I already code fast (and tight), but I needed to clone myself
a couple times over to make the deadlines. So when the announcement came this week
of CodeSmith 3.0, I decided I would take a new serious look at it and see what it
could do for me. 
</p>
        <p>
Holy crap! In a matter of hours I had some pretty solid templates up and running,
which will save the team many, many hours of redundant coding tasks in building this
application. I have so many ideas for new templates it's scary, and I have only
scratched the surface for what the tool can do. If you haven't looked at it yet, I
recommend immediately going to <a href="http://www.codesmithtools.com/" target="_blank">CodeSmith</a> and
downloading a trial.
</p>
        <p>
 
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=9371af86-0405-4beb-bd2e-b0b1f0884ae1" />
      </body>
      <title>CodeSmith rocks!</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,9371af86-0405-4beb-bd2e-b0b1f0884ae1.aspx</guid>
      <link>http://www.dotnettechnologies.com/2005/05/26/CodeSmithRocks.aspx</link>
      <pubDate>Thu, 26 May 2005 23:19:32 GMT</pubDate>
      <description>&lt;p&gt;
I bought CodeSmith back in v2, but I was so busy I never got a chance to do more than
play around with it. So now v3 is released, and I was looking at the improvements
(like Intellisense) and decided I would take a look at it again. Boy, was I glad I
did..
&lt;/p&gt;
&lt;p&gt;
Don't get me wrong, I wasn't putting it off because I think code generation and templates
are bad. In fact, quite the opposite. When I first started my business, I had a few
people working with me part-time, and then finally full time as the business grew.
What I found was that in the end, I apparently hold my coding standards to a higher
value than others and I would end up coding 90% of the application myself. I realized
quickly there were a few huge advantages to automated code generation. Here's a few:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Fewer errors (as long as you fix the templates as errors are encountered)&lt;/li&gt;
&lt;li&gt;
One developer can do the work of 4-5 once you get a good architecture set up&lt;/li&gt;
&lt;li&gt;
Standards enforcement is a no-brainer when you are all working off the same templates&lt;/li&gt;
&lt;li&gt;
You can spend more time on UI usability and data structure because 90% of the infrastructure
stuff is done automatically&lt;/li&gt;
&lt;li&gt;
Changes are easy. Change the structure and regenerate the code, and you are off again.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
I could go on and on about it. I had written a series of VB6 addins which I used based
off Rocky Lhotka's BusinessObjects book for VB5. In hours I could generate almost
all of my middle and data tier code. A tweak here and there, and I was doing the fun
stuff like UI coding. 
&lt;/p&gt;
&lt;p&gt;
Along comes .Net, and my addins were irrelevant. I created a couple of quick and dirty
addins, but I was so busy heads-down coding, I didn't have time to create new templates
to reflect the impact of .Net. I did create some common libraries of functions which
got me through a good chunk of redundant coding, so that was going to have to do the
job for the time.&amp;nbsp; I had always intended on going back and re-coding some new
templates, but it never happened. 
&lt;/p&gt;
&lt;p&gt;
I am currently working on a project and we are horribly understaffed, and there's
no relief in sight. There are some huge deadlines coming up, and it's time to make
the rubber hit the road. I already code fast (and tight), but I needed to clone myself
a couple times over to make the deadlines. So when the announcement came this week
of CodeSmith 3.0, I decided I would take a new serious look at it and see what it
could do for me. 
&lt;/p&gt;
&lt;p&gt;
Holy crap! In a matter of hours I had some pretty solid templates up and running,
which will save the team many, many hours of redundant coding tasks in building this
application. I have so many ideas for new templates it's scary, and&amp;nbsp;I have only
scratched the surface for what the tool can do. If you haven't looked at it yet, I
recommend immediately going to &lt;a href="http://www.codesmithtools.com/" target=_blank&gt;CodeSmith&lt;/a&gt; and
downloading a trial.
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=9371af86-0405-4beb-bd2e-b0b1f0884ae1" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,9371af86-0405-4beb-bd2e-b0b1f0884ae1.aspx</comments>
      <category>All Things</category>
      <category>C#</category>
      <category>CSharp</category>
      <category>Design</category>
      <category>General</category>
      <category>Tips and Tricks</category>
      <category>Tools</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=8e3e7285-b4a7-4a3a-910c-1a84d2b1cf75</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,8e3e7285-b4a7-4a3a-910c-1a84d2b1cf75.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,8e3e7285-b4a7-4a3a-910c-1a84d2b1cf75.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=8e3e7285-b4a7-4a3a-910c-1a84d2b1cf75</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
There's a lot of debate on the best type of error handling, where to log it (if at
all), and when to do it. For example, here's a debate today:
</p>
        <p>
          <a href="http://weblogs.asp.net/alex_papadimoulis/archive/2005/03/29/396141.aspx">http://weblogs.asp.net/alex_papadimoulis/archive/2005/03/29/396141.aspx</a>
        </p>
        <p>
In this debate, the question is Return codes vs. Throwing an Exception. You can read
the blog entry to see the debate. Here's my take, and why.
</p>
        <p>
First, I always handle the exception where it happens, and rarely bubble it up. Why?
First, what if the calling code doesn't handle the exception? Now you have an unhandled
error, and it could cause an application to crash. On a recent project for a large
chipmaking client, I got into this debate a few times with all levels of developers.
It was always an interesting debate with senior developers because they at least adopted
their belief into action and a bigger strategy. For example, they may trickle it up
and handle it at the highest level, but if they forget to handle it, the best developers
handle the uncaught errors at the thread level. The advantage is they have the error
information and can use it to provide the user some feedback as to the nature of the
problem.
</p>
        <p>
But those are good developers, and I would say the top 10%. As an example, I had this
debate with a mid-level developer who was convinced he was a senior level developer.
Now, as I tell this story, let me mention I am a very good poker player. He adamantly
felt errors should be bubbled up and handled at the UI. I countered him with the standard
“What happens when the exception isn't handled?” He advised me he never
forgets. Enter the poker player in me. 
</p>
        <p>
Being a consultant, you have to know when to shut up and let the “hand”
play out. This was an XP project (never again), and as we paired, I watched him write
some code, and I even reminded him about error handling. For the most part, with my
diligence and because we had just had the discussion this guy was being fairly consistant
in his exception handling at the UI level. However, I stopped reminding him (it's
instinct for me to do it now), and sure enough, he forgot, and the application crashed
a horrible death. The reason I wanted to have this discussion with him was because
his code was causing about 80% of the crashes on the team, and I was trying to help
him improve his skills (and our project). To finish the story, the guy's ego was so
big he refused to accept responsibility for the crashes or even acknowledge that I
had a valid point about forgetting error handling, and kept on his merry way.
</p>
        <p>
Back to the point, IMHO error handling should be handled where the error occurs. This
is especially true in multi-developer projects, as you cannot guarantee someone who
calls your code is diligent enough to handle things when problems occur.
</p>
        <p>
But that has a serious downside -- how do you let the user know there was a problem,
and it was handled? The answer -- return values. OK, there's a little more to it than
that. An error code is never enough information to provide feedback or to decide what
to do when the caller receives notice an error occurred. Even worse, a number is useless
in trying to relay relevant info to the end-user.
</p>
        <p>
What I have adopted is this: I have a base class which my other classes inherit from.
In that class, I have an ErrorMessage property (string) which is set where the error
occurs, or in a central error handler. When a method encounters an error, it returns
an integer value indicating failure. The calling routine (if desired) can check the
ErrorMessage property and use that value for displaying a message or get details as
to the nature of the problem.  It can also ignore it if it wants. The key thing
though is that the error will never go unhandled and cause the application to crash.
</p>
        <p>
I'll be happy to post up some examples if there is interest. This is just a very important
topic to me, and one I think which separates the wheat from the chaff, as they say!
</p>
        <p>
In the debate listed above, there's an argument over performance. There's a balance
here: you need to perform well, but performance is killed when the application
crashes. Find a solution which is robust but also performs. Not handling an exception
is not an option for robustness.
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=8e3e7285-b4a7-4a3a-910c-1a84d2b1cf75" />
      </body>
      <title>Error Handling Discussion</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,8e3e7285-b4a7-4a3a-910c-1a84d2b1cf75.aspx</guid>
      <link>http://www.dotnettechnologies.com/2005/04/14/ErrorHandlingDiscussion.aspx</link>
      <pubDate>Thu, 14 Apr 2005 16:49:54 GMT</pubDate>
      <description>&lt;p&gt;
There's a lot of debate on the best type of error handling, where to log it (if at
all), and when to do it. For example, here's a debate today:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://weblogs.asp.net/alex_papadimoulis/archive/2005/03/29/396141.aspx"&gt;http://weblogs.asp.net/alex_papadimoulis/archive/2005/03/29/396141.aspx&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
In this debate, the question is Return codes vs. Throwing an Exception. You can read
the blog entry to see the debate. Here's my take, and why.
&lt;/p&gt;
&lt;p&gt;
First, I always handle the exception where it happens, and rarely bubble it up. Why?
First, what if the calling code doesn't handle the exception? Now you have an unhandled
error, and it could cause an application to crash. On a recent project for a large
chipmaking client, I got into this debate a few times with all levels of developers.
It was always an interesting debate with senior developers because they at least adopted
their belief into action and a bigger strategy. For example, they may trickle it up
and handle it at the highest level, but if they forget to handle it, the best developers
handle the uncaught errors at the thread level. The advantage is they have the error
information and can use it to provide the user some feedback as to the nature of the
problem.
&lt;/p&gt;
&lt;p&gt;
But those are good developers, and I would say the top 10%. As an example, I had this
debate with a mid-level developer who was convinced he was a senior level developer.
Now, as I tell this story, let me mention I am a very good poker player. He adamantly
felt errors should be bubbled up and handled at the UI. I countered him with the standard
&amp;#8220;What happens when the exception isn't handled?&amp;#8221; He advised me he never
forgets. Enter the poker player in me. 
&lt;/p&gt;
&lt;p&gt;
Being a consultant, you have to know when to shut up and let the &amp;#8220;hand&amp;#8221;
play out. This was an XP project (never again), and as we paired, I watched him write
some code, and I even reminded him about error handling. For the most part, with my
diligence and because we had just had the discussion this guy was being fairly consistant
in his exception handling at the UI level. However, I stopped reminding him (it's
instinct for me to do it now), and sure enough, he forgot, and the application crashed
a horrible death. The reason I wanted to have this discussion with him was because
his code was causing about 80% of the crashes on the team, and I was trying to help
him improve his skills (and our project). To finish the story, the guy's ego was so
big he refused to accept responsibility for the crashes or even acknowledge that I
had a valid point about forgetting error handling, and kept on his merry way.
&lt;/p&gt;
&lt;p&gt;
Back to the point, IMHO error handling should be handled where the error occurs. This
is especially true in multi-developer projects, as you cannot guarantee someone who
calls your code is diligent enough to handle things when problems occur.
&lt;/p&gt;
&lt;p&gt;
But that has a serious downside -- how do you let the user know there was a problem,
and it was handled? The answer -- return values. OK, there's a little more to it than
that. An error code is never enough information to provide feedback or to decide what
to do when the caller receives notice an error occurred. Even worse, a number is useless
in trying to relay relevant info to the end-user.
&lt;/p&gt;
&lt;p&gt;
What I have adopted is this: I have a base class which my other classes inherit from.
In that class, I have an ErrorMessage property (string) which is set where the error
occurs, or in a central error handler. When a method encounters an error, it returns
an integer value indicating failure. The calling routine (if desired) can check the
ErrorMessage property and use that value for displaying a message or get details as
to the nature of the problem.&amp;nbsp; It can also ignore it if it wants. The key thing
though is that the error will never go unhandled and cause the application to crash.
&lt;/p&gt;
&lt;p&gt;
I'll be happy to post up some examples if there is interest. This is just a very important
topic to me, and one I think which separates the wheat from the chaff, as they say!
&lt;/p&gt;
&lt;p&gt;
In the debate listed above, there's an argument over performance. There's a balance
here: you need to perform well, but performance is killed&amp;nbsp;when the application
crashes. Find a solution which is robust but also performs. Not handling an exception
is not an option for robustness.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=8e3e7285-b4a7-4a3a-910c-1a84d2b1cf75" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,8e3e7285-b4a7-4a3a-910c-1a84d2b1cf75.aspx</comments>
      <category>All Things</category>
      <category>ASP.Net</category>
      <category>C#</category>
      <category>CSharp</category>
      <category>Design</category>
      <category>General</category>
      <category>Tips and Tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=80e3aae3-25f7-4fcb-ba45-62e0879ecc72</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,80e3aae3-25f7-4fcb-ba45-62e0879ecc72.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,80e3aae3-25f7-4fcb-ba45-62e0879ecc72.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=80e3aae3-25f7-4fcb-ba45-62e0879ecc72</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I am currently trying to go through a Code Review at a large bank to get our code
approved for release on the internet. One thing that came up was in some situations,
we are displaying the raw exception message which was listed as a no-no, which I disagree
with. While it's not particularly informative to the user which is potentially an
issue, I can't see where “Invalid use of null” is going to be particularly
useful to a hacker, but to a developer, that tidbit may help identify the problem
when the user calls for help (good application logging aside in this example). Ironically,
when errors weren't handled because the developer forgot, this passed code review.
</p>
        <p>
So my intent was to enumerate all the default error messages to determine if there
are any which would be particularly helpful to a hacker. While I am still looking
to find or create an application which will enumerate all the default messages that
.New throws out, I did come across a great article which lists the various error handling
philosophies, and tries to weigh out the pros and cons of each. Here's where to get
this pearl of wisdom:
</p>
        <p>
          <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/exceptdotnet.asp">http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/exceptdotnet.asp</a>
        </p>
        <p>
 
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=80e3aae3-25f7-4fcb-ba45-62e0879ecc72" />
      </body>
      <title>Tip of the Day -- Great Exception Handling article</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,80e3aae3-25f7-4fcb-ba45-62e0879ecc72.aspx</guid>
      <link>http://www.dotnettechnologies.com/2005/03/09/TipOfTheDayGreatExceptionHandlingArticle.aspx</link>
      <pubDate>Wed, 09 Mar 2005 17:47:50 GMT</pubDate>
      <description>&lt;p&gt;
I am currently trying to go through a Code Review at a large bank to get our code
approved for release on the internet. One thing that came up was in some situations,
we are displaying the raw exception message which was listed as a no-no, which I disagree
with. While it's not particularly informative to the user which is potentially an
issue, I can't see where &amp;#8220;Invalid use of null&amp;#8221; is going to be particularly
useful to a hacker, but to a developer, that tidbit may help identify the problem
when the user calls for help (good application logging aside in this example). Ironically,
when errors weren't handled because the developer forgot, this passed code review.
&lt;/p&gt;
&lt;p&gt;
So my intent was to enumerate all the default error messages to determine if there
are any which would be particularly helpful to a hacker. While I am still looking
to find or create an application which will enumerate all the default messages that
.New throws out, I did come across a great article which lists the various error handling
philosophies, and tries to weigh out the pros and cons of each. Here's where to get
this pearl of wisdom:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/exceptdotnet.asp"&gt;http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/exceptdotnet.asp&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=80e3aae3-25f7-4fcb-ba45-62e0879ecc72" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,80e3aae3-25f7-4fcb-ba45-62e0879ecc72.aspx</comments>
      <category>All Things</category>
      <category>ASP.Net</category>
      <category>C#</category>
      <category>Design</category>
      <category>General</category>
      <category>Tips and Tricks</category>
      <category>VB.Net</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=ceb433e0-0cca-45d4-9cf8-67f48d19a4d1</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,ceb433e0-0cca-45d4-9cf8-67f48d19a4d1.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,ceb433e0-0cca-45d4-9cf8-67f48d19a4d1.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=ceb433e0-0cca-45d4-9cf8-67f48d19a4d1</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I spent the past 11 months (as I mentioned previously) as part of a team of developers on
an 'agile' project, using the Extreme Programming methodology. As I was working out
today, I was reading the December 2004 issue of asp.net Pro magazine. The featured
article is about Test Driven Development (TDD), and it's place in agile development.
</p>
        <p>
First, let me preface this topic by saying I am absolutely FOR Test Driven Development.
In my opinion, there's too little focus given by developers on focusing in what can
go wrong with an application -- testing, error handling, malicious users, and a myriad
of other potential gotchas. The purpose of this blog is simply to provide some alternative
views on TDD, and some potential pitfalls, since there is little seen on the topic,
especially from those of us in the trenches. Combine this in your approach to TDD,
and you'll have a much better experience.
</p>
        <p>
Here's an executive summery of the caveats to TDD from my experience:
</p>
        <ol>
          <li>
No code is supposed to be written before the tests. Design first, then write the tests,
or you'll end up with a bad design. 
</li>
          <li>
When tests take longer to write and modify than the actual coding, the process gets
in the way. 
</li>
          <li>
TDD gives way to the erroneous philosophy that if your automated tests work, that's
all the testing you need (except user acceptance). 
</li>
          <li>
There is the dangerous thinking that you can write automated tests to cover every
scenario. See point 2 again. 
</li>
          <li>
There becomes a belief that the number of tests somehow correlates to the quality
of testing, or the the mere existence of an automated test provides a better application. 
</li>
          <li>
UI testing tools (especially the open source varieties) are lacking in the ability
to generate UI tests, at least from the web perspective in the trench I sat in. 
</li>
          <li>
When you data shunt the data access (and manipulation) portion of a class, that's
not a very valid test. The database MUST be tested, and your tests must accurately
reflect how the users are going to be actually using your objects for TDD to be of
any use.</li>
        </ol>
        <p>
Let's look at each point in a bit of detail, so I can provide some details on my OPINIONS
here... 
</p>
        <p>
First, the statement is made no code should be written before the test. OK, what exactly
are you going to be testing for? For example, let's say you might be wanting to test
customer creation. You envision the routine you want to test to return an integer
which ties to the ID the database generates. OK, great! But guess what, that's a DESIGN
DECISION. Why not set a read-only property of a class, and return a standard return
code? Are you going to follow this exact style with the rest of your classes? Will
the other developers do the same? Will the routine throw an error, or handle it itself?
If handled, how will I know there was an error?
</p>
        <p>
I know for a fact that if you don't lay out some very specific coding guidelines and
design, four developers are going to design the same class four different ways,
even when pairing. Given that fact, how can you possible write meaningful and consistent
tests without doing a basic architecture/design first. 
</p>
        <p>
Second, writing tests is time consuming. Maintaining tests can be even worse. On this
same project, test maintenance at times took more time than making a simple change.
Why? When the change is made, many times a refactoring occurs (in our case it was
almost a given since there was little thought placed on a unified design -- some day
I will write on why that occurred as part of a human dynamics of development topic).
Suddenly, the test needs to be re-written because the test now fails as a result of
the refactoring. A simple business rule change has now turned into a design and test
change. A task that might have taken an hour now takes two days. Sorry, as a business
owner, it's a bitter pill to swallow.
</p>
        <p>
Another mistake occurs when the developer takes on the attitude that when the automated
tests pass, the testing is complete. Let's face it, as developers, testing sits right
up there with documenting code. No one wants to do it, but it HAS to be done. With
TDD, it's an easy trap to fall into. I even heard “My tests run, let the customer
catch anything else in User Acceptance.” Wrong! The customer's are why we as
developers have jobs. We need to do due diligence in functional testing, integration
testing as well as usability testing. Automated testing is NOT going to do that for
us. To think your automated tests are going to catch all the errors is dangerous thinking.
No one has every promoted TDD to accomplish this, but I can tell you from experience,
the possibility that this mindset can exist is there.
</p>
        <p>
As I mentioned before, I am all for TDD and automated testing. However, I also like
to be thorough. I also only like to write valid tests. If I was to sit there and ponder
every single possible scenario, at my bill rate the client is going to be looking
elsewhere thinking I am nor getting enough done. Consultants beware! But seriously,
even if I could take the time to come up with test which can adequately test the possible
scenarios, how much have I gained (in the short term -- long term is a whole other
story which TDD clearly wins)? Testing scripts which repeatedly test the application,
written by the users and repeated each time in user acceptance is a far more effective
testing methodology (OK, devil's advocate time -- can you really get them to test
it completely every time? The tester also suffers from laziness or lack of attention in
repetitive tasks..) So writing tests is going to also be an iterative process which
never ends. When a bug shows up, we need to refactor our testing to cover that scenario
in the future. Now I am maintaining two projects which is even more time consuming.
</p>
        <p>
The next fallacy in TDD is that the sheer number of tests (metrics) means you have
good testing. In the environment I was working in, their reviews were actually based
in part on the number of tests they wrote. Never mind that the majority of the test
written were actually an effective test, but the sheer count was taken to be effective
testing. Quality in testing should be your number one priority. If you can only come
up with one test which effectively tests an object, then so be it. Adding five more
test which do nothing other than add time during a refactoring is little help to the
cause of good software.
</p>
        <p>
Right now, automated testing really focuses on the Data Access Layer (DAL) and Business
Objects Layer (BOL). When I discuss shunting next, you'll see it actually comes down
to the BOL in many cases. What about the UI? The tools, especially for ASP.Net in
the open source community are severely lacking in automated testing. How will you
know if the javascript works both on Netscape and IE without running it yourself? 
It's the UI the user sees, which is why the UI has to be thoroughly tested in both
how you expect the user to use it, and how they <strong>might</strong> use it. Users
always come up with useful scenarios to break our applications. Think of it as a fun
challenge and you'll be far less frustrated.
</p>
        <p>
To test out our BOL, we shunted the data using XML or pre-defined data tables. It
actually works great, but it's a limited test. What happens when the database schema
changes? If you've shunted the data, you'll never know the impact unless you do your
due diligence and fully integrate test, or the user finds it in user acceptance testing
(which is not where you want to catch these things). If you do shunt your data, that's
great and fine. Just make sure you test against the schema the application is going
to be deployed against as well. See my blog about getting a random record using NewId()
if you want to generate some good database based tests.
</p>
        <p>
OK, it probably sounds like I am really bummed about automated testing after my recent
experience with it. That belief is the farthest from the truth. In fact, I am
going to introduce it on my current project because I feel it can certainly add a
key dynamic to a complete testing process. But as Test Driven Development gains
acceptance, I felt it was time someone at least mentioned the things to consider
so it can be a more effective tool in your development cycle. Plan ahead and determine
how you can avoid these pitfalls and hopefully your investment in time will generate
more dividends from Test Driven Development.
</p>
        <p>
 
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=ceb433e0-0cca-45d4-9cf8-67f48d19a4d1" />
      </body>
      <title>Test Driven Development (Test First) -- is it everything it's supposed to be?</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,ceb433e0-0cca-45d4-9cf8-67f48d19a4d1.aspx</guid>
      <link>http://www.dotnettechnologies.com/2004/11/24/TestDrivenDevelopmentTestFirstIsItEverythingItsSupposedToBe.aspx</link>
      <pubDate>Wed, 24 Nov 2004 04:10:05 GMT</pubDate>
      <description>&lt;p&gt;
I spent the past 11 months (as I mentioned&amp;nbsp;previously) as part of a team of developers&amp;nbsp;on
an 'agile' project, using the Extreme Programming methodology. As I was working out
today, I was reading the December 2004 issue of asp.net Pro magazine. The featured
article is about Test Driven Development (TDD), and it's place in agile development.
&lt;/p&gt;
&lt;p&gt;
First, let me preface this topic by saying I am absolutely FOR Test Driven Development.
In my opinion, there's too little focus given by developers on focusing in what can
go wrong with an application -- testing, error handling, malicious users, and a myriad
of other potential gotchas. The purpose of this blog is simply to provide some alternative
views on TDD, and some potential pitfalls, since there is little seen on the topic,
especially from those of us in the trenches. Combine this in your approach to TDD,
and you'll have a much better experience.
&lt;/p&gt;
&lt;p&gt;
Here's an executive summery of the caveats to TDD from my experience:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
No code is supposed to be written before the tests. Design first, then write the tests,
or you'll end up with a bad design. 
&lt;li&gt;
When tests take longer to write and modify than the actual coding, the process gets
in the way. 
&lt;li&gt;
TDD gives way to the erroneous philosophy that if your automated tests work, that's
all the testing you need (except user acceptance). 
&lt;li&gt;
There is the&amp;nbsp;dangerous thinking that you can write automated tests to cover every
scenario. See point 2 again. 
&lt;li&gt;
There becomes a belief that the number of tests somehow correlates to the quality
of testing, or the the mere existence of an automated test provides a better application. 
&lt;li&gt;
UI testing tools (especially the open source varieties) are lacking in the ability
to generate UI tests, at least from the web perspective in the trench I sat in. 
&lt;li&gt;
When you data shunt the data access (and manipulation) portion of a class, that's
not a very valid test. The database MUST be tested, and your tests must accurately
reflect how the users are going to be actually using your objects for TDD to be of
any use.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
Let's look at each point in a bit of detail, so I can provide some details on my OPINIONS
here... 
&lt;/p&gt;
&lt;p&gt;
First, the statement is made no code should be written before the test. OK, what exactly
are you going to be testing for? For example, let's say you might be wanting to test
customer creation. You envision the routine you want to test to return an integer
which ties to the ID the database generates. OK, great! But guess what, that's a DESIGN
DECISION. Why not set a read-only property of a class, and return a standard return
code? Are you going to follow this exact style with the rest of your classes? Will
the other developers do the same? Will the routine throw an error, or handle it itself?
If handled, how will I know there was an error?
&lt;/p&gt;
&lt;p&gt;
I know for a fact that if you don't lay out some very specific coding guidelines and
design, four developers are going to design the same class&amp;nbsp;four different ways,
even when pairing. Given that fact, how can you possible write meaningful and consistent
tests without doing a basic architecture/design first. 
&lt;/p&gt;
&lt;p&gt;
Second, writing tests is time consuming. Maintaining tests can be even worse. On this
same project, test maintenance at times took more time than making a simple change.
Why? When the change is made, many times a refactoring occurs (in our case it was
almost a given since there was little thought placed on a unified design -- some day
I will write on why that occurred as part of a human dynamics of development topic).
Suddenly, the test needs to be re-written because the test now fails as a result of
the refactoring. A simple business rule change has now turned into a design and test
change. A task that might have taken an hour now takes two days. Sorry, as a business
owner, it's a bitter pill to swallow.
&lt;/p&gt;
&lt;p&gt;
Another mistake occurs when the developer takes on the attitude that when the automated
tests pass, the testing is complete. Let's face it, as developers, testing sits right
up there with documenting code. No one wants to do it, but it HAS to be done. With
TDD, it's an easy trap to fall into. I even heard &amp;#8220;My tests run, let the customer
catch anything else in User Acceptance.&amp;#8221; Wrong! The customer's are why we as
developers have jobs. We need to do due diligence in functional testing, integration
testing as well as usability testing. Automated testing is NOT going to do that for
us. To think your automated tests are going to catch all the errors is dangerous thinking.
No one has every promoted TDD to accomplish this, but I can tell you from experience,
the possibility that this mindset can exist is there.
&lt;/p&gt;
&lt;p&gt;
As I mentioned before, I am all for TDD and automated testing. However, I also like
to be thorough. I also only like to write valid tests. If I was to sit there and ponder
every single possible scenario, at my bill rate the client is going to be looking
elsewhere thinking I am nor getting enough done. Consultants beware! But seriously,
even if I could take the time to come up with test which can adequately test the possible
scenarios, how much have I gained (in the short term -- long term is a whole other
story which TDD clearly wins)? Testing scripts which repeatedly test the application,
written by the users and repeated each time in user acceptance is a far more effective
testing methodology (OK, devil's advocate time -- can you really get them to test
it completely every time? The tester also suffers from laziness or lack of attention&amp;nbsp;in
repetitive tasks..) So writing tests is going to also be an iterative process which
never ends. When a bug shows up, we need to refactor our testing to cover that scenario
in the future. Now I am maintaining two projects which is even more time consuming.
&lt;/p&gt;
&lt;p&gt;
The next fallacy in TDD is that the sheer number of tests (metrics) means you have
good testing. In the environment I was working in, their reviews were actually based
in part on the number of tests they wrote. Never mind that the majority of the test
written were actually an effective test, but the sheer count was taken to be effective
testing. Quality in testing should be your number one priority. If you can only come
up with one test which effectively tests an object, then so be it. Adding five more
test which do nothing other than add time during a refactoring is little help to the
cause of good software.
&lt;/p&gt;
&lt;p&gt;
Right now, automated testing really focuses on the Data Access Layer (DAL) and Business
Objects Layer (BOL). When I discuss shunting next, you'll see it actually comes down
to the BOL in many cases. What about the UI? The tools, especially for ASP.Net in
the open source community are severely lacking in automated testing. How will you
know if the javascript works both on Netscape and IE without running it yourself?&amp;nbsp;
It's the UI the user sees, which is why the UI has to be thoroughly tested in both
how you expect the user to use it, and how they &lt;strong&gt;might&lt;/strong&gt; use it. Users
always come up with useful scenarios to break our applications. Think of it as a fun
challenge and you'll be far less frustrated.
&lt;/p&gt;
&lt;p&gt;
To test out our BOL, we shunted the data using XML or pre-defined data tables. It
actually works great, but it's a limited test. What happens when the database schema
changes? If you've shunted the data, you'll never know the impact unless you do your
due diligence and fully integrate test, or the user finds it in user acceptance testing
(which is not where you want to catch these things). If you do shunt your data, that's
great and fine. Just make sure you test against the schema the application is going
to be deployed against as well. See my blog about getting a random record using NewId()
if you want to generate some good database based tests.
&lt;/p&gt;
&lt;p&gt;
OK, it probably sounds like I am really bummed about automated testing after&amp;nbsp;my&amp;nbsp;recent
experience&amp;nbsp;with it. That belief is the farthest from the truth. In fact, I am
going to introduce it on my current project because I feel it can certainly add a
key dynamic to a complete testing process. But as&amp;nbsp;Test Driven Development&amp;nbsp;gains
acceptance, I felt it was time someone at least mentioned the things to&amp;nbsp;consider
so it can be a more effective tool in your development cycle. Plan ahead and determine
how you can avoid these pitfalls and&amp;nbsp;hopefully your investment in time will generate
more dividends from Test Driven Development.
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=ceb433e0-0cca-45d4-9cf8-67f48d19a4d1" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,ceb433e0-0cca-45d4-9cf8-67f48d19a4d1.aspx</comments>
      <category>All Things</category>
      <category>ASP.Net</category>
      <category>Design</category>
      <category>General</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=7450e1ce-9e9b-4e68-aa3f-7ec0026ffdc5</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,7450e1ce-9e9b-4e68-aa3f-7ec0026ffdc5.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,7450e1ce-9e9b-4e68-aa3f-7ec0026ffdc5.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=7450e1ce-9e9b-4e68-aa3f-7ec0026ffdc5</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
On my last project, as part of the agile process, we utilized nAnt with Draco.Net
to create automated builds. I didn't implement that part of the project, but I certainly
did see the value in automating the build. So, while I set up my environment for my
topic of Component Based Development, I am going to write my learning's on generating
an automated build. If you've used these tools, feel free to hop in and add some help.
</p>
        <p>
That's one downside of open source projects -- the documentation can either be lacking
or just as distributed. So hopefully by blogging about it, I can save someone some
frustration.
</p>
        <p>
So I am going to start by looking at the tools I am planning on using:
</p>
        <p>
          <a href="http://nant.sourceforge.net/">nAnt Home Page</a> -- Get nAnt here. nAnt is
the tool you'll use to configure your build
</p>
        <p>
          <a href="http://draconet.sourceforge.net/">Draco.Net</a> -- How to generate a build
when your source control changes (or you trigger it)
</p>
        <p>
Some other interesting links I saw: 
</p>
        <p>
For nAnt help: <a href="http://nant.sourceforge.net/wiki/index.php/NAntUsage">NAntUsage
wiki</a> -- Some help on how to use nAnt
</p>
        <p>
For Draco.Net help: <a href="http://draconet.sourceforge.net/wiki/">Draco.Net wiki</a> --
Some help on how to use Draco.net
</p>
        <p>
Tomorrow I am going to start implementing nAnt on a fairly complex project, so I will
post my findings as I go along!
</p>
        <p>
          <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=7450e1ce-9e9b-4e68-aa3f-7ec0026ffdc5" />
        </p>
      </body>
      <title>My trek into automated builds</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,7450e1ce-9e9b-4e68-aa3f-7ec0026ffdc5.aspx</guid>
      <link>http://www.dotnettechnologies.com/2004/11/23/MyTrekIntoAutomatedBuilds.aspx</link>
      <pubDate>Tue, 23 Nov 2004 21:47:25 GMT</pubDate>
      <description>&lt;p&gt;
On my last project, as part of the agile process, we utilized nAnt with Draco.Net
to create automated builds. I didn't implement that part of the project, but I certainly
did see the value in automating the build. So, while I set up my environment for my
topic of Component Based Development, I am going to write my learning's on generating
an automated build. If you've used these tools, feel free to hop in and add some help.
&lt;/p&gt;
&lt;p&gt;
That's one downside of open source projects -- the documentation can either be lacking
or just as distributed. So hopefully by blogging about it, I can save someone some
frustration.
&lt;/p&gt;
&lt;p&gt;
So I am going to start by looking at the tools I am planning on using:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://nant.sourceforge.net/"&gt;nAnt Home Page&lt;/a&gt; -- Get nAnt here. nAnt is
the tool you'll use to configure your build
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://draconet.sourceforge.net/"&gt;Draco.Net&lt;/a&gt; -- How to generate a build
when your source control changes (or you trigger it)
&lt;/p&gt;
&lt;p&gt;
Some other interesting links I saw: 
&lt;/p&gt;
&lt;p&gt;
For nAnt help: &lt;a href="http://nant.sourceforge.net/wiki/index.php/NAntUsage"&gt;NAntUsage
wiki&lt;/a&gt;&amp;nbsp;-- Some help on how to use nAnt
&lt;/p&gt;
&lt;p&gt;
For Draco.Net help: &lt;a href="http://draconet.sourceforge.net/wiki/"&gt;Draco.Net wiki&lt;/a&gt;&amp;nbsp;--
Some help on how to use Draco.net
&lt;/p&gt;
&lt;p&gt;
Tomorrow I am going to start implementing nAnt on a fairly complex project, so I will
post my findings as I go along!&lt;p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=7450e1ce-9e9b-4e68-aa3f-7ec0026ffdc5" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,7450e1ce-9e9b-4e68-aa3f-7ec0026ffdc5.aspx</comments>
      <category>All Things</category>
      <category>Design</category>
      <category>General</category>
      <category>Tips and Tricks</category>
      <category>Tools</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=54bd1528-d671-4888-ad36-a7ed311e580d</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,54bd1528-d671-4888-ad36-a7ed311e580d.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,54bd1528-d671-4888-ad36-a7ed311e580d.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=54bd1528-d671-4888-ad36-a7ed311e580d</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
A very common task in application development is reporting. There are many tool packages
out there which do a great job, such as Crystal Reports, Active Reports and the new
kid on the block, SQL Server reporting tools. However, a lot of times these are overkill,
or too expensive a solution.
</p>
        <p>
Using ASP.Net, generating a UI for the results using a DataGrid or DataRepeater is
very easy and can look professional in minutes. However, users typically aren't happy
with just pulling out all the data. They want to be able to filter the data and quickly
narrow down the data they need to see.
</p>
        <p>
The solution is to create a data filter. A data filter provides a UI for selecting
one or more criteria and limiting the results displayed to the items selected in the
filter. Sometimes, the filter takes far longer to create for a deeloper than the actual
report, and from my experience not one of the 'cool' functionality to add.
</p>
        <p>
Case in point: A portal-based web site I helped develop for a large bank was about
90% reporting. By implementing base pages and styles, common grid functionality and
libraries, I was able to get the turnaround on a report from 2 weeks to a day or so.
As I analyzed the process, I noticed the report display only took a couple of hours,
but the ensuing filter could take a day or more between layout, creating the filter
items and modifying the query to handle the filter.
</p>
        <p>
Subsequently, I developed the FilterWizard, which is a User Control which handles
compiling the filter criteria, retrieving the data and making the data available to
other controls, exporting to Excel, or anything which consumes data. The beauty of
this control is that filters for individual fields can be added or removed with one
line of code. The layout of the filter can also be altered by changing single values.
</p>
        <p>
The requirements were fairly simple: Strong encapsulation of internal logic to a few
simple methods (Primarly a single point of entry for formatting the individual filters,
and a single point of entry for retrieving the values to filter on when the user pushes
a [Filter] button). When the filter is triggered, the FilterWizard should notify
the data consumer that data has been retrieved and is available for rendering.
</p>
        <p>
When formatting the individual filters, the developer should be able to change the
format of a filter simply by changing an enum value which represent the available
filter types. Examples of filter types might be a single-select combo box, a multi-select
listbox, a date range, a single value or a range of values. In the end, I wanted it
as extensible as possible so if a new filter requirement came up, I could add additional
filter types as quickly and easily as possible.
</p>
        <p>
Finally, the FilterWizard should also be able to clear itself and reset the individual
filters as well as display a summary of the filter values should the user choose to
print the page.
</p>
        <p>
There are actually two versions of this control. The first version used Dynamic SQL
to create the filtered data. It was written in VB.Net. While Dynamic SQL provides
some flexibility not easily duplicated using parameters, it's also more susceptible
to SQL Injection. The second version uses C#, and used parameterized queries. I plan
on discussing both because each has it's strengths and will reach a wider audience
of developers by providing source in both VB.Net and C#. 
</p>
        <p>
What did I come up with? A great and easy to use control which provides all that functionality.
And this is the start of my series on the FilterWizard which I will write more about,
and finally provide all the source for in upcoming writings!
</p>
        <p>
Now there's an idea for another topic (and a brief aside): C# vs. VB.net. I am a long
time VB user and fanatic, but I have to confess C# is where it's at. I will certainly
discuss this at length in the future, as there are definite advantages to using C#
(which may go away in VS 2005) which I think are largely overlooked in other discussions
on the subject. For now, let's suffice it to say if you have a choice, don't fear
C# and jump in it head first. If not, use it when you can just so you are familiar
with the syntax.
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=54bd1528-d671-4888-ad36-a7ed311e580d" />
      </body>
      <title>UI Abstraction -- Component Based Development Part #1 -- Description and Requirements</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,54bd1528-d671-4888-ad36-a7ed311e580d.aspx</guid>
      <link>http://www.dotnettechnologies.com/2004/11/18/UIAbstractionComponentBasedDevelopmentPart1DescriptionAndRequirements.aspx</link>
      <pubDate>Thu, 18 Nov 2004 05:14:36 GMT</pubDate>
      <description>&lt;p&gt;
A very common task in application development is reporting. There are many tool packages
out there which do a great job, such as Crystal Reports, Active Reports and the new
kid on the block, SQL Server reporting tools. However, a lot of times these are overkill,
or too expensive a solution.
&lt;/p&gt;
&lt;p&gt;
Using ASP.Net, generating a UI for the results using a DataGrid or DataRepeater is
very easy and can look professional in minutes. However, users typically aren't happy
with just pulling out all the data. They want to be able to filter the data and quickly
narrow down the data they need to see.
&lt;/p&gt;
&lt;p&gt;
The solution is to create a data filter. A data filter provides a UI for selecting
one or more criteria and limiting the results displayed to the items selected in the
filter. Sometimes, the filter takes far longer to create for a deeloper than the actual
report, and from my experience not one of the 'cool' functionality to add.
&lt;/p&gt;
&lt;p&gt;
Case in point: A portal-based web site I helped develop for a large bank was about
90% reporting. By implementing base pages and styles, common grid functionality and
libraries, I was able to get the turnaround on a report from 2 weeks to a day or so.
As I analyzed the process, I noticed the report display only took a couple of hours,
but the ensuing filter could take a day or more between layout, creating the filter
items and modifying the query to handle the filter.
&lt;/p&gt;
&lt;p&gt;
Subsequently, I developed the FilterWizard, which is a User Control which handles
compiling the filter criteria, retrieving the data and making the data available to
other controls, exporting to Excel, or anything which consumes data. The beauty of
this control is that filters for individual fields can be added or removed with one
line of code. The layout of the filter can also be altered by changing single values.
&lt;/p&gt;
&lt;p&gt;
The requirements were fairly simple: Strong encapsulation of internal logic to a few
simple methods (Primarly a single point of entry for formatting the individual filters,
and a single point of entry for retrieving the values to filter on when the user pushes
a [Filter] button). When the filter is triggered, the&amp;nbsp;FilterWizard should notify
the data consumer that data has been retrieved and is available for rendering.
&lt;/p&gt;
&lt;p&gt;
When formatting the individual filters, the developer should be able to change the
format of a filter simply by changing an enum value which represent the available
filter types. Examples of filter types might be a single-select combo box, a multi-select
listbox, a date range, a single value or a range of values. In the end, I wanted it
as extensible as possible so if a new filter requirement came up, I could add additional
filter types as quickly and easily as possible.
&lt;/p&gt;
&lt;p&gt;
Finally, the FilterWizard should also be able to clear itself and reset the individual
filters as well as display a summary of the filter values should the user choose to
print the page.
&lt;/p&gt;
&lt;p&gt;
There are actually two versions of this control. The first version used Dynamic SQL
to create the filtered data. It was written in VB.Net. While Dynamic SQL provides
some flexibility not easily duplicated using parameters, it's also more susceptible
to SQL Injection. The second version uses C#, and used parameterized queries. I plan
on discussing both because each has it's strengths and will reach a wider audience
of developers by providing source in both VB.Net and C#. 
&lt;/p&gt;
&lt;p&gt;
What did I come up with? A great and easy to use control which provides all that functionality.
And this is the start of my series on the FilterWizard which I will write more about,
and finally provide all the source for in upcoming writings!
&lt;/p&gt;
&lt;p&gt;
Now there's an idea for another topic (and a brief aside): C# vs. VB.net. I am a long
time VB user and fanatic, but I have to confess C# is where it's at. I will certainly
discuss this at length in the future, as there are definite advantages to using C#
(which may go away in VS 2005) which I think are largely overlooked in other discussions
on the subject. For now, let's suffice it to say if you have a choice, don't fear
C# and jump in it head first. If not, use it when you can just so you are familiar
with the syntax.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=54bd1528-d671-4888-ad36-a7ed311e580d" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,54bd1528-d671-4888-ad36-a7ed311e580d.aspx</comments>
      <category>All Things</category>
      <category>ASP.Net</category>
      <category>Design</category>
      <category>General</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=ef031338-faf2-4be6-a4cb-dc4beae66341</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,ef031338-faf2-4be6-a4cb-dc4beae66341.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,ef031338-faf2-4be6-a4cb-dc4beae66341.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=ef031338-faf2-4be6-a4cb-dc4beae66341</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I was thinking today that the daily tips are nice, there really isn't much I can't
write about that hasn't been written about in terms of tips. So what can I write about
that is not something I plan to make commercially available at some point, but can
enhance the .Net community?
</p>
        <p>
Today, I remembered an ASP.Net component I wrote which makes adding a complex
data filter to a report as quick as a few lines of code. It's fully extendable and
it demonstrates what UI abstraction can really do. I also have it already available
in VB.Net and C#, and an example of building dynamic SQL as well as integration with
stored procedures. It's in use for two of my large clients, and they swear by how
much time it saves them, so hopefully it can save someone out there in Blog-land a
bit of time too.
</p>
        <p>
I'll still include my daily tips, but I think this will be a great beginning to contributing
back to the ASP.Net development community which I have benefitted much from. So, stay
tuned while I get the components into a nice same project using the Northwind database.
</p>
        <p>
-- Daryl
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=ef031338-faf2-4be6-a4cb-dc4beae66341" />
      </body>
      <title>What's Next?</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,ef031338-faf2-4be6-a4cb-dc4beae66341.aspx</guid>
      <link>http://www.dotnettechnologies.com/2004/11/10/WhatsNext.aspx</link>
      <pubDate>Wed, 10 Nov 2004 04:58:13 GMT</pubDate>
      <description>&lt;p&gt;
I was thinking today that the daily tips are nice, there really isn't much I can't
write about that hasn't been written about in terms of tips. So what can I write about
that is not something I plan to make commercially available at some point, but can
enhance the .Net community?
&lt;/p&gt;
&lt;p&gt;
Today, I remembered an ASP.Net&amp;nbsp;component I wrote which makes adding a complex
data filter to a report as quick as a few lines of code. It's fully extendable and
it demonstrates what UI abstraction can really do. I also have it already available
in VB.Net and C#, and an example of building dynamic SQL as well as integration with
stored procedures. It's in use for two of my large clients, and they swear by how
much time it saves them, so hopefully it can save someone out there in Blog-land a
bit of time too.
&lt;/p&gt;
&lt;p&gt;
I'll still include my daily tips, but I think this will be a great beginning to contributing
back to the ASP.Net development community which I have benefitted much from. So, stay
tuned while I get the components into a nice same project using the Northwind database.
&lt;/p&gt;
&lt;p&gt;
-- Daryl
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=ef031338-faf2-4be6-a4cb-dc4beae66341" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,ef031338-faf2-4be6-a4cb-dc4beae66341.aspx</comments>
      <category>ASP.Net</category>
      <category>Design</category>
      <category>General</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=b37e885c-ab36-44a7-a0f8-41aad6f2035d</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,b37e885c-ab36-44a7-a0f8-41aad6f2035d.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,b37e885c-ab36-44a7-a0f8-41aad6f2035d.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=b37e885c-ab36-44a7-a0f8-41aad6f2035d</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
As a consultant, I need to be able to port a bag of tricks from one project to the
next. Accessing MS Repository isn't always the easiest, although I have used it in
the past for internal projects.
</p>
        <p>
I ran across <a href="http://dotnet.4all.cc/" target="_blank">CodeLib for .Net by
Fish</a>, and it's a great tool, with searching, the ability to append files, notes,
code (which it formats) as well as web pages (which I have yet to figure out how to
work with).
</p>
        <p>
Best of all, it's Freeware. So give it a try, you'll like it. Heck, once you get a
library put together, maybe we can swap! ;)
</p>
        <p>
 
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=b37e885c-ab36-44a7-a0f8-41aad6f2035d" />
      </body>
      <title>Another Great tool</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,b37e885c-ab36-44a7-a0f8-41aad6f2035d.aspx</guid>
      <link>http://www.dotnettechnologies.com/2004/11/09/AnotherGreatTool.aspx</link>
      <pubDate>Tue, 09 Nov 2004 05:34:42 GMT</pubDate>
      <description>&lt;p&gt;
As a consultant, I need to be able to port a bag of tricks from one project to the
next. Accessing MS Repository isn't always the easiest, although I have used it in
the past for internal projects.
&lt;/p&gt;
&lt;p&gt;
I ran across &lt;a href="http://dotnet.4all.cc/" target=_blank&gt;CodeLib for .Net by Fish&lt;/a&gt;,
and it's a great tool, with searching, the ability to append files, notes, code (which
it formats) as well as web pages (which I have yet to figure out how to work with).
&lt;/p&gt;
&lt;p&gt;
Best of all, it's Freeware. So give it a try, you'll like it. Heck, once you get a
library put together, maybe we can swap! ;)
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=b37e885c-ab36-44a7-a0f8-41aad6f2035d" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,b37e885c-ab36-44a7-a0f8-41aad6f2035d.aspx</comments>
      <category>All Things</category>
      <category>ASP.Net</category>
      <category>Design</category>
      <category>General</category>
      <category>Tips and Tricks</category>
      <category>Tools</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=ff152d67-a853-4be0-882b-518caaeaa7da</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,ff152d67-a853-4be0-882b-518caaeaa7da.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,ff152d67-a853-4be0-882b-518caaeaa7da.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=ff152d67-a853-4be0-882b-518caaeaa7da</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
With the advent of test driven and test first development, writing meaningful
tests can be a bear. There are a lot of methods, such as data shunting and hardcoding
values, which avoid using the database for testing. While this can test the code,
it doesn't test the database CRUD. I believe I once read that 80% of all applications
are database applications, so testing the database portion is critical.
</p>
        <p>
Personally, if you write tests which avoid directly testing your data schema and access
methods, you're asking for trouble unless your Business Object tier is very robust.
Even then, schema changes might be missed in testing if they don't actually interact
with the database. 
</p>
        <p>
I am currently using nUnit for running the automated tests, and so far I absolutely
love it. However, writing meaningful tests can sometimes take longer than writing
the actual code, and as enhancements occur maintaining your tests can bog down the
progress of the application. Changes inevitable, expecially in XP programming
with their short development iterations. 
</p>
        <p>
Automated testing also invites buggy code if the developer is not careful. Here's
some examples:
</p>
        <ul>
          <li>
Some developers feel this takes place of unit and integration testing. This absolutely
isn't true, as automated testing typically only checks individual functional testing
(unless you have a very comprensive set of test cases developed -- suddenly these
tests don't seem so agile).</li>
          <li>
Automated testing for the UI is limited at best. While nUnitAsp exists, it's not quite
up to par to replace real-life beating-the-hell-out-of-the-UI testing.</li>
          <li>
There's absolutely no way to predict all of the ways a user if going to use your application
unless you are a UI and Process Flow God/Goddess. Most programmers aren't, so you
aren't going to be able to foresee all possible combinations of testing.</li>
        </ul>
        <p>
Bottom line is this. Use automated testing to test functionality against expected
results, but this is only about 25% of the actual testing you need to do, regardless
of whether the application is internal or external.
</p>
        <p>
How a tip turned into a rant, I don't know.. So I guess I am putting this under Design,
and making a second tip out of it.
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=ff152d67-a853-4be0-882b-518caaeaa7da" />
      </body>
      <title>Automated Testing and Bugs</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,ff152d67-a853-4be0-882b-518caaeaa7da.aspx</guid>
      <link>http://www.dotnettechnologies.com/2004/10/21/AutomatedTestingAndBugs.aspx</link>
      <pubDate>Thu, 21 Oct 2004 05:51:54 GMT</pubDate>
      <description>&lt;p&gt;
With the advent of test driven and test first&amp;nbsp;development, writing meaningful
tests can be a bear. There are a lot of methods, such as data shunting and hardcoding
values, which avoid using the database for testing. While this can test the code,
it doesn't test the database CRUD. I believe I once read that 80% of all applications
are database applications, so testing the database portion is critical.
&lt;/p&gt;
&lt;p&gt;
Personally, if you write tests which avoid directly testing your data schema and access
methods, you're asking for trouble unless your Business Object tier is very robust.
Even then, schema changes might be missed in testing if they don't actually interact
with the database. 
&lt;/p&gt;
&lt;p&gt;
I am currently using nUnit for running the automated tests, and so far I absolutely
love it. However, writing meaningful tests can sometimes take longer than writing
the actual code, and as enhancements occur maintaining your tests can bog down the
progress of the application.&amp;nbsp;Changes inevitable, expecially in XP programming
with their short development iterations. 
&lt;/p&gt;
&lt;p&gt;
Automated testing also invites buggy code if the developer is not careful. Here's
some examples:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Some developers feel this takes place of unit and integration testing. This absolutely
isn't true, as automated testing typically only checks individual functional testing
(unless you have a very comprensive set of test cases developed -- suddenly these
tests don't seem so agile).&lt;/li&gt;
&lt;li&gt;
Automated testing for the UI is limited at best. While nUnitAsp exists, it's not quite
up to par to replace real-life beating-the-hell-out-of-the-UI testing.&lt;/li&gt;
&lt;li&gt;
There's absolutely no way to predict all of the ways a user if going to use your application
unless you are a UI and Process Flow God/Goddess. Most programmers aren't, so you
aren't going to be able to foresee all possible combinations of testing.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Bottom line is this. Use automated testing to test functionality against expected
results, but this is only about 25% of the actual testing you need to do, regardless
of whether the application is internal or external.
&lt;/p&gt;
&lt;p&gt;
How a tip turned into a rant, I don't know.. So I guess I am putting this under Design,
and making a second tip out of it.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=ff152d67-a853-4be0-882b-518caaeaa7da" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,ff152d67-a853-4be0-882b-518caaeaa7da.aspx</comments>
      <category>Design</category>
    </item>
    <item xml:lang="en">
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=355a9da7-0930-4c3e-afc4-5142835e7fe1</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,355a9da7-0930-4c3e-afc4-5142835e7fe1.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,355a9da7-0930-4c3e-afc4-5142835e7fe1.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=355a9da7-0930-4c3e-afc4-5142835e7fe1</wfw:commentRss>
      <slash:comments>3</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
As part of an ongoing discussion with a developer (let's call him JDOAGD) I am paired
with, I had the opportunity to discuss the importance of Error Handling within an
application. The two sides:
</p>
        <ul>
          <li>
Minimalist -- only at the UI layer, and only then when the code is likely to fail</li>
          <li>
Solid -- Assume errors can happen anywhere, and handle them gracefully at ALL layers
of a multiple application. 
</li>
        </ul>
        <p>
          <br />
There's a school of thought that when an error condition occurs, throw an error or
bubble it up to the highest layer and handle it. OK, that's a strategy, but what happens
when the top layer doesn't catch the error? Crash. Fortunately, I was able to demonstrate
this fact to the developer today who adamantly insisted on handling it at the UI only.
He forgot to handle it, and BAM!, a crash ensued. 
</p>
        <p>
I wish I felt this was isolated, but I have had the privledge of working with several
hundred developers over the past 10 years, and I would guess error handling is one
of the most overlooked aspects of an architecture. Of those hundreds of developers,
I would venture error trapping and handling was considered an afterthought by 90%
of them. Some examples:
</p>
        <ul>
          <li>
Degrades performance, so why do it? (how about a dead app really performs slow)</li>
          <li>
The applicaion is for internal customers, so they are more forgiving than if we were
trying to deploy for general release</li>
          <li>
What's error handling and logging?</li>
        </ul>
        <p>
          <br />
I recall a project which I was brought into a few years ago. The 4 developers had
spent a month learning the business rules involved, and were chomping at the bit to
get started. When I came in, they mentioned they were ready to code. So, I asked a
few obvious (or so I thought) questions so I too would know how to code with them.
</p>
        <ul>
          <li>
What's the error handling strategy?</li>
          <li>
What's the data access strategy?</li>
          <li>
What's the physical architecture?</li>
          <li>
What type of security model are we implementing?</li>
          <li>
...and many more.</li>
        </ul>
        <p>
          <br />
Scary thing was, they didn't have an answer for any of them. The other scary thing
was they were billed as “Expert Coders” and were billing at a significantly
higher rate than myself. Had I less ethics, I would have asked for more $$ instead
of pushing to resolve these issues. That whole project was “interesting”
to say the least and someday I might write more about those experiences.
</p>
        <p>
Back to today. So, since I am on their payroll, I listened to JDOAGD's reasons for
not having error handling except on the UI layer. I watched him also forget to place
any at the UI level he was so adament about it. I had the hook, and he finally saw
the light. What was my point?
</p>
        <p>
In a multiple developer environment, you can never assume the other develper using
your code will trap the error (this is an encapsulation issue, which this same developer
once vehemently added encapsulation was a bad thing. In a non-web environment, crashes
kill the application. The browser is very forgiving!
</p>
        <p>
Finally, internal or not, as developers we are serving customers. Without them, we'd
have no jobs. It's important to ALWAYS give them the best possible user experience.
Anything else is simply lazy and unprofessional.
</p>
        <p>
Logging is a whole other issue, which I will save for a future session. For now, I'd
love to hear other opinions and experiences in this area, so please, drop me a comment!
</p>
        <p>
-- Daryl
</p>
        <p>
          <br />
 
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=355a9da7-0930-4c3e-afc4-5142835e7fe1" />
      </body>
      <title>Error Handling</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,355a9da7-0930-4c3e-afc4-5142835e7fe1.aspx</guid>
      <link>http://www.dotnettechnologies.com/2004/10/20/ErrorHandling.aspx</link>
      <pubDate>Wed, 20 Oct 2004 04:09:24 GMT</pubDate>
      <description>&lt;p&gt;
As part of an ongoing discussion with a developer (let's call him JDOAGD) I am paired
with, I had the opportunity to discuss the importance of Error Handling within an
application. The two sides:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Minimalist -- only at the UI layer, and only then when the code is likely to fail&lt;/li&gt;
&lt;li&gt;
Solid -- Assume errors can happen anywhere, and handle them gracefully at ALL layers
of a multiple application. 
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&lt;br&gt;
There's a school of thought that when an error condition occurs, throw an error or
bubble it up to the highest layer and handle it. OK, that's a strategy, but what happens
when the top layer doesn't catch the error? Crash. Fortunately, I was able to demonstrate
this fact to the developer today who adamantly insisted on handling it at the UI only.
He forgot to handle it, and BAM!, a crash ensued. 
&lt;/p&gt;
&lt;p&gt;
I wish I felt this was isolated, but I have had the privledge of working with several
hundred developers over the past 10 years, and I would guess error handling is one
of the most overlooked aspects of an architecture. Of those hundreds of developers,
I would venture error trapping and handling was considered an afterthought by 90%
of them. Some examples:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Degrades performance, so why do it? (how about a dead app really performs slow)&lt;/li&gt;
&lt;li&gt;
The applicaion is for internal customers, so they are more forgiving than if we were
trying to deploy for general release&lt;/li&gt;
&lt;li&gt;
What's error handling and logging?&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&lt;br&gt;
I recall a project which I was brought into a few years ago. The 4 developers had
spent a month learning the business rules involved, and were chomping at the bit to
get started. When I came in, they mentioned they were ready to code. So, I asked a
few obvious (or so I thought) questions so I too would know how to code with them.
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
What's the error handling strategy?&lt;/li&gt;
&lt;li&gt;
What's the data access strategy?&lt;/li&gt;
&lt;li&gt;
What's the physical architecture?&lt;/li&gt;
&lt;li&gt;
What type of security model are we implementing?&lt;/li&gt;
&lt;li&gt;
...and many more.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&lt;br&gt;
Scary thing was, they didn't have an answer for any of them. The other scary thing
was they were billed as &amp;#8220;Expert Coders&amp;#8221; and were billing at a significantly
higher rate than myself. Had I less ethics, I would have asked for more $$ instead
of pushing to resolve these issues. That whole project was &amp;#8220;interesting&amp;#8221;
to say the least and someday I might write more about those experiences.
&lt;/p&gt;
&lt;p&gt;
Back to today. So, since I am on their payroll, I listened to JDOAGD's reasons for
not having error handling except on the UI layer. I watched him also forget to place
any at the UI level he was so adament about it. I had the hook, and he finally saw
the light. What was my point?
&lt;/p&gt;
&lt;p&gt;
In a multiple developer environment, you can never assume the other develper using
your code will trap the error (this is an encapsulation issue, which this same developer
once vehemently added encapsulation was a bad thing. In a non-web environment, crashes
kill the application. The browser is very forgiving!
&lt;/p&gt;
&lt;p&gt;
Finally, internal or not, as developers we are serving customers. Without them, we'd
have no jobs. It's important to ALWAYS give them the best possible user experience.
Anything else is simply lazy and unprofessional.
&lt;/p&gt;
&lt;p&gt;
Logging is a whole other issue, which I will save for a future session. For now, I'd
love to hear other opinions and experiences in this area, so please, drop me a comment!
&lt;/p&gt;
&lt;p&gt;
-- Daryl
&lt;/p&gt;
&lt;p&gt;
&lt;br&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=355a9da7-0930-4c3e-afc4-5142835e7fe1" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,355a9da7-0930-4c3e-afc4-5142835e7fe1.aspx</comments>
      <category>Design</category>
    </item>
  </channel>
</rss>