<?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>Just Your Average Geek</title>
	<atom:link href="http://justyouraveragegeek.com/blog/index.php/feed/" rel="self" type="application/rss+xml" />
	<link>http://justyouraveragegeek.com/blog</link>
	<description>Currently nuts about Javascript, C# and Patterns</description>
	<lastBuildDate>Fri, 04 Mar 2011 11:19:05 +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>Property changed event on Javascript objects.</title>
		<link>http://justyouraveragegeek.com/blog/index.php/2011/03/property-changed-event-on-javascript-objects/</link>
		<comments>http://justyouraveragegeek.com/blog/index.php/2011/03/property-changed-event-on-javascript-objects/#comments</comments>
		<pubDate>Fri, 04 Mar 2011 11:19:05 +0000</pubDate>
		<dc:creator>Michel van der Weide</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[changed]]></category>
		<category><![CDATA[changeevent]]></category>
		<category><![CDATA[Events]]></category>
		<category><![CDATA[property]]></category>
		<category><![CDATA[setter]]></category>
		<category><![CDATA[watcher]]></category>

		<guid isPermaLink="false">http://justyouraveragegeek.com/blog/?p=252</guid>
		<description><![CDATA[Recently I ran across a question on StackOverflow.com. The question was: &#8220;Is it possible to have an event that fires when the value of a certain variable changes&#8220;. My first reaction was &#8220;No&#8230; you can&#8217;t&#8221;. You must create a setter method on your object and pray that the users of your code use the setter ]]></description>
			<content:encoded><![CDATA[<p>Recently I ran across a question on StackOverflow.com. The question was: &#8220;<em>Is it possible to have an event that fires when the value of a certain variable changes</em>&#8220;. My first reaction was &#8220;No&#8230; you can&#8217;t&#8221;. You must create a setter method on your object and pray that the users of your code use the setter method instead of setting the variable itself.</p>
<p>But luckily there are people in this world who are more ingenious than me&#8230; it is possible. You must write a little bit of code on the Object-prototype but it is quite self explaining. The code is found here: <a href="https://gist.github.com/175649">Eli Grey&#8217;s Gist</a>.</p>
<p>I copy/pasted the code here below (changed some formatting). But again&#8230; All credits go to <a href="https://gist.github.com/175649">Eli Grey</a>.</p>
<pre class="brush: js">
// object.watch
if (!Object.prototype.watch)
{
    Object.prototype.watch = function (prop, handler)
    {
        var val = this[prop],
        getter = function ()
        {
            return val;
        },
        setter = function (newval) {
            return val = handler.call(this, prop, val, newval);
        };
        if (delete this[prop]) { // can't watch constants
            if (Object.defineProperty) { // ECMAScript 5
                Object.defineProperty(this, prop, {
                   get: getter,
                   set: setter
                });
            }
            else if (Object.prototype.__defineGetter__ &#038;&#038;
                     Object.prototype.__defineSetter__) //legacy
            {
                Object.prototype.__defineGetter__.call(this, prop, getter);
                Object.prototype.__defineSetter__.call(this, prop, setter);
            }
        }
    };
}

// object.unwatch
if (!Object.prototype.unwatch)
{
    Object.prototype.unwatch = function (prop) {
        var val = this[prop];
        delete this[prop]; // remove accessors
        this[prop] = val;
    };
}
</pre>
<p>That&#8217;s it&#8230; works great&#8230;</p>
<p>Happy Coding&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://justyouraveragegeek.com/blog/index.php/2011/03/property-changed-event-on-javascript-objects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Converting a negative Integer to String with leading zeros</title>
		<link>http://justyouraveragegeek.com/blog/index.php/2011/01/converting-a-negative-integer-to-string-with-leading-zeros/</link>
		<comments>http://justyouraveragegeek.com/blog/index.php/2011/01/converting-a-negative-integer-to-string-with-leading-zeros/#comments</comments>
		<pubDate>Thu, 20 Jan 2011 09:45:11 +0000</pubDate>
		<dc:creator>Michel van der Weide</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[format]]></category>
		<category><![CDATA[leading]]></category>
		<category><![CDATA[negative]]></category>
		<category><![CDATA[numeric]]></category>
		<category><![CDATA[padding]]></category>
		<category><![CDATA[padleft]]></category>
		<category><![CDATA[ToString()]]></category>
		<category><![CDATA[trailing]]></category>

		<guid isPermaLink="false">http://justyouraveragegeek.com/blog/?p=239</guid>
		<description><![CDATA[Quick post for today. While doing some refactoring I ran into the following code which was intended to convert a negative integer to a string with leading zeros. int value = GetValue(); string val = "-" + (value * -1).ToString().PadLeft(2, '0'); This can be done much easier. And it works for positive and negative integers. ]]></description>
			<content:encoded><![CDATA[<p>Quick post for today.</p>
<p>While doing some refactoring I ran into the following code which was intended to convert a negative integer to a string with leading zeros.</p>
<pre class="brush: csharp">
int value = GetValue();
string val = "-" + (value * -1).ToString().PadLeft(2, '0');
</pre>
<p>This can be done much easier. And it works for positive and negative integers. Check the improved code below.</p>
<pre class="brush: csharp">
int value = GetValue();
string val = value.ToString("D2");
</pre>
<p>For a complete list of the possibilities for converting a integer into an string check the <a href="http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx#DFormatString">MSDN</a> website for <a href="http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx#DFormatString">Standard Numeric Format Strings</a>:</p>
<p>Happy coding&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://justyouraveragegeek.com/blog/index.php/2011/01/converting-a-negative-integer-to-string-with-leading-zeros/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Hierarchical Ordering &#8211; Dependency Walker</title>
		<link>http://justyouraveragegeek.com/blog/index.php/2011/01/dependencywalker/</link>
		<comments>http://justyouraveragegeek.com/blog/index.php/2011/01/dependencywalker/#comments</comments>
		<pubDate>Sun, 02 Jan 2011 11:37:17 +0000</pubDate>
		<dc:creator>Michel van der Weide</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Build]]></category>
		<category><![CDATA[Dependency]]></category>
		<category><![CDATA[Hierarchical]]></category>
		<category><![CDATA[IComparable]]></category>
		<category><![CDATA[IComparer]]></category>
		<category><![CDATA[List]]></category>
		<category><![CDATA[merging]]></category>
		<category><![CDATA[OpenLayers]]></category>
		<category><![CDATA[Ordering]]></category>
		<category><![CDATA[Sort]]></category>
		<category><![CDATA[Sorting]]></category>
		<category><![CDATA[Walker]]></category>

		<guid isPermaLink="false">http://justyouraveragegeek.com/blog/?p=217</guid>
		<description><![CDATA[Recently I ran into some challenging moments trying to reorder some classes which had an hierarchical order. Implementing the IComparable&#60;T&#62; interface and calling the Sort method on the List&#60;T&#62; just wasn&#8217;t enough. This was caused by the fact that the CompareTo method doesn&#8217;t know anything about the nested hierarchy. The problem described above emerged when ]]></description>
			<content:encoded><![CDATA[<p>Recently I ran into some challenging moments trying to reorder some classes which had an hierarchical order. Implementing the IComparable&lt;T&gt; interface and calling the Sort method on the List&lt;T&gt; just wasn&#8217;t enough. This was caused by the fact that the CompareTo method doesn&#8217;t know anything about the nested hierarchy.</p>
<p>The problem described above emerged when I was working with OpenLayers. We have made a lot of changes to OpenLayers and therefore I do not use the merged OpenLayers file but the separate source files. OpenLayers comes with a Python build script which orders the sourcefiles (based on it&#8217;s hierarchy) and compresses it to one file. Due to some circumstances the standard OpenLayers build script had to be changed significantly. The changes where bigger than my knowledge of Python and therefore I decided to make a .NET builder which will do the same thing as the Python script but with my changes in it.  And then I ran into the problem with the correct order of files.</p>
<p>OpenLayers files has a &#8216;@ reguires&#8217; commentline in it&#8217;s files which determines the dependency between the files. I started to create a class which represents the OpenLayers file:</p>
<pre class="brush: csharp">internal class OpenLayersFile: IComparable&lt;OpenLayersFile&gt;
{
    public OpenLayersFile(string filename)
    { ... }

    public string Name { get; set; }
    public List&lt;string&gt; DependsOn { get; set; }
    public int CompareTo(OpenLayersFile otherFile)
    { ... }
}</pre>
<p>The class was simple. It has a Name &#8211; property which is the concatenated name of the file (e.g. OpenLayers/Layer/WMS.js). and a DependsOn &#8211; property which is a list of &#8220;Names&#8221; of the files it depends on. The CompareTo method just does a check if DependsOn contains the Name of the file it&#8217;s compared to. The logic is omitted because it will clutter up the code snippet and doesn&#8217;t add value to this post. </p>
<p>Because List&lt;T&gt;.Sort() didn&#8217;t work as described expected as described above I created my own Dependency Walker which runs down all the files and orders them correctly. This dependency walker also keeps in mind to order correct when we have a baseclass with a baseclass which has a baseclass (and so on). Here is the code:</p>
<pre class="brush: csharp">private static class DependencyWalker
{
     public static void Walk(List&lt;OpenLayersFile&gt; files)
     {
          for (int index = 0; index < files.Count; index++)
          {
              OpenLayersFile fileToCompare = files[index];
              for (int i = 0; i < index; i++)
              {
                  OpenLayersFile otherFile = files[i];
                  if (fileToCompare.CompareTo(otherFile) == -1)
                  {
                      files.Remove(fileToCompare);
                      files.Insert(i, fileToCompare);
                      index = 0;
                      break;
                   }
                }
           }
      }
}
</pre>
<p>This worked perfectly for me and I hope that it will help you too. I am also interested if you have a different solution to the problem. If so, please contact me.</p>
<p>Happy coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://justyouraveragegeek.com/blog/index.php/2011/01/dependencywalker/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ComVisible class with a non ComVisible baseclass</title>
		<link>http://justyouraveragegeek.com/blog/index.php/2010/03/comvisible-class-with-a-non-comvisible-baseclass/</link>
		<comments>http://justyouraveragegeek.com/blog/index.php/2010/03/comvisible-class-with-a-non-comvisible-baseclass/#comments</comments>
		<pubDate>Thu, 18 Mar 2010 19:15:38 +0000</pubDate>
		<dc:creator>Michel van der Weide</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[WinForms]]></category>
		<category><![CDATA[baseclass]]></category>
		<category><![CDATA[ClassInterface]]></category>
		<category><![CDATA[ClassInterfaceType]]></category>
		<category><![CDATA[ClassInterfaceType.None]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[ComVisible]]></category>
		<category><![CDATA[ObjectForScripting]]></category>

		<guid isPermaLink="false">http://justyouraveragegeek.com/blog/?p=191</guid>
		<description><![CDATA[In my previous post I was talking about using the WebBrowserControl in a WinForms application. I demonstrated how you can communicate to the JavaScript of the webpage loaded in the WebBrowserControl in your C# code and vice versa. While using this code I ran into a problem myself. The Form which was made ComVisible had ]]></description>
			<content:encoded><![CDATA[<p>In <a title="Winforms with a WebBrowserControl" href="http://justyouraveragegeek.com/blog/index.php/2010/03/winforms-with-a-webbrowsercontrol-fun-with-objectforscripting/" target="_blank">my previous post</a> I was talking about using the WebBrowserControl in a WinForms application. I demonstrated how you can communicate to the JavaScript of the webpage loaded in the WebBrowserControl in your C# code and vice versa.</p>
<p>While using this code I ran into a problem myself. The Form which was made ComVisible had a baseclass which was not ComVisible. When I ran my code I had this great exception when calling the C# code from JavaScript:</p>
<table style="border: 1px solid black; width: 100%;">
<tbody>
<tr>
<td style="border-right: none;">
<h5><img class="size-full wp-image-82 aligncenter" title="NonComVisibleBaseClass" src="http://justyouraveragegeek.com/blog/wp-content/uploads/2010/03/NonVisibleBaseClassDetected.png" alt="" width="455" height="283" />NonComVisibleBaseClass was detected</h5>
<h5>A QueryInterface call was made requesting the default IDispatch interface of COM visible managed class &#8216;JYAG.WebControlInWinforms.GeekBrowser&#8217;. However since this class does not have an explicit default interface and derives from non COM visible class &#8216;JYAG.WebControlInWinforms.GeekBasePage&#8217;, the QueryInterface call will fail. This is done to prevent the non COM visible base class from being constrained by the COM versioning rules.</h5>
</td>
</tr>
</tbody>
</table>
<p>The simplest solution  is to make the baseclass ComVisible just as well. But in my case it was not an option to expose the baseclass to Com-components. So what can we do to make this work without having to make the baseclass ComVisible.  There are three easy steps to take to accomplish this.</p>
<p><strong>Step 1 &#8211; Define a interface with the methods you&#8217;d like to call from JavaScript</strong></p>
<p>First we define a Interface and put all the methods we want to reach through JavaScript in there. We make the interface ComVisible. I took the <a title="TestProject" href="http://justyouraveragegeek.com/blog/wp-content/uploads/2010/03/WebBrowserControlInWinforms.zip">test-project of my previous post</a> and added a <em>IMapControlInteractable</em> interface which contains just one method.</p>
<pre class="brush: csharp">    [ComVisible(true)]
    public interface IMapControlInteractable
    {
        void ActivateControls();
    }
</pre>
<p><strong>Step 2 &#8211; Give the ComVisible class the ClassInterfaceAttribute</strong></p>
<p>To use the Interface in combination with the ComVisible attribute and effectivly let the JavaScript communicate with the C# code we give the class the ClassInterfaceAttribute and specify the type at &#8216;none&#8217;.</p>
<pre class="brush: csharp">    [ClassInterface(ClassInterfaceType.None)]</pre>
<p><strong>Step 3 &#8211; Implement the Interface</strong></p>
<p>The last thing we must do is implement the Interface. If we do so the code my look something like this.</p>
<pre class="brush: csharp">    //Make class visible for COM so we can set the ObjectForScripting
    //Specify ClassInterfaceType.None to use the ComVisible Interface
    [ComVisible(true)]
    [ClassInterface(ClassInterfaceType.None)]
    public partial class GeekBrowser : GeekBasePage, IMapControlInteractable
    {
</pre>
<p>That&#8217;s all there is to it. Now our exception at runtime disappears and our code works. And our baseclass is not ComVisible.</p>
<p><a title="New Test Project" href="http://justyouraveragegeek.com/blog/wp-content/uploads/2010/03/WebBrowserControlInWinformsWithBaseClass.zip" target="_blank">Download this code in the adjusted test project</a>.</p>
<p>For comments, questions  or suggestions contact me or leave a comment below.</p>
]]></content:encoded>
			<wfw:commentRss>http://justyouraveragegeek.com/blog/index.php/2010/03/comvisible-class-with-a-non-comvisible-baseclass/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Winforms with a WebBrowserControl, Fun with ObjectForScripting</title>
		<link>http://justyouraveragegeek.com/blog/index.php/2010/03/winforms-with-a-webbrowsercontrol-fun-with-objectforscripting/</link>
		<comments>http://justyouraveragegeek.com/blog/index.php/2010/03/winforms-with-a-webbrowsercontrol-fun-with-objectforscripting/#comments</comments>
		<pubDate>Thu, 04 Mar 2010 22:15:55 +0000</pubDate>
		<dc:creator>Michel van der Weide</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[WinForms]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[ObjectForScripting]]></category>
		<category><![CDATA[WebBrowserControl]]></category>

		<guid isPermaLink="false">http://justyouraveragegeek.com/blog/?p=156</guid>
		<description><![CDATA[Recently I had to put a map control (like Google Maps) in a Winforms application and I had to make the map control react on actions performed on the Winform. I discovered that this was very easy and fun to do with the ObjectForScripting. In this post I will explain the basics of how to ]]></description>
			<content:encoded><![CDATA[<p>Recently I had to put a map control (like Google Maps) in a Winforms application and I had to make the map control react on actions performed on the Winform. I discovered that this was very easy and fun to do with the <em>ObjectForScripting</em>.</p>
<p>In this post I will explain the basics of how to work and communicate with a WebBrowserControl in a Winforms application. I have made a test project which you can <a title="Test Project" href="http://justyouraveragegeek.com/blog/wp-content/uploads/2010/03/WebBrowserControlInWinforms.zip" target="_blank">download</a> so you can see the magic in action. Because I want to show you the basics of the <em>ObjectForScripting </em>I kept the project as simple as possible. No fancy code-patterns&#8230; just straightforward coding.</p>
<p>The idea of the project is:</p>
<ul>
<li>The Winform has several input fields for personal information which are all disabled</li>
<li>A button on a webpage in the WebBrowserControl activates the input fields of the Winform</li>
<li>The Winform contains a button which transfers the values of the input fields on the Winform to the input fields of a webpage</li>
</ul>
<p>By implementing this in my project I can demonstrate the communication from Webpage to Winform (activating the controls on the Winform) as well as the communication from Winform to the Webpage (filling the input fields). <a title="Download Test Project" href="http://justyouraveragegeek.com/blog/wp-content/uploads/2010/03/WebBrowserControlInWinforms.zip" target="_blank">Download the project</a> and examine it carefully.</p>
<p><strong>So now look at the code</strong><br />
<span id="more-156"></span>The communication between the WebBrowser and the Winform works through JavaScript. You can call methods of the JavaScript in your C# code like this:</p>
<pre class="brush: csharp">  this.webBrowser.Document.InvokeScript("alert", new object[] { "Hello World" });</pre>
<p>and you can call your C# methods in your JavaScript like this:</p>
<pre class="brush: js">  window.external.ActivateControls();</pre>
<p>But before you can do so you must enable the communication by setting the <em>ObjectForScripting </em>on the WebBrowserControl.</p>
<pre class="brush: csharp">  this.webBrowser.ObjectForScripting = this;</pre>
<p>The above line of code sets the object for scripting. In this case it is set to &#8216;this&#8217; which is the Winform in this project. The object set here is available in the JavaScript through <em>window.external</em>. So the methods of that object are available in the JavaScript.<br />
If you set this line of code and compile the project you will get an Error. This is because the JavaScript has got to have access to the C# code and so we must mark the C# code visible for COM. We do this by setting the <em>ComVisibleAttribute</em> on the object we passed as the ObjectForScripting.</p>
<pre class="brush: csharp">  [ComVisible(true)]
  public partial class GeekBrowser : Form</pre>
<p>There is one small difference in calling the C# code from JavaScript and vice versa. When you call C# code from JavaScript you can send in the parameters directly. When you want to send parameters from C# to JavaScript methods you must send it as an Array of Objects. In our test project the JavaScript method takes 5 parameters and therefore I have to create an Array of Objects and give it the 5 parameters and send that array to the method:</p>
<pre class="brush: csharp">  [ComVisible(true)]
  object[] args = new object[5];
  args[0] = this.firstNameTextBox.Text;
  args[1] = this.lastNameTextBox.Text;
  args[2] = this.addressTextBox.Text;
  args[3] = this.phoneTextBox.Text;
  args[4] = this.emailTextBox.Text;

  this.webBrowser.Document.InvokeScript("fillFields", args);</pre>
<p>And that is, in a nutshell, how you can make the Winform communicate with the contents of the WebBrowser.</p>
<p>Read more about <a title="Download Test Project" href="http://justyouraveragegeek.com/blog/wp-content/uploads/2010/03/WebBrowserControlInWinforms.zip" target="_blank">the test project</a> on page 2.</p>
]]></content:encoded>
			<wfw:commentRss>http://justyouraveragegeek.com/blog/index.php/2010/03/winforms-with-a-webbrowsercontrol-fun-with-objectforscripting/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Passed Microsofts 70-536 exam.</title>
		<link>http://justyouraveragegeek.com/blog/index.php/2010/02/passed-microsofts-70-536-exam/</link>
		<comments>http://justyouraveragegeek.com/blog/index.php/2010/02/passed-microsofts-70-536-exam/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 12:29:36 +0000</pubDate>
		<dc:creator>Michel van der Weide</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[70-536]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Exam]]></category>
		<category><![CDATA[MCPD]]></category>
		<category><![CDATA[MCTS]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Self Paced Training Kit]]></category>
		<category><![CDATA[TestKing]]></category>

		<guid isPermaLink="false">http://justyouraveragegeek.com/blog/?p=138</guid>
		<description><![CDATA[In 2009 I made a commitment to myself en to my employer. I would become at least an MCTS on ASP.NET in 2010. I have raised the bar even higher by saying that if I would be an MCTS at the beginning of August I would go on and become an MCPD on ASP.NET before ]]></description>
			<content:encoded><![CDATA[<p>In 2009 I made a commitment to myself en to my employer. I would become at least an MCTS on ASP.NET in 2010. I have raised the bar even higher by saying that if I would be an MCTS at the beginning of August I would go on and become an MCPD on ASP.NET before the end of 2010.<br />
Last Tuesday I went to the examcenter in Leusden and I took the first exam needed to become an MCTS: <strong>70-536 &#8220;Microsoft .Net Framework &#8211; Application Development Foundation</strong>. I passed the exam with a score of 930 out of 1000. A beautiful result, I should be happy. But am I?</p>
<p>Well, Yes&#8230; &#8230;I am happy with the result and me passing the test. But it left me with some mixed feelings. Let me explain.<br />
I started learning for this exam at the beginning of  January. Studied the Self Paced Training Kit. Made the examples (well most of them) and took the test per chapter. Some subjects where difficult for me to understand (like Code Access Security CAS) and so I read several chapters in reference books. The Training Kit came with a CD with test exams and I took those as well.  I gave up a lot of free evenings in the past two months and was proud to have learned a lot more then I thought I would learn. Oh&#8230; and just two days before the exam I decided to download some TestKings and look at them as well.</p>
<p>So eventually I was taking the exam with some nervousness but in the back of my mind was confidence. I did my best and I should be able to pass the exam. I had to answer 40 questions. From this 40 there where at least 25 questions that where almost identical to the questions of the TestKings. I am convinced that if I only studied the TestKings and did nothing more than that, I would have passed the exam just as well. Probably not with 930 but that doesn&#8217;t matter does it? It matters that you pass the exam. No one looks at the grades when you show the certificate.</p>
<p>I think it is time for Microsoft to redefine their exams. At this moment anyone can pass their exams and it takes away the status of the certificate. I am proud of what I have achieved in the past months and will continue studying at the same way for the next exams.</p>
<p>But I did not passed the exam with 930&#8230; I did the Microsoft Trick and got 930 points out of it.</p>
]]></content:encoded>
			<wfw:commentRss>http://justyouraveragegeek.com/blog/index.php/2010/02/passed-microsofts-70-536-exam/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Optimizing your for-loop</title>
		<link>http://justyouraveragegeek.com/blog/index.php/2010/02/optimizing-your-for-loop/</link>
		<comments>http://justyouraveragegeek.com/blog/index.php/2010/02/optimizing-your-for-loop/#comments</comments>
		<pubDate>Wed, 03 Feb 2010 10:53:14 +0000</pubDate>
		<dc:creator>Michel van der Weide</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[for]]></category>
		<category><![CDATA[for loop]]></category>
		<category><![CDATA[improvement]]></category>
		<category><![CDATA[length]]></category>
		<category><![CDATA[loop]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[performance improvement]]></category>

		<guid isPermaLink="false">http://justyouraveragegeek.com/blog/?p=130</guid>
		<description><![CDATA[I use for-loops on a daily basis. I use them when I write Javascript and in C#. The for-loop is very common and easy to use. Here is a typical example of a for-loop in C#: for (int i = 0; i &#60; arr.Length; i++) { object arrayItem = arr[i]; //do something with arrayItem } ]]></description>
			<content:encoded><![CDATA[<p>I use for-loops on a daily basis. I use them when I write Javascript and in C#. The for-loop is very common and easy to use. Here is a typical example of a for-loop in C#:</p>
<pre class="brush: csharp">for (int i = 0; i &lt; arr.Length; i++)
{
     object arrayItem = arr[i];
     //do something with arrayItem
}</pre>
<p>Even though this is a perfectly legal example of a for-loop there is room for improvement.<br />
Each iteration of the for-loop the <em>Length</em> property of the array will be retrieved. The performance penalty on this is minimal but when your array consists of thousands of objects the performance penalty can be noticeable. The answer is:  &#8216;caching&#8217;.</p>
<p>The for-loop can be changed to cache the <em>Length</em>-value in a variable and then use that variable instead of the length property. Example:</p>
<pre class="brush: csharp">for (int i = 0, len = arr.Length; i &lt; len; i++)
{
     object arrayItem = arr[i];
     //do something with arrayItem
}</pre>
<p>Caching the value of the Length-property is always a good thing to do even if you expect your array yo be minimal in length. There is no penalty for doing this on small arrays, only a benefit when used on large arrays. Therefore I recommend to always use caching in your array.</p>
<p>It works in C# as well as in Javascript and probably on a lot of more languages.</p>
<p>Happy coding.</p>
]]></content:encoded>
			<wfw:commentRss>http://justyouraveragegeek.com/blog/index.php/2010/02/optimizing-your-for-loop/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Model View Presenter: Control Model</title>
		<link>http://justyouraveragegeek.com/blog/index.php/2010/01/mvppattern-control-model/</link>
		<comments>http://justyouraveragegeek.com/blog/index.php/2010/01/mvppattern-control-model/#comments</comments>
		<pubDate>Wed, 20 Jan 2010 22:29:46 +0000</pubDate>
		<dc:creator>Michel van der Weide</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Patterns]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Control Model]]></category>
		<category><![CDATA[Design by contract]]></category>
		<category><![CDATA[Framework]]></category>
		<category><![CDATA[Interfaces]]></category>
		<category><![CDATA[Model]]></category>
		<category><![CDATA[Model View Presenter]]></category>
		<category><![CDATA[Passive View]]></category>
		<category><![CDATA[Pattern]]></category>
		<category><![CDATA[Presenter]]></category>
		<category><![CDATA[View]]></category>

		<guid isPermaLink="false">http://justyouraveragegeek.com/blog/?p=65</guid>
		<description><![CDATA[When you use the Model View Presenter (MVP) Pattern you design by contract. One of the contracts you specify is the contract which describes the graphical interface, called the view. Normally you will specify the contract with base types such as Strings and Booleans. I want to show you another way to define the view ]]></description>
			<content:encoded><![CDATA[<p>When you use the Model View Presenter (MVP) Pattern you design by contract. One of the contracts you specify is the contract which describes the graphical interface, called the <em>view</em>. Normally you will specify the contract with base types such as <em>Strings </em>and <em>Booleans</em>. I want to show you another way to define the view by using<em> contracts specifying controls</em>.</p>
<p>Martin Fowler called for the <a title="retirement" href="http://martinfowler.com/eaaDev/ModelViewPresenter.html" target="_blank"> retirement</a> of the MVP Pattern in July 2006 and suggested to separate the pattern into two new patterns, namely &#8216;<a title="Supervising Controller" href="http://martinfowler.com/eaaDev/SupervisingPresenter.html" target="_blank">Supervising Controller</a>&#8216; and &#8216;<a title="Passive View" href="http://martinfowler.com/eaaDev/PassiveScreen.html" target="_blank">Passive View</a>&#8216;. This blog-posting is not intended to explain the basics of the MVP-pattern. That being said, I even expect the reader to have a certain level of familiarity with the pattern.</p>
<p>The &#8216;Passive View&#8217; is a pattern in which the User Interface has as less logic as possible. I prefer the &#8216;Passive View&#8217; above the &#8216;Supervising Controller&#8217; because lesser logic makes it easier to substitute the user interface with a new one. I use the Passive View as the pattern of choice and when I talk here about the MVP pattern I am referring to the Passive View approach.</p>
<p>As said above, classic MVP models the interface which describes the GUI (view) with Strings, Booleans and perhaps some domainobjects. When you want a grid in your GUI you will specify a List&lt;object&gt; in your view interface. Then in your implementation of the view you will have to write some logic to put the list of objects into the grid.<br />
This approach has two major downfalls. The first is the amount of logic you have to put in your implementation. I am a big fan of the Passive View because the lack of logic in the implementation of the view makes the view easy to replace. The second downfall is that the logic you write in the implementation has to be written over and over again in the different forms and applications you create.<br />
<span id="more-65"></span><br />
To avoid this two downfalls I am suggesting a different way of modeling the view using contracts of controls. I would like to call it the <em>&#8216;Passive View Control Model&#8217;. </em>Instead of specifying that the view should have a string to get the username given by a user in a textbox I tell the view to have a ITextbox for the username, which could be a WinForms Textbox or a ASP.NET Textbox.</p>
<p>Let me clarify myself in an example on the next page.</p>
]]></content:encoded>
			<wfw:commentRss>http://justyouraveragegeek.com/blog/index.php/2010/01/mvppattern-control-model/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>C# Conditional Operator versus Null-Coalescing Operator</title>
		<link>http://justyouraveragegeek.com/blog/index.php/2009/09/c-conditional-operator-versus-null-coalescing-operator/</link>
		<comments>http://justyouraveragegeek.com/blog/index.php/2009/09/c-conditional-operator-versus-null-coalescing-operator/#comments</comments>
		<pubDate>Sun, 06 Sep 2009 08:38:38 +0000</pubDate>
		<dc:creator>Michel van der Weide</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Conditional Operator]]></category>
		<category><![CDATA[null]]></category>
		<category><![CDATA[Null-Coalescing Operator]]></category>

		<guid isPermaLink="false">http://justyouraveragegeek.com/blog/?p=42</guid>
		<description><![CDATA[In javascript I often use a phrase like this: var text = tempText &#124;&#124; &#8220;No Text Given&#8221;; With this phrase we assign the value of tempText to the variable text. If tempText is null we assign &#8220;No Text Given&#8221; to the text variable. To do the same trick in C# I was using the Conditional ]]></description>
			<content:encoded><![CDATA[<p>In javascript I often use a phrase like this:</p>
<p><strong>var text = tempText || &#8220;No Text Given&#8221;;</strong></p>
<p>With this phrase we assign the value of tempText to the variable text. If tempText is null we assign &#8220;No Text Given&#8221; to the text variable.</p>
<p>To do the same trick in C# I was using the Conditional Operator:</p>
<p><strong>string text = tempText != null ? tempText :  &#8220;No Text Given&#8221;;</strong></p>
<p>In my opinion this isn&#8217;t very nice code. So I started searching and I found the nice Null-Coalescing Operator. It goes like this:</p>
<p><strong>string text = tempText ?? &#8220;No Text Given&#8221;;</strong></p>
<p>This looks much better.<br />
For all you javascript-geeks. The javascript notation also checks for empty string. The Null-Coalescing Operator does not.</p>
<p>Happy coding!!</p>
]]></content:encoded>
			<wfw:commentRss>http://justyouraveragegeek.com/blog/index.php/2009/09/c-conditional-operator-versus-null-coalescing-operator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Runtime vs Compilation time</title>
		<link>http://justyouraveragegeek.com/blog/index.php/2009/07/runtime-vs-compilation-time/</link>
		<comments>http://justyouraveragegeek.com/blog/index.php/2009/07/runtime-vs-compilation-time/#comments</comments>
		<pubDate>Tue, 28 Jul 2009 13:43:35 +0000</pubDate>
		<dc:creator>Michel van der Weide</dc:creator>
				<category><![CDATA[ExtAppBuilder]]></category>

		<guid isPermaLink="false">http://justyouraveragegeek.com/blog/?p=36</guid>
		<description><![CDATA[Not much code changes these days. But I have a good excuse. It is my holiday and tomorrow I&#8217;ll be heading towards Austria and Italy. But this doesn&#8217;t mean that I haven&#8217;t been thinking about ExtAppBuilder. In my previous post I was thinking about some way to convert the C# code to JavaScript code. I ]]></description>
			<content:encoded><![CDATA[<p>Not much code changes these days. But I have a good excuse. It is my holiday and tomorrow I&#8217;ll be heading towards Austria and Italy. But this doesn&#8217;t mean that I haven&#8217;t been thinking about <a title="ExtAppBuilder" href="http://code.google.com/p/extappbuilder/" target="_blank">ExtAppBuilder</a>.</p>
<p>In<a title="Seen the light" href="http://justyouraveragegeek.com/blog/index.php/2009/07/seen-the-light/" target="_blank"> my previous post</a> I was thinking about some way to convert the C# code to JavaScript code. I figured out that the skeleton functions must remain and return null or 0. But my opinion has changed, because there is a difference between compilationtime and runtime.</p>
<p>When I write code to add a Panel only if the current user is in a certain role then this must be checked at runtime and not at compilation. To accomplish this the skeleton code still must return null or 0 but also must write a line of JavaScript code at the time they are called, runtime.</p>
<p>So what to do at compilation time. On compilation we must check the written code for functions which should be in a handler. We must create the handlers with two partial classes (just like your aspx.cs and aspx.designer.cs) and put the necessary code in it. This will ease the job of the developer because they don&#8217;t have to worry about writing handlers. This will be handled by ExtAppBuilder in a generic way</p>
<p>This might seem a bit cryptic and I write this down mostly as a reminder for myself. But in my next post, when I am back from holiday and when I understand the way of writing code blocks with WP (duh), I will explain my theory with code examples.</p>
]]></content:encoded>
			<wfw:commentRss>http://justyouraveragegeek.com/blog/index.php/2009/07/runtime-vs-compilation-time/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

