<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Kristof's Blog</title>
	
	<link>http://kristofmattei.be</link>
	<description>A blog on my experiences in programming, school, and life!</description>
	<lastBuildDate>Thu, 11 Feb 2010 12:12:22 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/KristofsBlog" /><feedburner:info uri="kristofsblog" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>C# Late binding,</title>
		<link>http://feedproxy.google.com/~r/KristofsBlog/~3/m_svHrB2bQ8/</link>
		<comments>http://kristofmattei.be/2010/02/11/c-late-binding/#comments</comments>
		<pubDate>Thu, 11 Feb 2010 12:12:22 +0000</pubDate>
		<dc:creator>Kristof</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://kristofmattei.be/2010/02/11/c-late-binding/</guid>
		<description><![CDATA[Today I was working on a project in VB.NET, which I had to convert to C#.
The problem was that they used late binding, they knew that some properties on objects existed, but they couldn’t be deduced by the compiler since the object’s type was Object.
For Example:
Option Strict Off

Imports Microsoft.VisualBasic

Public Class TestClass
    Public [...]]]></description>
			<content:encoded><![CDATA[<p>Today I was working on a project in VB.NET, which I had to convert to C#.</p>
<p>The problem was that they used late binding, they knew that some properties on objects existed, but they couldn’t be deduced by the compiler since the object’s type was Object.</p>
<p>For Example:</p>
<pre class="code"><span style="color: blue">Option Strict Off

Imports </span>Microsoft.VisualBasic

<span style="color: blue">Public Class </span><span style="color: #2b91af">TestClass
    </span><span style="color: blue">Public Sub </span>Test()
        <span style="color: blue">Dim </span>chart <span style="color: blue">As </span>Excel.ChartObject

        <span style="color: blue">Dim </span>workbook = chart.Parent.Parent
    <span style="color: blue">End Sub

End Class
</span></pre>
<p><a href="http://11011.net/software/vspaste"></a>Now ofcourse, if you compile this, it will work since Option Strict is off. </p>
<p>But when you set it on (or port it to C#) for that matter it won’t compile, since chart.Parent returns a type of Object. And the compiler cannot find the .Parent property on Object.</p>
<p>Too bad. How do we solve this? </p>
<p>One option is: casting:</p>
<pre class="code"><span style="color: blue">Option Strict On

Imports </span>Microsoft.VisualBasic

<span style="color: blue">Public Class </span><span style="color: #2b91af">TestClass
    </span><span style="color: blue">Public Sub </span>Test()
        <span style="color: blue">Dim </span>chart <span style="color: blue">As </span>Excel.ChartObject

        <span style="color: blue">Dim </span>workbook <span style="color: blue">As </span>Excel.Workbook = <span style="color: blue">CType</span>(<span style="color: blue">CType</span>(chart.Parent, Excel.Worksheet).Parent, Excel.Workbook)
    <span style="color: blue">End Sub

End Class

</span></pre>
<p><a href="http://11011.net/software/vspaste"></a>This will work.</p>
<p>Unfortunately sometimes there are properties you can set, but they don’t appear in your intellisense, so you can’t get/set that property.</p>
<p>If you are using VB.NET with Option Strict Off this is no problem, but again: with Option Strict On or in C# it IS a problem.</p>
<p>So I’ve come up with a solution:</p>
<p>(I will continue in C#):</p>
<pre class="code"><span style="color: #2b91af">PropertyInfo </span>propertyInfo = GetType(Excel.<span style="color: #2b91af">Chart</span>).GetProperty(<span style="color: #a31515">&quot;ThePropertyYouWant&quot;</span>);

propertyInfo.SetValue(someChart, someValue, <span style="color: #2b91af">BindingFlags</span>.SetProperty, <span style="color: blue">null</span>, <span style="color: blue">null</span>, <span style="color: blue">null</span>);</pre>
<p>This won’t work either, since the compiler cannot find the propertyInfo of that property, it just doesn’t exist. You will get a NullReferenceException.</p>
<p>The final solution is:</p>
<pre class="code">GetType(Excel.<span style="color: #2b91af">Chart</span>).InvokeMember(<span style="color: #a31515">&quot;ThePropertyYouWant&quot;</span>, <span style="color: #2b91af">BindingFlags</span>.SetProperty, <span style="color: blue">null</span>, someChart, <span style="color: blue">new object</span>[] { someValue });</pre>
<p>Guess what, this works.</p>
<p>I spent ages on this.</p>
<img src="http://feeds.feedburner.com/~r/KristofsBlog/~4/m_svHrB2bQ8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://kristofmattei.be/2010/02/11/c-late-binding/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://kristofmattei.be/2010/02/11/c-late-binding/</feedburner:origLink></item>
		<item>
		<title>Windows Azure SDK: connecting to non SQLExpress Instance</title>
		<link>http://feedproxy.google.com/~r/KristofsBlog/~3/MCIIyCaNNVo/</link>
		<comments>http://kristofmattei.be/2010/01/28/windows-azure-sdk-connecting-to-non-sqlexpress-instance/#comments</comments>
		<pubDate>Thu, 28 Jan 2010 08:45:38 +0000</pubDate>
		<dc:creator>Kristof</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Azure]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://kristofmattei.be/2010/01/28/windows-azure-sdk-connecting-to-non-sqlexpress-instance/</guid>
		<description><![CDATA[When you want to build an Azure application, but you don’t have SQL Express installed the build action in Visual Studio will fail.
You will receive the following message in your output window:
Windows Azure Tools: Failed to initialize the Development Storage service. Unable to start Development Storage. Failed to start Development Storage: the SQL Server instance [...]]]></description>
			<content:encoded><![CDATA[<p>When you want to build an Azure application, but you don’t have SQL Express installed the build action in Visual Studio will fail.</p>
<p>You will receive the following message in your output window:</p>
<blockquote><p>Windows Azure Tools: Failed to initialize the Development Storage service. Unable to start Development Storage. Failed to start Development Storage: the SQL Server instance ‘localhost\SQLExpress’ could not be found. Please configure the SQL Server instance for Development Storage using the ‘DSInit’ utility in the Windows Azure SDK.</p></blockquote>
<p>To fix this you open the Windows Azure SDK Command Prompt:</p>
<p><a href="http://kristofmattei.be/wp-content/uploads/2010/01/image2.png" rel="lightbox[883]"><img style="display: inline" title="Windows Azure SDK Command Prompt" alt="Windows Azure SDK Command Prompt" src="http://kristofmattei.be/wp-content/uploads/2010/01/image_thumb2.png" width="429" height="388" /></a></p>
<p>And enter the following text:</p>
<pre>dsinit /sqlinstance:.</pre>
<p><a href="http://kristofmattei.be/wp-content/uploads/2010/01/image3.png" rel="lightbox[883]"><img style="width: 658px; display: inline" title="dsinit /sqlinstance:." alt="dsinit /sqlinstance:." src="http://kristofmattei.be/wp-content/uploads/2010/01/image_thumb3.png" width="677" height="342" /></a></p>
<p>This will cause Azure to use the default instance (with no name). You can switch this to whatever you like, just replace the . (dot) by the appropriate MS SQL instance.</p>
<p>The result will look like this:</p>
<p><a href="http://kristofmattei.be/wp-content/uploads/2010/01/image5.png" rel="lightbox[883]"><img style="display: inline" title="Development Storage Initialization" alt="Development Storage Initialization" src="http://kristofmattei.be/wp-content/uploads/2010/01/image_thumb5.png" width="484" height="372" /></a> </p>
<p>Good luck, happy coding.</p>
<img src="http://feeds.feedburner.com/~r/KristofsBlog/~4/MCIIyCaNNVo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://kristofmattei.be/2010/01/28/windows-azure-sdk-connecting-to-non-sqlexpress-instance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://kristofmattei.be/2010/01/28/windows-azure-sdk-connecting-to-non-sqlexpress-instance/</feedburner:origLink></item>
		<item>
		<title>Debugging applications in virtual machines with VMware Workstation 7 and Visual Studio 2008 SP1</title>
		<link>http://feedproxy.google.com/~r/KristofsBlog/~3/KNfIcQdcd5w/</link>
		<comments>http://kristofmattei.be/2010/01/20/debugging-applications-in-virtual-machines-with-vmware-workstation-7-and-visual-studio-2008-sp1-2/#comments</comments>
		<pubDate>Wed, 20 Jan 2010 21:44:00 +0000</pubDate>
		<dc:creator>Kristof</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://kristofmattei.be/?p=863</guid>
		<description><![CDATA[Can be a hassle, that’s why I’m writing this post for you:
First of all some prerequisites:

VMware Workstation 7 (6.5 probably will be the same) 
A VM, XP / Vista / 7, whatever you want 
Visual Studio 2008 SP1 

Second of all: VMware can be a little cryptic with it’s error messages so stay calm!
We start [...]]]></description>
			<content:encoded><![CDATA[<p>Can be a hassle, that’s why I’m writing this post for you:</p>
<p>First of all some prerequisites:</p>
<ul>
<li>VMware Workstation 7 (6.5 probably will be the same) </li>
<li>A VM, XP / Vista / 7, whatever you want </li>
<li>Visual Studio 2008 SP1 </li>
</ul>
<p>Second of all: VMware can be a little cryptic with it’s error messages so stay calm!</p>
<p>We start by having our sample application we want to run on the VM:</p>
<p>&lt;screenshot&gt;</p>
<p>Next we click the wrench tool on the VMware toolbar in Visual Studio:</p>
<p><a href="http://kristofmattei.be/wp-content/uploads/2009/12/image5.png" rel="lightbox[863]"><img style="display: inline" title="Click the wrench tool" alt="Click the wrench tool" src="http://kristofmattei.be/wp-content/uploads/2009/12/image_thumb5.png" width="401" height="138" /></a></p>
<p>This opens the following dialog:</p>
<p><a href="http://kristofmattei.be/wp-content/uploads/2009/12/image6.png" rel="lightbox[863]"><img style="width: 415px; display: inline" title="Virtual Debugger Configuration Pages" alt="Virtual Debugger Configuration Pages" src="http://kristofmattei.be/wp-content/uploads/2009/12/image_thumb6.png" width="421" height="283" /></a></p>
<p>For your convenience I highlighted the settings you need to change.</p>
<p>The following order is not the order in the window, but the order that seems the most understandable in my opinion:</p>
<p><strong>Virtual Machine:</strong> The VM you want to debug into, just select a suitable vmx.</p>
<p><strong>Remote Debug Monitor Path: </strong>The path to Remote Debugger folder on <span style="text-decoration: underline">the host computer</span> NOT on the guest! So for 32-bit debugging that would be:</p>
<pre>C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\Remote Debugger\x86\msvsmon.exe</pre>
<p>Replace x86 with x64 if you require 64-bit debugging.</p>
<p><strong>Shared Folders: </strong>This one is not used</p>
<p><strong>Guest Command:</strong> The command to be executed on the guest to start the application. This one was quite the hassle for me. If you leave it on the standard it will result in the following (cryptic) error:</p>
<p><a href="http://kristofmattei.be/wp-content/uploads/2009/12/image7.png" rel="lightbox[863]"><img style="display: inline" title="A valid executable name has not been specified in Debugger settings. You can change this in Project &gt; Properties &gt; Debugging." alt="A valid executable name has not been specified in Debugger settings. You can change this in Project &gt; Properties &gt; Debugging." src="http://kristofmattei.be/wp-content/uploads/2009/12/image_thumb7.png" width="487" height="171" /></a></p>
<p>So instead of leaving it on default you enter this;</p>
<pre>\\vmware-host\Shared Folders\test\application.exe</pre>
<p>Please replace application.exe to the name of your executable! </p>
<p>The last item, <strong>Guest Logon Credentials</strong>, is the easiest. This should be the username and password you use to log in to the VM.</p>
<p>Next up is setting the shared folder between the guest and the host.</p>
<p>While I tried this with the Shared Folder Item in the window we just filled in, I just can’t seem to get it to work. So I bypassed this.</p>
<p>Go to the settings of the VM (in VMware Workstation –&gt; VM –&gt; Settings (CTRL+D)):</p>
<p><a href="http://kristofmattei.be/wp-content/uploads/2010/01/image.png" rel="lightbox[863]"><img style="display: inline" title="image" alt="image" src="http://kristofmattei.be/wp-content/uploads/2010/01/image_thumb.png" width="240" height="199" /></a>&#160; </p>
<p>On the second tab, you take shared folders, and click add (as pointed on the picture).</p>
<p>On the wizard I would suggest opening the shared folder in the debug folder of your application and name the shared folder ‘test’</p>
<p><a href="http://kristofmattei.be/wp-content/uploads/2010/01/image1.png" rel="lightbox[863]"><img style="display: inline" title="image" alt="image" src="http://kristofmattei.be/wp-content/uploads/2010/01/image_thumb1.png" width="240" height="209" /></a> </p>
<p>Enable the share in the following window, and make it read-write.</p>
<p>Now we can start the debugging from Visual Studio. The application will then be started through the shared folder we just created.</p>
<img src="http://feeds.feedburner.com/~r/KristofsBlog/~4/KNfIcQdcd5w" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://kristofmattei.be/2010/01/20/debugging-applications-in-virtual-machines-with-vmware-workstation-7-and-visual-studio-2008-sp1-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://kristofmattei.be/2010/01/20/debugging-applications-in-virtual-machines-with-vmware-workstation-7-and-visual-studio-2008-sp1-2/</feedburner:origLink></item>
		<item>
		<title>Getting the DNS servers with .NET without WMI</title>
		<link>http://feedproxy.google.com/~r/KristofsBlog/~3/lEmRF7pZPho/</link>
		<comments>http://kristofmattei.be/2010/01/07/getting-the-dns-servers-with-net-through-wmi/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 09:44:41 +0000</pubDate>
		<dc:creator>Kristof</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://kristofmattei.be/2010/01/07/getting-the-dns-servers-with-net-through-wmi/</guid>
		<description><![CDATA[Someone pointed me at System.Net.NetworkInformation, which has a lot of interesting objects.
You don’t have to use strings and query the WMI at runtime, which means you get compile time checking!
using System;
using System.Net;
using System.Net.NetworkInformation;

namespace WMITest
{
    internal class Program
    {
        public static int Main(string[] [...]]]></description>
			<content:encoded><![CDATA[<p>Someone pointed me at System.Net.NetworkInformation, which has a lot of interesting objects.</p>
<p>You don’t have to use strings and query the WMI at runtime, which means you get compile time checking!</p>
<pre class="code"><span style="color: blue;">using </span>System;
<span style="color: blue;">using </span>System.Net;
<span style="color: blue;">using </span>System.Net.NetworkInformation;

<span style="color: blue;">namespace </span>WMITest
{
    <span style="color: blue;">internal class </span><span style="color: #2b91af;">Program
    </span>{
        <span style="color: blue;">public static int </span>Main(<span style="color: blue;">string</span>[] args)
        {
            <span style="color: #2b91af;">NetworkInterface</span>[] adapters = <span style="color: #2b91af;">NetworkInterface</span>.GetAllNetworkInterfaces();
            <span style="color: blue;">foreach </span>(<span style="color: #2b91af;">NetworkInterface </span>adapter <span style="color: blue;">in </span>adapters)
            {
                <span style="color: #2b91af;">IPInterfaceProperties </span>properties = adapter.GetIPProperties();

                <span style="color: blue;">foreach </span>(<span style="color: #2b91af;">IPAddress </span>dnsServer <span style="color: blue;">in </span>properties.DnsAddresses)
                {
                    <span style="color: #2b91af;">Console</span>.WriteLine(<span style="color: #a31515;">"{0} "</span>, dnsServer);
                }

                <span style="color: #2b91af;">Console</span>.WriteLine(<span style="color: #a31515;">"----------------------"</span>);
            }

            <span style="color: #2b91af;">Console</span>.ReadLine();
            <span style="color: blue;">return </span>0;
        }
    }
}</pre>
<p><a href="http://11011.net/software/vspaste"></a>Hope it helps <img src='http://kristofmattei.be/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<img src="http://feeds.feedburner.com/~r/KristofsBlog/~4/lEmRF7pZPho" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://kristofmattei.be/2010/01/07/getting-the-dns-servers-with-net-through-wmi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://kristofmattei.be/2010/01/07/getting-the-dns-servers-with-net-through-wmi/</feedburner:origLink></item>
		<item>
		<title>Enabling Edit and Continue on 64-bit machines.</title>
		<link>http://feedproxy.google.com/~r/KristofsBlog/~3/680czy5B5YQ/</link>
		<comments>http://kristofmattei.be/2009/12/07/enabling-edit-and-continue-on-64-bit-machines/#comments</comments>
		<pubDate>Mon, 07 Dec 2009 18:49:05 +0000</pubDate>
		<dc:creator>Kristof</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://kristofmattei.be/2009/12/07/enabling-edit-and-continue-on-64-bit-machines/</guid>
		<description><![CDATA[Ever had this error?
This occurs on 64-bit machines when trying to do Edit and Continue (a feature of the .NET CLR) on a 64-bit application.
It’s only available on 32-bit applications.
Now it’s up to the reader to determine if he needs a 64-bit application. 95% of the time the answer will be no.
So for those people [...]]]></description>
			<content:encoded><![CDATA[<p>Ever had this error?</p>
<div class="wp-caption alignnone" style="width: 528px"><a href="http://kristofmattei.be/wp-content/uploads/2009/12/image2.png" rel="lightbox[837]"><img class=" " style="display: inline;" title="Changes to 64-bit applications are not allowed" src="http://kristofmattei.be/wp-content/uploads/2009/12/image_thumb2.png" alt="changes to 64-bit applications are not allowed" width="518" height="216" /></a><p class="wp-caption-text">changes to 64-bit applications are not allowed</p></div>
<p>This occurs on 64-bit machines when trying to do Edit and Continue (a feature of the .NET CLR) on a 64-bit application.</p>
<p>It’s only available on 32-bit applications.</p>
<p>Now it’s up to the reader to determine if he needs a 64-bit application. 95% of the time the answer will be no.</p>
<p>So for those people I present the solution:</p>
<p><a href="http://kristofmattei.be/wp-content/uploads/2009/12/image3.png" rel="lightbox[837]"><img style="width: 658px; display: inline;" title="image" src="http://kristofmattei.be/wp-content/uploads/2009/12/image_thumb3.png" alt="image" width="996" height="390" /></a></p>
<p>It’s quite simple. Go to properties, build and set the platform target to x86. And you’re ready to <span style="text-decoration: line-through;">go</span> Edit and Continue.</p>
<p>Please do read <a href="http://msdn.microsoft.com/en-us/library/ms164927%28VS.100%29.aspx" target="_blank">this</a> about Edit and Continue.</p>
<img src="http://feeds.feedburner.com/~r/KristofsBlog/~4/680czy5B5YQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://kristofmattei.be/2009/12/07/enabling-edit-and-continue-on-64-bit-machines/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://kristofmattei.be/2009/12/07/enabling-edit-and-continue-on-64-bit-machines/</feedburner:origLink></item>
		<item>
		<title>SqlConnection, Close and deconstructor: Internal .Net Framework Data Provider error 1.</title>
		<link>http://feedproxy.google.com/~r/KristofsBlog/~3/eexrZH8JyZU/</link>
		<comments>http://kristofmattei.be/2009/12/01/sqlconnection-close-and-deconstructor-internal-net-framework-data-provider-error-1/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 15:34:35 +0000</pubDate>
		<dc:creator>Kristof</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://kristofmattei.be/2009/12/01/sqlconnection-close-and-deconstructor-internal-net-framework-data-provider-error-1/</guid>
		<description><![CDATA[Today I experienced the following issue:
I had a class where I would open a SqlConnection, do some actions, and then in the deconstructor I closed the SqlConnection.
~Dumper()
{
    this._sqlConnection.Close();
}
Unfortunately every time my program ran it stopped with this error:
(click to enlarge)
Well it seems that you cannot close a SqlConnection in a ~Deconstructor block.
So [...]]]></description>
			<content:encoded><![CDATA[<p>Today I experienced the following issue:</p>
<p>I had a class where I would open a SqlConnection, do some actions, and then in the deconstructor I closed the SqlConnection.</p>
<pre class="code">~Dumper()
{
    <span style="color: blue">this</span>._sqlConnection.Close();
}</pre>
<p>Unfortunately every time my program ran it stopped with this error:</p>
<div class="wp-caption alignnone" style="width: 375px"><a href="http://kristofmattei.be/wp-content/uploads/2009/12/image1.png" rel="lightbox[827]"><img style="width: 359px; display: inline;" title="Internal .Net Framework Data Provider error 1." src="http://kristofmattei.be/wp-content/uploads/2009/12/image_thumb1.png" alt="image" width="365" height="215" /></a><p class="wp-caption-text">Internal .Net Framework Data Provider error 1.</p></div>
<p>(click to enlarge)</p>
<p>Well it seems that you cannot close a SqlConnection in a ~Deconstructor block.</p>
<p>So the solution is implementing the <a href="http://msdn.microsoft.com/en-us/library/system.idisposable%28VS.100%29.aspx" target="_blank">IDisposable</a> interface</p>
<pre class="code"><span style="color: blue">internal class </span><span style="color: #2b91af">Dumper </span>: <span style="color: #2b91af">IDisposable
</span>{
    <span style="color: blue">private readonly </span><span style="color: #2b91af">SqlConnection </span>_sqlConnection;

    <span style="color: blue">public </span>Dumper()
    {
        <span style="color: green">//build and open the connection
        </span><span style="color: blue">this</span>._sqlConnection = <span style="color: blue">new </span><span style="color: #2b91af">SqlConnection</span>(<span style="color: #2b91af">Settings</span>.Default.ConnectionString);
        <span style="color: blue">this</span>._sqlConnection.Open();
    }

    <span style="color: gray">/// &lt;summary&gt;
    /// </span><span style="color: green">Some function
    </span><span style="color: gray">/// &lt;/summary&gt;
    /// &lt;param name="param"&gt;</span><span style="color: green">param</span><span style="color: gray">&lt;/param&gt;
    </span><span style="color: blue">public void </span>SomeFunction(<span style="color: #2b91af">SomeParameter</span> param)
    {
    }

    <span style="color: blue">public void </span>Dispose()
    {
        <span style="color: blue">this</span>._sqlConnection.Close();
    }
}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>And to use it you do this:</p>
<pre class="code"><span style="color: blue">using </span>(<span style="color: #2b91af">Dumper </span>dumper = <span style="color: blue">new </span><span style="color: #2b91af">Dumper</span>())
{
    dumper.SomeFunction(myParam);
}</pre>
<p>This will cause dumper to be Disposed after the } and it will no longer be available</p>
<img src="http://feeds.feedburner.com/~r/KristofsBlog/~4/eexrZH8JyZU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://kristofmattei.be/2009/12/01/sqlconnection-close-and-deconstructor-internal-net-framework-data-provider-error-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://kristofmattei.be/2009/12/01/sqlconnection-close-and-deconstructor-internal-net-framework-data-provider-error-1/</feedburner:origLink></item>
		<item>
		<title>.NET 3.5 pager, generate pages from List&lt;T&gt;</title>
		<link>http://feedproxy.google.com/~r/KristofsBlog/~3/Q2-ABYxCYxc/</link>
		<comments>http://kristofmattei.be/2009/12/01/net-3-5-pager-generate-pages-from-listt/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 13:04:34 +0000</pubDate>
		<dc:creator>Kristof</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[3.5]]></category>
		<category><![CDATA[linq to objects]]></category>
		<category><![CDATA[pager]]></category>

		<guid isPermaLink="false">http://kristofmattei.be/2009/12/01/net-3-5-pager-generate-pages-from-listt/</guid>
		<description><![CDATA[A friend of mine asked me to generate pages from a List&#60;T&#62;. This is my implementation:
using System;
using System.Collections.Generic;
using System.Linq;

namespace Pager
{
    static class Program
    {
        static void Main()
        {
        [...]]]></description>
			<content:encoded><![CDATA[<p>A friend of mine asked me to generate pages from a List&lt;T&gt;. This is my implementation:</p>
<pre class="code"><span style="color: blue">using </span>System;
<span style="color: blue">using </span>System.Collections.Generic;
<span style="color: blue">using </span>System.Linq;

<span style="color: blue">namespace </span>Pager
{
    <span style="color: blue">static class </span><span style="color: #2b91af">Program
    </span>{
        <span style="color: blue">static void </span>Main()
        {
            <span style="color: #2b91af">List</span>&lt;<span style="color: blue">int</span>&gt; list = <span style="color: blue">new </span><span style="color: #2b91af">List</span>&lt;<span style="color: blue">int</span>&gt;();

            <span style="color: green">//add 26 items
            </span><span style="color: blue">for </span>(<span style="color: blue">int </span>x = 0; x &lt; 26; x++)
            {
                list.Add(x);
            }

            <span style="color: green">//generate pages
            </span><span style="color: #2b91af">List</span>&lt;<span style="color: blue">int</span>&gt;[] pagesList = Pager&lt;<span style="color: blue">int</span>&gt;(list, 4);

            <span style="color: #2b91af">Console</span>.WriteLine(<span style="color: #a31515">&quot;Please examine pagesList&quot;</span>);
            System.Diagnostics.<span style="color: #2b91af">Debugger</span>.Break();

        }

        <span style="color: gray">/// &lt;summary&gt;
        /// </span><span style="color: green">Converts a collection of T to an array of pages
        </span><span style="color: gray">/// &lt;/summary&gt;
        /// &lt;typeparam name=&quot;T&quot;&gt;</span><span style="color: green">The type of items in the list, can be inferred most of the time</span><span style="color: gray">&lt;/typeparam&gt;
        /// &lt;param name=&quot;list&quot;&gt;</span><span style="color: green">The list to page</span><span style="color: gray">&lt;/param&gt;
        /// &lt;param name=&quot;itemsPerPage&quot;&gt;</span><span style="color: green">Items per page</span><span style="color: gray">&lt;/param&gt;
        /// &lt;returns&gt;</span><span style="color: green">An array of lists, pages if you will</span><span style="color: gray">&lt;/returns&gt;
        </span><span style="color: blue">static </span><span style="color: #2b91af">List</span>&lt;T&gt;[] Pager&lt;T&gt;(<span style="color: #2b91af">ICollection</span>&lt;T&gt; list, <span style="color: blue">int </span>itemsPerPage)
        {
            <span style="color: blue">int </span>pages = (<span style="color: blue">int</span>)<span style="color: #2b91af">Math</span>.Ceiling((<span style="color: blue">double</span>)list.Count / itemsPerPage);

            <span style="color: #2b91af">List</span>&lt;T&gt;[] pagesList = <span style="color: blue">new </span><span style="color: #2b91af">List</span>&lt;T&gt;[pages];

            <span style="color: blue">for </span>(<span style="color: blue">int </span>currentPage = 0; currentPage &lt; pages; currentPage++)
            {
                pagesList[currentPage] = list.Skip(currentPage * itemsPerPage).Take(itemsPerPage).ToList();
            }

            <span style="color: blue">return </span>pagesList;
        }
    }
}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<img src="http://feeds.feedburner.com/~r/KristofsBlog/~4/Q2-ABYxCYxc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://kristofmattei.be/2009/12/01/net-3-5-pager-generate-pages-from-listt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://kristofmattei.be/2009/12/01/net-3-5-pager-generate-pages-from-listt/</feedburner:origLink></item>
		<item>
		<title>Expand an array to a given size</title>
		<link>http://feedproxy.google.com/~r/KristofsBlog/~3/kzMKeJ2DuHY/</link>
		<comments>http://kristofmattei.be/2009/11/30/expand-an-array-to-a-given-size/#comments</comments>
		<pubDate>Mon, 30 Nov 2009 15:01:10 +0000</pubDate>
		<dc:creator>Kristof</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://kristofmattei.be/?p=817</guid>
		<description><![CDATA[Some functions expect an array with a minimum size. While this is generally bad coding sometimes you can’t avoid it (e.g. with csv files).
That’s when this piece of code comes in handy: (it&#8217;s an extension method, so it only works on .NET 3.5)
public static class ArrayHelper
{
    /// &#60;summary&#62;
    /// [...]]]></description>
			<content:encoded><![CDATA[<p>Some functions expect an array with a minimum size. While this is generally bad coding sometimes you can’t avoid it (e.g. with csv files).</p>
<p>That’s when this piece of code comes in handy: (it&#8217;s an extension method, so it only works on .NET 3.5)</p>
<pre class="code"><span style="color: blue">public static class </span><span style="color: #2b91af">ArrayHelper
</span>{
    <span style="color: gray">/// &lt;summary&gt;
    /// </span><span style="color: green">Expands an array to the given </span><span style="color: gray">&lt;paramref name="size"/&gt;
    /// &lt;/summary&gt;
    /// &lt;typeparam name="T"&gt;</span><span style="color: green">The type of the array (not neccesairy, can be infered).</span><span style="color: gray">&lt;/typeparam&gt;
    /// &lt;param name="array"&gt;</span><span style="color: green">The array</span><span style="color: gray">&lt;/param&gt;
    /// &lt;param name="size"&gt;</span><span style="color: green">The size it should become</span><span style="color: gray">&lt;/param&gt;
    /// &lt;returns&gt;</span><span style="color: green">The array expanded to the given size</span><span style="color: gray">&lt;/returns&gt;
    </span><span style="color: blue">public static </span>T[] Expand&lt;T&gt;(<span style="color: blue">this </span>T[] array, <span style="color: blue">int </span>size)
    {
        <span style="color: blue">if </span>(size &lt; array.Length)
        {
            <span style="color: blue">throw new </span><span style="color: #2b91af">ArgumentException</span>(<span style="color: #a31515">"size &lt; array.Length, this will cause data to be truncated, canceling"</span>, <span style="color: #a31515">"size"</span>);
        }

        T[] list = <span style="color: blue">new </span>T[size];

        <span style="color: blue">for </span>(<span style="color: blue">int </span>index = 0; index &lt; array.Length; index++)
        {
            list[index] = array[index];
        }

        <span style="color: blue">return </span>list;
    }
}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>Usage:</p>
<pre class="code"><span style="color: blue">class </span><span style="color: #2b91af">Program
</span>{
    <span style="color: blue">static void </span>Main(<span style="color: blue">string</span>[] args)
    {
        <span style="color: blue">string</span>[] array = <span style="color: blue">new string</span>[] { <span style="color: #a31515">"test1"</span>, <span style="color: #a31515">"test2"</span>, <span style="color: #a31515">"test3" </span>};

        <span style="color: green">//array1 has a length of 3
        </span><span style="color: #2b91af">Console</span>.WriteLine(<span style="color: #a31515">"array.Length = {0}"</span>, array.Length); 

        array = array.Expand&lt;<span style="color: blue">string</span>&gt;(10);

        <span style="color: green">//now array has a length of 10
        </span><span style="color: #2b91af">Console</span>.WriteLine(<span style="color: #a31515">"array.Length = {0}"</span>, array.Length);

        <span style="color: #2b91af">Console</span>.ReadLine();
    }
}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>Enjoy <img src='http://kristofmattei.be/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<img src="http://feeds.feedburner.com/~r/KristofsBlog/~4/kzMKeJ2DuHY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://kristofmattei.be/2009/11/30/expand-an-array-to-a-given-size/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://kristofmattei.be/2009/11/30/expand-an-array-to-a-given-size/</feedburner:origLink></item>
		<item>
		<title>Programming with Exceptions: some thoughts.</title>
		<link>http://feedproxy.google.com/~r/KristofsBlog/~3/p8jRfz-oFfo/</link>
		<comments>http://kristofmattei.be/2009/11/10/programming-with-exceptions-some-thoughts/#comments</comments>
		<pubDate>Tue, 10 Nov 2009 15:42:20 +0000</pubDate>
		<dc:creator>Kristof</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://kristofmattei.be/2009/11/10/programming-with-exceptions-some-thoughts/</guid>
		<description><![CDATA[This is something I’ve been thinking about a lot. When do I throw an exception? Do I program with exceptions? Do I catch those exceptions.
Consider this piece of code:
public Product GetProduct(int id)
{
    //get the product, or null if not found
    Product p = //...

    return p;
}

Now [...]]]></description>
			<content:encoded><![CDATA[<p>This is something I’ve been thinking about a lot. When do I throw an exception? Do I program with exceptions? Do I catch those exceptions.</p>
<p>Consider this piece of code:</p>
<pre class="code"><span style="color: blue">public </span><span style="color: #2b91af">Product </span>GetProduct(<span style="color: blue">int </span>id)
{
    <span style="color: green">//get the product, or null if not found
    </span><span style="color: #2b91af">Product </span>p = <span style="color: green">//...

</span>    <span style="color: blue">return </span>p;
}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>Now you can ask yourself the following question: </p>
<p>Is it ok to return null if the product is not found? After all, the calling layer assumes that we’ll be getting a Product, not a null.</p>
<p>So now the calling layer needs to check if the product != null. </p>
<p>It would be exceptional if no product was found. </p>
<p>So in my opinion you throw an exception if no product is found. And that get’s handled in the calling layer. </p>
<p>But on the other hand: if you would just return a null and test on that in the calling layer you would use less resources since exception throwing is expensive.</p>
<p>I’d still go with the first one since it goes better with my consume code thoughts.</p>
<p>But this is an agreement you need to make across your team, and across your API. </p>
<img src="http://feeds.feedburner.com/~r/KristofsBlog/~4/p8jRfz-oFfo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://kristofmattei.be/2009/11/10/programming-with-exceptions-some-thoughts/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://kristofmattei.be/2009/11/10/programming-with-exceptions-some-thoughts/</feedburner:origLink></item>
		<item>
		<title>Format after BitLocker.</title>
		<link>http://feedproxy.google.com/~r/KristofsBlog/~3/Kglk6dUssew/</link>
		<comments>http://kristofmattei.be/2009/11/08/format-after-bitlocker/#comments</comments>
		<pubDate>Sun, 08 Nov 2009 16:50:19 +0000</pubDate>
		<dc:creator>Kristof</dc:creator>
				<category><![CDATA[7]]></category>
		<category><![CDATA[OS]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://kristofmattei.be/2009/11/08/format-after-bitlocker/</guid>
		<description><![CDATA[So yesterday I reinstalled my laptop because some beta driver was acting up, no big deal. I had both of my partitions secured with Bitlocker (and a BIOS password set up) so that my laptop is secure.
After formatting I noticed that my C drive wasn’t encrypted anymore (which is obvious, it was formatted).
But my D [...]]]></description>
			<content:encoded><![CDATA[<p>So yesterday I reinstalled my laptop because some beta driver was acting up, no big deal. I had both of my partitions secured with Bitlocker (and a BIOS password set up) so that my laptop is secure.</p>
<p>After formatting I noticed that my C drive wasn’t encrypted anymore (which is obvious, it was formatted).</p>
<p>But my D drive looked like this:</p>
<p><a href="http://kristofmattei.be/wp-content/uploads/2009/11/locked.png" rel="lightbox[807]"><img style="display: inline" title="locked" alt="locked" src="http://kristofmattei.be/wp-content/uploads/2009/11/locked_thumb.png" width="240" height="150" /></a> </p>
<p>It was locked. Fortunately I printed my recovery key so I was able to unlock the drive.</p>
<p>Please print the keys, and keep them safe!</p>
<img src="http://feeds.feedburner.com/~r/KristofsBlog/~4/Kglk6dUssew" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://kristofmattei.be/2009/11/08/format-after-bitlocker/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://kristofmattei.be/2009/11/08/format-after-bitlocker/</feedburner:origLink></item>
	</channel>
</rss><!-- Dynamic page generated in 0.983 seconds. --><!-- Cached page generated by WP-Super-Cache on 2010-03-11 14:30:11 -->
