<?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>.Net Bits and Pieces &#187; .Net</title>
	<atom:link href="http://www.dotnetbitsandpieces.com/?feed=rss2&#038;tag=dotnet" rel="self" type="application/rss+xml" />
	<link>http://www.dotnetbitsandpieces.com</link>
	<description>What ever I find interesting to tell about .Net</description>
	<lastBuildDate>Sat, 06 Apr 2013 21:31:17 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=3.9.40</generator>
	<item>
		<title>Document Generation with OOXML Part 2</title>
		<link>http://www.dotnetbitsandpieces.com/?p=83</link>
		<comments>http://www.dotnetbitsandpieces.com/?p=83#comments</comments>
		<pubDate>Thu, 04 Apr 2013 20:47:49 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Document Generation]]></category>
		<category><![CDATA[OOMXL]]></category>

		<guid isPermaLink="false">http://www.dotnetbitsandpieces.com/?p=83</guid>
		<description><![CDATA[When creating a document from Word templates are used when creating documents. These can be default templates or templates created by users. It is their for essential that these templates can be used when generating OOXML documents. With the Document Generator library templates can be loaded when a new document is created. //Load a template [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><span style="font-size: small">When creating a document from Word templates are used when creating documents. These can be default templates or templates created by users. It is their for essential that these templates can be used when generating OOXML documents. With the Document Generator library templates can be loaded when a new document is created.</span></p>
<div class="codecolorer-container csharp geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008080; font-style: italic;">//Load a template from file. document is the name of the new document.</span><br />
<span style="color: #008080; font-style: italic;">//template is the name and full path of the template file</span><br />
<span style="color: #008080; font-style: italic;">//true indicates that the document can override documents with the same name.</span><br />
var document <span style="color: #008000;">=</span> TextDocument<span style="color: #008000;">.</span><span style="color: #0000FF;">Create</span><span style="color: #008000;">&#40;</span>document, template, <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
<span style="color: #008080; font-style: italic;">//Load a template from a stream</span><br />
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008000;">&#40;</span>var stream <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> FileStream<span style="color: #008000;">&#40;</span>templateFile, FileMode<span style="color: #008000;">.</span><span style="color: #0000FF;">Open</span>, FileAccess<span style="color: #008000;">.</span><span style="color: #0000FF;">Read</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008000;">&#40;</span>var reader <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> StreamReader<span style="color: #008000;">&#40;</span>stream<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">//stream is the stream of the template.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; var document <span style="color: #008000;">=</span> TextDocument<span style="color: #008000;">.</span><span style="color: #0000FF;">Create</span><span style="color: #008000;">&#40;</span>stream<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<p><span style="font-size: small">Once the template is loaded the styles defined in the template can be used. As long as the styles are the default for the header and the paragraphs only the level needs to be defined.</span></p>
<div class="codecolorer-container csharp geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008080; font-style: italic;">//This adds a new paragraph with the paragraph text and heading text.</span><br />
<span style="color: #008080; font-style: italic;">//The styles used are Heading2 and Normal2. When the styles cannot be found then</span><br />
<span style="color: #008080; font-style: italic;">//Heading1 and normal will be used as styles.</span><br />
var paragraph <span style="color: #008000;">=</span> document<span style="color: #008000;">.</span><span style="color: #0000FF;">AddParagraph</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Paragraph Text&quot;</span>, <span style="color: #666666;">&quot;Heading Text&quot;</span>, <span style="color: #FF0000;">2</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></div></div>
<p><span style="font-size: small">Templates can also define custom styles. When the name of the style in the template is known the style can be used with the Document Generator library.<br />
The style can be applied to paragraphs and headers</p>
<div class="codecolorer-container csharp geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008080; font-style: italic;">//Creates a paragraph and assigns it the MyParagraphStyle.</span><br />
var paragraph <span style="color: #008000;">=</span> document<span style="color: #008000;">.</span><span style="color: #0000FF;">AddParagraph</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;This is the paragraph&quot;</span>, <span style="color: #666666;">&quot;MyParagraphStyle&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
<span style="color: #008080; font-style: italic;">//Creates a paragraph and assigns it the MyParagraphStyle.</span><br />
<span style="color: #008080; font-style: italic;">//and gives it a header with the style MyHeaderStyle</span><br />
var paragraph <span style="color: #008000;">=</span> document<span style="color: #008000;">.</span><span style="color: #0000FF;">AddParagraph</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;This is the paragraph&quot;</span>, <span style="color: #666666;">&quot;Header for Paragraph&quot;</span>, <span style="color: #666666;">&quot;MyParagraphStyle&quot;</span>, <span style="color: #666666;">&quot;MyHeaderStyle&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></div></div>
<p><span style="font-size: small">In this post I showed you how you can use a template when creating documents and how to use custom styles in the template.<br />
In the next part I will show how you can replace content in documents using Content Controls.</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dotnetbitsandpieces.com/?feed=rss2&#038;p=83</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Document Generation with OOXML Part 1</title>
		<link>http://www.dotnetbitsandpieces.com/?p=33</link>
		<comments>http://www.dotnetbitsandpieces.com/?p=33#comments</comments>
		<pubDate>Sun, 31 Mar 2013 08:27:57 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[Document Generation]]></category>
		<category><![CDATA[OOMXL]]></category>

		<guid isPermaLink="false">http://www.dotnetbitsandpieces.com/?p=33</guid>
		<description><![CDATA[For a while I have been working on a private project called Document Generator. Document Generator is a .Net library for creating text documents in OOXML and in ODF. With the library you can create an outline for a document with paragraphs, image, etc and generate an OOXML or ODF document. I recently thought it [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><span style="font-size: small">For a while I have been working on a private project called Document Generator. Document Generator is a .Net library for creating text documents in OOXML and in ODF. With the library you can create an outline for a document with paragraphs, image, etc and generate an OOXML or ODF document. I recently thought it was mature enough to make it a final release. You can find the project at <a title="here" href="http://docgenerator.codeplex.com/" target="_blank">Codeplex </a>.</span></p>
<p><span style="font-size: small">To explain the library I decided to write a serie of articles and this is the first part. It will explain how to get started with the library.</span></p>
<h2>Pre-requisites</h2>
<p><span style="font-size: small">The library is using OOXML SDK 2.5 for creating OOXML documents and this requires .Net Framework 4.0.</span></p>
<h2>Installation</h2>
<p><span style="font-size: small">Document generator does not require any installation. Download the <a href="http://docgenerator.codeplex.com/releases/view/99752" target="_blank">zip</a> file with the latest version and extract the contents to a directory of choice. The zip file contains:</span></p>
<ul><span style="font-size: small"></p>
<li>DocumentGenerator.dll</li>
<li>DocumentFormat.OpenXml.dll (<em>This is the dll for the OOXML SDK 2.5</em>)</li>
<li>ICSharpCode.SharpZipLib.dll (<em>This dll is required for creating ODF files</em>)</li>
<p></span>
</ul>
<h2>Setup the project</h2>
<ol>
<span style="font-size: small"></p>
<li>Create a new console project in Visual Studio</li>
<li>Add a reference to the dll’s for the document generation:
<ul>
<li>DocumentGenerator.dll</li>
<li>DocumentFormat.OpenXml.dll</li>
<li>ICSharpCode.SharpZipLib.dll</li>
</ul>
</li>
<p></span>
</ol>
<h2> Generate Documents</h2>
<ol>
<span style="font-size: small"></p>
<li>The first step in generating a document is to create a Textdocument object. This is the container of the document to generate and is the same for OOXML and ODF documents. For OOXML documents it is also possible to start from a template (.dotx) or an existing document (.docx).</li>
<div class="codecolorer-container csharp geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008080; font-style: italic;">//Create a new text document</span><br />
var document <span style="color: #008000;">=</span> TextDocument<span style="color: #008000;">.</span><span style="color: #0000FF;">Create</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
<span style="color: #008080; font-style: italic;">//Create a new text document with a file name (including the file location)</span><br />
<span style="color: #008080; font-style: italic;">//The Boolean indicates whether the file can be overridden if a file</span><br />
<span style="color: #008080; font-style: italic;">//with the same name is found.</span><br />
var document <span style="color: #008000;">=</span> TextDocument<span style="color: #008000;">.</span><span style="color: #0000FF;">Create</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;MyFilename&quot;</span>, <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
<span style="color: #008080; font-style: italic;">//Create a new text document based on a template</span><br />
var document <span style="color: #008000;">=</span> TextDocument<span style="color: #008000;">.</span><span style="color: #0000FF;">Create</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;MyFilename&quot;</span>,<span style="color: #666666;">&quot;myTemplate&quot;</span>, <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
<span style="color: #008080; font-style: italic;">//Open an existing ooxml document.</span><br />
var document <span style="color: #008000;">=</span> TextDocument<span style="color: #008000;">.</span><span style="color: #0000FF;">Open</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;MyFile&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></div></div>
<li>When the text document is created headers and paragraphs can be added.</li>
<div class="codecolorer-container csharp geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008080; font-style: italic;">//Add a paragraph to the document. Level is an integer used for the style.</span><br />
<span style="color: #008080; font-style: italic;">//of the paragraph, e.g. level &quot;0&quot; set style &quot;Normal&quot; </span><br />
<span style="color: #008080; font-style: italic;">//and level &quot;1&quot; style &quot;Normal1&quot;</span><br />
document<span style="color: #008000;">.</span><span style="color: #0000FF;">AddParagraph</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;The paragraph text&quot;</span>, level<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
<span style="color: #008080; font-style: italic;">//Add a paragraph and a header. Level is an integer is used for the style.</span><br />
<span style="color: #008080; font-style: italic;">//E.g. level &quot;1&quot; applies &quot;Header1&quot; level &quot;2&quot; applies &quot;Header2&quot;</span><br />
document<span style="color: #008000;">.</span><span style="color: #0000FF;">AddParagraph</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;The header&quot;</span>,<span style="color: #666666;">&quot;The paragraph text&quot;</span>, level<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
<span style="color: #008080; font-style: italic;">//Add only a header. Leaving the text for the paragraph empty</span><br />
<span style="color: #008080; font-style: italic;">//will add only a header.</span><br />
document<span style="color: #008000;">.</span><span style="color: #0000FF;">AddParagraph</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;The header&quot;</span>,<span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Empty</span>, level<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></div></div>
<li>Finally the document can be save in OOXML or ODF format.</li>
<div class="codecolorer-container csharp geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008080; font-style: italic;">//First set a filename (including the file location), if not already set</span><br />
document<span style="color: #008000;">.</span><span style="color: #0000FF;">Filename</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;MyFile&quot;</span><span style="color: #008000;">;</span><br />
<br />
<span style="color: #008080; font-style: italic;">//Save the document in OOXML format.</span><br />
document<span style="color: #008000;">.</span><span style="color: #0000FF;">Save</span><span style="color: #008000;">&#40;</span>DocumentType<span style="color: #008000;">.</span><span style="color: #0000FF;">OOXMLTextDocument</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
<span style="color: #008080; font-style: italic;">//Save the document in ODF format.</span><br />
document<span style="color: #008000;">.</span><span style="color: #0000FF;">Save</span><span style="color: #008000;">&#40;</span>DocumentType<span style="color: #008000;">.</span><span style="color: #0000FF;">ODFTextDocument</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></div></div>
<p></span>
</ol>
<p><span style="font-size: small">In this post I showed you how you can create a document, add contents to the document and save this document in either OOXML or ODF format.<br />
I also showed how you can use a dotx template or an existing ooxml document to create new documents.</span></p>
<p><span style="font-size: small">In the next post I will go through some more advanced features such as creating tables and lists and replace content in OOXML documents.<br />
If you cannot wait for these posts you can have a look a the DocumentGeneratorTest project in Codeplex to see the use of these features.<br />
</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dotnetbitsandpieces.com/?feed=rss2&#038;p=33</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Enum.HasFlag() versus Bitwise comparison</title>
		<link>http://www.dotnetbitsandpieces.com/?p=11</link>
		<comments>http://www.dotnetbitsandpieces.com/?p=11#comments</comments>
		<pubDate>Mon, 14 Jan 2013 21:15:31 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Enum]]></category>

		<guid isPermaLink="false">http://www.dotnetbitsandpieces.com/?p=11</guid>
		<description><![CDATA[Call me a bit slow, but I recently discovered that Microsoft has implemented an HasFlag method on the Enum class since .Net 4. The method is meant as replacement for the bitwise comparison between values of an enumeration that has the FlagAttribute. For more information about the the FlagAttribute and bitwise comparison you can have [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><span style="font-size: small;">Call me a bit slow, but I recently discovered that Microsoft has implemented an HasFlag method on the Enum class since .Net 4. The method is meant as replacement for the bitwise comparison between values of an enumeration that has the FlagAttribute. For more information about the the FlagAttribute and bitwise comparison you can have a look at </span><a href="http://geekswithblogs.net/BlackRabbitCoder/archive/2010/07/22/c-fundamentals-combining-enum-values-with-bit-flags.aspx" target="_blank"><span style="font-size: small;">this blog</span></a><span style="font-size: small;">. </span></p>
<p><span style="font-size: small;">For a project I am working on I am using the bitwise comparison extensively, so using the HasFlag method would make the code much more readable. Before using it I wanted to get some more information about how the HasFlag method works and I found this </span><a href="http://www.codeproject.com/Tips/441086/NETs-Enum-HasFlag-and-performance-costs" target="_blank"><span style="font-size: small;">article</span></a><span style="font-size: small;">. It shows the inner workings of the method, but also mentions that there is a performance cost to pay. However it does not mention what the cost is.</span></p>
<p><span style="font-size: small;">I therefor did my own test to see what the performance overhead would be and if it was worth to change.<span id="more-11"></span></span></p>
<p><span style="font-size: small;">The first part was to create an enumeration</span></p>
<pre>

<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">public enum EnumValues<br />
{<br />
&nbsp; Value1 = 1,<br />
&nbsp; Value2 = 2,<br />
&nbsp; ...,<br />
&nbsp; Value16 = 32768<br />
}</div></div>

</pre>
<p><span style="font-size: small;">Next I needed a class to evaluate the different comparison methods</span></p>
<pre>

<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">public class EnumsClass<br />
{<br />
&nbsp; public bool CheckEnum(EnumValues values)<br />
&nbsp; {<br />
&nbsp; &nbsp; bool isTrue = false;<br />
&nbsp; &nbsp; if ((values &amp;amp; EnumValues.Value8) == EnumValues.Value8) isTrue = true;<br />
&nbsp; &nbsp; return isTrue;<br />
&nbsp; }<br />
<br />
&nbsp; public bool CheckEnumWithFlagMethod(EnumValues values)<br />
&nbsp; {<br />
&nbsp; &nbsp; bool isTrue = false;<br />
&nbsp; &nbsp; if (values.HasFlag(EnumValues.Value8)) isTrue = true;<br />
&nbsp; &nbsp; return isTrue;<br />
&nbsp; }<br />
}</div></div>

</pre>
<p><span style="font-size: small;">The last part I needed was a class to call these two methods and determine how long each of the methods would take to run. I decided to use the unit test in Visual Studio 2012 as this also shows how long each test method takes.<br />
</span></p>
<pre>

<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">[TestClass]<br />
public class EnumTest<br />
{<br />
&nbsp; private EnumsClass _enumsClass;<br />
<br />
&nbsp; [TestInitialize]<br />
&nbsp; public void Initialize()<br />
&nbsp; {<br />
&nbsp; &nbsp; _enumsClass = new EnumsClass();<br />
&nbsp; }<br />
<br />
&nbsp; [TestMethod]<br />
&nbsp; public void TestForFalseValueWithFlag()<br />
&nbsp; {<br />
&nbsp; &nbsp; Assert.IsFalse(_enumsClass.CheckEnumWithFlagMethod(EnumValues.Value1 | EnumValues.Value10));<br />
&nbsp; }<br />
<br />
&nbsp; [TestMethod]<br />
&nbsp; public void TestForFalseValue()<br />
&nbsp; {<br />
&nbsp; &nbsp; Assert.IsFalse(_enumsClass.CheckEnum(EnumValues.Value1 | EnumValues.Value10));<br />
&nbsp; }<br />
<br />
&nbsp; [TestMethod]<br />
&nbsp; public void TestForTrueValue()<br />
&nbsp; {<br />
&nbsp; &nbsp; Assert.IsTrue(_enumsClass.CheckEnum(EnumValues.Value8 | EnumValues.Value10));<br />
&nbsp; }<br />
<br />
&nbsp; [TestMethod]<br />
&nbsp; public void TestForTrueValueWithFlag()<br />
&nbsp; {<br />
&nbsp; &nbsp; Assert.IsTrue(_enumsClass.CheckEnumWithFlagMethod(EnumValues.Value8 | EnumValues.Value10));<br />
&nbsp; }<br />
}</div></div>

</pre>
<p><span style="font-size: small;">To make sure that there was no difference between a true and false result I used both methods in the EnumsClass to return both <em>true</em> and <em>false. </em>I also repeated the different calls multiple times in a foreach loop. The results are in the below.</span></p>
<table width="400" border="0" cellspacing="0" cellpadding="2">
<tbody>
<tr>
<td valign="top" width="200">Test</td>
<td valign="top" width="200">1x</td>
<td valign="top" width="200">10000x</td>
<td valign="top" width="200">100000x</td>
<td valign="top" width="200">1000000x</td>
<td valign="top" width="200">10000000x</td>
</tr>
<tr>
<td valign="top" width="200">TestForTrueValue</td>
<td valign="top" width="200">&lt; 1 ms</td>
<td valign="top" width="200">&lt; 1 ms</td>
<td valign="top" width="200">&lt; 1 ms</td>
<td valign="top" width="200">7 ms</td>
<td valign="top" width="200">79 ms</td>
</tr>
<tr>
<td valign="top" width="200">TestForTrueValueWithFlag</td>
<td valign="top" width="200">&lt; 1 ms</td>
<td valign="top" width="200">&lt; 1 ms</td>
<td valign="top" width="200">4 ms</td>
<td valign="top" width="200">45 ms</td>
<td valign="top" width="200">453 ms</td>
</tr>
<tr>
<td valign="top" width="200">TestForFalseValue</td>
<td valign="top" width="200">&lt; 1 ms</td>
<td valign="top" width="200">&lt; 1 ms</td>
<td valign="top" width="200">&lt; 1 ms</td>
<td valign="top" width="200">6 ms</td>
<td valign="top" width="200">78 ms</td>
</tr>
<tr>
<td valign="top" width="200">TestForFalseValueWithFlag</td>
<td valign="top" width="200">&lt; 1 ms</td>
<td valign="top" width="200">&lt; 1 ms</td>
<td valign="top" width="200">5 ms</td>
<td valign="top" width="200">46 ms</td>
<td valign="top" width="200">477 ms</td>
</tr>
</tbody>
</table>
<p><span style="font-size: small;">So, there is an performance cost to using the HasFlag() method. It seems that the HasFlag() method is about 6 times as slow as the good old bitwise comparison. However you will notice the difference once you need to execute the call over 100000 times.</span><br />
<span style="font-size: small;">It is up to the programmer to see if the performance cost is worth the readability. I will stick to the bitwise comparison for now.</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dotnetbitsandpieces.com/?feed=rss2&#038;p=11</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Just another blog</title>
		<link>http://www.dotnetbitsandpieces.com/?p=6</link>
		<comments>http://www.dotnetbitsandpieces.com/?p=6#comments</comments>
		<pubDate>Sat, 12 Jan 2013 15:50:29 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[Geen categorie]]></category>
		<category><![CDATA[.Net]]></category>

		<guid isPermaLink="false">http://www.dotnetbitsandpieces.com/?p=6</guid>
		<description><![CDATA[This is the first blog post on my new blog DotNet Bits and Pieces. Like the name says I will blog here about the things that I will run into while working with the .Net Framework. Because of my work most post will probably be about Visual Studio and C#, but we will see when [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>This is the first blog post on my new blog DotNet Bits and Pieces. Like the name says I will blog here about the things that I will run into while working with the .Net Framework.</p>
<p>Because of my work most post will probably be about Visual Studio and C#, but we will see when time goes by.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dotnetbitsandpieces.com/?feed=rss2&#038;p=6</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
