﻿<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Programming By A Tool &#187; .Net</title>
	<atom:link href="http://byatool.com/tag/net/feed/" rel="self" type="application/rss+xml" />
	<link>http://byatool.com</link>
	<description>This is my recorded stumbling through ASP.Net, Framework 3.5, C# 3.0, Ajax, Javascript, and Love.  Stay, learn, destroy.  It's your life.</description>
	<lastBuildDate>Thu, 03 May 2012 17:28:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Microsoft Charting Controls: Adding Charts Dynamically</title>
		<link>http://byatool.com/ui/microsoft-charting-controls-adding-dynamically/</link>
		<comments>http://byatool.com/ui/microsoft-charting-controls-adding-dynamically/#comments</comments>
		<pubDate>Thu, 04 Dec 2008 21:31:18 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[UI]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[Charting]]></category>
		<category><![CDATA[Dynamic]]></category>
		<category><![CDATA[Dynamic Controls]]></category>

		<guid isPermaLink="false">http://byatool.com/?p=122</guid>
		<description><![CDATA[So this is kind of repost as I had already posted this at StackOverflow but I thought it might have some merit here. Whatever. Charts are hot right now so I&#8217;m going to push the damned bandwagon. You don&#8217;t like it? Well then go do something to yourself that you would consider rude for me [...]]]></description>
			<content:encoded><![CDATA[<p>So this is kind of repost as I had already posted this at <a href="http://www.stackoverflow.com">StackOverflow</a> but I thought it might have some merit here. Whatever. Charts are hot right now so I&#8217;m going to push the damned bandwagon. You don&#8217;t like it? Well then go do something to yourself that you would consider rude for me to suggest it. Anyways, this might have been overkill but hey, that&#8217;s me.</p>
<pre lang="csharp">
protected void Page_Load(object sender, EventArgs e)
{
Bench benchList;
FoodIntake foodIntakeList;
Panel panelChartHolder;

panelChartHolder = new Panel();
Controls.Add(panelChartHolder);

benchList = Bench.GetAll();
AddNewCharts(benchList, panelChartHolder, GetBenchXValue, GetBenchYValue);

foodIntakeList = FoodIntake.GetAll();
AddNewCharts(foodIntakeList, panelChartHolder, GetFoodIntakeXValue, GetFoodIntakeYValue);
}
</pre>
<p>Ok so this first part is simple. Create a panel to hold the charts you are adding, get the lists you want represented by the charts and call the method to create the charts.</p>
<pre>  <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> AddNewCharts(T[] listToAdd, <span style="color: #33cccc;">Panel</span> panelToAddTo,
     <span style="color: #33cccc;">Func</span>&lt;T, <span style="color: #33cccc;">DateTime</span>&gt; xMethod, <span style="color: #33cccc;">Func</span>&lt;T, <span style="color: #33cccc;">Int32</span>&gt;)
  {

    <span style="color: #33cccc;">ChartArea</span> mainArea;
    <span style="color: #33cccc;">Chart</span> mainChart;
    <span style="color: #33cccc;">Series</span> mainSeries;

    mainChart = <span style="color: #0000ff;">new</span> <span style="color: #33cccc;">Chart</span>();
    mainSeries = <span style="color: #0000ff;">new</span> <span style="color: #33cccc;">Series</span>(<span style="color: #ff0000;">"MainSeries"</span>);

    <span style="color: #0000ff;">for</span> (<span style="color: #33cccc;">Int32</span> loopCounter = 0; loopCounter &lt; listToAdd.Length; loopCounter++)
    {
      mainSeries.Points.AddXY(xMethod(listToAdd[loopCounter]),
        yMethod(listToAdd[loopCounter]));
    }

    mainChart.Series.Add(mainSeries);
    mainArea = <span style="color: #0000ff;">new</span> <span style="color: #33cccc;">ChartArea</span>(<span style="color: #ff0000;">"MainArea"</span>);
    mainChart.ChartAreas.Add(mainArea);

    panelToAddTo.Controls.Add(mainChart);
  }</pre>
<p>As you can see, I just created a new chart, added a series to it, and added a ChartArea to it. Next part is pretty much just looping through the collection and adding each item in it to the list itself. It uses the passed in delegate methods (Func) to get the X and Y values.</p>
<p>Last part holds the four methods responsible for getting the X and Y values from the two lists. Basically I did this to allow the chart creating method to be a generic as possible. Might be overkill.</p>
<pre>  <span style="color: #0000ff;">private</span> <span style="color: #33cccc;">DateTime</span> GetBenchXValue(Bench currentBench)
  {
    <span style="color: #0000ff;">return</span> currentBench.DateLifted;
  }

  <span style="color: #0000ff;">private</span> <span style="color: #33cccc;">Int32</span> GetBenchYValue(Bench currentBench)
  {
    <span style="color: #0000ff;">return</span> currentBench.BenchAmount;
  }

  <span style="color: #0000ff;">private</span> <span style="color: #33cccc;">DateTime</span> GetFoodIntakeXValue(FoodIntake currentIntake)
  {
    <span style="color: #0000ff;">return</span> currentIntake.DateEaten;
  }

  <span style="color: #0000ff;">private</span> <span style="color: #33cccc;">Int32</span> GetFoodIntakeYValue(FoodIntake currentIntake)
  {
    <span style="color: #0000ff;">return</span> currentIntake.Calories;
  }</pre>
<p>And so when you run this, you will get two graphs side by side. Mind you, they will be very plain as there are million different properties that can be set to improve the look. I guess the main point of this was to show that it&#8217;s pretty easy to create graphs dynamically using any kind of object list. You know what? Screw you. This is my blog and I&#8217;ll post whatever I want to. If you don&#8217;t like that then you can just come back at a later time and read something else I post. Yeah so there.</p>
<pre>  <span style="color: #0000ff;">using</span> System;
  <span style="color: #0000ff;">using</span> System.Web.UI.DataVisualization.Charting;
  <span style="color: #0000ff;">using</span> System.Web.UI.WebControls;</pre>
]]></content:encoded>
			<wfw:commentRss>http://byatool.com/ui/microsoft-charting-controls-adding-dynamically/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Microsoft Charting Control: So easy an idiot can use it&#8230; And I have.</title>
		<link>http://byatool.com/ui/microsoft-charting-control-so-easy-an-idiot-can-use-it-and-i-have/</link>
		<comments>http://byatool.com/ui/microsoft-charting-control-so-easy-an-idiot-can-use-it-and-i-have/#comments</comments>
		<pubDate>Tue, 02 Dec 2008 15:49:58 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[UI]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[Charting]]></category>
		<category><![CDATA[Dynamic]]></category>
		<category><![CDATA[Dynamic Controls]]></category>

		<guid isPermaLink="false">http://byatool.com/?p=111</guid>
		<description><![CDATA[So just recently it was announced that there was a new charting control out for .Net/Visual Studios so I thought I would give it shot. How hard could it be? Well considering it took me 2? years to figure out my Playstation 3 had a wireless card, an uphill battle wasn&#8217;t out of the question. [...]]]></description>
			<content:encoded><![CDATA[<p>So just recently it was announced that there was a new charting control out for .Net/Visual Studios so I thought I would give it shot. How hard could it be? Well considering it took me 2? years to figure out my Playstation 3 had a wireless card, an uphill battle wasn&#8217;t out of the question.</p>
<p>So what the hell has to be done first? Well you need the 3.5 Framework (Sucks if you don&#8217;t have that) and <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=ab99342f-5d1a-413d-8319-81da479ab0d7&amp;displaylang=en" target="_blank">service pack 1</a> (Which doesn&#8217;t suck as much but still annoying. I WANT EASY THINGS).<br />
Have those? Great, way to be in the know. Now for the next step, more downloads. Here is the <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=130f7986-bf49-4fe5-9ca8-910ae6ea442c&amp;DisplayLang=en" target="_self">charting install</a> and you need <a href="http://www.microsoft.com/downloads/details.aspx?familyid=1D69CE13-E1E5-4315-825C-F14D33A303E9&amp;displaylang=en" target="_blank">this too</a> to see the actual tool in your toolbox. AMAZING. Now you just have to run the installs, which oddly enough are easy to do. First time for everything.</p>
<p>So now you have them installed right? Ok well do the normal project create/startup, add a new page, and view Design. Go to the old toolbox and look under the Data tab. (Don&#8217;t ask me why it&#8217;s there because I don&#8217;t know and will be compelled to cut you.) Now under the chance you don&#8217;t see it there you either didn&#8217;t install the second download or you have to add the namespace the control falls under. No problem. Just right click the Data tab and select &#8220;Choose Items&#8221;. Now in the.Net Framework Components tab look for the Namespace &#8220;System.Web.UI.DataVisiualization.Charting&#8221; and you should see the name Chart to the right of it. Select that item.</p>
<p>Ok, so now there should be a Chart control in your ToolBox in the Data Tab. You can now drag that thing over. Now in the markup you should see:</p>
<p><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;">&lt;</span></span><span style="font-size: x-small; color: #a31515;">asp</span><span style="font-size: x-small; color: #0000ff;">:</span><span style="font-size: x-small; color: #a31515;">Chart</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff0000;">ID</span><span style="font-size: x-small; color: #0000ff;">=&#8221;Chart1&#8243;</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff0000;">runat</span><span style="font-size: x-small; color: #0000ff;">=&#8221;server&#8221;&gt;</span><br />
<span style="font-size: x-small; color: #0000ff;">  &lt;</span><span style="font-size: x-small; color: #a31515;">Series</span><span style="font-size: x-small; color: #0000ff;">&gt;</span><br />
<span style="font-size: x-small; color: #0000ff;">    &lt;</span><span style="font-size: x-small; color: #a31515;">asp</span><span style="font-size: x-small; color: #0000ff;">:</span><span style="font-size: x-small; color: #a31515;">Series</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff0000;">Name</span><span style="font-size: x-small; color: #0000ff;">=&#8221;Series1&#8243;&gt;</span><span style="font-size: x-small; color: #0000ff;">&lt;/</span><span style="font-size: x-small; color: #a31515;">asp</span><span style="font-size: x-small; color: #0000ff;">:</span><span style="font-size: x-small; color: #a31515;">Series</span><span style="font-size: x-small; color: #0000ff;">&gt;</span><br />
<span style="font-size: x-small; color: #0000ff;">  &lt;/</span><span style="font-size: x-small; color: #a31515;">Series</span><span style="font-size: x-small; color: #0000ff;">&gt;</span><br />
<span style="font-size: x-small; color: #0000ff;">&lt;</span><span style="font-size: x-small; color: #a31515;">ChartAreas</span><span style="font-size: x-small; color: #0000ff;">&gt;</span><br />
<span style="font-size: x-small; color: #0000ff;">    &lt;</span><span style="font-size: x-small; color: #a31515;">asp</span><span style="font-size: x-small; color: #0000ff;">:</span><span style="font-size: x-small; color: #a31515;">ChartArea</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff0000;">Name</span><span style="font-size: x-small; color: #0000ff;">=&#8221;ChartArea1&#8243;&gt;</span><span style="font-size: x-small; color: #0000ff;">&lt;/</span><span style="font-size: x-small; color: #a31515;">asp</span><span style="font-size: x-small; color: #0000ff;">:</span><span style="font-size: x-small; color: #a31515;">ChartArea</span><span style="font-size: x-small; color: #0000ff;">&gt;</span><br />
<span style="font-size: x-small; color: #0000ff;">    &lt;/</span><span style="font-size: x-small; color: #a31515;">ChartAreas</span><span style="font-size: x-small; color: #0000ff;">&gt;</span><br />
<span style="font-size: x-small; color: #0000ff;">&lt;/</span><span style="font-size: x-small; color: #a31515;">asp</span><span style="font-size: x-small; color: #0000ff;">:</span><span style="font-size: x-small; color: #a31515;">Chart</span><span style="font-size: x-small; color: #0000ff;">&gt;</span></p>
<p>If that doesn&#8217;t excite you, then I don&#8217;t know what will. Anyhow, it&#8217;s actually very simple. Series is the line or whatever you are representing the data as and the chart area is what holds the series(s). Seems easy enough, but don&#8217;t worry, it gets easier. Now for this example I&#8217;m going to actually have two series and they are going to represent amount of weight Bench Pressed and the caloric intake for a given day. Best thing I could come up with right now since today was bench day.</p>
<p><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;">&lt;</span></span><span style="font-size: x-small; color: #a31515;">asp</span><span style="font-size: x-small; color: #0000ff;">:</span><span style="font-size: x-small; color: #a31515;">Chart</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff0000;">ID</span><span style="font-size: x-small; color: #0000ff;">=&#8221;chartMain&#8221;</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff0000;">runat</span><span style="font-size: x-small; color: #0000ff;">=&#8221;server&#8221;&gt;</span><span style="font-size: x-small;"><span style="font-size: x-small;"> </span></span></p>
<p><span style="font-size: x-small; color: #0000ff;">  &lt;</span><span style="font-size: x-small; color: #a31515;">Series</span><span style="font-size: x-small; color: #0000ff;">&gt;</span><span style="font-size: x-small;"><span style="font-size: x-small;"> </span></span><br />
<span style="font-size: x-small; color: #0000ff;">    &lt;</span><span style="font-size: x-small; color: #a31515;">asp</span><span style="font-size: x-small; color: #0000ff;">:</span><span style="font-size: x-small; color: #a31515;">Series</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff0000;">Name</span><span style="font-size: x-small; color: #0000ff;">=&#8221;seriesBenchAmount&#8221;</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #0000ff;">/&gt;</span><br />
<span style="font-size: x-small; color: #0000ff;">    &lt;</span><span style="font-size: x-small; color: #a31515;">asp</span><span style="font-size: x-small; color: #0000ff;">:</span><span style="font-size: x-small; color: #a31515;">Series</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff0000;">Name</span><span style="font-size: x-small; color: #0000ff;">=&#8221;seriesFoodIntake&#8221;</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #0000ff;">/&gt;</span><br />
<span style="font-size: x-small; color: #0000ff;">  &lt;/</span><span style="font-size: x-small; color: #a31515;">Series</span><span style="font-size: x-small; color: #0000ff;">&gt;</span><br />
<span style="font-size: x-small; color: #0000ff;">  &lt;</span><span style="font-size: x-small; color: #a31515;">ChartAreas</span><span style="font-size: x-small; color: #0000ff;">&gt;</span><br />
<span style="font-size: x-small; color: #0000ff;">    &lt;</span><span style="font-size: x-small; color: #a31515;">asp</span><span style="font-size: x-small; color: #0000ff;">:</span><span style="font-size: x-small; color: #a31515;">ChartArea</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff0000;">Name</span><span style="font-size: x-small; color: #0000ff;">=&#8221;chartAreaMain&#8221;</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #0000ff;">/&gt;</span><br />
<span style="font-size: x-small; color: #0000ff;">  &lt;/</span><span style="font-size: x-small; color: #a31515;">ChartAreas</span><span style="font-size: x-small; color: #0000ff;">&gt;</span><br />
<span style="font-size: x-small; color: #0000ff;">&lt;/</span><span style="font-size: x-small; color: #a31515;">asp</span><span style="font-size: x-small; color: #0000ff;">:</span><span style="font-size: x-small; color: #a31515;">Chart</span><span style="font-size: x-small; color: #0000ff;">&gt;</span></p>
<p>Yeah that&#8217;s pretty good. So now what I need is to throw some fake data at it, and to do that I created a Bench table and a FoodIntake table followed by using Linq To Sql to create the needed classes. When all was said and done I could easily do this:</p>
<pre>  private const String CHART_AREA_MAIN = "chartAreaMain";
  private const String SERIES_BENCH_AMOUNT = "seriesBenchAmount";
  private const String SERIES_FOOD_INTAKE = "seriesFoodIntake";

  <span style="color: #0000ff;">protected</span> <span style="color: #0000ff;">void</span> Page_Load(<span style="color: #0000ff;">object</span> sender, <span style="color: #33cccc;">EventArgs</span> e)
  {
    <span style="color: #33cccc;">Bench</span>[] benchList;
    <span style="color: #33cccc;">Series</span> currentSeries;
    <span style="color: #33cccc;">FoodIntake</span>[] foodIntakeList;

    benchList = Bench.GetAllBenches();
    currentSeries = chartMain.Series[SERIES_BENCH_AMOUNT];
    <span style="color: #0000ff;">for</span> (<span style="color: #33cccc;">Int32</span> loopCounter = 0; loopCounter &lt; benchList.Length; loopCounter++)
    {
      currentSeries.Points.AddXY(benchList[loopCounter].DateLifted,
         benchList[loopCounter].BenchAmount);
    }

    foodIntakeList = FoodIntake.GetAll();
    currentSeries = chartMain.Series[SERIES_FOOD_INTAKE];
    <span style="color: #0000ff;">for</span>(<span style="color: #33cccc;">Int32</span> loopCounter = 0; loopCounter &lt; foodIntakeList.Length; loopCounter++)
    {
      currentSeries.Points.AddXY(foodIntakeList[loopCounter].DateEaten,
          foodIntakeList[loopCounter].Calories / 10);
      }
  }</pre>
<p>Now believe it or not, that&#8217;s all you have to do to get a graph. Pretty easy to say the least. Now the graph that you get will be default everything (And in this case it gives you a bar graph) but still at least that&#8217;s something to work with. (Note that I cheated with the food intake by dividing by 10. Unfortunately the graph would look odd with a day of 3500 calories and a 325 bench.)</p>
<p>Now maybe you want this to be a line graph&#8230; Whatever can we do?</p>
<pre>protected override void CreateChildControls()
{
    base.CreateChildControls();
    <span style="color: #33cccc;">Series</span> currentSeries;
    <span style="color: #33cccc;">ChartArea</span> currentArea; 

    currentSeries = chartMain.Series[SERIES_BENCH_AMOUNT];
    currentSeries.XValueType = <span style="color: #33cccc;">ChartValueType</span>.DateTime;
    currentSeries.YValueType = <span style="color: #33cccc;">ChartValueType</span>.Int32;
    currentSeries.ChartType = <span style="color: #33cccc;">SeriesChartType</span>.Line;
    currentSeries.BorderWidth = 3; currentSeries.MarkerStyle = <span style="color: #33cccc;">MarkerStyle</span>.Square;

    currentSeries = chartMain.Series[SERIES_FOOD_INTAKE];
    currentSeries.XValueType = <span style="color: #33cccc;">ChartValueType</span>.DateTime;
    currentSeries.YValueType = <span style="color: #33cccc;">ChartValueType</span>.Int32;
    currentSeries.ChartType = <span style="color: #33cccc;">SeriesChartType</span>.Line;
    currentSeries.MarkerStyle = <span style="color: #33cccc;">MarkerStyle</span>.Circle;
    currentSeries.MarkerColor = <span style="color: #33cccc;">Color</span>.Red;
    currentSeries.BorderWidth = 3;

    currentArea = chartMain.ChartAreas[CHART_AREA_MAIN];
    currentArea.Area3DStyle.Enable3D = <span style="color: #0000ff;">false</span>;
}</pre>
<p>So what&#8217;s all this? Well this:</p>
<div id="attachment_118" class="wp-caption alignnone" style="width: 307px"><a href="http://byatool.com/wp-content/uploads/2008/12/chartplainline.jpg"><img class="size-medium wp-image-118" title="chartplainline" src="http://byatool.com/wp-content/uploads/2008/12/chartplainline.jpg" alt="I MADE THIS!!11" width="297" height="289" /></a><p class="wp-caption-text">I MADE THIS!!11</p></div>
<p>So pretty, yah? So what does it all mean?</p>
<pre>    currentSeries.XValueType = <span style="color: #33cccc;">ChartValueType</span>.DateTime;
    currentSeries.YValueType = <span style="color: #33cccc;">ChartValueType</span>.Int32;</pre>
<p>Well this is pretty simple, this merely sets the types for the X and Y axis. I told you it was simple.</p>
<pre>    currentSeries.ChartType = <span style="color: #33cccc;">SeriesChartType</span>.Line;</pre>
<p>If you can&#8217;t figure that one out, try another profession like engineering.</p>
<pre>    currentSeries.MarkerStyle = <span style="color: #33cccc;">MarkerStyle</span>.Circle;
    currentSeries.MarkerColor = <span style="color: #33cccc;">Color</span>.Red;</pre>
<p>Ok these three things are used to control how the points on the lines (Markers) actually look. Pretty self explanatory once the word &#8220;marker&#8221; is translated.</p>
<pre>    currentSeries.BorderWidth = 3;</pre>
<p>This is the thickness of the line itself.</p>
<pre>    currentArea.Area3DStyle.Enable3D = <span style="color: #0000ff;">false</span>;</pre>
<p>If you guessed this was a way to make the grid 3d, you were right on and probably able remind yourself to breathe at a maximum 3 times a day.</p>
<p>So now you are thinking you have this down to an expert level and I say,&#8221;sure why not?&#8221; &#8216;cept with a little work on the mark up I could make it look like this:</p>
<div id="attachment_119" class="wp-caption alignnone" style="width: 310px"><a href="http://byatool.com/wp-content/uploads/2008/12/chartadvancedline.jpg"><img class="size-medium wp-image-119" title="chartadvancedline" src="http://byatool.com/wp-content/uploads/2008/12/chartadvancedline-300x208.jpg" alt="OoooOooOo" width="300" height="208" /></a><p class="wp-caption-text">OoooOooOo</p></div>
<p>And just like Beloch said in Raiders of the Lost Arc before his face exploded, &#8220;It&#8217;s Bewtifewl!&#8221;</p>
<p>Now for the Usings!!11</p>
<pre>    <span style="color: #33cccc;">using</span> System;
    <span style="color: #33cccc;">using</span> System.Drawing;
    <span style="color: #33cccc;">using</span> System.Web.UI.DataVisualization.Charting;</pre>
<p>And the final markup:</p>
<p><span style="font-size: x-small; color: #0000ff;"><span style="font-size: x-small; color: #0000ff;">&lt;</span></span><span style="font-size: x-small; color: #a31515;">asp</span><span style="font-size: x-small; color: #0000ff;">:</span><span style="font-size: x-small; color: #a31515;">Chart</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff0000;">ID</span><span style="font-size: x-small; color: #0000ff;">=&#8221;chartMain&#8221;</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff0000;">runat</span><span style="font-size: x-small; color: #0000ff;">=&#8221;server&#8221;</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff0000;">Palette</span><span style="font-size: x-small; color: #0000ff;">=&#8221;EarthTones&#8221;</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff0000;">BackColor</span><span style="font-size: x-small; color: #0000ff;">=&#8221;Azure&#8221;</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff0000;">ImageType</span><span style="font-size: x-small; color: #0000ff;">=&#8221;Jpeg&#8221;</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff0000;">ImageLocation</span><span style="font-size: x-small; color: #0000ff;">=&#8221;~/ChartImages/ChartPic_#SEQ(300,3)&#8221;</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff0000;">Width</span><span style="font-size: x-small; color: #0000ff;">=&#8221;412px&#8221;</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff0000;">Height</span><span style="font-size: x-small; color: #0000ff;">=&#8221;296px&#8221;</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff0000;">BorderDashStyle</span><span style="font-size: x-small; color: #0000ff;">=&#8221;Solid&#8221;</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff0000;">BackGradientStyle</span><span style="font-size: x-small; color: #0000ff;">=&#8221;TopBottom&#8221;</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff0000;">BorderWidth</span><span style="font-size: x-small; color: #0000ff;">=&#8221;2&#8243;</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff0000;">BorderColor</span><span style="font-size: x-small; color: #0000ff;">=&#8221;181, 64, 1&#8243;&gt;</span><span style="font-size: x-small;"><span style="font-size: x-small;"> </span></span><br />
<span style="font-size: x-small; color: #0000ff;">  &lt;</span><span style="font-size: x-small; color: #a31515;">series</span><span style="font-size: x-small; color: #0000ff;">&gt;</span><span style="font-size: x-small;"><span style="font-size: x-small;"> </span></span><br />
<span style="font-size: x-small; color: #0000ff;">    &lt;</span><span style="font-size: x-small; color: #a31515;">asp</span><span style="font-size: x-small; color: #0000ff;">:</span><span style="font-size: x-small; color: #a31515;">Series</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff0000;">Name</span><span style="font-size: x-small; color: #0000ff;">=&#8221;seriesBenchAmount&#8221;</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff0000;">MarkerSize</span><span style="font-size: x-small; color: #0000ff;">=&#8221;3&#8243;</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff0000;">BorderWidth</span><span style="font-size: x-small; color: #0000ff;">=&#8221;3&#8243;</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff0000;">ShadowColor</span><span style="font-size: x-small; color: #0000ff;">=&#8221;Black&#8221;</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff0000;">BorderColor</span><span style="font-size: x-small; color: #0000ff;">=&#8221;180, 26, 59, 105&#8243;</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff0000;">Color</span><span style="font-size: x-small; color: #0000ff;">=&#8221;220, 65, 140, 240&#8243;</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff0000;">ShadowOffset</span><span style="font-size: x-small; color: #0000ff;">=&#8221;2&#8243;</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #0000ff;">/&gt;</span><span style="font-size: x-small;"><span style="font-size: x-small;"> </span></span><br />
<span style="font-size: x-small; color: #0000ff;">    &lt;</span><span style="font-size: x-small; color: #a31515;">asp</span><span style="font-size: x-small; color: #0000ff;">:</span><span style="font-size: x-small; color: #a31515;">Series</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff0000;">Name</span><span style="font-size: x-small; color: #0000ff;">=&#8221;seriesFoodIntake&#8221;</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff0000;">MarkerSize</span><span style="font-size: x-small; color: #0000ff;">=&#8221;3&#8243;</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff0000;">BorderWidth</span><span style="font-size: x-small; color: #0000ff;">=&#8221;3&#8243;</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff0000;">ShadowColor</span><span style="font-size: x-small; color: #0000ff;">=&#8221;Black&#8221;</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff0000;">BorderColor</span><span style="font-size: x-small; color: #0000ff;">=&#8221;180, 26, 59, 105&#8243;</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff0000;">Color</span><span style="font-size: x-small; color: #0000ff;">=&#8221;220, 224, 64, 10&#8243;</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff0000;">ShadowOffset</span><span style="font-size: x-small; color: #0000ff;">=&#8221;2&#8243;</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #0000ff;">/&gt;</span><span style="font-size: x-small;"><span style="font-size: x-small;"> </span></span><br />
<span style="font-size: x-small; color: #0000ff;">  &lt;/</span><span style="font-size: x-small; color: #a31515;">series</span><span style="font-size: x-small; color: #0000ff;">&gt;</span><span style="font-size: x-small;"><span style="font-size: x-small;"></p>
<p></span></span></p>
<p><span style="font-size: x-small; color: #0000ff;">  &lt;</span><span style="font-size: x-small; color: #a31515;">chartareas</span><span style="font-size: x-small; color: #0000ff;">&gt;</span><span style="font-size: x-small;"><span style="font-size: x-small;"> </span></span><br />
<span style="font-size: x-small; color: #0000ff;">    &lt;</span><span style="font-size: x-small; color: #a31515;">asp</span><span style="font-size: x-small; color: #0000ff;">:</span><span style="font-size: x-small; color: #a31515;">ChartArea</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff0000;">Name</span><span style="font-size: x-small; color: #0000ff;">=&#8221;chartAreaMain&#8221;</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff0000;">BorderColor</span><span style="font-size: x-small; color: #0000ff;">=&#8221;64, 64, 64, 64&#8243;</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff0000;">BorderDashStyle</span><span style="font-size: x-small; color: #0000ff;">=&#8221;Solid&#8221;</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff0000;">BackSecondaryColor</span><span style="font-size: x-small; color: #0000ff;">=&#8221;White&#8221;</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff0000;">BackColor</span><span style="font-size: x-small; color: #0000ff;">=&#8221;OldLace&#8221;</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff0000;">ShadowColor</span><span style="font-size: x-small; color: #0000ff;">=&#8221;Transparent&#8221;</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff0000;">BackGradientStyle</span><span style="font-size: x-small; color: #0000ff;">=&#8221;TopBottom&#8221;&gt;</span><span style="font-size: x-small;"><span style="font-size: x-small;"> </span></span><br />
<span style="font-size: x-small; color: #0000ff;">      &lt;</span><span style="font-size: x-small; color: #a31515;">area3dstyle</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff0000;">Rotation</span><span style="font-size: x-small; color: #0000ff;">=&#8221;25&#8243;</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff0000;">Perspective</span><span style="font-size: x-small; color: #0000ff;">=&#8221;9&#8243;</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff0000;">LightStyle</span><span style="font-size: x-small; color: #0000ff;">=&#8221;Realistic&#8221;</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff0000;">Inclination</span><span style="font-size: x-small; color: #0000ff;">=&#8221;40&#8243;</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff0000;"><span style="color: #0000ff;">          </span>IsRightAngleAxes</span><span style="font-size: x-small; color: #0000ff;">=&#8221;False&#8221;</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff0000;">WallWidth</span><span style="font-size: x-small; color: #0000ff;">=&#8221;3&#8243;</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff0000;">IsClustered</span><span style="font-size: x-small; color: #0000ff;">=&#8221;False&#8221;</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #0000ff;">/&gt;</span><span style="font-size: x-small;"><span style="font-size: x-small;"> </span></span><br />
<span style="font-size: x-small; color: #0000ff;">      &lt;</span><span style="font-size: x-small; color: #a31515;">axisy</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff0000;">LineColor</span><span style="font-size: x-small; color: #0000ff;">=&#8221;64, 64, 64, 64&#8243;&gt;</span><span style="font-size: x-small;"><span style="font-size: x-small;"> </span></span><br />
<span style="font-size: x-small; color: #0000ff;">        &lt;</span><span style="font-size: x-small; color: #a31515;">LabelStyle</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff0000;">Font</span><span style="font-size: x-small; color: #0000ff;">=&#8221;Trebuchet MS, 8.25pt, style=Bold&#8221;</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #0000ff;">/&gt;</span><span style="font-size: x-small;"><span style="font-size: x-small;"> </span></span><br />
<span style="font-size: x-small; color: #0000ff;">        &lt;</span><span style="font-size: x-small; color: #a31515;">MajorGrid</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff0000;">LineColor</span><span style="font-size: x-small; color: #0000ff;">=&#8221;64, 64, 64, 64&#8243;</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #0000ff;">/&gt;</span><span style="font-size: x-small;"><span style="font-size: x-small;"> </span></span><br />
<span style="font-size: x-small; color: #0000ff;">      &lt;/</span><span style="font-size: x-small; color: #a31515;">axisy</span><span style="font-size: x-small; color: #0000ff;">&gt;</span><span style="font-size: x-small;"><span style="font-size: x-small;"> </span></span><br />
<span style="font-size: x-small; color: #0000ff;">      &lt;</span><span style="font-size: x-small; color: #a31515;">axisx</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff0000;">LineColor</span><span style="font-size: x-small; color: #0000ff;">=&#8221;64, 64, 64, 64&#8243;&gt;</span><span style="font-size: x-small;"><span style="font-size: x-small;"> </span></span><br />
<span style="font-size: x-small; color: #0000ff;">        &lt;</span><span style="font-size: x-small; color: #a31515;">LabelStyle</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff0000;">Font</span><span style="font-size: x-small; color: #0000ff;">=&#8221;Trebuchet MS, 8.25pt, style=Bold&#8221;</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #0000ff;">/&gt;</span><span style="font-size: x-small;"><span style="font-size: x-small;"> </span></span><br />
<span style="font-size: x-small; color: #0000ff;">        &lt;</span><span style="font-size: x-small; color: #a31515;">MajorGrid</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #ff0000;">LineColor</span><span style="font-size: x-small; color: #0000ff;">=&#8221;64, 64, 64, 64&#8243;</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #0000ff;">/&gt;</span><span style="font-size: x-small;"> </span><br />
<span style="font-size: x-small; color: #0000ff;">      &lt;/</span><span style="font-size: x-small; color: #a31515;">axisx</span><span style="font-size: x-small; color: #0000ff;">&gt;</span><span style="font-size: x-small;"><span style="font-size: x-small;"> </span></span><br />
<span style="font-size: x-small; color: #0000ff;">    &lt;/</span><span style="font-size: x-small; color: #a31515;">asp</span><span style="font-size: x-small; color: #0000ff;">:</span><span style="font-size: x-small; color: #a31515;">ChartArea</span><span style="font-size: x-small; color: #0000ff;">&gt;</span><span style="font-size: x-small;"><span style="font-size: x-small;"> </span></span><br />
<span style="font-size: x-small; color: #0000ff;">  &lt;/</span><span style="font-size: x-small; color: #a31515;">chartareas</span><span style="font-size: x-small; color: #0000ff;">&gt;</span><span style="font-size: x-small;"><span style="font-size: x-small;"> </span></span><br />
<span style="font-size: x-small; color: #0000ff;">&lt;/</span><span style="font-size: x-small; color: #a31515;">asp</span><span style="font-size: x-small; color: #0000ff;">:</span><span style="font-size: x-small; color: #a31515;">Chart</span><span style="font-size: x-small; color: #0000ff;">&gt;</span></p>
]]></content:encoded>
			<wfw:commentRss>http://byatool.com/ui/microsoft-charting-control-so-easy-an-idiot-can-use-it-and-i-have/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linq Extension Methods Versus Linq Query Language&#8230; DEATHMATCH</title>
		<link>http://byatool.com/general-coding/linq-extension-methods-versus-linq-query-language-deathmatch/</link>
		<comments>http://byatool.com/general-coding/linq-extension-methods-versus-linq-query-language-deathmatch/#comments</comments>
		<pubDate>Thu, 13 Nov 2008 03:09:38 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[General Coding]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Func]]></category>
		<category><![CDATA[Lambda]]></category>
		<category><![CDATA[Linq]]></category>

		<guid isPermaLink="false">http://byatool.com/?p=86</guid>
		<description><![CDATA[Today I was writing out an example of why the extension methods are for the most part better to use than the querying language. Go figure I would find a case where that&#8217;s not entirely true. Say you are using these three funcs: Func&#60;User, String&#62; userName = user =&#62; user.UserName; Func&#60;User, Boolean&#62; userIDOverTen = user [...]]]></description>
			<content:encoded><![CDATA[<p>Today I was writing out an example of why the extension methods are for the most part better to use than the querying language.  Go figure I would find a case where that&#8217;s not entirely true.  Say you are using these three funcs:</p>
<pre><span style="color: #33cccc;">    Func</span>&lt;<span style="color: #33cccc;">User</span>, <span style="color: #33cccc;">String</span>&gt; userName = user =&gt; user.UserName;
<span style="color: #33cccc;">    <span>Func</span></span>&lt;<span style="color: #33cccc;">User</span>, <span style="color: #33cccc;">Boolean</span>&gt; userIDOverTen = user =&gt; user.UserID &lt; 10;
<span style="color: #33cccc;">    <span>Func</span></span>&lt;<span style="color: #33cccc;">User</span>, <span style="color: #33cccc;">Boolean</span>&gt; userIDUnderTen = user =&gt; user.UserID &gt; 10;</pre>
<p>As you can see the first one replaces the lamdba expression to get the user name, the second replaces a lamdba expression used to check if the ID is lower than 10, and let&#8217;s face it, the third should be pretty easy to understand now.</p>
<p>NOTE:  This is a  silly example but it works.</p>
<pre><span style="color: #33cccc;">    </span><span style="color: #0000ff;">var</span> userList =
<span style="color: #33cccc;">      </span><span style="color: #0000ff;">from</span> user <span style="color: #0000ff;">in</span> userList
<span style="color: #33cccc;">      </span><span style="color: #0000ff;">where</span> userIDOverTen(user)
<span style="color: #33cccc;">      </span><span style="color: #0000ff;">select</span> userName;
Versus

<span style="color: #33cccc;">    </span><span style="color: #0000ff;">var</span> otherList =
<span style="color: #33cccc;">      </span>userList
<span style="color: #33cccc;">      </span>.Where(IDIsBelowNumber)
<span style="color: #33cccc;">      </span>.Select(userName)</pre>
<p>In this example, the second is a little less verbose since the extension method can make full use of the Func, but he Linq expression can&#8217;t since it is look just for a Boolean rather than a Func that returns boolean.   However, this is where it might be better to use the expression language.  Say you already had a method that takes in more than just a user:</p>
<pre><span style="color: #33cccc;">    </span><span style="color: #0000ff;">private</span> <span style="color: #33cccc;">Boolean</span> IDIsBelowNumber(<span style="color: #33cccc;">User</span> user, <span style="color: #33cccc;">Int32</span> someNumber, <span style="color: #33cccc;">Boolean</span> doSomething)
<span style="color: #33cccc;">    </span>{
<span style="color: #33cccc;">      </span><span style="color: #0000ff;">return</span> user.UserID &lt; someNumber;
    }</pre>
<p>Note:  doSomething is just there because of the where extension method being ok with a method that takes in a user and integer and returns boolean.  Kind of annoying for this example.</p>
<p>Now if you look at the Linq query:</p>
<pre><span style="color: #33cccc;">    </span><span style="color: #0000ff;">var</span> completeList =
<span style="color: #33cccc;">      </span><span style="color: #0000ff;">from</span> user <span style="color: #0000ff;">in</span> userList
<span style="color: #33cccc;">      </span><span style="color: #0000ff;">where</span> userIDOverTen(user, 10)
<span style="color: #33cccc;">      </span><span style="color: #0000ff;">select</span> userName;</pre>
<p>You&#8217;re good for it.  Now the Extension Method:</p>
<pre><span style="color: #33cccc;">    </span><span style="color: #0000ff;">var</span> otherList =
<span style="color: #33cccc;">      </span>userList
<span style="color: #33cccc;">      </span>.Where(IDIsBelowNumber????)
<span style="color: #33cccc;">      </span>.Select(userName)</pre>
<p>Without a lambda expression, I really can&#8217;t call that method.  So now what I have to do is create a method that creates a Func based off the original method call.</p>
<pre><span style="color: #33cccc;">    </span><span style="color: #0000ff;">private</span> <span style="color: #33cccc;">Func</span>&lt;<span style="color: #33cccc;">User</span>, <span style="color: #33cccc;">Boolean</span>&gt; IDIsBelowNumberFunc(<span style="color: #33cccc;">Int32</span> number)
<span style="color: #33cccc;">    </span>{
<span style="color: #33cccc;">      </span><span style="color: #0000ff;">return</span> user =&gt; IDIsBelowNumber(user, number, <span style="color: #0000ff;">true</span>);
<span style="color: #33cccc;">    </span>}</pre>
<p>And then plug it in:</p>
<pre><span style="color: #33cccc;">    </span><span style="color: #0000ff;">var</span> otherList =
<span style="color: #33cccc;">      </span>userList
<span style="color: #33cccc;">      </span>.Where(IDIsBelowNumberFunc(10))
<span style="color: #33cccc;">      </span>.Select(userName)</pre>
<p>What does this all mean?  You just lost 5 minutes of your life.  I hope it was worth it.</p>
]]></content:encoded>
			<wfw:commentRss>http://byatool.com/general-coding/linq-extension-methods-versus-linq-query-language-deathmatch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Change Target Framework on a Class Library (Visual Studios 2008)</title>
		<link>http://byatool.com/net-issues/change-target-framework-on-a-class-library/</link>
		<comments>http://byatool.com/net-issues/change-target-framework-on-a-class-library/#comments</comments>
		<pubDate>Sun, 09 Nov 2008 19:44:17 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[.Net Issues]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[Target Framework]]></category>

		<guid isPermaLink="false">http://byatool.com/?p=83</guid>
		<description><![CDATA[Ok so this is a quick one but annoys the hell of of me. Basically I am working with a 2.0 class library project and I wanted to use Linq. Now you would think when you &#8220;upgrade&#8221; the project to 3.5 using the wizard, the target framework would follow. Well, you are stupid. Now for [...]]]></description>
			<content:encoded><![CDATA[<p>Ok so this is a quick one but annoys the hell of of me.</p>
<p>Basically I am working with a 2.0 class library project and I wanted to use Linq. Now you would think when you &#8220;upgrade&#8221; the project to 3.5 using the wizard, the target framework would follow. Well, you are stupid. Now for web projects it seems you can look at the properties -&gt; build and boom you can see it bright as day. Try doing this with a class library you and got nothin&#8217;.</p>
<p>Here&#8217;s the solution:</p>
<p>Goto the project properties -&gt; compile -&gt; Advanced Compile Options AND YOU WILL BE VICTORY!!11</p>
<p>So easy even a child could do it&#8230; after an hour of searching on google&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://byatool.com/net-issues/change-target-framework-on-a-class-library/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Skins in ASP.Net and how behind I am</title>
		<link>http://byatool.com/ui/skins-and-how-behind-i-am/</link>
		<comments>http://byatool.com/ui/skins-and-how-behind-i-am/#comments</comments>
		<pubDate>Mon, 03 Nov 2008 21:27:44 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[UI]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://byatool.com/?p=75</guid>
		<description><![CDATA[So something that has been around for while that I just stumbled upon is Skinning. Basically, this allows you to sent a certain look (using style sheets) for every control in the site. This even includes the built in controls like Tables and Textboxes. How is this done? Well maybe I can tell you. First [...]]]></description>
			<content:encoded><![CDATA[<p>So something that has been around for while that I just stumbled upon is Skinning.  Basically, this allows you to sent a certain look (using style sheets) for every control in the site.  This even includes the built in controls like Tables and Textboxes.  How is this done?  Well maybe I can tell you.</p>
<p>First you have to go to your project and right click (yes I could make images, but honestly that&#8217;s more work than needed.) the project itself. Add -&gt; Add Asp.net Folder -&gt; Theme.</p>
<p>Yay, you have a folder. Sweet. Now you actually have to add the skin itself. Guess what you have to right click? Yes, the new folder. Add -&gt; New Item -&gt; Skin File. Name it whatever (I say you call it Basic because that&#8217;s what I called it for this example) and open it up.</p>
<p>Now you have to create a .css file, if you don&#8217;t already have one, and for this example let&#8217;s say you make one called SkinMe.css. Now you get to add these meaningless classes:</p>
<pre>.<span style="color: #800000;">defaultTable
</span>{
    <span style="color: #ff0000;">width:</span><span style="color: #3366ff;">500px</span>;
    <span style="color: #ff0000;">border-color:</span><span style="color: #3366ff;">Black</span>;
    <span style="color: #ff0000;">border-style:</span><span style="color: #3366ff;">solid</span>;
    <span style="color: #ff0000;">border-width:</span><span style="color: #3366ff;">thin</span>;
}

.<span style="color: #800000;">defaultTable tr</span>
{
    <span style="color: #ff0000;">width:</span><span style="color: #3366ff;">500px</span>;
    <span style="color: #ff0000;">background-color:</span><span style="color: #3366ff;">Navy</span>;
}

.<span style="color: #800000;">defaultTable td</span>
{
    <span style="color: #ff0000;">color:</span><span style="color: #3366ff;">Red</span>;
}

.<span style="color: #800000;">nonDefaultTable</span>
{
    <span style="color: #ff0000;">width:</span><span style="color: #3366ff;">300px</span>;
    <span style="color: #ff0000;">border-color:</span><span style="color: #3366ff;">Black</span>;
    <span style="color: #ff0000;">border-style:</span><span style="color: #3366ff;">dotted</span>;
    <span style="color: #ff0000;">border-width:</span><span style="color: #3366ff;">thick</span>;
}

.<span style="color: #800000;">nonDefaultTable tr</span>
{
    <span style="color: #ff0000;">width:</span><span style="color: #3366ff;">500px</span>;
    <span style="color: #ff0000;">background-color:</span><span style="color: #3366ff;">Navy</span>;
}

.<span style="color: #800000;">nonDefaultTable td</span>
{
    <span style="color: #ff0000;">color:</span><span style="color: #3366ff;">Red</span>;
}</pre>
<p>Basically, I have two different classes for tables, with really only one difference. (border-style:dotted) Now you need that actual markup file to hold these wonderful tables:</p>
<pre>    <span style="color: #800000;">&lt;asp:Table ID=</span><span style="color: #3366ff;">"</span><span style="color: #0000ff;">tableSkinDefault"</span> <span style="color: #800000;">runat=</span><span style="color: #0000ff;">"server"</span><span style="color: #800000;">&gt;</span>
        <span style="color: #800000;">&lt;asp:TableRow ID=</span><span style="color: #0000ff;">"tableRowSkinDefault"</span> <span style="color: #800000;">runat=</span><span style="color: #0000ff;">"server"</span> <span style="color: #800000;">&gt;</span>
            <span style="color: #800000;">&lt;asp:TableCell ID=</span><span style="color: #0000ff;">"tableCellSkinDefault"</span> <span style="color: #800000;">runat=</span><span style="color: #0000ff;">"server"</span> <span style="color: #800000;">&gt;</span>
                hihihi
            <span style="color: #800000;">&lt;/asp:TableCell&gt;</span>
        <span style="color: #800000;">&lt;/asp:TableRow&gt;</span>
    <span style="color: #800000;">&lt;/asp:Table&gt;</span>

    <span style="color: #800000;">&lt;asp:Table ID=</span><span style="color: #0000ff;">"tableNonDefault"</span> <span style="color: #800000;">runat=</span><span style="color: #0000ff;">"server"</span> <span style="color: #800000;">SkinID=</span><span style="color: #0000ff;">"nonDefaultSkin" </span><span style="color: #800000;">&gt;</span>
        <span style="color: #800000;">&lt;asp:TableRow ID=</span><span style="color: #0000ff;">"tableRowNonDefault"</span> <span style="color: #800000;">runat=</span><span style="color: #0000ff;">"server" </span><span style="color: #800000;">&gt;</span>
            <span style="color: #800000;">&lt;asp:TableCell ID=</span><span style="color: #0000ff;">"tableCellNonDefault"</span> <span style="color: #800000;">runat=</span><span style="color: #0000ff;">"server" </span><span style="color: #800000;">&gt;</span>
                hihihi
            <span style="color: #800000;">&lt;/asp:TableCell&gt;</span>
        <span style="color: #800000;">&lt;/asp:TableRow&gt;</span>
    <span style="color: #800000;">&lt;/asp:Table&gt;</span></pre>
<p>Now you might notice that the second table is using the SkinID tag. This will make sense in the next part. Have your skin file open? Gooood. Now just paste this into it:</p>
<pre>    <span style="color: #800000;">&lt;asp:Table runat=</span><span style="color: #0000ff;">"server"</span> <span style="color: #800000;">CssClass=</span><span style="color: #0000ff;">"defaultTable"</span> <span style="color: #800000;">/&gt;</span>
    <span style="color: #800000;">&lt;asp:Table runat=</span><span style="color: #0000ff;">"server"</span> <span style="color: #800000;">CssClass=</span><span style="color: #0000ff;">"nonDefaultTable"</span> <span style="color: #800000;">SkinId=</span><span style="color: #0000ff;">"nonDefaultSkin"</span> <span style="color: #800000;">/&gt;</span></pre>
<p>Now it might be making more sense. Once I added the SkinId tag to the skin file, this allowed me to have the same control take on two different classes. Now, you can only have one default (The first one as it doesn&#8217;t have the SkinId tag) and any others for the same control have to use the SkinId tag.</p>
<p>Now go back to the two tables and once again you&#8217;ll see there is one with a SkinId tag and one without. The one without will take the default look and the one with will take the named look. Pretty simple, right? Well we&#8217;re not completely done yet. Two more small steps:</p>
<p>Be sure to remember to link the style sheet on the page with the tables:</p>
<pre>    <span style="color: #800000;">&lt;link href=</span><span style="color: #0000ff;">"../CSS/SkinMe.css"</span> <span style="color: #800000;">type=</span><span style="color: #0000ff;">"text/css"</span> <span style="color: #800000;">rel=</span><span style="color: #0000ff;">"stylesheet"</span> <span style="color: #800000;">/&gt;</span></pre>
<p>And you have find the &#8220;pages&#8221; section of the web.config and add a tag:</p>
<pre>    <span style="color: #800000;">&lt;pages styleSheetTheme=</span><span style="color: #0000ff;">"Basic"</span><span style="color: #800000;">&gt;</span></pre>
<p>And now you have the ability to set every table&#8217;s class in the entire site. Best thing is, this can be used for other properties too. Say you have a name property on some usercontrol (We&#8217;ll call it MapControl). You can do this:</p>
<pre>    <span style="color: #800000;">&lt;%</span><span style="color: #0000ff;">@</span> <span style="color: #800000;">Register Assembly=</span><span style="color: #0000ff;">"Some.Control.Assembly"</span> <span style="color: #800000;">Namespace=</span><span style="color: #0000ff;">"Some.Control.Assembly.Controls"</span> <span style="color: #800000;">TagPrefix=</span><span style="color: #0000ff;">"someControl"</span> <span style="color: #800000;">%&gt;</span>

    <span style="color: #800000;">&lt;someControl:MapControl</span> <span style="color: #800000;">Name=</span><span style="color: #0000ff;">"Hi"</span> <span style="color: #800000;">/&gt;
</span></pre>
<p>And now every MapControl will have the Name property set to &#8220;hi&#8221;. Kind of nice.</p>
]]></content:encoded>
			<wfw:commentRss>http://byatool.com/ui/skins-and-how-behind-i-am/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>UpdatePanel and UserControl Events</title>
		<link>http://byatool.com/ui/updatepanel-and-usercontrol-events/</link>
		<comments>http://byatool.com/ui/updatepanel-and-usercontrol-events/#comments</comments>
		<pubDate>Wed, 22 Oct 2008 19:24:28 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[UI]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Event]]></category>

		<guid isPermaLink="false">http://byatool.com/?p=71</guid>
		<description><![CDATA[So on the funnest programmin&#8217; site evar someone had asked how to allow an UpdatePanel on a page handle an event of a UserControl. So here&#8217;s the situation: Let&#8217;s say you have a UserControl and on that UserControl you have a DropDownList. I know, this is getting complex, but just bare with me. Now imagine, [...]]]></description>
			<content:encoded><![CDATA[<p>So <a href="http://www.stackoverflow.com">on the funnest programmin&#8217; site evar</a> someone had asked how to allow an UpdatePanel on a page handle an event of a UserControl. So here&#8217;s the situation:</p>
<p>Let&#8217;s say you have a UserControl and on that UserControl you have a DropDownList. I know, this is getting complex, but just bare with me. Now imagine, if you will, you want the Parent page&#8217;s UpdatePanel to trigger off of the mentioned DropDownList. As it stands, this isn&#8217;t going to happen. Why? Because the Parent really can&#8217;t capture the event firing on the control since it is localized to the UserControl. What to do? Easy, just pass the event on.</p>
<pre>    <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">partial</span> <span style="color: #0000ff;">class</span> CatchMyEvent : UserControl
    {
        <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">delegate</span> <span style="color: #0000ff;">void</span> <span style="color: #33cccc;">ChangedIndex</span>(<span style="color: #0000ff;">object</span> sender, <span style="color: #33cccc;">EventArgs</span> e);
        <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">event</span> <span style="color: #33cccc;">ChangedIndex</span> <span style="color: #33cccc;">SelectedIndexChanged</span>;

        <span style="color: #0000ff;">protected</span> <span style="color: #0000ff;">override</span> <span style="color: #0000ff;">void</span> OnInit(<span style="color: #33cccc;">EventArgs</span> e)
        {
            base.OnInit(e);
            dropDownListThrow.SelectedIndexChanged +=
               <span style="color: #0000ff;">new</span> EventHandler(dropDownListThrow_SelectedIndexChanged);
        }

        <span style="color: #0000ff;">protected</span> <span style="color: #0000ff;">override</span> <span style="color: #0000ff;">void</span> OnLoad(<span style="color: #33cccc;">EventArgs</span> e)
        {
            base.OnLoad(e);
        }

        <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> dropDownListThrow_SelectedIndexChanged(<span style="color: #0000ff;">object</span> sender, <span style="color: #33cccc;">EventArgs</span> e)
        {
            <span style="color: #0000ff;">if</span>(SelectedIndexChanged != <span style="color: #0000ff;">null</span>)
            {
                SelectedIndexChanged(sender, e);
            }
        }
    }</pre>
<p>As you can see, all I&#8217;ve done</p>
<ol>
<li>Created a PUBLIC delegate and event that has the same signature as the SelectedIndexChanged event</li>
<li>Captured the SelectedIndexChanged event in the UserControl</li>
<li>Fired off the created event</li>
</ol>
<p>It&#8217;s like I&#8217;m just handing off the event firing to the next guy, the next guy being the Parent page in this instance. Now the code behind for the Parent page is really simple:</p>
<pre>    <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">partial</span> <span style="color: #0000ff;">class</span> <span style="color: #33cccc;">Catcher</span> : <span style="color: #33cccc;">Page</span>
    {
        <span style="color: #0000ff;">protected</span> <span style="color: #0000ff;">override</span> <span style="color: #0000ff;">void</span> OnInit(<span style="color: #33cccc;">EventArgs</span> e)
        {
            base.OnInit(e);
            catchMyEventMain.SelectedIndexChanged += dropDownListThrow_SelectedIndexChanged;
        }

        <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> dropDownListThrow_SelectedIndexChanged(<span style="color: #0000ff;">object</span> sender, <span style="color: #33cccc;">EventArgs</span> e)
        {
            labelSelectedValue.Text = ((<span style="color: #33cccc;">DropDownList</span>)sender).SelectedItem.Text;
        }
    }</pre>
<p>As you can see, the Parent now is also looking for the DropDownList SelectedIndexChanged event to fire, except we both know that it&#8217;s not the official SelectedIndexChanged event, but an event that is merely passing on the information. Now for the Parent page markup:</p>
<pre>    <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">asp:ScriptManager</span> <span style="color: #ff0000;">ID</span><span style="color: #0000ff;">="smMain"</span> <span style="color: #ff0000;">runat</span><span style="color: #0000ff;">="server"</span> <span style="color: #0000ff;">/</span><span style="color: #0000ff;">&gt;</span>
    <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">asp:UpdatePanel</span> <span style="color: #ff0000;">ID</span><span style="color: #0000ff;">="upMain"</span> <span style="color: #ff0000;">runat</span><span style="color: #0000ff;">="server"</span> <span style="color: #0000ff;">&gt;</span>
        <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">Triggers</span><span style="color: #0000ff;">&gt;</span>
            <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">asp:AsyncPostBackTrigger</span> <span style="color: #ff0000;">ControlID</span><span style="color: #0000ff;">="catchMyEventMain"</span> <span style="color: #ff0000;">EventName</span><span style="color: #0000ff;">="SelectedIndexChanged"</span> <span style="color: #0000ff;">/&gt;</span>
        <span style="color: #0000ff;">&lt;/</span><span style="color: #800000;">Triggers</span><span style="color: #0000ff;">&gt;</span>
        <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">ContentTemplate</span><span style="color: #0000ff;">&gt;</span>
            <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">uc1:CatchMyEvent</span> <span style="color: #ff0000;">ID</span><span style="color: #0000ff;">="catchMyEventMain"</span> <span style="color: #ff0000;">runat</span><span style="color: #0000ff;">="server"</span> <span style="color: #0000ff;">/&gt;</span>
            <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">asp:Label</span> <span style="color: #ff0000;">ID</span><span style="color: #0000ff;">="labelSelectedValue"</span> <span style="color: #ff0000;">runat</span><span style="color: #0000ff;">="server"</span> <span style="color: #0000ff;">/&gt;</span>
         <span style="color: #0000ff;">&lt;/</span><span style="color: #800000;">ContentTemplate</span><span style="color: #0000ff;">&gt;</span>
    <span style="color: #0000ff;">&lt;/</span><span style="color: #800000;">asp:UpdatePanel</span><span style="color: #0000ff;">&gt;</span></pre>
<p>So in all this will update a label&#8217;s text on the Parent page to equal that of the SelectedItem.Value of the DropDownList of the UserControl. And all without the annoying page refresh.</p>
<p>Just remember, the DropDownList has to have AutoPostback set to true.  Don&#8217;t be dumb like me and forget that when testing.</p>
]]></content:encoded>
			<wfw:commentRss>http://byatool.com/ui/updatepanel-and-usercontrol-events/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Switch Remover: Convert Switch Statements to Dictionaries</title>
		<link>http://byatool.com/general-coding/the-switch-remover/</link>
		<comments>http://byatool.com/general-coding/the-switch-remover/#comments</comments>
		<pubDate>Fri, 17 Oct 2008 13:30:10 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[General Coding]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[Action]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Dynamic]]></category>
		<category><![CDATA[Lambda]]></category>

		<guid isPermaLink="false">http://byatool.com/?p=65</guid>
		<description><![CDATA[Folks, what if I told you that Switch is a thing of the past? What if I told you I had a way to reduce code in certain areas so that you don&#8217;t have that messy Switch logic? What would you pay for that? Would you pay $19.95? Not convinced? Well take this: switch(someDropDownList.SelectedValue) { [...]]]></description>
			<content:encoded><![CDATA[<p>Folks, what if I told you that Switch is a thing of the past? What if I told you I had a way to reduce code in certain areas so that you don&#8217;t have that messy Switch logic? What would you pay for that? Would you pay $19.95? Not convinced? Well take this:</p>
<pre>  <span style="color: #0000ff;">switch</span>(someDropDownList.SelectedValue)
  {
     <span style="color: #0000ff;">case</span> <span style="color: #ff0000;">"hi"</span>:
        CallThisMethod();
        CallThatMethod();
        CallAnotherMethod();
        <span style="color: #0000ff;">break</span>;
     <span style="color: #0000ff;">case</span> <span style="color: #ff0000;">"there"</span>:
        CallThisMethod();
        CallThatMethod();
        CallAnotherMethod();
        CallSomethingElse();
        <span style="color: #0000ff;">break</span>;
  }</pre>
<p>And I&#8217;ll give you this:</p>
<pre>  doSomething[someDropDownList.SelectedValue]();</pre>
<p>I bet you&#8217;re ready to pay $19.95, but wait there&#8217;s more. I&#8217;ll actually throw in how I did such an amazing thing.</p>
<pre>  <span style="color: #33cccc;">Dictionary</span>&lt;<span style="color: #33cccc;">String</span>, <span style="color: #33cccc;">Action</span>&gt; switchRemover = <span style="color: #0000ff;">new</span> <span style="color: #33cccc;">Dictionary</span>&lt;<span style="color: #33cccc;">String</span>, <span style="color: #33cccc;">Action</span>&gt;();
  switchRemover.Add(<span style="color: #ff0000;">"hi"</span>, () =&gt; RunHiMethod();
  switchRemover.Add(<span style="color: #ff0000;">"there"</span>, () =&gt; RunThereMethod();</pre>
<p>Why that&#8217;s amazing! But wait, I must be pulling something. What are these RunHiMethod and RunThereMethod methods? I must be pulling a fast one. Well, all they are is what the switch was doing before all wrapped up into one method. Don&#8217;t get it?</p>
<pre>  <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> RunHiMethod()
  {
      CallThisMethod();
      CallThatMethod();
      CallAnotherMethod();
  }</pre>
<p>But&#8230; but what if I had to pass something in? What would I do then??? Boy you got me there, I could tell you but I&#8217;d have to charge you more. Wait&#8230; I&#8217;ll even throw that in for free. That&#8217;s right. Remember that old mess we had?</p>
<pre>  <span style="color: #0000ff;">switch</span>(someDropDownList.SelectedValue)
  {
     <span style="color: #0000ff;">case</span> <span style="color: #ff0000;">"hi"</span>:
        CallThisMethod(someUser);
        CallThatMethod();
        CallAnotherMethod();
        <span style="color: #0000ff;">break</span>;
     <span style="color: #0000ff;">case</span> <span style="color: #ff0000;">"there"</span>:
        CallThisMethod(someUser);
        CallThatMethod();
        CallAnotherMethod();
        CallSomethingElse();
        <span style="color: #0000ff;">break</span>;
}</pre>
<p>Well shoot,we could do something like this:</p>
<pre>  <span style="color: #33cccc;">Dictionary</span>&lt;<span style="color: #33cccc;">String</span>, <span style="color: #33cccc;">Action</span>&lt;<span style="color: #33cccc;">User</span>&gt;&gt; switchRemover = <span style="color: #0000ff;">new</span> <span style="color: #33cccc;">Dictionary</span>&lt;<span style="color: #33cccc;">String</span>, <span style="color: #33cccc;">Action</span>&gt;();
  switchRemover.Add(<span style="color: #ff0000;">"hi"</span>, currentUser =&gt; RunHiMethod(currentUser);
  switchRemover.Add(<span style="color: #ff0000;">"there"</span>, currentUser =&gt; RunThereMethod(currentUser );</pre>
<p>And then:</p>
<pre>  doSomething[someDropDownList.SelectedValue](currentUser);</pre>
<p>That&#8217;s amazing! You ready with your credit card? I knew you would be.</p>
<p>The Switch Remover does not come with a warranty.<br />
The Switch Remover can not be used in all circumstances.<br />
The Switch Remover assumes no fault for any physical conditions caused by the sudden surge of awesomeness you might feel.</p>
<p>SO BUY IT NOW!</p>
]]></content:encoded>
			<wfw:commentRss>http://byatool.com/general-coding/the-switch-remover/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What Is Readable</title>
		<link>http://byatool.com/pontification/what-is-readable/</link>
		<comments>http://byatool.com/pontification/what-is-readable/#comments</comments>
		<pubDate>Fri, 10 Oct 2008 14:51:57 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Pontification]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[FizzBuzz]]></category>
		<category><![CDATA[Func]]></category>
		<category><![CDATA[Lambda]]></category>
		<category><![CDATA[Linq]]></category>
		<category><![CDATA[Select]]></category>

		<guid isPermaLink="false">http://byatool.com/?p=56</guid>
		<description><![CDATA[So a couple of posts I read recently have been about readability of Linq, more so Linq query expressions versus the Linq methods. Don&#8217;t know what I mean? Expression: var result = from knowledge in Sean select knowledge.Linq; As opposed to: var result = Sean.Select(knowledge =&#62; knowledge.Linq); Personally I would replace the lambda expression with [...]]]></description>
			<content:encoded><![CDATA[<p>So a couple of posts I read recently have been about readability of Linq, more so Linq query expressions versus the Linq methods.  Don&#8217;t know what I mean?</p>
<p>Expression:</p>
<pre><span style="color: #0000ff;">var</span> result = <span style="color: #0000ff;">from</span> knowledge <span style="color: #0000ff;">in</span> Sean
             <span style="color: #0000ff;">select</span> knowledge.Linq;</pre>
<p>As opposed to:</p>
<pre><span style="color: #0000ff;">var</span> result = Sean.Select(knowledge =&gt; knowledge.Linq);</pre>
<p>Personally I would replace the lambda expression with a Func, but I can live with it right now. Anywho, the argument is that the first looks better than the second. I really don&#8217;t see this as a looks problem, but a useage problem. Fact is, they both have their uses and you should know how to read both. Why is that? Well here&#8217;s an example CAUSE I KNOW YOU WANT ONE!</p>
<p>One of my earlier posts had to do with <a title="FizzBuzz" href="http://byatool.com/?p=46">solving the FizzBuzz</a> thing with Linq where I gave you this bad ass solution:</p>
<pre> <span style="color: #0000ff;">var</span> result =
      listToConvert
      .<span style="color: #000000;">Where</span>(WhereBothDivisible(fizzNumber, buzzNumber))
      .<span style="color: #000000;">Select</span>(selectKeyValuePair(<span style="color: #ff0000;">"FizzBuzz"</span>))
      .Concat(
            listToConvert
            .Where(WhereBuzzDivisable(fizzNumber, buzzNumber))
            .Select(selectKeyValuePair(<span style="color: #ff0000;">"Buzz"</span>)))
            .Concat(
                  listToConvert
                  .Where(WhereFizzDivisable(fizzNumber, buzzNumber))
                  .Select(selectKeyValuePair(<span style="color: #ff0000;">"Fizz"</span>)))
                  .Concat(
                         listToConvert
                        .Where(WhereNeitherDivisable(fizzNumber, buzzNumber))
                        .Select(selectKeyValuePair(<span style="color: #ff0000;">"Nothing"</span>)));</pre>
<p>As you can see, I&#8217;ve used both Func fields and methods to return Funcs to clean up how this would look. I&#8217;ll even show what it would look like without this approach:</p>
<pre><span style="color: #0000ff;">var</span> result = listToConvert.Where(currentItem =&gt;
             IsDivisible(currentItem, fizzNumber) &amp;&amp; IsDivisible(currentItem, buzzNumber)
             ).Select(currentItem =&gt; new KeyValuePair(currentItem, <span style="color: #ff0000;">"FizzBuzz"</span>)).Concat(...</pre>
<p>Now I can totally admit that this second one I am showing is just ouch. So the first lesson to be learn is that Funcs and Methods that return Funcs can significantly clean up the Linq Method approach.</p>
<p>Now you could do the same with expressions:</p>
<pre> <span style="color: #0000ff;">var</span> fizzBuzz = <span style="color: #0000ff;">from</span> currentNumber <span style="color: #0000ff;">in</span> listToConvert
                <span style="color: #0000ff;">where</span> WhereBuzzDivisable(fizzNumber, buzzNumber)
                <span style="color: #0000ff;">select</span> selectKeyValuePair(<span style="color: #ff0000;">"FizzBuzz"</span>);

 <span style="color: #0000ff;">var</span> buzz = <span style="color: #0000ff;">from</span> currentNumber <span style="color: #0000ff;">in</span> listToConvert
            <span style="color: #0000ff;">where</span> WhereBuzzDivisable(fizzNumber, buzzNumber)
            <span style="color: #0000ff;">select</span> selectKeyValuePair(<span style="color: #ff0000;">"Buzz"</span>);

 <span style="color: #0000ff;">var</span> fizz = <span style="color: #0000ff;">from</span> currentNumber <span style="color: #0000ff;">in</span> listToConvert
            <span style="color: #0000ff;">where</span> WhereFizzDivisable(fizzNumber, buzzNumber)
            <span style="color: #0000ff;">select</span> selectKeyValuePair(<span style="color: #ff0000;">"Fizz"</span>);

<span style="color: #0000ff;">var</span> neither = <span style="color: #0000ff;">from</span> currentNumber <span style="color: #0000ff;">in</span> listToConvert
              <span style="color: #0000ff;">where</span> WhereNeitherDivisable(fizzNumber, buzzNumber)
              <span style="color: #0000ff;">select</span> selectKeyValuePair(<span style="color: #ff0000;">"Fizz"</span>);</pre>
<p>Ok so nice and pretty, but now what? Concatenation. This is where is gets ugly:</p>
<pre>  fizzBuzz.Concat(fizz.Concat(buzz.Concat(neither))));</pre>
<p>OR</p>
<pre> <span style="color: #0000ff;">var</span> fizzBuzz = <span style="color: #0000ff;">from</span> currentNumber <span style="color: #0000ff;">in</span> listToConvert
                <span style="color: #0000ff;">where</span> WhereBuzzDivisable(fizzNumber, buzzNumber)
                <span style="color: #0000ff;">select</span> selectKeyValuePair(<span style="color: #ff0000;">"FizzBuzz"</span>)
                .Concat(
                     <span style="color: #0000ff;">from</span> currentNumber <span style="color: #0000ff;">in</span> listToConvert
                     <span style="color: #0000ff;">where</span> WhereBuzzDivisable(fizzNumber, buzzNumber)
                     <span style="color: #0000ff;">select</span> selectKeyValuePair(<span style="color: #ff0000;">"Buzz"</span>))
                     .Concat(....);</pre>
<p>See what I&#8217;m getting at? The non expression one is looking a bit better now or maybe this is a fight to see which is less fugly. Now I admit that this may not be the best FizzBuzz solution, but it gives an example or where the Linq queries can go very wrong.</p>
]]></content:encoded>
			<wfw:commentRss>http://byatool.com/pontification/what-is-readable/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mulitple Constraint Generics and Test Base Classes</title>
		<link>http://byatool.com/test/mulitple-constraint-generics-and-test-base-classes/</link>
		<comments>http://byatool.com/test/mulitple-constraint-generics-and-test-base-classes/#comments</comments>
		<pubDate>Tue, 01 Jul 2008 12:23:00 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Test]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Generics]]></category>

		<guid isPermaLink="false">http://rockcityghost.wordpress.com/2008/07/01/mulitple-constraint-generics-and-test-base-classes/</guid>
		<description><![CDATA[This was basically an idea I had to have test classes inherit a TestBase that has a Static Create method on it. The reason for this is that I have found it easier to have a Create method that takes care of creating a temporary class of the type the test represents. Say I have [...]]]></description>
			<content:encoded><![CDATA[<p>This was basically an idea I had to have test classes inherit a TestBase that has a Static Create method on it. The reason for this is that I have found it easier to have a Create method that takes care of creating a temporary class of the type the test represents. Say I have a UserTest class and I need an address. Instead of creating and filling a whole address object in the UserTest, it easier to have a Create Method on the AddressTest class that gives me a premade Address object. Why would I want to redo a lot of the same code by having the create method on every class when I can have it on a base class and just have the non base classes specify how to create the object?</p>
<p>Is this really needed? I can&#8217;t argue absolutely, but this forces a Create method to appear on any test class that inherits from TestBase and by use of Exceptions, forces the child classes to define how to create the object they represent. (As in it forces AddressTest to define how to create an Address object.) This also allows the Create method to be static and inherited. You could make it abstract, to skip the need for the two create methods(Create and CreateInstance), but that would hose the whole situation since static abstract is a no no. Static is a must for this situation.</p>
<p>The idea behind the code is to have a static Create method on the TestBase class that when called will create the test class type passed in through generics.</p>
<pre><span style="color: #3333ff;">public static</span> I Create()
 {
     I returnValue;
     J testToUse;

     testToUse = System.<span style="color: #00cccc;">Activator</span>.CreateInstance&lt;J&gt;();
     returnValue = testToUse.CreateInstance();

     <span style="color: #3333ff;">return</span> returnValue;
 }</pre>
<p>Where J is the test class type to create. Once that test class is instantiated, the virtual method CreateInstance is called. This is where the test class creates the instance of the object it represents.</p>
<pre><span style="color: #3333ff;">protected override</span> I CreateInstance()
{
     I returnValue;

     returnValue = (I)<span style="color: #3333ff;">new</span> <span style="color: #00cccc;">SimpleItem</span>();
     returnValue.IsSimple = <span style="color: #3333ff;">true</span>;
     <span style="color: #3333ff;">return</span> returnValue;
}</pre>
<p>Where I is the type of object it is going to create. In use it will look something like this:</p>
<pre>  <span style="color: #00cccc;">ItemBase</span> itemToCreate;

  itemToCreate = <span style="color: #00cccc;">SimpleItemTest</span>&lt;<span style="color: #00cccc;">SimpleItem</span>&gt;.Create();</pre>
<p>Now for the code:</p>
<pre><span style="color: #009900;">//Some junk base items to demostrate the creating of an item with a base class</span>
<span style="color: #3333ff;">public class</span> <span style="color: #00cccc;">ItemBase </span>
{
}

<span style="color: #009900;">//One item that will be created</span>
<span style="color: #3333ff;">public class</span> <span style="color: #00cccc;">SimpleItem </span>: <span style="color: #00cccc;">ItemBase</span>
{
 <span style="color: #3333ff;">public </span><span style="color: #00cccc;">Boolean </span>IsSimple { <span style="color: #3333ff;">get</span>; <span style="color: #3333ff;">set</span>; }
}

<span style="color: #009900;">//The other item that can be created.</span>
<span style="color: #3333ff;">public class</span> <span style="color: #00cccc;">ComplexItem </span>: <span style="color: #00cccc;">ItemBase</span>
{
 <span style="color: #3333ff;">public</span> <span style="color: #00cccc;">Boolean </span>IsComplex { <span style="color: #3333ff;">get</span>; <span style="color: #3333ff;">set</span>; }
 <span style="color: #3333ff;">public</span> <span style="color: #00cccc;">Boolean </span>IsNotSimple { <span style="color: #3333ff;">get</span>; <span style="color: #3333ff;">set</span>; }
}

<span style="color: #009900;">//This test will be used to create a SimpleItem</span>
<span style="color: #3333ff;">public class</span> <span style="color: #00cccc;">SimpleItemTest</span>&lt;I&gt;<span style="color: #00cccc;"> </span>: <span style="color: #00cccc;">TestBase</span>&lt;I, <span style="color: #00cccc;">SimpleItemTest</span>&lt;I&gt;&gt; <span style="color: #3333ff;">where</span> I : <span style="color: #00cccc;">SimpleItem</span>
{
 <span style="color: #3333ff;">protected override</span> I CreateInstance()
 {
     I returnValue;

     returnValue = (I)<span style="color: #3333ff;">new</span> <span style="color: #00cccc;">SimpleItem</span>();
     returnValue.IsSimple = <span style="color: #3333ff;">true</span>;
     <span style="color: #3333ff;">return</span> returnValue;
 }
}

<span style="color: #009900;">//This test will be used to create a ComplexItem</span>
<span style="color: #3333ff;">public class</span> <span style="color: #00cccc;">ComplexItemTest</span>&lt;I&gt; : <span style="color: #00cccc;">TestBase</span>&lt;I, <span style="color: #00cccc;">ComplexItemTest</span>&lt;I&gt;&gt; <span style="color: #3333ff;">where</span> I : <span style="color: #00cccc;">ComplexItem</span>
{
 <span style="color: #3333ff;">protected override</span> I CreateInstance()
 {
     I returnValue;

     returnValue = (I)<span style="color: #3333ff;">new</span> ComplexItem();
     returnValue.IsComplex = <span style="color: #3333ff;">true</span>;
     returnValue.IsNotSimple = <span style="color: #3333ff;">true</span>;
     <span style="color: #00cccc;">return</span> returnValue;
 }
}

<span style="color: #009900;">//This is the base class where the Create Method resides</span>
<span style="color: #3333ff;">public class</span> <span style="color: #00cccc;">TestBase</span>&lt;I, j&gt; <span style="color: #3333ff;">where</span> I : <span style="color: #3333ff;">class</span> <span style="color: #3333ff;">where</span> J : <span style="color: #00cccc;">TestBase</span>&lt;I, j&gt;
{
 <span style="color: #009900;">//This will either be overridden or throw an error.  Kind of a forced</span>
<span style="color: #009900;"> //abstract.  This is the method that the child test classes will use to</span>
<span style="color: #009900;"> //create whatever class they represent.</span>
 <span style="color: #3333ff;">protected</span> <span style="color: #3333ff;">virtual</span> I CreateInstance()
 {
     <span style="color: #3333ff;">throw</span> <span style="color: #3333ff;">new</span> System.<span style="color: #00cccc;">NotImplementedException</span>();
 }

 <span style="color: #009900;">//This is used to create a test class and call the CreateInstance method</span>
<span style="color: #009900;"> //so that this method can return the correct object.  The object type is</span>
<span style="color: #009900;"> //dependent on the type of test class that is being created.</span>
 <span style="color: #3333ff;">public static</span> I Create()
 {
     I returnValue;
     J testToUse;

     testToUse = System.<span style="color: #00cccc;">Activator</span>.CreateInstance&lt;J&gt;();
     returnValue = testToUse.CreateInstance();

     <span style="color: #3333ff;">return</span> returnValue;
 }
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://byatool.com/test/mulitple-constraint-generics-and-test-base-classes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Test Projects and Unit Tests In Visual Studio 2008</title>
		<link>http://byatool.com/test/test-projects-and-unit-tests-part-1/</link>
		<comments>http://byatool.com/test/test-projects-and-unit-tests-part-1/#comments</comments>
		<pubDate>Mon, 30 Jun 2008 12:52:00 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Test]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Project]]></category>

		<guid isPermaLink="false">http://rockcityghost.wordpress.com/2008/06/30/test-projects-and-unit-tests-part-1/</guid>
		<description><![CDATA[A quick thing about setting up test projects through Visual Studios&#8230; basically how to do so. Add new Project -&#62; Test (Project Types) -&#62; Test Project. Now the easiest way I&#8217;ve added actual tests is just to add a normal class. Say SomeClassTest. using Microsoft.VisualStudio.TestTools.UnitTesting; [TestClass] public class SomeClassTest() { [TestMethod] public void SomeClass_CreateWithNull() { [...]]]></description>
			<content:encoded><![CDATA[<p>A quick thing about setting up test projects through Visual Studios&#8230; basically how to do so.</p>
<p>Add new Project -&gt; Test (Project Types) -&gt; Test Project.</p>
<p>Now the easiest way I&#8217;ve added actual tests is just to add a normal class. Say SomeClassTest.</p>
<pre><strong>
using Microsoft.VisualStudio.TestTools.UnitTesting;

[TestClass]
public class SomeClassTest()
{
   [TestMethod]
   public void SomeClass_CreateWithNull()
   {
   }
}
</strong></pre>
<p>What is [TestClass]? Well that is an attribute you are adding to the class so that .net knows certain methods in it may be test methods. Guess what [TestMethod] does&#8230;</p>
<p>Ok so now I have a TestClass and TestMethod, now what? Well in the menu:</p>
<p>Test -&gt; Windows -&gt; TestView</p>
<p>You should see that your method now shows up on the list. Simple huh? If the method isn&#8217;t showing up on the list make sure it is:</p>
<ul>
<li>Tagged with the [TestMethod] attribute</li>
<li>Contained in a PUBLIC [TestClass]</li>
<li>Public</li>
<li>void</li>
<li>Non static</li>
</ul>
<p>If you have all of those and still nothing, right click the method name in the Test View and look at it&#8217;s properties. There is a property called &#8220;Non-Runnable Error&#8221;. This will tell you what you need to get it rolling.</p>
<p>All right, now you have everything set&#8230; so next? Simple, right click the method name in the Test View and you can either Run or Debug the test. If you just Run the test, the Test Results window will pop up and you&#8217;ll see the progress. If it passes, then yay. If not, it will give you things unhandled/expected exception, failed asserts, and expected exceptions. If you debug, the same happens except, CRAZY SURPRISE AHEAD!!!, you can step through it. Also, you can run multiple tests by selecting however many you want and running them.</p>
<p>There are some useful options in the test view. If you right click the column area, you can add columns such as Class Name to help with ordering. After all, you might have a bunch of methods that are named the same in different classes, which sucks. Another thing you can do is left click the down arrow to the right of the refresh button for group by options.</p>
<p><em>End Note: If you don&#8217;t recognize the word &#8220;attribute&#8221; that&#8217;s ok. Most likely you have seen the [Something] notation before if you have used web controls (Possibly winforms controls, no idea). Simply put, attributes are like attaching extra information to just about anything so that later on you can use that information at runtime to perform actions. With the use of reflection, you could, for instance, check for only specific properties on a class that you want to fill dynamically. Say you have a dataset with the &#8220;UserName&#8221; column and a User class with the property Name. If you wanted to fill that Name property normally you could do something like:</em></p>
<pre><strong>
user.Name = dataset["UserName"];
</strong></pre>
<p><em><br />
but with relfection you could get the property info, check the properties for a the ones with a certain attribute, and match the value in the attribute to the column name.<br />
</em></p>
]]></content:encoded>
			<wfw:commentRss>http://byatool.com/test/test-projects-and-unit-tests-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hashing and you</title>
		<link>http://byatool.com/general-coding/hashing-and-you/</link>
		<comments>http://byatool.com/general-coding/hashing-and-you/#comments</comments>
		<pubDate>Fri, 27 Jun 2008 14:53:00 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[General Coding]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Hash]]></category>
		<category><![CDATA[Password]]></category>

		<guid isPermaLink="false">http://rockcityghost.wordpress.com/2008/06/27/hashing-and-you/</guid>
		<description><![CDATA[This is really simple, but don&#8217;t feel bad if you didn&#8217;t know about this. No one tells me nothin&#8217; either. The other day while reading through a blog, I got schooled without going to class. I had no idea that passwords should be one way only, as in you shouldn&#8217;t be able to retrieve a [...]]]></description>
			<content:encoded><![CDATA[<p>This is really simple, but don&#8217;t feel bad if you didn&#8217;t know about this. No one tells me nothin&#8217; either.</p>
<p>The other day while <a href="http://www.codinghorror.com/blog/archives/001140.html">reading through a blog, </a>I got schooled without going to class. I had no idea that passwords should be one way only, as in you shouldn&#8217;t be able to retrieve a forgotten password, only reset it. Well shoot, I missed that one. So they start talking about hashing the password and saving that. Good thing I had built something to hash request items in a url to help stop people with screwing with a site url. Well ok, I didn&#8217;t totally build it. I got the idea from somewhere else. But I f-ing integrated it so don&#8217;t look at me like that.</p>
<p>Basically you take a password, add a salt (fancy name for a predetermined string or number) to the password, and get the hash value for that.</p>
<p><em>Why getting the same hash everytime sucks</em></p>
<p>Well the problem with hashing, or really the reason why we are doing this, is that the word &#8220;pass&#8221; creates the same hash value every time. Now if some sort of mean person figures out the hash for &#8220;pass&#8221; (That isn&#8217;t too hard since most people use some sort of standard like the .net MD5CryptoServiceProvider), he/she could search for a slew of typical password words. See the problem? Now enters the salt. The salt is some word that you come up with to add anywhere you want. This makes it a little difficult to figure out since the word &#8220;passSalt&#8221; is no longer like &#8220;pass&#8221;. one could try every word known and still fail because said person doesn&#8217;t know to add the word &#8220;Salt&#8221;.</p>
<p><em>Why getting the same hash everytime is great:</em></p>
<p>Right now you might be wonder what the point of having a password saved that can&#8217;t be unhashed to check against. Easy, you don&#8217;t have to unhash. Since the hash for &#8220;passSalt&#8221; will always be the same, the password in the database will always match the entered password + the salt. So basically the user enters the password, the system adds the salt to the password, the system then gets the hash, and finally checks that against the database record. Fun huh?</p>
<p>Now for the code:</p>
<pre><strong>
public class HashString
{
 private const String DEFAULT_SALT = "8745";

 public static String CreateHash(String originalValue, String salt)
 {
   Byte[] computedHash;
   StringBuilder hashedValues;
   StringBuilder hashString;

   <span style="color: #009900;">//Take the string and append your "secret" string at the end.</span>
   hashString = new StringBuilder(originalValue);
   hashString.Append(salt);

   <span style="color: #009900;">//Get the hash for the new word.</span>
   computedHash = new MD5CryptoServiceProvider().ComputeHash(Encoding.UTF8.GetBytes(hashString.ToString()));
   hashedValues = new StringBuilder();

   <span style="color: #009900;">//Go through computedHash and create a string from it.</span>
   computedHash.ToList().ForEach(currentItem =&gt;
ashedValues.Append(currentItem.ToString("x2")));

   return hashedValues.ToString();
 }

 //Not needed overload, just have it here for ease of use
 public static String CreateHash(String originalValue)
 {
   return CreateHash(originalValue, DEFAULT_SALT);
 }
}
</strong></pre>
<p>And I even have a test for you&#8230; if you have VS Professional or higher. If not, no big deal. Just remove the asserts, attributes, and step through.</p>
<pre><strong>
[TestClass]
public class HashStringTest
{
 private class UserTable
 {
   private const String SALT_VALUE = "SomeValue";
   private List table;

   public UserTable()
   {
     table = new List();
   }

   public void AddUser(String password, String userName)
   {
     table.Add(new UserRow(){Password = HashString.CreateHash(password, SALT_VALUE), UserName = userName});
   }

   public Boolean UserExists(String password, String userName)
   {
     String hashedPassword;

     hashedPassword = HashString.CreateHash(password, SALT_VALUE);

     var query = from user in table
                 where user.Password == hashedPassword &amp;&amp; user.UserName == userName
                 select user;

     return query.ToList().Count == 1;
   }

   private class UserRow
   {
     public String Password { get; set; }
     public String UserName { get; set; }
   }
 }

 [TestMethod]
 public void CreateHash_PasswordMatchPass()
 {
   UserTable table;
   String userName;
   String goodPassword;
   String failedPassword;

   userName = "SomeUser";
   goodPassword = "goodPassword";

   table = new UserTable();
   table.AddUser(goodPassword, userName);
   Assert.IsTrue(table.UserExists(goodPassword, userName));

   failedPassword = "failedPassword";
   Assert.IsFalse(table.UserExists(userName, failedPassword));
 }
}
</strong></pre>
<p>And last, the namespaces:</p>
<pre><strong>
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
using Microsoft.VisualStudio.TestTools.UnitTesting;
</strong></pre>
<p>For the record, I hate the word salt in this use.</p>
]]></content:encoded>
			<wfw:commentRss>http://byatool.com/general-coding/hashing-and-you/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Random String of Specified Length with Enumerable</title>
		<link>http://byatool.com/utilities/random-string-of-specified-length-with-enumerable/</link>
		<comments>http://byatool.com/utilities/random-string-of-specified-length-with-enumerable/#comments</comments>
		<pubDate>Thu, 26 Jun 2008 16:30:00 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Utilities]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Random]]></category>
		<category><![CDATA[String]]></category>

		<guid isPermaLink="false">http://rockcityghost.wordpress.com/2008/06/26/random-string-of-specified-length-with-enumerable/</guid>
		<description><![CDATA[using System; using System.Collections.Generic; using System.Linq; using System.Text; public static String RandomString(Int32 length) { Random randomGenerator; String returnValue; randomGenerator = new Random(); returnValue = new string(Enumerable.Range(0, length).Select(i =&#62; (char)('A' + randomGenerator.Next(0, 25))).ToArray()); return returnValue; } What this does: Enumerable.Range basically says, &#8220;Give me a collection of numbers from the first parameter to the second&#8221;, or [...]]]></description>
			<content:encoded><![CDATA[<pre><strong>
<span style="color: #33cccc;">using</span> System;
<span style="color: #33cccc;">using</span> System.Collections.Generic;
<span style="color: #33cccc;">using</span> System.Linq;
<span style="color: #33cccc;">using</span> System.Text;

<span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #33cccc;">String</span> RandomString(<span style="color: #33cccc;">Int32</span> length)
{
 <span style="color: #33cccc;">Random</span> randomGenerator;
 <span style="color: #33cccc;">String</span> returnValue;

  randomGenerator = <span style="color: #0000ff;">new</span> <span style="color: #33cccc;">Random</span>();

  returnValue = <span style="color: #0000ff;">new</span> <span style="color: #0000ff;">string</span>(<span style="color: #33cccc;">Enumerable</span>.Range(0, length).Select(i =&gt; (<span style="color: #0000ff;">char</span>)(<span style="color: #ff0000;">'A'</span> + randomGenerator.Next(0, 25))).ToArray());

 <span style="color: #0000ff;">return</span> returnValue;
}
</strong></pre>
<p>What this does:</p>
<p>Enumerable.Range basically says, &#8220;Give me a collection of numbers from the first parameter to the second&#8221;, or in this case from 0 to length.</p>
<p>Select basically is a method that takes in an anonymous method (Lamdba expression in this case), goes through each of the items in the collection, and runs the anonymous method for every item in the collection. Not exactly sure what Select does specifically, but it is most likely something like this: (roughish psuedo code)</p>
<pre><strong>
<span style="color: #33cccc;">public</span> <span style="color: #0000ff;">static</span> Array Select(<span style="color: #33cccc;">Func</span> func))
{

 <span style="color: #33cccc;">Array</span> returnValue;

 <span style="color: #0000ff;">foreach</span>(<span style="color: #33cccc;">Int32</span> currentItem <span style="color: #0000ff;">in</span> Items)
 {
    returnValue.Add(func());
 }

 return returnValue;

}
</strong></pre>
<p>Where Func is:</p>
<pre><strong>
<span style="color: #0000ff;">public</span> <span style="color: #33cccc;">Char</span> Func()
{
 return  (<span style="color: #0000ff;">char</span>)(<span style="color: #ff0000;">'A'</span> + randomGenerator.Next(0, 25);
}
</strong></pre>
]]></content:encoded>
			<wfw:commentRss>http://byatool.com/utilities/random-string-of-specified-length-with-enumerable/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Random Enumeration Generator with Generics</title>
		<link>http://byatool.com/general-coding/random-enumeration-generator-with-generics/</link>
		<comments>http://byatool.com/general-coding/random-enumeration-generator-with-generics/#comments</comments>
		<pubDate>Wed, 25 Jun 2008 21:04:00 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[General Coding]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Enumeration]]></category>
		<category><![CDATA[Random]]></category>

		<guid isPermaLink="false">http://rockcityghost.wordpress.com/2008/06/25/random-enumeration-generator-with-generics/</guid>
		<description><![CDATA[public static I RandomEnumeration&#60;I&#62;() { I enumerationToCheck; Int32 indexToUse; String[] names; //Use activator to create an instance of the type I enumerationToCheck = System.Activator.CreateInstance&#60;I&#62;(); //Make sure the instance is an Enumeration //Unfortunately you can't check that in the method //delcaring using "which". if (enumerationToCheck as Enum == null) { throw new InvalidOperationException(); } //Get the [...]]]></description>
			<content:encoded><![CDATA[<pre><strong>
public static I RandomEnumeration&lt;I&gt;()
{
  I enumerationToCheck;
  Int32 indexToUse;
  String[] names;

  <span style="color: #009900;">//Use activator to create an instance of the type I</span>
  enumerationToCheck = System.Activator.CreateInstance&lt;I&gt;();

  <span style="color: #009900;">//Make sure the instance is an Enumeration</span>
<span style="color: #009900;">   //Unfortunately you can't check that in the method </span>
<span style="color: #009900;">   //delcaring using "which".</span>
  if (enumerationToCheck as Enum == null)
  {
    throw new InvalidOperationException();
  }

  <span style="color: #009900;">//Get the list of the enumeration item names</span>
  names = Enum.GetNames(typeof(I));

  if (names.Length &gt; 0)
  {
    <span style="color: #009900;">//Grab a random name within the boundaries of the</span>
<span style="color: #009900;">     //names collection.</span>
    indexToUse = RandomInt32(0, names.Length);
    <span style="color: #009900;">//parse the name to create the random enum</span>
    enumerationToCheck = (I)Enum.Parse(typeof(I), names[indexToUse]);
  }

  return enumerationToCheck;

}
</strong></pre>
<p>Usage:</p>
<pre><strong>
  SomeEnum test = RandomEnumeration();
</strong></pre>
<p>Why bother? For unit testing and creating test classes. Possibly<br />
for defaults on an enumeration, but not really needed since<br />
they are value types. Oh yeah AND BECAUSE I FELT LIKE IT. I don&#8217;t<br />
have to explain myself to you.</p>
]]></content:encoded>
			<wfw:commentRss>http://byatool.com/general-coding/random-enumeration-generator-with-generics/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

