<?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>Mason McCuskey &#187; c#</title>
	<atom:link href="http://www.masonmc.com/category/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.masonmc.com</link>
	<description>Mason's  blog</description>
	<lastBuildDate>Mon, 26 Apr 2010 18:49:43 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Never Code Tired</title>
		<link>http://www.masonmc.com/2009/never-code-tired/</link>
		<comments>http://www.masonmc.com/2009/never-code-tired/#comments</comments>
		<pubDate>Sun, 30 Aug 2009 15:49:25 +0000</pubDate>
		<dc:creator>mason</dc:creator>
				<category><![CDATA[CuttlefishEngine]]></category>
		<category><![CDATA[c#]]></category>

		<guid isPermaLink="false">http://www.masonmc.com/?p=200</guid>
		<description><![CDATA[Never try to calculate the bounding rectangle of a circle when you&#8217;re tired, distracted, or less than fully sober. I must have been some combination of all three of those when I wrote this masterpiece:

public override RectangleF BoundingRect
{
  get
  {
    float x = WorldPos.X - (m_radius / 2.0f);
   [...]]]></description>
			<content:encoded><![CDATA[<p>Never try to calculate the bounding rectangle of a circle when you&#8217;re tired, distracted, or less than fully sober. I must have been some combination of all three of those when I wrote this masterpiece:</p>
<pre class="brush: csharp">
public override RectangleF BoundingRect
{
  get
  {
    float x = WorldPos.X - (m_radius / 2.0f);
    float y = WorldPos.Y - (m_radius / 2.0f);
    return new RectangleF(x, y, m_radius, m_radius);
  }
}
</pre>
<p>I spent an hour this morning wondering why my mouse click code thought my circles were half as big as they were.  Sigh.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.masonmc.com/2009/never-code-tired/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Loving The Lambda as Predicate</title>
		<link>http://www.masonmc.com/2009/loving-the-lambda-as-predicate/</link>
		<comments>http://www.masonmc.com/2009/loving-the-lambda-as-predicate/#comments</comments>
		<pubDate>Sun, 28 Jun 2009 03:17:26 +0000</pubDate>
		<dc:creator>mason</dc:creator>
				<category><![CDATA[c#]]></category>

		<guid isPermaLink="false">http://www.masonmc.com/?p=167</guid>
		<description><![CDATA[Old and busted:

public State FindByName(string name)
{
  foreach(State thisState in this.StateList)
  {
    if (string.Compare(thisState.Name, name) == 0)
    {
      return thisState;
    }
  }
  return null;
}

New Hotness:

public State FindByName(string name)
{
  return States.Find(
    state => (string.Compare(state.Name, name) [...]]]></description>
			<content:encoded><![CDATA[<p>Old and busted:</p>
<pre class="brush: csharp">
public State FindByName(string name)
{
  foreach(State thisState in this.StateList)
  {
    if (string.Compare(thisState.Name, name) == 0)
    {
      return thisState;
    }
  }
  return null;
}
</pre>
<p>New Hotness:</p>
<pre class="brush: csharp">
public State FindByName(string name)
{
  return States.Find(
    state => (string.Compare(state.Name, name) == 0)
  );
}
</pre>
<p>Sweet sweet syntactic sugar!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.masonmc.com/2009/loving-the-lambda-as-predicate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XmlInclude getting ignored</title>
		<link>http://www.masonmc.com/2008/xmlinclude-getting-ignored/</link>
		<comments>http://www.masonmc.com/2008/xmlinclude-getting-ignored/#comments</comments>
		<pubDate>Sun, 14 Dec 2008 08:35:44 +0000</pubDate>
		<dc:creator>mason</dc:creator>
				<category><![CDATA[c#]]></category>

		<guid isPermaLink="false">http://masonmc.com/?p=99</guid>
		<description><![CDATA[So, when pointing the XmlSerializer at a document that contains a list of abstract base objects, I came across a fairly standard exception:
System.InvalidOperationException: There was an error generating the XML document. System.InvalidOperationException: The type  was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically.
But, even after I [...]]]></description>
			<content:encoded><![CDATA[<p>So, when pointing the XmlSerializer at a document that contains a list of abstract base objects, I came across a fairly standard exception:</p>
<blockquote><p>System.InvalidOperationException: There was an error generating the XML document. System.InvalidOperationException: The type <whatever> was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically.</p></blockquote>
<p>But, even after I put in the XmlIncludes, OR when using the serializer constructor overload that takes a list of types, I was still getting the error.</p>
<p>Turns out my problem, strangely, was this line:</p>
<pre class="brush: csharp">[XmlRootAttribute(
  "Document",
  Namespace = "http://www.cuttlefishindustries.com/mycoolnamespace",
  IsNullable = false)]</pre>
<p>I didn&#8217;t investigate it that much but it appears that if you specify a Namespace, the serializer ignores the additional types you supply (either via XmlInclude or the constructor overload).  Once I took out my document&#8217;s XML root attribute, my serializer worked.  Huh.  So, there ya go, hopefully this&#8217;ll save someone some time, sometime.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.masonmc.com/2008/xmlinclude-getting-ignored/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting System Colors In C#</title>
		<link>http://www.masonmc.com/2008/getting-system-colors-in-c/</link>
		<comments>http://www.masonmc.com/2008/getting-system-colors-in-c/#comments</comments>
		<pubDate>Sun, 29 Jun 2008 18:17:46 +0000</pubDate>
		<dc:creator>mason</dc:creator>
				<category><![CDATA[c#]]></category>
		<category><![CDATA[GetSysColor]]></category>
		<category><![CDATA[system colors]]></category>

		<guid isPermaLink="false">http://www.masonmc.com/2008/getting-system-colors-in-c/</guid>
		<description><![CDATA[*** READ THE COMMENTS!  I have been enlightened.   ***
Maybe it&#8217;s just me, but it took me forever to figure out how to set the background color of a control to the &#8220;window&#8221; color the user has set up in the control panel.  99% of the time this is white but since [...]]]></description>
			<content:encoded><![CDATA[<p><strong>*** READ THE COMMENTS!  I have been enlightened. <img src='http://www.masonmc.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ***</strong></p>
<p>Maybe it&#8217;s just me, but it took me forever to figure out how to set the background color of a control to the &#8220;window&#8221; color the user has set up in the control panel.  99% of the time this is white but since I&#8217;m one of those guys who runs with dark window colors, I was determined not to make that assumption and do things the right way.</p>
<p><strong>Ways you can&#8217;t do it:</strong></p>
<ul>
<li><strong>System.Windows.Forms.SystemInformation</strong>: You can get a wealth of information from here, including whether or not the user has chosen to always show pull-down menu access key underlines, or only when ALT is held&#8230; but no color information.  Close, but no cigar.</li>
<li><strong>Color.System.<whatever></strong>: all the other colors live here.  I was hoping for a &#8220;System&#8230;&#8221; subsection under here or at least names like &#8220;ActiveBorder&#8221; intermingled with &#8220;hard coded&#8221; names (Lemon Chiffon!), but couldn&#8217;t find any.</li>
<li><strong>Control.DefaultBackColor</strong>: So close!  This appears to return the 3D face color, but regardless isn&#8217;t what I was looking for.  I want a big list of all the system colors, not just a one-off.</li>
</ul>
<p><strong>The Way:<br />
</strong><br />
System colors, in C#, are called &#8220;known colors.&#8221;  Once you know this it&#8217;s easy to find:</p>
<p><strong>System.Drawing.Color.FromKnownColor(KnownColor.Window);</strong></p>
<p>And, as you&#8217;d expect, the KnownColor enumeration contains all of the other user-definable colors (active window border, whatever).</p>
<p>I don&#8217;t understand the logic behind calling these colors &#8220;known colors.&#8221;  If anything, Lemon Chiffon is a Known Color (well, OK maybe not to all of us, but to interior decorators at least), and the current window color is Unknown, or at least &#8220;user-defined.&#8221;  But even more perplexing is why C# deviates from calling them &#8220;system colors.&#8221; In Win32 you&#8217;d call GetSysColor() (and truth be told, I almost just pinvoked that).  KnownColors is a wart that detracts from the beautiful organization of C# in other places (for example, Process or System.IO.Ports).</p>
<p>If I were running the C# show, I would have put the system colors in with the rest of the system information.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.masonmc.com/2008/getting-system-colors-in-c/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Tidying up the C# Output Window</title>
		<link>http://www.masonmc.com/2008/tidying-up-the-c-output-window/</link>
		<comments>http://www.masonmc.com/2008/tidying-up-the-c-output-window/#comments</comments>
		<pubDate>Sun, 22 Jun 2008 16:18:47 +0000</pubDate>
		<dc:creator>mason</dc:creator>
				<category><![CDATA[IntlConspiracy]]></category>
		<category><![CDATA[c#]]></category>

		<guid isPermaLink="false">http://www.masonmc.com/2008/tidying-up-the-c-output-window/</guid>
		<description><![CDATA[So I&#8217;m working on this XNA game and have recently become annoyed with the amount of absolute garbage that appears in the output window.  Check this out:

The top line is where I start the build, and the bottom line is the first error from the complation.  But everything in between is completely useless. [...]]]></description>
			<content:encoded><![CDATA[<p>So I&#8217;m working on this XNA game and have recently become annoyed with the amount of absolute garbage that appears in the output window.  Check this out:</p>
<p><a href='http://www.masonmc.com/wp-content/uploads/2008/06/csgarbage.png' title='garbage in the output window'><img src='http://www.masonmc.com/wp-content/uploads/2008/06/csgarbage.png' alt='garbage in the output window' /></a></p>
<p>The top line is where I start the build, and the bottom line is the first error from the complation.  But everything in between is completely useless. Specifically it looks like an echo of the command line for the C# compiler (csc) &#8211; the bulk of which is just all the CS files to compile.</p>
<p>That&#8217;s annoying, but what&#8217;s worse is that when you hit F4 to go to your first error the IDE takes you to this line instead.  This morning, after working in c# for almost 3 years, for some reason, I just couldn&#8217;t take it anymore.  </p>
<p>As it turns out the &#8220;magic option&#8221; is here:</p>
<p><img src='http://www.masonmc.com/wp-content/uploads/2008/06/msbuildsetting.png' alt='Magic MSBuild Option' /></p>
<p>By default the &#8220;MSBuild Project Build Output Verbosity&#8221; setting is &#8220;Minimal,&#8221; which for me isn&#8217;t nearly minimal enough.  Set it to Quiet and behold:</p>
<p><img src='http://www.masonmc.com/wp-content/uploads/2008/06/cleanmsbuild.png' alt='nice and clean output window' /></p>
<p>I am kind of terrified to see what the &#8220;Diagnostic&#8221; setting would do to my poor output window.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.masonmc.com/2008/tidying-up-the-c-output-window/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
