<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>Jonathan Dickinson</title>
        <link>http://geekswithblogs.net/jcdickinson/Default.aspx</link>
        <description>Moved to: jonathan.dickinsons.co.za/blog</description>
        <language>en-ZA</language>
        <copyright>Jonathan Dickinson</copyright>
        <managingEditor>jonathand@k2.com</managingEditor>
        <generator>Subtext Version 0.0.0.0</generator>
        <creativeCommons:license>http://creativecommons.org/licenses/by/2.5/za/</creativeCommons:license>
        <image>
            <title>Jonathan Dickinson</title>
            <url>http://geekswithblogs.net/images/RSS2Image.gif</url>
            <link>http://geekswithblogs.net/jcdickinson/Default.aspx</link>
            <width>77</width>
            <height>60</height>
        </image>
        <item>
            <title>Moved</title>
            <category>Born Again</category>
            <category>Reading</category>
            <category>K2</category>
            <category>Operating System</category>
            <category>Tips</category>
            <category>C#</category>
            <category>Behaviour Injection</category>
            <category>Patterns and Practices</category>
            <link>http://geekswithblogs.net/jcdickinson/archive/2009/07/11/moved.aspx</link>
            <description>&lt;p&gt;Originally posted on: &lt;a href='http://geekswithblogs.net/jcdickinson/archive/2009/07/11/moved.aspx'&gt;http://geekswithblogs.net/jcdickinson/archive/2009/07/11/moved.aspx&lt;/a&gt;&lt;/p&gt;This blog is now over at &lt;a href="http://jonathan.dickinsons.co.za/blog"&gt;http://jonathan.dickinsons.co.za/blog&lt;/a&gt; &lt;img src="http://geekswithblogs.net/jcdickinson/aggbug/133423.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Jonathan Dickinson</dc:creator>
            <guid>http://geekswithblogs.net/jcdickinson/archive/2009/07/11/moved.aspx</guid>
            <pubDate>Sat, 11 Jul 2009 18:56:42 GMT</pubDate>
            <comments>http://geekswithblogs.net/jcdickinson/archive/2009/07/11/moved.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/jcdickinson/comments/commentRss/133423.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Safer Duck</title>
            <category>Patterns and Practices</category>
            <link>http://geekswithblogs.net/jcdickinson/archive/2009/04/27/rubberducky.aspx</link>
            <description>&lt;p&gt;Originally posted on: &lt;a href='http://geekswithblogs.net/jcdickinson/archive/2009/04/27/rubberducky.aspx'&gt;http://geekswithblogs.net/jcdickinson/archive/2009/04/27/rubberducky.aspx&lt;/a&gt;&lt;/p&gt;&lt;p&gt;No, it's not made from Latex. It can still quack like a duck and walk like a duck - but you'd be saved from trying to make it qauck like a duck. I call it a &lt;a href="http://en.wikipedia.org/wiki/Rubberduck"&gt;Rubberduck&lt;/a&gt; language (for obvious reasons).&lt;/p&gt;
&lt;p&gt;So how do you make a safer (and faster) duck-typed language? By using regex.&lt;/p&gt;
&lt;p&gt;This would be a good example of a rubberduck method:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;public IEnumerable&amp;lt;string&amp;gt; ~Get_(&amp;lt;table&amp;gt;[^_]*)_by_(&amp;lt;field&amp;gt;[^(]*)~ GetTableRowByFieldValue(string fieldValue)
{
 if(table == "users")
   return Foo(field, fieldValue);
 else
   return Bar(field, fieldValue);
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That defines a method that uses a regex to provide more type safety. Thus you can use the method like:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Database.Get_users_by_name("fred");&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And in other languages:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Database.GetTableRowByFieldValue("users", "name", "fred");&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The great thing is the compiler still has a lot of optimization oppurtunity than a simple 'dynamic resolve' method (i.e. the IDynamicType interface in C# 4.0).&lt;/p&gt;
&lt;p&gt;What do I mean by this? The compiler would essentially emit the following types and methods:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// Used for runtime dynamic method creation.
delegate IEnumerable&amp;lt;string&amp;gt; GetTableRowByFieldValueDelegate(string fieldValue);

// Used by other languages.
public IEnumerable&amp;lt;string&amp;gt; GetTableRowByFieldValue(string table, string field, string fieldValue)
{
 if(table == "users")
   return Foo(field, fieldValue);
 else
   reutnr Bar(field, fieldValue);
}

// Used to create the method at runtime.
public GetTableRowByFieldValueDelegate Create_GetTableRowByFieldValue(string table, string field)
{
 DynamicMethod method = CreateMethod(); // etc.&lt;br /&gt;
 if(table == "users")
 {
   method.Push(method.Param("field"));
   method.Push(method.Param("fieldValue"));
   method.AddCall(this, "$C$0001");
   method.AddReturn();
 }
 else
 {
   method.Push(method.Param("field"));
   method.Push(method.Param("fieldValue"));
   method.AddCall(this, "$C$0002");
   method.AddReturn();
 }
 return method.CompileAs&amp;lt;GetTableRowByFieldValueDelegate&amp;gt;();
}

// Used by method creation.
public IEnumerable&amp;lt;string&amp;gt; $C$0001(string field, string fieldValue)
{&lt;br /&gt;   // Need to do this for private fields and methods.
   Foo(field, fieldValue);&lt;br /&gt;   // Could be skipped if the field or method is not private.&lt;br /&gt;&lt;/code&gt;&lt;code&gt;}

public IEnumerable&amp;lt;string&amp;gt; $C$0002(string field, string fieldValue)
{
   Bar(field, fieldValue);
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Furthermore, the compiler would be able to create concrete methods if the dynamic method is called from the same assembly.&lt;/p&gt; &lt;img src="http://geekswithblogs.net/jcdickinson/aggbug/131520.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Jonathan Dickinson</dc:creator>
            <guid>http://geekswithblogs.net/jcdickinson/archive/2009/04/27/rubberducky.aspx</guid>
            <pubDate>Tue, 28 Apr 2009 09:38:59 GMT</pubDate>
            <comments>http://geekswithblogs.net/jcdickinson/archive/2009/04/27/rubberducky.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/jcdickinson/comments/commentRss/131520.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Wrapping on Specific Characters</title>
            <category>Tips</category>
            <category>C#</category>
            <link>http://geekswithblogs.net/jcdickinson/archive/2009/04/23/wrapping-on-specific-characters.aspx</link>
            <description>&lt;p&gt;Originally posted on: &lt;a href='http://geekswithblogs.net/jcdickinson/archive/2009/04/23/wrapping-on-specific-characters.aspx'&gt;http://geekswithblogs.net/jcdickinson/archive/2009/04/23/wrapping-on-specific-characters.aspx&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Recently on a project I was working I needed to wrap on backslash characters (file and registry paths). Unfortunately the only help StringFormat can provide is intelligent trimming (e.g. C:\Program Files\....\Foo) and not wrapping options.&lt;/p&gt;
&lt;p&gt;I wasn't so keen on writing my own text drawing/wrapping algorithm, but how to wrap at a specific character? One of my co-workers gave me the spark I needed to figure the whole thing out: use spaces. Now, that is a hack that is visible to the user, and is plain nasty (C:\ Foo\ Bar just doesn't cut it) - but we live in a unicode world; and unicode has some very interesting characters. The one that helps in this situation is ZERO WIDTH SPACE (U + 200B).&lt;/p&gt;
&lt;p&gt;How do we use it? Simply do the following:&lt;/p&gt;
&lt;code&gt;
&lt;pre&gt; string wrappable = unwrappable.Replace("\\", "\\\u200B");
&lt;/pre&gt;
&lt;/code&gt;
&lt;p&gt;That will allow wraps after backslashes. I am sure you could find non-wrap counterparts for most wrap characters as well (e.g. NON BREAK SPACE). I started writing a util class to allow you to wrap before/after any character (that doesn't usually wrap) or not wrap before/after a character (that usually wraps) - but it was decidedly boring; so I never finished it.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt; &lt;img src="http://geekswithblogs.net/jcdickinson/aggbug/131401.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Jonathan Dickinson</dc:creator>
            <guid>http://geekswithblogs.net/jcdickinson/archive/2009/04/23/wrapping-on-specific-characters.aspx</guid>
            <pubDate>Thu, 23 Apr 2009 13:00:14 GMT</pubDate>
            <comments>http://geekswithblogs.net/jcdickinson/archive/2009/04/23/wrapping-on-specific-characters.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/jcdickinson/comments/commentRss/131401.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Browser != OS</title>
            <category>Operating System</category>
            <link>http://geekswithblogs.net/jcdickinson/archive/2009/04/20/browser--os.aspx</link>
            <description>&lt;p&gt;Originally posted on: &lt;a href='http://geekswithblogs.net/jcdickinson/archive/2009/04/20/browser--os.aspx'&gt;http://geekswithblogs.net/jcdickinson/archive/2009/04/20/browser--os.aspx&lt;/a&gt;&lt;/p&gt;&lt;p&gt;I just read a &lt;a target="_blank" href="http://blogs.zdnet.com/BTL/?p=16590"&gt;ZDNet Article by Jason Hiner&lt;/a&gt;, and I strongly believe he is missing the point.&lt;/p&gt;
&lt;p&gt;Before I delve into the details, I would just like to state my opinion. The browser has become frankenstein - these word processors (if you can call them that) and so forth are using the browser for things that it was never designed for. Sure you have V8 in Chrome now - but JS will never match real OOP languages like C# and Java in terms of maintainability. These are 'cool' things that should have remained 'cool.' Honestly, compare Google Docs to Word - I doubt a serious typesetter would consider using Google Docs. GMail is a great idea; Google Docs is an abomination. You need to know when to stop.&lt;/p&gt;
&lt;p&gt;For the same reason, people are often fooled into thinking that the browser is the OS. His article is titled "&lt;font face="Arial"&gt;Have we arrived in the post-Windows era?," however, do you see a single graph of OS popularity? Nope there goes the good old IE versus Firefox graph. That graph used to be relevant in the argument when people were complacent about the default browser on Windows.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;His entire argument is based on browsers - and Firefox and Chrome install fine on my copy of Windows. He indicates that Vista and 7 bring nothing new to the table. Linux is still the same beast it was years ago. Sure you have Compiz now, but at the same time Vista has DWM - and it got a big question mark for that one. It is really hard to evolve when all the ideas are out there already; and I think Microsoft is doing a stellar job in that environment.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;He says people use Windows XP because they are unwilling to upgrade to Vista. If people are using Windows XP does it not mean that Windows isn't reaching the end of its lifetime?&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;I wouldn't take that article seriously. He starts off claiming that Windows is dead, and then that all operating systems are dead. Typical web-head perspective - they never realise that you need something to run IIS/Apache/MSSQL/MySQL.&lt;/p&gt;
&lt;p&gt;This must be the 20th article I read in the past 4 years claiming that Windows is meeting its demise (yes, even before Microsoft made a mess with Vista). Four years on the the corporate machine is still thriving; why? Because web-apps don't run without an OS dammnit!&lt;/p&gt; &lt;img src="http://geekswithblogs.net/jcdickinson/aggbug/131340.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Jonathan Dickinson</dc:creator>
            <guid>http://geekswithblogs.net/jcdickinson/archive/2009/04/20/browser--os.aspx</guid>
            <pubDate>Tue, 21 Apr 2009 09:10:49 GMT</pubDate>
            <comments>http://geekswithblogs.net/jcdickinson/archive/2009/04/20/browser--os.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/jcdickinson/comments/commentRss/131340.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Professional K2 blackpearl is out</title>
            <category>K2</category>
            <category>Reading</category>
            <link>http://geekswithblogs.net/jcdickinson/archive/2009/01/22/professional-k2-blackpearl-is-out.aspx</link>
            <description>&lt;p&gt;Originally posted on: &lt;a href='http://geekswithblogs.net/jcdickinson/archive/2009/01/22/professional-k2-blackpearl-is-out.aspx'&gt;http://geekswithblogs.net/jcdickinson/archive/2009/01/22/professional-k2-blackpearl-is-out.aspx&lt;/a&gt;&lt;/p&gt;We have finally released a K2 [blackpearl] Book called &lt;a href="http://www.k2.com/k2book" target="_blank"&gt;"Professional K2 blackpearl"&lt;/a&gt;.  I will be getting the book at some point so I will definitely do another post. Previous experience has shown me that these "Professional [product]" books tend to be quite good (having gone through "Professional SQL Server 2005" and "Professional SQL Server Integration Services") - so I am looking forward to it. &lt;img src="http://geekswithblogs.net/jcdickinson/aggbug/128925.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Jonathan Dickinson</dc:creator>
            <guid>http://geekswithblogs.net/jcdickinson/archive/2009/01/22/professional-k2-blackpearl-is-out.aspx</guid>
            <pubDate>Fri, 23 Jan 2009 05:21:03 GMT</pubDate>
            <comments>http://geekswithblogs.net/jcdickinson/archive/2009/01/22/professional-k2-blackpearl-is-out.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/jcdickinson/comments/commentRss/128925.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Ternary If Statement in C#</title>
            <category>C#</category>
            <category>Tips</category>
            <link>http://geekswithblogs.net/jcdickinson/archive/2008/12/04/ternary-if-statement-in-c.aspx</link>
            <description>&lt;p&gt;Originally posted on: &lt;a href='http://geekswithblogs.net/jcdickinson/archive/2008/12/04/ternary-if-statement-in-c.aspx'&gt;http://geekswithblogs.net/jcdickinson/archive/2008/12/04/ternary-if-statement-in-c.aspx&lt;/a&gt;&lt;/p&gt;Sometimes you just need a ternary statement, i.e. you don't want to return a value from the condition ? true : false construct. Here is an extension method to help you out (the usage example isn't the best).

&lt;pre&gt;
    class Program
    {
        static void Main(string[] args)
        {
            List&amp;lt;string&amp;gt; test = new List&amp;lt;string&amp;gt;();
            ArrayList source = new ArrayList();

            source.Add(1);
            source.Add("hello");

            source.Each&amp;lt;object&amp;gt;(x =&amp;gt; 
                (x is String).IfElse
                    (
                        () =&amp;gt; test.Add((string)x),
                        () =&amp;gt; test.Add(x.ToString())
                    ));
        }
    }

    static class Extensions
    {
        public static void If(this bool @this, Action isTrue)
        {
            if (@this)
                isTrue();
        }

        public static void IfElse(this bool @this, Action isTrue, Action isFalse)
        {
            if (@this)
                isTrue();
            else
                isFalse();
        }

        internal static void Each&amp;lt;T&amp;gt;(this IEnumerable&amp;lt;T&amp;gt; @this, Action&amp;lt;T&amp;gt; action)
        {
            foreach (T t in @this)
                action(t);
        }

        internal static void Each&amp;lt;T&amp;gt;(this IEnumerable @this, Action&amp;lt;T&amp;gt; action)
        {
            foreach (object t in @this)
                if (t is T)
                {
                    action((T)t);
                }
        }
    }
&lt;/pre&gt; &lt;img src="http://geekswithblogs.net/jcdickinson/aggbug/127597.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Jonathan Dickinson</dc:creator>
            <guid>http://geekswithblogs.net/jcdickinson/archive/2008/12/04/ternary-if-statement-in-c.aspx</guid>
            <pubDate>Fri, 05 Dec 2008 07:28:30 GMT</pubDate>
            <comments>http://geekswithblogs.net/jcdickinson/archive/2008/12/04/ternary-if-statement-in-c.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/jcdickinson/comments/commentRss/127597.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Ruby-like each statement in C#</title>
            <category>Tips</category>
            <category>C#</category>
            <link>http://geekswithblogs.net/jcdickinson/archive/2008/12/04/ruby-like-each-statement-in-c.aspx</link>
            <description>&lt;p&gt;Originally posted on: &lt;a href='http://geekswithblogs.net/jcdickinson/archive/2008/12/04/ruby-like-each-statement-in-c.aspx'&gt;http://geekswithblogs.net/jcdickinson/archive/2008/12/04/ruby-like-each-statement-in-c.aspx&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Funny this isn't in the provided Enumerable extension methods.&lt;/p&gt;

&lt;p&gt;In any case, here it is:&lt;/p&gt;

&lt;pre&gt;
        internal static void Each&amp;lt;T&amp;gt;(this IEnumerable&amp;lt;T&amp;gt; @this, Action&amp;lt;T&amp;gt; action)
        {
            foreach(T t in @this)
                action(t);
        }

        internal static void Each&amp;lt;T&amp;gt;(this IEnumerable @this, Action&amp;lt;T&amp;gt; action)
        {
            foreach (object t in @this)
                if (t is T)
                {
                    action((T)t);
                }
        }
&lt;/pre&gt;

&lt;p&gt;An example:&lt;/p&gt;

&lt;pre&gt;
   objects.Each&lt;foo&gt;(x =&amp;gt; DoSomethingFunky(x, "some parameter"));
&lt;/foo&gt;&lt;/pre&gt; &lt;img src="http://geekswithblogs.net/jcdickinson/aggbug/127596.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Jonathan Dickinson</dc:creator>
            <guid>http://geekswithblogs.net/jcdickinson/archive/2008/12/04/ruby-like-each-statement-in-c.aspx</guid>
            <pubDate>Fri, 05 Dec 2008 07:13:36 GMT</pubDate>
            <comments>http://geekswithblogs.net/jcdickinson/archive/2008/12/04/ruby-like-each-statement-in-c.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/jcdickinson/comments/commentRss/127596.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Using Is.Gd/Bitly/TinyUrl/Facebook Post in Chrome</title>
            <category>Tips</category>
            <link>http://geekswithblogs.net/jcdickinson/archive/2008/12/04/using-isgd-bitly-tinyurl-facebook-postin-chrome.aspx</link>
            <description>&lt;p&gt;Originally posted on: &lt;a href='http://geekswithblogs.net/jcdickinson/archive/2008/12/04/using-isgd-bitly-tinyurl-facebook-postin-chrome.aspx'&gt;http://geekswithblogs.net/jcdickinson/archive/2008/12/04/using-isgd-bitly-tinyurl-facebook-postin-chrome.aspx&lt;/a&gt;&lt;/p&gt;&lt;p&gt;This morning I got sick of having to constantly open my bookmark toolbar to use Is.Gd (it just messes with the zen of Chrome) so I tried to figure out how to have it as a shortcut.&lt;/p&gt;

&lt;p&gt;One option is to name the bookmark something like !gd, while this works, you have to type it in and press (down) twice, then enter. Not my cup of tea.&lt;/p&gt;

&lt;p&gt;As it turns out Chrome doesn't really need a query for a search engine, if you make a engine with no location for the query string pressing Enter will invoke it immediately.&lt;/p&gt;

&lt;p&gt;So here are the steps:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Open your bookmarks tab (CTRL+B).&lt;/li&gt;
  &lt;li&gt;Drag the bookmarklet onto it.&lt;/li&gt;
  &lt;li&gt;Right click the new bookmark -&amp;gt; Edit...&lt;/li&gt;
  &lt;li&gt;Copy the entire URL.&lt;/li&gt;
  &lt;li&gt;Close.&lt;/li&gt;
  &lt;li&gt;(Wrench) -&amp;gt; Options&lt;/li&gt;
  &lt;li&gt;Basics tab.&lt;/li&gt;
  &lt;li&gt;To the right of "Default Search:" click Manage.&lt;/li&gt;
  &lt;li&gt;Click Add.&lt;/li&gt;
  &lt;li&gt;Give it a name (mine was is.gd)&lt;/li&gt;
  &lt;li&gt;Give it a keyword (like sht).&lt;/li&gt;
  &lt;li&gt;Paste in the URL.&lt;/li&gt;
  &lt;li&gt;Ok. Close. Close.&lt;/li&gt;
  &lt;li&gt;Right click the bookmark on your bookmark tab.&lt;/li&gt;
  &lt;li&gt;Delete.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To use it go to the page of choice and type in the keyword in your address bar and hit Enter.&lt;/p&gt;

&lt;p&gt;Justice.&lt;/p&gt; &lt;img src="http://geekswithblogs.net/jcdickinson/aggbug/127594.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Jonathan Dickinson</dc:creator>
            <guid>http://geekswithblogs.net/jcdickinson/archive/2008/12/04/using-isgd-bitly-tinyurl-facebook-postin-chrome.aspx</guid>
            <pubDate>Fri, 05 Dec 2008 05:52:45 GMT</pubDate>
            <comments>http://geekswithblogs.net/jcdickinson/archive/2008/12/04/using-isgd-bitly-tinyurl-facebook-postin-chrome.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/jcdickinson/comments/commentRss/127594.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Forcibly Closing a Start Tag with XmlTextWriter</title>
            <category>C#</category>
            <category>Tips</category>
            <link>http://geekswithblogs.net/jcdickinson/archive/2008/10/02/forcibly-closing-a-start-tag-with-xmltextwriter.aspx</link>
            <description>&lt;p&gt;Originally posted on: &lt;a href='http://geekswithblogs.net/jcdickinson/archive/2008/10/02/forcibly-closing-a-start-tag-with-xmltextwriter.aspx'&gt;http://geekswithblogs.net/jcdickinson/archive/2008/10/02/forcibly-closing-a-start-tag-with-xmltextwriter.aspx&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Recently with my forays into the XMPP land, I have needed to handle the case of writing out the following XML (as is, without the closing tag):&lt;/p&gt;
&lt;p&gt;&amp;lt;stream:stream xmlns="http://etherx.jabber.org/streams" xmlns="jabber:client" from="bob" to="server"&amp;gt;&lt;/p&gt;
&lt;p&gt;Note that the tag is closed. The .Net XML writer keeps that open until you try and go into a conflicting state such as a new start tag, comment, PI, or such. Calling Flush() simply doesn't work.&lt;/p&gt;
&lt;p&gt;My previous methodology used a comment to close it. Thus something like this was sent out:&lt;/p&gt;
&lt;p&gt;&amp;lt;stream:stream xmlns="http://etherx.jabber.org/streams" xmlns="jabber:client" from="bob" to="server"&amp;gt;&amp;lt;!-- Start Stream --&amp;gt;&lt;/p&gt;
&lt;p&gt;Not the best. Some clients dont like comments and the XMPP specification says that comments SHOULD NOT be used (note, not MUST NOT), so some parsers fall over.&lt;/p&gt;
&lt;p&gt;I finally decided to give fixing it a go. I created a root XML writer class that had one abstract method: CompleteElement(). I won't paste that class in because it is trivial. I cracked open Reflector and figured out if there was a common method in XmlTextWriter that handles this. I was in luck, there was (AutoComplete)! My first attempt simply reflected over the XmlTextWriter and found the method, enum and enum field. It didn't work. XmlWriter.Create() hands out XmlWellFormedWriters (you can't instantiate these directly, the class is internal). So I looked at it using Reflector and I was in luck again! The only thing that is different is the name of the method (AdvanceState) and everything else was exactly the same.&lt;/p&gt;
&lt;p&gt;Here it is (most of it is purely wrappers):&lt;/p&gt;
&lt;pre&gt;    /// &amp;lt;summary&amp;gt;
    /// Represents a streaming xml text writer.
    /// &amp;lt;/summary&amp;gt;
    public class StreamingXmlTextWriter : StreamingXmlWriter
    {
        private static object __autoCompleteComment;
        private static MethodInfo __autoCompleteMethod;

        static StreamingXmlTextWriter()
        {
            // Get the type.
            Type wellFormedWriter = typeof(XmlTextWriter).Assembly.GetType("System.Xml.XmlWellFormedWriter");

            // Find the method.
            __autoCompleteMethod = wellFormedWriter.GetMethod("AdvanceState", BindingFlags.Instance | BindingFlags.NonPublic);

            // Find the argument.
            Type tokenEnum = wellFormedWriter.GetNestedType("Token", BindingFlags.NonPublic);
            FieldInfo tokenField = tokenEnum.GetField("Comment", BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
            __autoCompleteComment = tokenField.GetValue(null);
        }


        private XmlWriter writer;
        public StreamingXmlTextWriter(Stream stream, Encoding encoding)
            : base(stream, encoding)
        {
            XmlWriterSettings settings = new XmlWriterSettings();
            settings.Encoding = encoding;
            settings.OmitXmlDeclaration = true;

            writer = XmlWriter.Create(stream, settings);
        }

        #region Wrapped Methods
        public override void Close()
        {
            writer.Close();
        }

        public override void Flush()
        {
            writer.Flush();
        }

        public override string LookupPrefix(string ns)
        {
            return writer.LookupPrefix(ns);
        }

        public override void WriteBase64(byte[] buffer, int index, int count)
        {
            if (skippedAttribute)
                return;

            writer.WriteBase64(buffer, index, count);
        }

        public override void WriteCData(string text)
        {
            if (skippedAttribute)
                return;

            writer.WriteCData(text);
        }

        public override void WriteCharEntity(char ch)
        {
            if (skippedAttribute)
                return;

            writer.WriteCharEntity(ch);
        }

        public override void WriteChars(char[] buffer, int index, int count)
        {
            if (skippedAttribute)
                return;

            writer.WriteChars(buffer, index, count);
        }

        public override void WriteComment(string text)
        {
            writer.WriteComment(text);
        }

        public override void WriteDocType(string name, string pubid, string sysid, string subset)
        {
            writer.WriteDocType(name, pubid, sysid, subset);
        }

        public override void WriteEndAttribute()
        {
            if (skippedAttribute)
            {
                skippedAttribute = false;
                return;
            }

            writer.WriteEndAttribute();
        }

        public override void WriteEndDocument()
        {
            writer.WriteEndDocument();
        }

        public override void WriteEndElement()
        {
            writer.WriteEndElement();
        }

        public override void WriteEntityRef(string name)
        {
            if (skippedAttribute)
                return;

            writer.WriteEntityRef(name);
        }

        public override void WriteFullEndElement()
        {
            writer.WriteFullEndElement();
        }

        public override void WriteProcessingInstruction(string name, string text)
        {
            writer.WriteProcessingInstruction(name, text);
        }

        public override void WriteRaw(string data)
        {
            writer.WriteRaw(data);
        }

        public override void WriteRaw(char[] buffer, int index, int count)
        {
            writer.WriteRaw(buffer, index, count);
        }

        private bool skippedAttribute;
        public override void WriteStartAttribute(string prefix, string localName, string ns)
        {
            // XSI/XSD must not be emitted.
            if (prefix == "xmlns" || localName == "xmlns")
            {
                if (localName == "xsi" || localName == "xsd")
                {
                    skippedAttribute = true;
                    return;
                }

                ApplyNamespace(prefix, localName, ref ns);
            }
            writer.WriteStartAttribute(prefix, localName, ns);
        }

        public override void WriteStartDocument(bool standalone)
        {
            writer.WriteStartDocument(standalone);
        }

        public override void WriteStartDocument()
        {
            writer.WriteStartDocument();
        }

        public override void WriteStartElement(string prefix, string localName, string ns)
        {
            writer.WriteStartElement(prefix, localName, ns);
        }

        public override System.Xml.WriteState WriteState
        {
            get { return writer.WriteState; }
        }

        public override void WriteString(string text)
        {
            if (skippedAttribute)
                return;

            writer.WriteString(text);
        }

        public override void WriteSurrogateCharEntity(char lowChar, char highChar)
        {

            if (skippedAttribute)
                return;

            writer.WriteSurrogateCharEntity(lowChar, highChar);
        }

        public override void WriteWhitespace(string ws)
        {

            if (skippedAttribute)
                return;

            writer.WriteWhitespace(ws);
        }

        public override XmlWriterSettings Settings
        {
            get
            {
                return writer.Settings;
            }
        }

        public override string XmlLang
        {
            get
            {
                return writer.XmlLang;
            }
        }

        public override XmlSpace XmlSpace
        {
            get
            {
                return writer.XmlSpace;
            }
        }
        #endregion

        public override void CompleteElement()
        {
            PerformAutoComplete();
        }

        private void PerformAutoComplete()
        {
            __autoCompleteMethod.Invoke(writer, new object[] { __autoCompleteComment });
        }
    }
&lt;/pre&gt; &lt;img src="http://geekswithblogs.net/jcdickinson/aggbug/125615.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Jonathan Dickinson</dc:creator>
            <guid>http://geekswithblogs.net/jcdickinson/archive/2008/10/02/forcibly-closing-a-start-tag-with-xmltextwriter.aspx</guid>
            <pubDate>Fri, 03 Oct 2008 07:27:15 GMT</pubDate>
            <comments>http://geekswithblogs.net/jcdickinson/archive/2008/10/02/forcibly-closing-a-start-tag-with-xmltextwriter.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/jcdickinson/comments/commentRss/125615.aspx</wfw:commentRss>
        </item>
        <item>
            <title>ROAM landscapes with XNA</title>
            <category>Born Again</category>
            <category>C#</category>
            <link>http://geekswithblogs.net/jcdickinson/archive/2008/09/28/roam-landscapes-with-xna.aspx</link>
            <description>&lt;p&gt;Originally posted on: &lt;a href='http://geekswithblogs.net/jcdickinson/archive/2008/09/28/roam-landscapes-with-xna.aspx'&gt;http://geekswithblogs.net/jcdickinson/archive/2008/09/28/roam-landscapes-with-xna.aspx&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Landscapes in games are always a mission. I have started implementing a ROAM landscape that uses quadtrees, and it is looking pretty good (compared to my previous triangular one).&lt;/p&gt;

&lt;p&gt;One of the things that I made to make the whole thing so much easier is a IndexedVertexBuffer. This beast handles my indices and vertices for  me, all I need to is say buffer.AddIndex(0), for example. It can then be rendered to screen with a single call.&lt;/p&gt;

&lt;p&gt;The whole thing is loosely based on &lt;a href="http://www.gamasutra.com/features/20000228/ulrich_01.htm"&gt;Gamasutra article by Thatcher Ulrich&lt;/a&gt;. There are a few more optimizations that I can do on it, but so far I am getting zero problems with holes in the landscape.&lt;/p&gt;

&lt;p&gt;The structure I have is persistent, with the cost of memory these days I don't see the point of regenerating it each time. Because of this, the whole process is quite CPU friendly and loading the terrain is almost instant. I did use a rather novel approach to generating the structure which warrants some explanation.&lt;/p&gt;

&lt;p&gt;Firstly, I make the maximum resolution structure (in a 2D array, but this array is discarded in any case). I then repeatedly simplify it. A more typical approach would have been to generate the structure using recursion, but this means that you could get a stack overflow, and setting neighbor relationships would be a nightmare. It is actually far simpler my way (about 15 lines of clear code).&lt;/p&gt;

&lt;p&gt;In any case I am going to put some screenshots up in the gallery (if I can figure out how to use it). Have a look :). I have marked up all the bits of interest.&lt;/p&gt;

&lt;p&gt;&lt;i&gt;Edit: &lt;/i&gt;The shots are up &lt;a href="http://geekswithblogs.net/jcdickinson/gallery/8739.aspx"&gt;here&lt;/a&gt;.&lt;/p&gt; &lt;img src="http://geekswithblogs.net/jcdickinson/aggbug/125515.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Jonathan Dickinson</dc:creator>
            <guid>http://geekswithblogs.net/jcdickinson/archive/2008/09/28/roam-landscapes-with-xna.aspx</guid>
            <pubDate>Mon, 29 Sep 2008 07:25:20 GMT</pubDate>
            <comments>http://geekswithblogs.net/jcdickinson/archive/2008/09/28/roam-landscapes-with-xna.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/jcdickinson/comments/commentRss/125515.aspx</wfw:commentRss>
        </item>
    </channel>
</rss>