<?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>The Blog of Zachary Snow</title>
	<atom:link href="http://zacharysnow.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://zacharysnow.net</link>
	<description></description>
	<lastBuildDate>Sun, 15 Aug 2010 18:02:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Nystrom&#8217;s Programming Patterns</title>
		<link>http://zacharysnow.net/2010/08/13/nystroms-programming-patterns/</link>
		<comments>http://zacharysnow.net/2010/08/13/nystroms-programming-patterns/#comments</comments>
		<pubDate>Fri, 13 Aug 2010 15:50:24 +0000</pubDate>
		<dc:creator>Zachary</dc:creator>
				<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[game-programming-patterns]]></category>

		<guid isPermaLink="false">http://zacharysnow.net/?p=343</guid>
		<description><![CDATA[I was reading the Scientific Ninja Blog this morning and he has posted a link to an in progress site / book by Robert Nystrom about game programming patterns. It&#8217;s not complete yet but it&#8217;s quite an interesting read to say the least. Game Programming Patterns]]></description>
			<content:encoded><![CDATA[<p>I was reading the <a href="http://scientificninja.com/blog/nystroms-programming-patterns">Scientific Ninja Blog</a> this morning and he has posted a link to an in progress site / book by <a href="http://twitter.com/munificentbob">Robert Nystrom</a> about game programming patterns. It&#8217;s not complete yet but it&#8217;s quite an interesting read to say the least.</p>
<p><a href="http://gameprogrammingpatterns.com/">Game Programming Patterns</a></p>
]]></content:encoded>
			<wfw:commentRss>http://zacharysnow.net/2010/08/13/nystroms-programming-patterns/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Visual Studio: Move referenced DLL to different directory after Build</title>
		<link>http://zacharysnow.net/2010/07/20/visual-studio-move-referenced-dll-to-different-directory-after-build/</link>
		<comments>http://zacharysnow.net/2010/07/20/visual-studio-move-referenced-dll-to-different-directory-after-build/#comments</comments>
		<pubDate>Tue, 20 Jul 2010 17:16:37 +0000</pubDate>
		<dc:creator>Zachary</dc:creator>
				<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://zacharysnow.net/?p=337</guid>
		<description><![CDATA[If you need to move a referenced DLL to a different directory after build, add these commands to the &#8220;Post Build event command line&#8221; box in the &#8220;Build Events&#8221; tab of the project properties: mkdir $(TargetDir)dir move $(TargetDir)myDLL.dll $(TargetDir)dir\myDLL.dll]]></description>
			<content:encoded><![CDATA[<p>If you need to move a referenced DLL to a different directory after build, add these commands to the &#8220;<strong>Post Build event command line</strong>&#8221; box in the &#8220;<strong>Build Events</strong>&#8221; tab of the project properties:</p>
<pre name="code">
mkdir $(TargetDir)dir
move $(TargetDir)myDLL.dll $(TargetDir)dir\myDLL.dll
</pre>
]]></content:encoded>
			<wfw:commentRss>http://zacharysnow.net/2010/07/20/visual-studio-move-referenced-dll-to-different-directory-after-build/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Xna: Load Texture2D from Embedded Resource</title>
		<link>http://zacharysnow.net/2010/07/03/xna-load-texture2d-from-embedded-resource/</link>
		<comments>http://zacharysnow.net/2010/07/03/xna-load-texture2d-from-embedded-resource/#comments</comments>
		<pubDate>Sat, 03 Jul 2010 10:46:07 +0000</pubDate>
		<dc:creator>Zachary</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[XNA]]></category>

		<guid isPermaLink="false">http://zacharysnow.net/?p=338</guid>
		<description><![CDATA[If you&#8217;re writing an app which uses Xna, you may need to load a texture from an embedded resource. Here&#8217;s how: First embed the resource in your app. Do so by choosing Embedded Resource as the Build Action in the properties of the resource. After that you can load the Texture2D using a stream handle]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re writing an app which uses Xna, you may need to load a texture from an embedded resource. Here&#8217;s how:</p>
<p>First embed the resource in your app. Do so by choosing <strong>Embedded Resource</strong> as the <strong>Build Action</strong> in the properties of the resource.</p>
<p><a href="http://zacharysnow.net/wp-content/uploads/2010/07/embed-resource.png"><img src="http://zacharysnow.net/wp-content/uploads/2010/07/embed-resource.png" alt="Properties Dialog for a File" title="embed-resource" width="281" height="175" class="alignnone size-full wp-image-339" /></a></p>
<p>After that you can load the <strong>Texture2D</strong> using a stream handle to the embedded file.</p>
<pre name="code" class="c#">
Stream stream = Assembly.GetCallingAssembly().GetManifestResourceStream("AppNamespace.Folder.font.bmp");
return Texture2D.FromFile(graphicsDevice, stream);
</pre>
<p><strong>GetCallingAssembly()</strong> can be exchanged with <strong>GetExecutingAssembly()</strong> if needed. The name of the resource must be fully qualified with the app&#8217;s namespace and folders. I usually keep my resources in a folder <strong>Resources</strong> so I would have: AppNamespace.Resources.font.bmp.</p>
]]></content:encoded>
			<wfw:commentRss>http://zacharysnow.net/2010/07/03/xna-load-texture2d-from-embedded-resource/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Same Game Xna 2.0 Alpha</title>
		<link>http://zacharysnow.net/2010/06/29/same-game-xna-2-0-alpha/</link>
		<comments>http://zacharysnow.net/2010/06/29/same-game-xna-2-0-alpha/#comments</comments>
		<pubDate>Tue, 29 Jun 2010 16:31:29 +0000</pubDate>
		<dc:creator>Zachary</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://zacharysnow.net/?p=334</guid>
		<description><![CDATA[I&#8217;ve released what I&#8217;m calling the 2.0 alpha version of Same Game Xna. Codeplex Project Link Release Link]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve released what I&#8217;m calling the 2.0 alpha version of Same Game Xna.</p>
<p><a href="http://zacharysnow.net/wp-content/uploads/2010/06/SameGameXna-2.0-alpha.png"><img src="http://zacharysnow.net/wp-content/uploads/2010/06/SameGameXna-2.0-alpha-150x150.png" alt="" title="SameGameXna-2.0-alpha" width="150" height="150" class="alignnone size-thumbnail wp-image-335" /></a></p>
<p><a href="http://samegamexna.codeplex.com/">Codeplex Project Link</a><br />
<a href="http://samegamexna.codeplex.com/releases/view/47975">Release Link</a></p>
]]></content:encoded>
			<wfw:commentRss>http://zacharysnow.net/2010/06/29/same-game-xna-2-0-alpha/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Implementing basic Dependency Injection using a Service Container</title>
		<link>http://zacharysnow.net/2010/06/21/implementing-basic-dependency-injection-using-services-container/</link>
		<comments>http://zacharysnow.net/2010/06/21/implementing-basic-dependency-injection-using-services-container/#comments</comments>
		<pubDate>Mon, 21 Jun 2010 19:09:14 +0000</pubDate>
		<dc:creator>Zachary</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Dependency Injection]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[dependency-injection]]></category>
		<category><![CDATA[design-patterns]]></category>
		<category><![CDATA[service-continer]]></category>

		<guid isPermaLink="false">http://zacharysnow.net/?p=321</guid>
		<description><![CDATA[By extending your Service Container class, a very basic version of dependency injection can be implemented. We&#8217;ll implement two forms of dependency injection: constructor and property injection. We&#8217;ll start by defining the Injectable attribute. [AttributeUsage(AttributeTargets.Constructor &#124; AttributeTargets.Property, AllowMultiple = false, Inherited = true)] public class InjectableAttribute : Attribute { } We&#8217;ll use this attribute to]]></description>
			<content:encoded><![CDATA[<p>By extending your Service Container class, a very basic version of dependency injection can be implemented. We&#8217;ll implement two forms of dependency injection: constructor and property injection. </p>
<p><span id="more-321"></span></p>
<p>We&#8217;ll start by defining the <strong>Injectable</strong> attribute. </p>
<pre name="code" class="c#">
[AttributeUsage(AttributeTargets.Constructor | AttributeTargets.Property,
	AllowMultiple = false, Inherited = true)]
public class InjectableAttribute : Attribute
{
}
</pre>
<p>We&#8217;ll use this attribute to mark our constructors and properties for dependency injection. Next we&#8217;ll define an interface for our dependency injector:</p>
<pre name="code" class="c#">
public interface IDependencyInjector
{
	T Construct&lt;T&gt;();
	void Inject(object instance);
}
</pre>
<p>We&#8217;ll define our service container like so:</p>
<pre name="code" class="c#">
public class ServiceContainer : IDependencyInjector, IServiceProvider
{
	Dictionary&lt;Type, Object&gt; services;

	public ServiceContainer()
		: base()
	{
		this.services = new Dictionary&lt;Type, object&gt;();
	}

	public void AddService(Type type, Object provider)
	{
		if(null == type)
			throw new ArgumentNullException("type");

		if(null == provider)
			throw new ArgumentNullException("provider");

		if(this.services.ContainsKey(type))
			throw new InvalidOperationException("A provider is already registered the type " + type);

		var providerType = provider.GetType();

		if(!type.IsAssignableFrom(providerType))
			throw new InvalidOperationException(providerType + " is not an instance of " + type);

		this.services.Add(type, provider);
	}

	public object GetService(Type type)
	{
		if(null == type)
			throw new ArgumentNullException("type");

		if(this.services.ContainsKey(type))
			return this.services[type];

		return null;
	}

	public void RemoveService(Type type)
	{
		if(null == type)
			throw new ArgumentNullException("type");

		this.services.Remove(type);
	}

	protected object GetInjectableService(Type type)
	{
		if(type == typeof(IDependencyInjector) ||
		   type == typeof(IServiceProvider))
		{
			return this;
		}
		else
		{
			object service = this.GetService(type);

			if(service == null)
				throw new InvalidOperationException("Failed to find " + type + " depenedency.");

			return service;
		}
	}

	public T Construct&lt;T&gt;()
	{
		ConstructorInfo injectableConstructor = null;
		foreach(ConstructorInfo constructor in typeof(T).GetConstructors())
		{
			foreach(Attribute attribute in constructor.GetCustomAttributes(true))
			{
				if(attribute is InjectableAttribute)
				{
					injectableConstructor = constructor;
					break;
				}
			}

			if(injectableConstructor != null)
				break;
		}

		if(injectableConstructor == null)
			throw new InvalidOperationException("No injectable constructor found.");

		var parameters = injectableConstructor.GetParameters();
		var services = new object[parameters.Length];

		int i = 0;
		foreach(ParameterInfo parameter in parameters)
			services[i++] = GetInjectableService(parameter.ParameterType);

		return (T)injectableConstructor.Invoke(services);
	}

	public void Inject(object instance)
	{
		foreach(PropertyInfo property in instance.GetType().GetProperties())
		{
			foreach(Attribute attribute in property.GetCustomAttributes(true))
			{
				if(attribute is InjectableAttribute)
				{
					if(!property.CanWrite)
						throw new InvalidOperationException(property.Name + " is marked as Injectable but not writable.");

					property.SetValue(instance, GetInjectableService(property.PropertyType), null);
				}
			}
		}
	}
}
</pre>
<p>You can now construct new instances and inject dependencies on existing instances. Some usage examples:</p>
<pre name="code" class="c#">
public interface IFoo
{
	int Value { get; }
}

public class Foo : IFoo
{
	public int Value
	{
		get;
		set;
	}

	[Injectable]
	public Foo()
	{
	}

	public void DoIt()
	{
		Console.WriteLine(this.Value);
	}
}

public interface IBar
{
	string Value { get; }
}

public class Bar : IBar
{
	IFoo foo;

	public string Value
	{
		get;
		set;
	}

	[Injectable]
	public Bar(IFoo foo)
	{
		this.foo = foo;
	}

	public void DoIt()
	{
		Console.WriteLine(this.Value + ": " + this.foo.Value);
	}
}

public class Baz
{
	[Injectable]
	public IFoo Foo
	{
		get;
		set;
	}

	[Injectable]
	public IBar Bar
	{
		get;
		set;
	}

	public void DoIt()
	{
		Console.WriteLine(this.Bar.Value + " | " + this.Foo.Value);
	}
}

class Program
{
	static void Main(string[] args)
	{
		var container = new ServiceContainer();

		var foo = container.Construct&lt;Foo&gt;();
		foo.Value = 5;
		container.AddService(typeof(IFoo), foo);

		var bar = container.Construct&lt;Bar&gt;();
		container.AddService(typeof(IBar), bar);
		bar.Value = "Hello World!";
		bar.DoIt();

		var baz = new Baz();
		container.Inject(baz);
		baz.DoIt();
	}
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://zacharysnow.net/2010/06/21/implementing-basic-dependency-injection-using-services-container/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>500 Downloads of the Same Game</title>
		<link>http://zacharysnow.net/2010/06/09/500-downloads-of-the-same-game/</link>
		<comments>http://zacharysnow.net/2010/06/09/500-downloads-of-the-same-game/#comments</comments>
		<pubDate>Wed, 09 Jun 2010 20:17:28 +0000</pubDate>
		<dc:creator>Zachary</dc:creator>
				<category><![CDATA[XNA]]></category>
		<category><![CDATA[codeplex]]></category>
		<category><![CDATA[SameGameXna]]></category>
		<category><![CDATA[WinForms]]></category>

		<guid isPermaLink="false">http://zacharysnow.net/2010/06/09/500-downloads-of-the-same-game/</guid>
		<description><![CDATA[My little Xna game that I wrote nearly 2 years ago reached the 500 downloads mark (binaries and source) the other day. With that said, I&#8217;d like to say that I&#8217;m working on version 2.0. In version 2.0 I&#8217;m going to make the code more event driven. The old code uses the Xna Game class]]></description>
			<content:encoded><![CDATA[<p>My little Xna game that I wrote nearly 2 years ago reached the 500 downloads mark (binaries and source) the other day. With that said, I&#8217;d like to say that I&#8217;m working on version 2.0.</p>
<p>In version 2.0 I&#8217;m going to make the code more event driven. The old code uses the Xna Game class and in the new version I&#8217;ll be making it WinForms based. Almost a complete rewrite.</p>
<p>My work so far is available through SVN on the project&#8217;s <a href="http://samegamexna.codeplex.com/">Codeplex page</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://zacharysnow.net/2010/06/09/500-downloads-of-the-same-game/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Progress Bar in Windows 7 Taskbars</title>
		<link>http://zacharysnow.net/2010/06/01/progress-bars-in-windows-7-taskbars/</link>
		<comments>http://zacharysnow.net/2010/06/01/progress-bars-in-windows-7-taskbars/#comments</comments>
		<pubDate>Tue, 01 Jun 2010 18:00:20 +0000</pubDate>
		<dc:creator>Zachary</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Windows 7]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[win7]]></category>

		<guid isPermaLink="false">http://zacharysnow.net/?p=308</guid>
		<description><![CDATA[I decided to add progress bar to the Windows 7 Taskbar in my Timer app. I started by downloading and compiling the Windows API Code Pack in Release mode. I then added a reference to the Microsoft.WindowsAPICodePack.dll and Microsoft.WindowsAPICodePack.Shell.dll files to the project. After that add the lines: using Microsoft.WindowsAPICodePack.Taskbar; to your using statements. When]]></description>
			<content:encoded><![CDATA[<p>I decided to add progress bar to the Windows 7 Taskbar in my Timer app.</p>
<p><a href="http://zacharysnow.net/wp-content/uploads/2010/06/TimerProgressBar.png"><img src="http://zacharysnow.net/wp-content/uploads/2010/06/TimerProgressBar.png" alt="" title="TimerProgressBar" width="139" height="40" class="alignnone size-full wp-image-309" /></a></p>
<p>I started by downloading and compiling the <a href="http://code.msdn.microsoft.com/WindowsAPICodePack">Windows API Code Pack</a> in Release mode. I then added a reference to the Microsoft.WindowsAPICodePack.dll and Microsoft.WindowsAPICodePack.Shell.dll files to the project. After that add the lines:</p>
<pre name="code" class="c#">
using Microsoft.WindowsAPICodePack.Taskbar;
</pre>
<p>to your using statements. When the clock starts running I create the progress bar in the taskbar with:</p>
<pre name="code" class="c#">
// Initialize progress bar
if(TaskbarManager.IsPlatformSupported)
{
	TaskbarManager.Instance.SetProgressState(TaskbarProgressBarState.Normal);
	TaskbarManager.Instance.SetProgressValue(0, (int)this.totalTime.TotalSeconds, this.Handle);
}
</pre>
<p>to stop the progress bar:</p>
<pre name="code" class="c#">
// Stop progress bar
if(TaskbarManager.IsPlatformSupported)
	TaskbarManager.Instance.SetProgressState(TaskbarProgressBarState.NoProgress);
</pre>
<p>and finally to update the progress bar on each tick:</p>
<pre name="code" class="c#">
// Update progress bar
if(TaskbarManager.IsPlatformSupported)
	TaskbarManager.Instance.SetProgressValue((int)this.totalTime.TotalSeconds - (int)this.time.TotalSeconds, (int)this.totalTime.TotalSeconds, this.Handle);
</pre>
<p><a href="/files/TimerWin7Taskbar.zip">Download Binary</a><br />
<a href="/files/TimerWin7TaskbarSrc.zip">Download Source</a></p>
]]></content:encoded>
			<wfw:commentRss>http://zacharysnow.net/2010/06/01/progress-bars-in-windows-7-taskbars/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WinForms and MVC</title>
		<link>http://zacharysnow.net/2010/05/26/winforms-and-mvc/</link>
		<comments>http://zacharysnow.net/2010/05/26/winforms-and-mvc/#comments</comments>
		<pubDate>Wed, 26 May 2010 18:53:09 +0000</pubDate>
		<dc:creator>Zachary</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[WinForms]]></category>
		<category><![CDATA[mvc]]></category>

		<guid isPermaLink="false">http://zacharysnow.net/?p=304</guid>
		<description><![CDATA[I recently became interested in doing MVC inside of a Windows Forms app. I found a few MVC frameworks which work with WinForms (see here) but they didn&#8217;t really interest me. Too heavy I felt for what I was looking to do. I ended up with a solution looking something like this: There is really]]></description>
			<content:encoded><![CDATA[<p>I recently became interested in doing MVC inside of a Windows Forms app. I found a few MVC frameworks which work with WinForms (<a href="http://stackoverflow.com/questions/2406/looking-for-a-mvc-sample-for-winforms">see here</a>) but they didn&#8217;t really interest me. Too heavy I felt for what I was looking to do. I ended up with a solution looking something like this:</p>
<p><a href="http://zacharysnow.net/wp-content/uploads/2010/05/WinFormsMvcSolution.png"><img src="http://zacharysnow.net/wp-content/uploads/2010/05/WinFormsMvcSolution-150x150.png" alt="WinForms MVC Solution" title="WinForms MVC Solution" width="150" height="150" class="alignnone size-thumbnail wp-image-305" /></a></p>
<p>There is really only one controller and that is the &#8220;Application&#8221; class. It contains all the methods your app can call to manipulate your models, which are in the &#8220;Data&#8221; folder / namespace. The &#8220;WinFormsApplication&#8221; class inherits from the &#8220;Application&#8221; class and just sets the view to an instance of &#8220;WinFormsView&#8221;. The &#8220;Application&#8221; class communicates with the view through the &#8220;IView&#8221; interface. The &#8220;WinFormsView&#8221; class is a Windows Forms implementation of that view. The &#8220;Application&#8221; class and your models are not coupled in any way to your Windows Forms implementation of the view.</p>
<p>If you want you view to be as dumb as possible, your view can communicate with the &#8220;Application&#8221; class only through events. In my case though, I choose to go with a smart view and have the view call back to methods in the &#8220;Application&#8221; class. The &#8220;Application&#8221; class tells the view when models are loaded and unloaded. The view subscribes to events on the models and reacts to the events.</p>
<p>All of my forms and controls communicate with each other through the &#8220;WinFormsView&#8221; class. One control might change the value of a property in the &#8220;WinFormsView&#8221; class and another control might subscribe to a change event and update as necessary. This keeps the controls and forms slightly less coupled.</p>
<p>It&#8217;s not a perfect implementation of MVC but it keeps my model logic decoupled enough from my view logic that I can later implement a WPF version of the view I think.</p>
]]></content:encoded>
			<wfw:commentRss>http://zacharysnow.net/2010/05/26/winforms-and-mvc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Drawing Rectangles with SpriteBatch</title>
		<link>http://zacharysnow.net/2010/03/29/drawing-rectangles-with-spritebatch/</link>
		<comments>http://zacharysnow.net/2010/03/29/drawing-rectangles-with-spritebatch/#comments</comments>
		<pubDate>Mon, 29 Mar 2010 17:14:25 +0000</pubDate>
		<dc:creator>Zachary</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[Extension Methods]]></category>
		<category><![CDATA[XNA]]></category>
		<category><![CDATA[c#]]></category>

		<guid isPermaLink="false">http://zacharysnow.net/2010/03/29/drawing-rectangles-with-spritebatch/</guid>
		<description><![CDATA[Just a quick code snippet which adds an extension method for drawing Rectangles to SpriteBatch: public static class SpriteBatchHelper { static Texture2D pixel; private static void LoadPixel(GraphicsDevice graphicsDevice) { if(pixel == null) { pixel = new Texture2D(graphicsDevice, 1, 1); pixel.SetData&#60;Color&#62;(new Color[] { Color.White }); } } public static void DrawRectangle(this SpriteBatch spriteBatch, Rectangle rectangle, Color]]></description>
			<content:encoded><![CDATA[<p>Just a quick code snippet which adds an extension method for drawing Rectangles to SpriteBatch:</p>
<pre name="code" class="c#">
public static class SpriteBatchHelper
{
	static Texture2D pixel;

	private static void LoadPixel(GraphicsDevice graphicsDevice)
	{
		if(pixel == null)
		{
			pixel = new Texture2D(graphicsDevice, 1, 1);
			pixel.SetData&lt;Color&gt;(new Color[] { Color.White });
		}
	}

	public static void DrawRectangle(this SpriteBatch spriteBatch, Rectangle rectangle, Color color)
	{
		LoadPixel(spriteBatch.GraphicsDevice);
		spriteBatch.Draw(pixel, rectangle, color);
	}
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://zacharysnow.net/2010/03/29/drawing-rectangles-with-spritebatch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C# Extension Methods in your own Library</title>
		<link>http://zacharysnow.net/2010/03/08/csharp-extension-methods-in-your-own-library/</link>
		<comments>http://zacharysnow.net/2010/03/08/csharp-extension-methods-in-your-own-library/#comments</comments>
		<pubDate>Mon, 08 Mar 2010 19:54:06 +0000</pubDate>
		<dc:creator>Zachary</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Extension Methods]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[extension-methods]]></category>

		<guid isPermaLink="false">http://zacharysnow.net/?p=295</guid>
		<description><![CDATA[Normally I use extension methods in C# to extend a library that I did not write and therefore I have no control over. There are situations where it makes sense to use extension methods for a library that you yourself are writing. For example, when you have interfaces in your library. You want to keep]]></description>
			<content:encoded><![CDATA[<p>Normally I use extension methods in C# to extend a library that I did not write and therefore I have no control over. There are situations where it makes sense to use extension methods for a library that you yourself are writing.</p>
<p>For example, when you have interfaces in your library. You want to keep the number of methods in that interface as low as possible so that classes implementing the interface don&#8217;t have to do a lot of heavy lifting. This means cutting out methods in an interface that are for the most part just syntactic sugar for another method in the interface.</p>
<pre name="code" class="c#">

public interface IServiceContainer
{
    void AddService(Type type, Object provider);
    object GetService(Type type);
}

public static class IServiceContainerExtensions
{
    public static void AddService&lt;T&gt;(this IServiceContainer services, object provider)
    {
        services.AddService(typeof(T), provider);
    }

    public static T GetService&lt;T&gt;(this IServiceContainer services) where T : class
    {
        return services.GetService(typeof(T)) as T;
    }

    public static T GetRequiredService&lt;T&gt;(this IServiceContainer services) where T : class
    {
        T service = services.GetService(typeof(T)) as T;

        if(service == null)
            throw new ServiceNotFoundException(typeof(T));

        return service;
    }
}
</pre>
<p>All of the methods in IServiceContainerExtensions are just helper methods for method in IServiceContainer. By making them extension methods in our own library though, we&#8217;ve made the barrier to entry lower. Other people can implement the interface and in a sense &#8220;inherit&#8221; the helper methods as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://zacharysnow.net/2010/03/08/csharp-extension-methods-in-your-own-library/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
