<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" 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:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Ruurd Boeke Enterprise development and technobabble - Code</title>
    <link>http://www.sitechno.com/Blog/</link>
    <description>All about agile, OR-mapping and winfx - yeah baby!</description>
    <language>en-us</language>
    <copyright>Ruurd Boeke</copyright>
    <lastBuildDate>Fri, 17 Apr 2009 04:15:54 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 1.9.6264.0</generator>
    <managingEditor>contact@sitechno.com</managingEditor>
    <webMaster>contact@sitechno.com</webMaster>
    <item>
      <trackback:ping>http://www.sitechno.com/Blog/Trackback.aspx?guid=5fb8ee52-a629-406c-acdf-6a0841ea2f13</trackback:ping>
      <pingback:server>http://www.sitechno.com/Blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.sitechno.com/Blog/PermaLink,guid,5fb8ee52-a629-406c-acdf-6a0841ea2f13.aspx</pingback:target>
      <dc:creator>Ruurd Boeke</dc:creator>
      <wfw:comment>http://www.sitechno.com/Blog/CommentView,guid,5fb8ee52-a629-406c-acdf-6a0841ea2f13.aspx</wfw:comment>
      <wfw:commentRss>http://www.sitechno.com/Blog/SyndicationService.asmx/GetEntryCommentsRss?guid=5fb8ee52-a629-406c-acdf-6a0841ea2f13</wfw:commentRss>
      <slash:comments>5</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a href="http://themechanicalbride.blogspot.com/2009/04/f-solution-to-eric-lippert-challenge.html" target="_blank">Jafar
Husain</a> told me that he was working on a challenge by <a href="http://blogs.msdn.com/ericlippert/archive/2009/04/15/comma-quibbling.aspx" target="_blank">Eric
Lippert</a>. <a href="http://blogs.msdn.com/delay/" target="_blank">David Anson</a> followed
and they posted solutions to the challenge on their blog. I thought it was quite a
bit of fun so I quickly wrote something up that I like. 
</p>
        <p>
I will copy the problem from Erics website. It challenges you to transform a sequence
of strings into a nicely delimited form.
</p>
        <p>
(1) If the sequence is empty then the resulting string is "{}". 
<br />
(2) If the sequence is a single item "ABC" then the resulting string is
"{ABC}". 
<br />
(3) If the sequence is the two item sequence "ABC", "DEF" then
the resulting string is "{ABC and DEF}". 
<br />
(4) If the sequence has more than two items, say, "ABC", "DEF",
"G", "H" then the resulting string is "{ABC, DEF, G and H}".
(Note: no Oxford comma!)
</p>
        <p>
He noted he was mostly interested in readable code, so I came up with a nice Linq
solution. However, Jafar was unimpressed and noted that performance was still important.
I was traversing the sequence too often for his taste. Back to the drawing board and
coming up with a less readable, but pretty quick implementation:
</p>
        <pre class="brush: csharp; gutter: false;">string lastWord = String.Empty;

StringBuilder sb = new StringBuilder();
foreach(string s in input)
{
    sb.Append(s);
    sb.Append(", ");
    lastWord = s;
}

int lastWordIndex = (sb.Length -1) - lastWord.Length - 3;

if (lastWordIndex &gt; 0)
{
    Console.WriteLine("{" + sb.ToString(0, lastWordIndex) + " and " + lastWord + "}");
}
else if (sb.Length == 0)
{
    Console.WriteLine("{}");
}
else
{
    Console.WriteLine("{" + sb.ToString(0, sb.Length -2) + "}");
}</pre>
        <p>
 
</p>
        <p>
I like this solution quite a bit. Obviously not optimized the return statements, and
the readability is quite a bit worse than my first attempt. But it’s short, only goes
over the sequence once and should perform well. 
</p>
        <p>
          <strong>edit:</strong> The linq version:
</p>
        <pre class="brush: csharp; gutter: false;">StringBuilder t = new StringBuilder();

            int count = input.Count();

            var middleStrings = input.Where((s, i) =&gt; i &gt; 0 &amp;&amp; i &lt; count - 1);

            t.Append("{");

            t.Append(input.FirstOrDefault());

            // linq reads better than foreach.
            middleStrings.ToList().ForEach(s =&gt;
                                              {
                                                 t.Append(", ");
                                                 t.Append(s);
                                              });

            if (count &gt; 1)
            {
                t.Append(" and ");
                t.Append(input.LastOrDefault());
            }

            t.Append("}");

            return t.ToString();</pre>
        <p>
Oh well. 
</p>
        <img width="0" height="0" src="http://www.sitechno.com/Blog/aggbug.ashx?id=5fb8ee52-a629-406c-acdf-6a0841ea2f13" />
      </body>
      <title>Comma quibbling</title>
      <guid isPermaLink="false">http://www.sitechno.com/Blog/PermaLink,guid,5fb8ee52-a629-406c-acdf-6a0841ea2f13.aspx</guid>
      <link>http://www.sitechno.com/Blog/CommaQuibbling.aspx</link>
      <pubDate>Fri, 17 Apr 2009 04:15:54 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a href="http://themechanicalbride.blogspot.com/2009/04/f-solution-to-eric-lippert-challenge.html" target="_blank"&gt;Jafar
Husain&lt;/a&gt; told me that he was working on a challenge by &lt;a href="http://blogs.msdn.com/ericlippert/archive/2009/04/15/comma-quibbling.aspx" target="_blank"&gt;Eric
Lippert&lt;/a&gt;. &lt;a href="http://blogs.msdn.com/delay/" target="_blank"&gt;David Anson&lt;/a&gt; followed
and they posted solutions to the challenge on their blog. I thought it was quite a
bit of fun so I quickly wrote something up that I like. 
&lt;/p&gt;
&lt;p&gt;
I will copy the problem from Erics website. It challenges you to transform a sequence
of strings into a nicely delimited form.
&lt;/p&gt;
&lt;p&gt;
(1) If the sequence is empty then the resulting string is &amp;quot;{}&amp;quot;. 
&lt;br /&gt;
(2) If the sequence is a single item &amp;quot;ABC&amp;quot; then the resulting string is
&amp;quot;{ABC}&amp;quot;. 
&lt;br /&gt;
(3) If the sequence is the two item sequence &amp;quot;ABC&amp;quot;, &amp;quot;DEF&amp;quot; then
the resulting string is &amp;quot;{ABC and DEF}&amp;quot;. 
&lt;br /&gt;
(4) If the sequence has more than two items, say, &amp;quot;ABC&amp;quot;, &amp;quot;DEF&amp;quot;,
&amp;quot;G&amp;quot;, &amp;quot;H&amp;quot; then the resulting string is &amp;quot;{ABC, DEF, G and H}&amp;quot;.
(Note: no Oxford comma!)
&lt;/p&gt;
&lt;p&gt;
He noted he was mostly interested in readable code, so I came up with a nice Linq
solution. However, Jafar was unimpressed and noted that performance was still important.
I was traversing the sequence too often for his taste. Back to the drawing board and
coming up with a less readable, but pretty quick implementation:
&lt;/p&gt;
&lt;pre class="brush: csharp; gutter: false;"&gt;string lastWord = String.Empty;

StringBuilder sb = new StringBuilder();
foreach(string s in input)
{
    sb.Append(s);
    sb.Append(&amp;quot;, &amp;quot;);
    lastWord = s;
}

int lastWordIndex = (sb.Length -1) - lastWord.Length - 3;

if (lastWordIndex &amp;gt; 0)
{
    Console.WriteLine(&amp;quot;{&amp;quot; + sb.ToString(0, lastWordIndex) + &amp;quot; and &amp;quot; + lastWord + &amp;quot;}&amp;quot;);
}
else if (sb.Length == 0)
{
    Console.WriteLine(&amp;quot;{}&amp;quot;);
}
else
{
    Console.WriteLine(&amp;quot;{&amp;quot; + sb.ToString(0, sb.Length -2) + &amp;quot;}&amp;quot;);
}&lt;/pre&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
I like this solution quite a bit. Obviously not optimized the return statements, and
the readability is quite a bit worse than my first attempt. But it’s short, only goes
over the sequence once and should perform well. 
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;edit:&lt;/strong&gt; The linq version:
&lt;/p&gt;
&lt;pre class="brush: csharp; gutter: false;"&gt;StringBuilder t = new StringBuilder();

            int count = input.Count();

            var middleStrings = input.Where((s, i) =&amp;gt; i &amp;gt; 0 &amp;amp;&amp;amp; i &amp;lt; count - 1);

            t.Append(&amp;quot;{&amp;quot;);

            t.Append(input.FirstOrDefault());

            // linq reads better than foreach.
            middleStrings.ToList().ForEach(s =&amp;gt;
                                              {
                                                 t.Append(&amp;quot;, &amp;quot;);
                                                 t.Append(s);
                                              });

            if (count &amp;gt; 1)
            {
                t.Append(&amp;quot; and &amp;quot;);
                t.Append(input.LastOrDefault());
            }

            t.Append(&amp;quot;}&amp;quot;);

            return t.ToString();&lt;/pre&gt;
&lt;p&gt;
Oh well. 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.sitechno.com/Blog/aggbug.ashx?id=5fb8ee52-a629-406c-acdf-6a0841ea2f13" /&gt;</description>
      <comments>http://www.sitechno.com/Blog/CommentView,guid,5fb8ee52-a629-406c-acdf-6a0841ea2f13.aspx</comments>
      <category>Code</category>
    </item>
    <item>
      <trackback:ping>http://www.sitechno.com/Blog/Trackback.aspx?guid=bc92ba62-cd46-4f3f-8604-1d5b3d871abd</trackback:ping>
      <pingback:server>http://www.sitechno.com/Blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.sitechno.com/Blog/PermaLink,guid,bc92ba62-cd46-4f3f-8604-1d5b3d871abd.aspx</pingback:target>
      <dc:creator>Ruurd Boeke</dc:creator>
      <wfw:comment>http://www.sitechno.com/Blog/CommentView,guid,bc92ba62-cd46-4f3f-8604-1d5b3d871abd.aspx</wfw:comment>
      <wfw:commentRss>http://www.sitechno.com/Blog/SyndicationService.asmx/GetEntryCommentsRss?guid=bc92ba62-cd46-4f3f-8604-1d5b3d871abd</wfw:commentRss>
      <slash:comments>5</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I’m very excited that Silverlight 2 has been released. I’m too new to Microsoft to
claim even the slightest involvement, but it’s wonderful to see the excitement both
within Microsoft as outside. 
<br />
It will be interesting to see what will happen with the (already great) uptake of
Silverlight by the market.
</p>
        <p>
As I am spending most of my days knee-deep in Xaml nowadays, I always try to find
things that will help me be more productive. It happens quite often that I want to
select a complete xaml tag. It’s way too much effort to use the mouse to select it,
so I often use the control-m-m shortcut to collapse a tag and then select it. However,
a few days ago I took 5 minutes to automate this.
</p>
        <p>
          <a href="http://www.sitechno.com/Blog/content/binary/WindowsLiveWriter/MacroforquicklyselectingacompleteXaomlta_BAA6/image_2.png">
            <img style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.sitechno.com/Blog/content/binary/WindowsLiveWriter/MacroforquicklyselectingacompleteXaomlta_BAA6/image_thumb.png" width="244" height="55" />
          </a>
        </p>
        <p>
When you put your mouse somewhere in the Grid tag, and use my macro, you end up with
this:
</p>
        <p>
          <a href="http://www.sitechno.com/Blog/content/binary/WindowsLiveWriter/MacroforquicklyselectingacompleteXaomlta_BAA6/image_4.png">
            <img style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.sitechno.com/Blog/content/binary/WindowsLiveWriter/MacroforquicklyselectingacompleteXaomlta_BAA6/image_thumb_1.png" width="244" height="55" />
          </a>
        </p>
        <p>
You can even put your mouse in the endtag. I bound it to Control-Q and it has made
my life that much better!
</p>
        <p>
The macro is as simple as this: 
<br /></p>
        <pre>
          <pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
            <span style="color: blue">Sub</span> SelectXMLTagContents() </pre>
          <pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">        DTE.ActiveDocument.Selection.StartOfLine(VsStartOfLineOptions.VsStartOfLineOptionsFirstColumn)
</pre>
          <pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">        DTE.ExecuteCommand(<span style="color: maroon">"Edit.ToggleOutliningExpansion"</span>) </pre>
          <pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">        DTE.ActiveDocument.Selection.StartOfLine(VsStartOfLineOptions.VsStartOfLineOptionsFirstColumn)
</pre>
          <pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">        DTE.ActiveDocument.Selection.EndOfLine(<span style="color: maroon">True</span>) </pre>
          <pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">        DTE.ExecuteCommand(<span style="color: maroon">"Edit.ToggleOutliningExpansion"</span>) </pre>
          <span style="color: blue">End</span>
          <span style="color: blue">Sub</span>
        </pre>
        <p>
It collapses a tag, jumps to the first column, selects the line and then does an uncollapse. 
</p>
        <p>
For those using a tool like Karl’s ‘<a target="_blank" href="http://karlshifflett.wordpress.com/xaml-power-toys/">Xaml
Power Toys</a>’, it might also be a worthwile addition to their shortcuts.
</p>
        <img width="0" height="0" src="http://www.sitechno.com/Blog/aggbug.ashx?id=bc92ba62-cd46-4f3f-8604-1d5b3d871abd" />
      </body>
      <title>Macro for quickly selecting a complete X(a/o)ml tag</title>
      <guid isPermaLink="false">http://www.sitechno.com/Blog/PermaLink,guid,bc92ba62-cd46-4f3f-8604-1d5b3d871abd.aspx</guid>
      <link>http://www.sitechno.com/Blog/MacroForQuicklySelectingACompleteXaomlTag.aspx</link>
      <pubDate>Sun, 19 Oct 2008 20:17:36 GMT</pubDate>
      <description>&lt;p&gt;
I’m very excited that Silverlight 2 has been released. I’m too new to Microsoft to
claim even the slightest involvement, but it’s wonderful to see the excitement both
within Microsoft as outside. 
&lt;br /&gt;
It will be interesting to see what will happen with the (already great) uptake of
Silverlight by the market.
&lt;/p&gt;
&lt;p&gt;
As I am spending most of my days knee-deep in Xaml nowadays, I always try to find
things that will help me be more productive. It happens quite often that I want to
select a complete xaml tag. It’s way too much effort to use the mouse to select it,
so I often use the control-m-m shortcut to collapse a tag and then select it. However,
a few days ago I took 5 minutes to automate this.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.sitechno.com/Blog/content/binary/WindowsLiveWriter/MacroforquicklyselectingacompleteXaomlta_BAA6/image_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.sitechno.com/Blog/content/binary/WindowsLiveWriter/MacroforquicklyselectingacompleteXaomlta_BAA6/image_thumb.png" width="244" height="55" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
When you put your mouse somewhere in the Grid tag, and use my macro, you end up with
this:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.sitechno.com/Blog/content/binary/WindowsLiveWriter/MacroforquicklyselectingacompleteXaomlta_BAA6/image_4.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.sitechno.com/Blog/content/binary/WindowsLiveWriter/MacroforquicklyselectingacompleteXaomlta_BAA6/image_thumb_1.png" width="244" height="55" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
You can even put your mouse in the endtag. I bound it to Control-Q and it has made
my life that much better!
&lt;/p&gt;
&lt;p&gt;
The macro is as simple as this: 
&lt;br /&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;    &lt;span style="color: blue"&gt;Sub&lt;/span&gt; SelectXMLTagContents() &lt;/pre&gt;
&lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        DTE.ActiveDocument.Selection.StartOfLine(VsStartOfLineOptions.VsStartOfLineOptionsFirstColumn)
&lt;/pre&gt;
&lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        DTE.ExecuteCommand(&lt;span style="color: maroon"&gt;&amp;quot;Edit.ToggleOutliningExpansion&amp;quot;&lt;/span&gt;) &lt;/pre&gt;
&lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        DTE.ActiveDocument.Selection.StartOfLine(VsStartOfLineOptions.VsStartOfLineOptionsFirstColumn)
&lt;/pre&gt;
&lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        DTE.ActiveDocument.Selection.EndOfLine(&lt;span style="color: maroon"&gt;True&lt;/span&gt;) &lt;/pre&gt;
&lt;pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"&gt;        DTE.ExecuteCommand(&lt;span style="color: maroon"&gt;&amp;quot;Edit.ToggleOutliningExpansion&amp;quot;&lt;/span&gt;) &lt;/pre&gt;
&lt;span style="color: blue"&gt;End&lt;/span&gt; &lt;span style="color: blue"&gt;Sub&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
It collapses a tag, jumps to the first column, selects the line and then does an uncollapse. 
&lt;/p&gt;
&lt;p&gt;
For those using a tool like Karl’s ‘&lt;a target="_blank" href="http://karlshifflett.wordpress.com/xaml-power-toys/"&gt;Xaml
Power Toys&lt;/a&gt;’, it might also be a worthwile addition to their shortcuts.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.sitechno.com/Blog/aggbug.ashx?id=bc92ba62-cd46-4f3f-8604-1d5b3d871abd" /&gt;</description>
      <comments>http://www.sitechno.com/Blog/CommentView,guid,bc92ba62-cd46-4f3f-8604-1d5b3d871abd.aspx</comments>
      <category>Code;Silverlight;Tools;WF (Workflow);WPF (Avalon)</category>
    </item>
    <item>
      <trackback:ping>http://www.sitechno.com/Blog/Trackback.aspx?guid=1432c859-cadf-4b16-9552-c0c2a34d49b4</trackback:ping>
      <pingback:server>http://www.sitechno.com/Blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.sitechno.com/Blog/PermaLink,guid,1432c859-cadf-4b16-9552-c0c2a34d49b4.aspx</pingback:target>
      <dc:creator>Ruurd Boeke</dc:creator>
      <wfw:comment>http://www.sitechno.com/Blog/CommentView,guid,1432c859-cadf-4b16-9552-c0c2a34d49b4.aspx</wfw:comment>
      <wfw:commentRss>http://www.sitechno.com/Blog/SyndicationService.asmx/GetEntryCommentsRss?guid=1432c859-cadf-4b16-9552-c0c2a34d49b4</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I'll probably dedicate a bigger post to this soon, but I wanted to show you a domainmodel,
some code and the xml it generates. 
<br />
What you see here is two attributes that take on quite a bit of work. 
<br /><em>EditableBusinessObject</em> implements IEditableObject for you and also allows
you to copy the currentvalues to a loadedvalues state. 
<br /><em>CreateSerializeSurrogate</em> generates a surrogate class that knows how to deal
with loadedvalues and with circular references. 
<br />
Together, they form the backbone of the client-side of your domainmodel. 
</p>
        <p>
Here is an example.
</p>
        <p>
          <strong>DomainModel</strong>: 
<br />
(notice this is the full class, no other properties are here) 
<br /></p>
        <div style="background: #000000; color: #f2f0df; font-family: monospace">
          <span style="color: teal"> 
0 </span>
          <span style="color: #eeeeee">[</span>
          <span style="color: #ff0080">EditableBusinessObject</span>
          <span style="color: #eeeeee">]</span>
          <br />
          <div style="background: #222222">
            <span style="color: teal">  1 </span>
            <span style="color: #eeeeee">[</span>
            <span style="color: #ff0080">CreateSerializeSurrogate</span>
            <span style="color: #eeeeee">]</span>
          </div>
          <span style="color: teal">  2 </span>
          <span style="color: #eeeeee">[</span>
          <span style="color: #ff0080">Serializable</span>
          <span style="color: #eeeeee">]</span>
          <br />
          <div style="background: #222222">
            <span style="color: teal">  3 </span>
            <span style="color: #eeeeee">[</span>
            <span style="color: #ff0080">DataContract</span>
            <span style="color: #eeeeee">(Namespace </span>
            <span style="color: #c0c0c0">=</span>
            <span style="color: #eeeeee"> </span>
            <span style="color: #00ffff">"myNamespace"</span>
            <span style="color: #eeeeee">,
Name </span>
            <span style="color: #c0c0c0">=</span>
            <span style="color: #eeeeee"> </span>
            <span style="color: #00ffff">"Person"</span>
            <span style="color: #eeeeee">)]</span>
          </div>
          <span style="color: teal">  4 </span>
          <span style="color: #eeeeee"> </span>
          <span style="color: #90ee90">public</span>
          <span style="color: #eeeeee"> </span>
          <span style="color: #90ee90">class</span>
          <span style="color: #eeeeee"> </span>
          <span style="color: #ff0080">Person</span>
          <br />
          <div style="background: #222222">
            <span style="color: teal">  5 </span>
            <span style="color: #eeeeee">{</span>
          </div>
          <span style="color: teal">  6 </span>
          <span style="color: #eeeeee">  [</span>
          <span style="color: #ff0080">DataMember</span>
          <span style="color: #eeeeee">]</span>
          <br />
          <div style="background: #222222">
            <span style="color: teal">  7 </span>
            <span style="color: #eeeeee">  </span>
            <span style="color: #90ee90">public</span>
            <span style="color: #eeeeee"> </span>
            <span style="color: #90ee90">int</span>
            <span style="color: #eeeeee"> IntProperty
{ </span>
            <span style="color: #90ee90">get</span>
            <span style="color: #eeeeee">; </span>
            <span style="color: #90ee90">set</span>
            <span style="color: #eeeeee">;
}</span>
          </div>
          <span style="color: teal">  8 </span>
          <br />
          <div style="background: #222222">
            <span style="color: teal">  9 </span>
            <span style="color: #eeeeee"> 
[</span>
            <span style="color: #ff0080">DataMember</span>
            <span style="color: #eeeeee">]</span>
          </div>
          <span style="color: teal">  10 </span>
          <span style="color: #eeeeee">  </span>
          <span style="color: #90ee90">public</span>
          <span style="color: #eeeeee"> </span>
          <span style="color: #90ee90">string</span>
          <span style="color: #eeeeee"> StringProperty
{ </span>
          <span style="color: #90ee90">get</span>
          <span style="color: #eeeeee">; </span>
          <span style="color: #90ee90">set</span>
          <span style="color: #eeeeee">;
}</span>
          <br />
          <div style="background: #222222">
            <span style="color: teal">  11 </span>
          </div>
          <span style="color: teal">  12 </span>
          <span style="color: #eeeeee">  [</span>
          <span style="color: #ff0080">DataMember</span>
          <span style="color: #eeeeee">]</span>
          <br />
          <div style="background: #222222">
            <span style="color: teal">  13 </span>
            <span style="color: #eeeeee">  </span>
            <span style="color: #90ee90">public</span>
            <span style="color: #eeeeee"> </span>
            <span style="color: #90ee90">string</span>
            <span style="color: #eeeeee"> StringProperty2
{ </span>
            <span style="color: #90ee90">get</span>
            <span style="color: #eeeeee">; </span>
            <span style="color: #90ee90">set</span>
            <span style="color: #eeeeee">;
}</span>
          </div>
          <span style="color: teal">  14 </span>
          <br />
          <div style="background: #222222">
            <span style="color: teal">  15 </span>
            <span style="color: #eeeeee">  </span>
            <span style="color: #90ee90">int</span>
            <span style="color: #eeeeee"> neverSetInt;</span>
          </div>
          <span style="color: teal">  16 </span>
          <span style="color: #eeeeee">  [</span>
          <span style="color: #ff0080">DataMember</span>
          <span style="color: #eeeeee">]</span>
          <br />
          <div style="background: #222222">
            <span style="color: teal">  17 </span>
            <span style="color: #eeeeee">  </span>
            <span style="color: #90ee90">public</span>
            <span style="color: #eeeeee"> </span>
            <span style="color: #90ee90">int</span>
            <span style="color: #eeeeee"> NeverSetInt</span>
          </div>
          <span style="color: teal">  18 </span>
          <span style="color: #eeeeee">  {</span>
          <br />
          <div style="background: #222222">
            <span style="color: teal">  19 </span>
            <span style="color: #eeeeee">   </span>
            <span style="color: #90ee90">get</span>
          </div>
          <span style="color: teal">  20 </span>
          <span style="color: #eeeeee">  
{</span>
          <br />
          <div style="background: #222222">
            <span style="color: teal">  21 </span>
            <span style="color: #eeeeee">    </span>
            <span style="color: #90ee90">return</span>
            <span style="color: #eeeeee"> neverSetInt;</span>
          </div>
          <span style="color: teal">  22 </span>
          <span style="color: #eeeeee">  
}</span>
          <br />
          <div style="background: #222222">
            <span style="color: teal">  23 </span>
            <span style="color: #eeeeee">   </span>
            <span style="color: #90ee90">set</span>
            <span style="color: #eeeeee"> {
neverSetInt </span>
            <span style="color: #c0c0c0">=</span>
            <span style="color: #eeeeee"> </span>
            <span style="color: #90ee90">value</span>
            <span style="color: #eeeeee">;
}</span>
          </div>
          <span style="color: teal">  24 </span>
          <span style="color: #eeeeee">  }</span>
          <br />
          <div style="background: #222222">
            <span style="color: teal">  25 </span>
          </div>
          <span style="color: teal">  26 </span>
          <span style="color: #eeeeee">  [</span>
          <span style="color: #ff0080">DataMember</span>
          <span style="color: #eeeeee">]</span>
          <br />
          <div style="background: #222222">
            <span style="color: teal">  27 </span>
            <span style="color: #eeeeee">  </span>
            <span style="color: #90ee90">public</span>
            <span style="color: #eeeeee"> </span>
            <span style="color: #ff0080">List</span>
            <span style="color: #c0c0c0">&lt;</span>
            <span style="color: #90ee90">string</span>
            <span style="color: #c0c0c0">&gt;</span>
            <span style="color: #eeeeee"> StringLijst
{ </span>
            <span style="color: #90ee90">get</span>
            <span style="color: #eeeeee">; </span>
            <span style="color: #90ee90">set</span>
            <span style="color: #eeeeee">;
}</span>
          </div>
          <span style="color: teal">  28 </span>
          <br />
          <div style="background: #222222">
            <span style="color: teal">  29 </span>
            <span style="color: #eeeeee"> 
[</span>
            <span style="color: #ff0080">DataMember</span>
            <span style="color: #eeeeee">]</span>
          </div>
          <span style="color: teal">  30 </span>
          <span style="color: #eeeeee">  </span>
          <span style="color: #90ee90">public</span>
          <span style="color: #eeeeee"> </span>
          <span style="color: #ff0080">List</span>
          <span style="color: #c0c0c0">&lt;</span>
          <span style="color: #90ee90">int</span>
          <span style="color: #c0c0c0">&gt;</span>
          <span style="color: #eeeeee"> IntLijst
{ </span>
          <span style="color: #90ee90">get</span>
          <span style="color: #eeeeee">; </span>
          <span style="color: #90ee90">set</span>
          <span style="color: #eeeeee">;
}</span>
          <br />
          <div style="background: #222222">
            <span style="color: teal">  31 </span>
          </div>
          <span style="color: teal">  32 </span>
          <span style="color: #eeeeee">  </span>
          <span style="color: #90ee90">public</span>
          <span style="color: #eeeeee"> Person()</span>
          <br />
          <div style="background: #222222">
            <span style="color: teal">  33 </span>
            <span style="color: #eeeeee"> 
{</span>
          </div>
          <span style="color: teal">  34 </span>
          <span style="color: #eeeeee">  
StringLijst </span>
          <span style="color: #c0c0c0">=</span>
          <span style="color: #eeeeee"> </span>
          <span style="color: #90ee90">new</span>
          <span style="color: #eeeeee"> </span>
          <span style="color: #ff0080">List</span>
          <span style="color: #c0c0c0">&lt;</span>
          <span style="color: #90ee90">string</span>
          <span style="color: #c0c0c0">&gt;</span>
          <span style="color: #eeeeee">();</span>
          <br />
          <div style="background: #222222">
            <span style="color: teal">  35 </span>
            <span style="color: #eeeeee">  
IntLijst </span>
            <span style="color: #c0c0c0">=</span>
            <span style="color: #eeeeee"> </span>
            <span style="color: #90ee90">new</span>
            <span style="color: #eeeeee"> </span>
            <span style="color: #ff0080">List</span>
            <span style="color: #c0c0c0">&lt;</span>
            <span style="color: #90ee90">int</span>
            <span style="color: #c0c0c0">&gt;</span>
            <span style="color: #eeeeee">();</span>
          </div>
          <span style="color: teal">  36 </span>
          <span style="color: #eeeeee">  }</span>
          <br />
          <div style="background: #222222">
            <span style="color: teal">  37 </span>
          </div>
          <span style="color: teal">  38 </span>
          <span style="color: #eeeeee">}</span>
          <br />
          <div style="background: #222222">
            <span style="color: teal">  39 </span>
            <span style="color: #000000">
            </span>
          </div>
        </div>
        <p>
        </p>
        <p>
          <strong>Some testcode</strong>: 
<br />
(notice line 16 where we do a endEdit. If we had cancelled, we would've had a proper
rollback) 
<br /></p>
        <div style="background: #000000; color: #f2f0df; font-family: monospace">
          <span style="color: teal"> 
0 </span>
          <span style="color: #eeeeee">   </span>
          <span style="color: #ff0080">Person</span>
          <span style="color: #eeeeee"> p </span>
          <span style="color: #c0c0c0">=</span>
          <span style="color: #eeeeee"> </span>
          <span style="color: #90ee90">new</span>
          <span style="color: #eeeeee"> </span>
          <span style="color: #ff0080">Person</span>
          <span style="color: #eeeeee">();</span>
          <br />
          <div style="background: #222222">
            <span style="color: teal">  1 </span>
            <span style="color: #eeeeee">  
p</span>
            <span style="color: #c0c0c0">.</span>
            <span style="color: #eeeeee">IntProperty </span>
            <span style="color: #c0c0c0">=</span>
            <span style="color: #eeeeee"> </span>
            <span style="color: #00ffff">1</span>
            <span style="color: #eeeeee">;</span>
          </div>
          <span style="color: teal">  2 </span>
          <span style="color: #eeeeee">  
p</span>
          <span style="color: #c0c0c0">.</span>
          <span style="color: #eeeeee">StringProperty </span>
          <span style="color: #c0c0c0">=</span>
          <span style="color: #eeeeee"> </span>
          <span style="color: #00ffff">"Ruurd"</span>
          <span style="color: #eeeeee">;</span>
          <br />
          <div style="background: #222222">
            <span style="color: teal">  3 </span>
            <span style="color: #eeeeee">  
p</span>
            <span style="color: #c0c0c0">.</span>
            <span style="color: #eeeeee">StringProperty2 </span>
            <span style="color: #c0c0c0">=</span>
            <span style="color: #eeeeee"> </span>
            <span style="color: #00ffff">"Boeke"</span>
            <span style="color: #eeeeee">;</span>
          </div>
          <span style="color: teal">  4 </span>
          <br />
          <div style="background: #222222">
            <span style="color: teal">  5 </span>
            <span style="color: #eeeeee">  
p</span>
            <span style="color: #c0c0c0">.</span>
            <span style="color: #eeeeee">StringLijst</span>
            <span style="color: #c0c0c0">.</span>
            <span style="color: #eeeeee">Add(</span>
            <span style="color: #00ffff">"a"</span>
            <span style="color: #eeeeee">);</span>
          </div>
          <span style="color: teal">  6 </span>
          <span style="color: #eeeeee">  
p</span>
          <span style="color: #c0c0c0">.</span>
          <span style="color: #eeeeee">IntLijst</span>
          <span style="color: #c0c0c0">.</span>
          <span style="color: #eeeeee">Add(</span>
          <span style="color: #00ffff">1</span>
          <span style="color: #eeeeee">);</span>
          <br />
          <div style="background: #222222">
            <span style="color: teal">  7 </span>
          </div>
          <span style="color: teal">  8 </span>
          <span style="color: #eeeeee">  
(p </span>
          <span style="color: #90ee90">as</span>
          <span style="color: #eeeeee"> </span>
          <span style="color: #ff80c0">IEditableBusinessObject</span>
          <span style="color: #eeeeee">)</span>
          <span style="color: #c0c0c0">.</span>
          <span style="color: #eeeeee">CopyCurrentToLoaded();</span>
          <br />
          <div style="background: #222222">
            <span style="color: teal">  9 </span>
          </div>
          <span style="color: teal">  10 </span>
          <span style="color: #eeeeee">  
(p </span>
          <span style="color: #90ee90">as</span>
          <span style="color: #eeeeee"> </span>
          <span style="color: #ff80c0">IEditableBusinessObject</span>
          <span style="color: #eeeeee">)</span>
          <span style="color: #c0c0c0">.</span>
          <span style="color: #eeeeee">BeginEdit();</span>
          <br />
          <div style="background: #222222">
            <span style="color: teal">  11 </span>
          </div>
          <span style="color: teal">  12 </span>
          <span style="color: #eeeeee">  
p</span>
          <span style="color: #c0c0c0">.</span>
          <span style="color: #eeeeee">IntLijst</span>
          <span style="color: #c0c0c0">.</span>
          <span style="color: #eeeeee">Add(</span>
          <span style="color: #00ffff">2</span>
          <span style="color: #eeeeee">);</span>
          <br />
          <div style="background: #222222">
            <span style="color: teal">  13 </span>
            <span style="color: #eeeeee">  
p</span>
            <span style="color: #c0c0c0">.</span>
            <span style="color: #eeeeee">StringLijst</span>
            <span style="color: #c0c0c0">.</span>
            <span style="color: #eeeeee">Add(</span>
            <span style="color: #00ffff">"b"</span>
            <span style="color: #eeeeee">);</span>
          </div>
          <span style="color: teal">  14 </span>
          <span style="color: #eeeeee">  
p</span>
          <span style="color: #c0c0c0">.</span>
          <span style="color: #eeeeee">StringProperty </span>
          <span style="color: #c0c0c0">=</span>
          <span style="color: #eeeeee"> </span>
          <span style="color: #00ffff">"Ruurd
Boeke"</span>
          <span style="color: #eeeeee">;</span>
          <br />
          <div style="background: #222222">
            <span style="color: teal">  15 </span>
          </div>
          <span style="color: teal">  16 </span>
          <span style="color: #eeeeee">  
(p </span>
          <span style="color: #90ee90">as</span>
          <span style="color: #eeeeee"> </span>
          <span style="color: #ff80c0">IEditableBusinessObject</span>
          <span style="color: #eeeeee">)</span>
          <span style="color: #c0c0c0">.End</span>
          <span style="color: #eeeeee">Edit();</span>
          <br />
          <div style="background: #222222">
            <span style="color: teal">  17 </span>
          </div>
          <span style="color: teal">  18 </span>
          <span style="color: #eeeeee">   </span>
          <span style="color: #ff0080">DataContractSerializer</span>
          <span style="color: #eeeeee"> s </span>
          <span style="color: #c0c0c0">=</span>
          <span style="color: #eeeeee"> </span>
          <span style="color: #90ee90">new</span>
          <span style="color: #eeeeee"> </span>
          <span style="color: #ff0080">DataContractSerializer</span>
          <span style="color: #eeeeee">(p</span>
          <span style="color: #c0c0c0">.</span>
          <span style="color: #eeeeee">GetType(), </span>
          <span style="color: #90ee90">null</span>
          <span style="color: #eeeeee">, </span>
          <span style="color: #90ee90">int</span>
          <span style="color: #c0c0c0">.</span>
          <span style="color: #eeeeee">MaxValue, </span>
          <span style="color: #90ee90">false</span>
          <span style="color: #eeeeee">, </span>
          <span style="color: #90ee90">false</span>
          <span style="color: #eeeeee">, </span>
          <span style="color: #90ee90">new</span>
          <span style="color: #eeeeee"> </span>
          <span style="color: #ff0080">SubstituteDomainDataContractSurrogate</span>
          <span style="color: #eeeeee">());</span>
          <br />
          <div style="background: #222222">
            <span style="color: teal">  19 </span>
          </div>
          <span style="color: teal">  20 </span>
          <span style="color: #eeeeee">   </span>
          <span style="color: #90ee90">string</span>
          <span style="color: #eeeeee"> outMessage </span>
          <span style="color: #c0c0c0">=</span>
          <span style="color: #eeeeee"> GetWellFormedToContract(p,
s);</span>
          <br />
        </div>
        <p>
        </p>
        <p>
And the <strong>generated xml</strong>: 
<br />
(notice how the lists and 'StringProperty' are changed, and see the original value).
</p>
        <pre>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
            <span style="color: blue">&lt;</span>
            <span style="color: maroon">PersonSurrogate</span>
            <span style="color: red">xmlns:i</span>="<span style="color: blue">http://www.w3.org/2001/XMLSchema-instance</span>" <span style="color: red">xmlns</span>="<span style="color: blue">myNamespace</span>"<span style="color: blue">&gt;</span></pre>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">
            <span style="color: blue">&lt;</span>
            <span style="color: maroon">IntLijst</span>
            <span style="color: red">xmlns:d2p1</span>="<span style="color: blue">http://schemas.microsoft.com/2003/10/Serialization/Arrays</span>"<span style="color: blue">&gt;</span></pre>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
            <span style="color: blue">&lt;</span>
            <span style="color: maroon">d2p1:int</span>
            <span style="color: blue">&gt;</span>1<span style="color: blue">&lt;</span>/<span style="color: maroon">d2p1:int</span><span style="color: blue">&gt;</span></pre>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">
            <span style="color: blue">&lt;</span>
            <span style="color: maroon">d2p1:int</span>
            <span style="color: blue">&gt;</span>2<span style="color: blue">&lt;</span>/<span style="color: maroon">d2p1:int</span><span style="color: blue">&gt;</span></pre>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
            <span style="color: blue">&lt;</span>/<span style="color: maroon">IntLijst</span><span style="color: blue">&gt;</span></pre>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">
            <span style="color: blue">&lt;</span>
            <span style="color: maroon">IntProperty</span>
            <span style="color: blue">&gt;</span>1<span style="color: blue">&lt;</span>/<span style="color: maroon">IntProperty</span><span style="color: blue">&gt;</span></pre>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
            <span style="color: blue">&lt;</span>
            <span style="color: maroon">SerializationID</span>
            <span style="color: blue">&gt;</span>0<span style="color: blue">&lt;</span>/<span style="color: maroon">SerializationID</span><span style="color: blue">&gt;</span></pre>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">
            <span style="color: blue">&lt;</span>
            <span style="color: maroon">StringLijst</span>
            <span style="color: red">xmlns:d2p1</span>="<span style="color: blue">http://schemas.microsoft.com/2003/10/Serialization/Arrays</span>"<span style="color: blue">&gt;</span></pre>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
            <span style="color: blue">&lt;</span>
            <span style="color: maroon">d2p1:string</span>
            <span style="color: blue">&gt;</span>a<span style="color: blue">&lt;</span>/<span style="color: maroon">d2p1:string</span><span style="color: blue">&gt;</span></pre>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">
            <span style="color: blue">&lt;</span>
            <span style="color: maroon">d2p1:string</span>
            <span style="color: blue">&gt;</span>b<span style="color: blue">&lt;</span>/<span style="color: maroon">d2p1:string</span><span style="color: blue">&gt;</span></pre>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
            <span style="color: blue">&lt;</span>/<span style="color: maroon">StringLijst</span><span style="color: blue">&gt;</span></pre>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">
            <span style="color: blue">&lt;</span>
            <span style="color: maroon">StringProperty</span>
            <span style="color: blue">&gt;</span>Ruurd
Boeke<span style="color: blue">&lt;</span>/<span style="color: maroon">StringProperty</span><span style="color: blue">&gt;</span></pre>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
            <span style="color: blue">&lt;</span>
            <span style="color: maroon">StringProperty2</span>
            <span style="color: blue">&gt;</span>Boeke<span style="color: blue">&lt;</span>/<span style="color: maroon">StringProperty2</span><span style="color: blue">&gt;</span></pre>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">
            <span style="color: blue">&lt;</span>
            <span style="color: maroon">OriginalValue_IntLijst</span>
            <span style="color: red">xmlns:d2p1</span>="<span style="color: blue">http://schemas.microsoft.com/2003/10/Serialization/Arrays</span>"<span style="color: blue">&gt;</span></pre>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
            <span style="color: blue">&lt;</span>
            <span style="color: maroon">d2p1:int</span>
            <span style="color: blue">&gt;</span>1<span style="color: blue">&lt;</span>/<span style="color: maroon">d2p1:int</span><span style="color: blue">&gt;</span></pre>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">
            <span style="color: blue">&lt;</span>/<span style="color: maroon">OriginalValue_IntLijst</span><span style="color: blue">&gt;</span></pre>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
            <span style="color: blue">&lt;</span>
            <span style="color: maroon">OriginalValue_IntProperty</span>
            <span style="color: blue">&gt;</span>1<span style="color: blue">&lt;</span>/<span style="color: maroon">OriginalValue_IntProperty</span><span style="color: blue">&gt;</span></pre>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">
            <span style="color: blue">&lt;</span>
            <span style="color: maroon">OriginalValue_StringLijst</span>
            <span style="color: red">xmlns:d2p1</span>="<span style="color: blue">http://schemas.microsoft.com/2003/10/Serialization/Arrays</span>"<span style="color: blue">&gt;</span></pre>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
            <span style="color: blue">&lt;</span>
            <span style="color: maroon">d2p1:string</span>
            <span style="color: blue">&gt;</span>a<span style="color: blue">&lt;</span>/<span style="color: maroon">d2p1:string</span><span style="color: blue">&gt;</span></pre>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">
            <span style="color: blue">&lt;</span>/<span style="color: maroon">OriginalValue_StringLijst</span><span style="color: blue">&gt;</span></pre>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
            <span style="color: blue">&lt;</span>
            <span style="color: maroon">OriginalValue_StringProperty</span>
            <span style="color: blue">&gt;</span>Ruurd<span style="color: blue">&lt;</span>/<span style="color: maroon">OriginalValue_StringProperty</span><span style="color: blue">&gt;</span></pre>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">
            <span style="color: blue">&lt;</span>
            <span style="color: maroon">OriginalValue_StringProperty2</span>
            <span style="color: blue">&gt;</span>Boeke<span style="color: blue">&lt;</span>/<span style="color: maroon">OriginalValue_StringProperty2</span><span style="color: blue">&gt;</span></pre>
          <span style="color: blue">&lt;</span>/<span style="color: maroon">PersonSurrogate</span><span style="color: blue">&gt;</span></pre>
        <p>
What is left, is deserializing, maybe propagating the beginedit commands to all children
and then create the serverside EF variant. 
<br />
Oh, and I don't like the originalValue representation. Maybe I'll generate a OriginalValue
class to keep it tidy.
</p>
        <img width="0" height="0" src="http://www.sitechno.com/Blog/aggbug.ashx?id=1432c859-cadf-4b16-9552-c0c2a34d49b4" />
      </body>
      <title>Sneak preview: serializing objects with original values</title>
      <guid isPermaLink="false">http://www.sitechno.com/Blog/PermaLink,guid,1432c859-cadf-4b16-9552-c0c2a34d49b4.aspx</guid>
      <link>http://www.sitechno.com/Blog/SneakPreviewSerializingObjectsWithOriginalValues.aspx</link>
      <pubDate>Mon, 17 Mar 2008 21:28:31 GMT</pubDate>
      <description>&lt;p&gt;
I'll probably dedicate a bigger post to this soon, but I wanted to show you a domainmodel,
some code and the xml it generates. 
&lt;br /&gt;
What you see here is two attributes that take on quite a bit of work. 
&lt;br /&gt;
&lt;em&gt;EditableBusinessObject&lt;/em&gt; implements IEditableObject for you and also allows
you to copy the currentvalues to a loadedvalues state. 
&lt;br /&gt;
&lt;em&gt;CreateSerializeSurrogate&lt;/em&gt; generates a surrogate class that knows how to deal
with loadedvalues and with circular references. 
&lt;br /&gt;
Together, they form the backbone of the client-side of your domainmodel. 
&lt;/p&gt;
&lt;p&gt;
Here is an example.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;DomainModel&lt;/strong&gt;: 
&lt;br /&gt;
(notice this is the full class, no other properties are here) 
&lt;br /&gt;
&lt;/p&gt;
&lt;div style="background: #000000; color: #f2f0df; font-family: monospace"&gt;&lt;span style="color: teal"&gt;&amp;#160;
0 &lt;/span&gt;&lt;span style="color: #eeeeee"&gt;[&lt;/span&gt;&lt;span style="color: #ff0080"&gt;EditableBusinessObject&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;]&lt;/span&gt; 
&lt;br /&gt;
&lt;div style="background: #222222"&gt;&lt;span style="color: teal"&gt;&amp;#160; 1 &lt;/span&gt;&lt;span style="color: #eeeeee"&gt;[&lt;/span&gt;&lt;span style="color: #ff0080"&gt;CreateSerializeSurrogate&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;]&lt;/span&gt;
&lt;/div&gt;
&lt;span style="color: teal"&gt;&amp;#160; 2 &lt;/span&gt;&lt;span style="color: #eeeeee"&gt;[&lt;/span&gt;&lt;span style="color: #ff0080"&gt;Serializable&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;]&lt;/span&gt; 
&lt;br /&gt;
&lt;div style="background: #222222"&gt;&lt;span style="color: teal"&gt;&amp;#160; 3 &lt;/span&gt;&lt;span style="color: #eeeeee"&gt;[&lt;/span&gt;&lt;span style="color: #ff0080"&gt;DataContract&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;(Namespace &lt;/span&gt;&lt;span style="color: #c0c0c0"&gt;=&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: #00ffff"&gt;&amp;quot;myNamespace&amp;quot;&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;,
Name &lt;/span&gt;&lt;span style="color: #c0c0c0"&gt;=&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: #00ffff"&gt;&amp;quot;Person&amp;quot;&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;)]&lt;/span&gt;
&lt;/div&gt;
&lt;span style="color: teal"&gt;&amp;#160; 4 &lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: #90ee90"&gt;public&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: #90ee90"&gt;class&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: #ff0080"&gt;Person&lt;/span&gt; 
&lt;br /&gt;
&lt;div style="background: #222222"&gt;&lt;span style="color: teal"&gt;&amp;#160; 5 &lt;/span&gt;&lt;span style="color: #eeeeee"&gt;{&lt;/span&gt;
&lt;/div&gt;
&lt;span style="color: teal"&gt;&amp;#160; 6 &lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160; [&lt;/span&gt;&lt;span style="color: #ff0080"&gt;DataMember&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;]&lt;/span&gt; 
&lt;br /&gt;
&lt;div style="background: #222222"&gt;&lt;span style="color: teal"&gt;&amp;#160; 7 &lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160; &lt;/span&gt;&lt;span style="color: #90ee90"&gt;public&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: #90ee90"&gt;int&lt;/span&gt;&lt;span style="color: #eeeeee"&gt; IntProperty
{ &lt;/span&gt;&lt;span style="color: #90ee90"&gt;get&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;; &lt;/span&gt;&lt;span style="color: #90ee90"&gt;set&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;;
}&lt;/span&gt;
&lt;/div&gt;
&lt;span style="color: teal"&gt;&amp;#160; 8 &lt;/span&gt; 
&lt;br /&gt;
&lt;div style="background: #222222"&gt;&lt;span style="color: teal"&gt;&amp;#160; 9 &lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160;
[&lt;/span&gt;&lt;span style="color: #ff0080"&gt;DataMember&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;]&lt;/span&gt;
&lt;/div&gt;
&lt;span style="color: teal"&gt;&amp;#160; 10 &lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160; &lt;/span&gt;&lt;span style="color: #90ee90"&gt;public&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: #90ee90"&gt;string&lt;/span&gt;&lt;span style="color: #eeeeee"&gt; StringProperty
{ &lt;/span&gt;&lt;span style="color: #90ee90"&gt;get&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;; &lt;/span&gt;&lt;span style="color: #90ee90"&gt;set&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;;
}&lt;/span&gt; 
&lt;br /&gt;
&lt;div style="background: #222222"&gt;&lt;span style="color: teal"&gt;&amp;#160; 11 &lt;/span&gt;
&lt;/div&gt;
&lt;span style="color: teal"&gt;&amp;#160; 12 &lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160; [&lt;/span&gt;&lt;span style="color: #ff0080"&gt;DataMember&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;]&lt;/span&gt; 
&lt;br /&gt;
&lt;div style="background: #222222"&gt;&lt;span style="color: teal"&gt;&amp;#160; 13 &lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160; &lt;/span&gt;&lt;span style="color: #90ee90"&gt;public&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: #90ee90"&gt;string&lt;/span&gt;&lt;span style="color: #eeeeee"&gt; StringProperty2
{ &lt;/span&gt;&lt;span style="color: #90ee90"&gt;get&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;; &lt;/span&gt;&lt;span style="color: #90ee90"&gt;set&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;;
}&lt;/span&gt;
&lt;/div&gt;
&lt;span style="color: teal"&gt;&amp;#160; 14 &lt;/span&gt; 
&lt;br /&gt;
&lt;div style="background: #222222"&gt;&lt;span style="color: teal"&gt;&amp;#160; 15 &lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160; &lt;/span&gt;&lt;span style="color: #90ee90"&gt;int&lt;/span&gt;&lt;span style="color: #eeeeee"&gt; neverSetInt;&lt;/span&gt;
&lt;/div&gt;
&lt;span style="color: teal"&gt;&amp;#160; 16 &lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160; [&lt;/span&gt;&lt;span style="color: #ff0080"&gt;DataMember&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;]&lt;/span&gt; 
&lt;br /&gt;
&lt;div style="background: #222222"&gt;&lt;span style="color: teal"&gt;&amp;#160; 17 &lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160; &lt;/span&gt;&lt;span style="color: #90ee90"&gt;public&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: #90ee90"&gt;int&lt;/span&gt;&lt;span style="color: #eeeeee"&gt; NeverSetInt&lt;/span&gt;
&lt;/div&gt;
&lt;span style="color: teal"&gt;&amp;#160; 18 &lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160; {&lt;/span&gt; 
&lt;br /&gt;
&lt;div style="background: #222222"&gt;&lt;span style="color: teal"&gt;&amp;#160; 19 &lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: #90ee90"&gt;get&lt;/span&gt;
&lt;/div&gt;
&lt;span style="color: teal"&gt;&amp;#160; 20 &lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160;&amp;#160;
{&lt;/span&gt; 
&lt;br /&gt;
&lt;div style="background: #222222"&gt;&lt;span style="color: teal"&gt;&amp;#160; 21 &lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: #90ee90"&gt;return&lt;/span&gt;&lt;span style="color: #eeeeee"&gt; neverSetInt;&lt;/span&gt;
&lt;/div&gt;
&lt;span style="color: teal"&gt;&amp;#160; 22 &lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160;&amp;#160;
}&lt;/span&gt; 
&lt;br /&gt;
&lt;div style="background: #222222"&gt;&lt;span style="color: teal"&gt;&amp;#160; 23 &lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: #90ee90"&gt;set&lt;/span&gt;&lt;span style="color: #eeeeee"&gt; {
neverSetInt &lt;/span&gt;&lt;span style="color: #c0c0c0"&gt;=&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: #90ee90"&gt;value&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;;
}&lt;/span&gt;
&lt;/div&gt;
&lt;span style="color: teal"&gt;&amp;#160; 24 &lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160; }&lt;/span&gt; 
&lt;br /&gt;
&lt;div style="background: #222222"&gt;&lt;span style="color: teal"&gt;&amp;#160; 25 &lt;/span&gt;
&lt;/div&gt;
&lt;span style="color: teal"&gt;&amp;#160; 26 &lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160; [&lt;/span&gt;&lt;span style="color: #ff0080"&gt;DataMember&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;]&lt;/span&gt; 
&lt;br /&gt;
&lt;div style="background: #222222"&gt;&lt;span style="color: teal"&gt;&amp;#160; 27 &lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160; &lt;/span&gt;&lt;span style="color: #90ee90"&gt;public&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: #ff0080"&gt;List&lt;/span&gt;&lt;span style="color: #c0c0c0"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #90ee90"&gt;string&lt;/span&gt;&lt;span style="color: #c0c0c0"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #eeeeee"&gt; StringLijst
{ &lt;/span&gt;&lt;span style="color: #90ee90"&gt;get&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;; &lt;/span&gt;&lt;span style="color: #90ee90"&gt;set&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;;
}&lt;/span&gt;
&lt;/div&gt;
&lt;span style="color: teal"&gt;&amp;#160; 28 &lt;/span&gt; 
&lt;br /&gt;
&lt;div style="background: #222222"&gt;&lt;span style="color: teal"&gt;&amp;#160; 29 &lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160;
[&lt;/span&gt;&lt;span style="color: #ff0080"&gt;DataMember&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;]&lt;/span&gt;
&lt;/div&gt;
&lt;span style="color: teal"&gt;&amp;#160; 30 &lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160; &lt;/span&gt;&lt;span style="color: #90ee90"&gt;public&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: #ff0080"&gt;List&lt;/span&gt;&lt;span style="color: #c0c0c0"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #90ee90"&gt;int&lt;/span&gt;&lt;span style="color: #c0c0c0"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #eeeeee"&gt; IntLijst
{ &lt;/span&gt;&lt;span style="color: #90ee90"&gt;get&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;; &lt;/span&gt;&lt;span style="color: #90ee90"&gt;set&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;;
}&lt;/span&gt; 
&lt;br /&gt;
&lt;div style="background: #222222"&gt;&lt;span style="color: teal"&gt;&amp;#160; 31 &lt;/span&gt;
&lt;/div&gt;
&lt;span style="color: teal"&gt;&amp;#160; 32 &lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160; &lt;/span&gt;&lt;span style="color: #90ee90"&gt;public&lt;/span&gt;&lt;span style="color: #eeeeee"&gt; Person()&lt;/span&gt; 
&lt;br /&gt;
&lt;div style="background: #222222"&gt;&lt;span style="color: teal"&gt;&amp;#160; 33 &lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160;
{&lt;/span&gt;
&lt;/div&gt;
&lt;span style="color: teal"&gt;&amp;#160; 34 &lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160;&amp;#160;
StringLijst &lt;/span&gt;&lt;span style="color: #c0c0c0"&gt;=&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: #90ee90"&gt;new&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: #ff0080"&gt;List&lt;/span&gt;&lt;span style="color: #c0c0c0"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #90ee90"&gt;string&lt;/span&gt;&lt;span style="color: #c0c0c0"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;();&lt;/span&gt; 
&lt;br /&gt;
&lt;div style="background: #222222"&gt;&lt;span style="color: teal"&gt;&amp;#160; 35 &lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160;&amp;#160;
IntLijst &lt;/span&gt;&lt;span style="color: #c0c0c0"&gt;=&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: #90ee90"&gt;new&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: #ff0080"&gt;List&lt;/span&gt;&lt;span style="color: #c0c0c0"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #90ee90"&gt;int&lt;/span&gt;&lt;span style="color: #c0c0c0"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;();&lt;/span&gt;
&lt;/div&gt;
&lt;span style="color: teal"&gt;&amp;#160; 36 &lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160; }&lt;/span&gt; 
&lt;br /&gt;
&lt;div style="background: #222222"&gt;&lt;span style="color: teal"&gt;&amp;#160; 37 &lt;/span&gt;
&lt;/div&gt;
&lt;span style="color: teal"&gt;&amp;#160; 38 &lt;/span&gt;&lt;span style="color: #eeeeee"&gt;}&lt;/span&gt; 
&lt;br /&gt;
&lt;div style="background: #222222"&gt;&lt;span style="color: teal"&gt;&amp;#160; 39 &lt;/span&gt;&lt;span style="color: #000000"&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Some testcode&lt;/strong&gt;: 
&lt;br /&gt;
(notice line 16 where we do a endEdit. If we had cancelled, we would've had a proper
rollback) 
&lt;br /&gt;
&lt;/p&gt;
&lt;div style="background: #000000; color: #f2f0df; font-family: monospace"&gt;&lt;span style="color: teal"&gt;&amp;#160;
0 &lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: #ff0080"&gt;Person&lt;/span&gt;&lt;span style="color: #eeeeee"&gt; p &lt;/span&gt;&lt;span style="color: #c0c0c0"&gt;=&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: #90ee90"&gt;new&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: #ff0080"&gt;Person&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;();&lt;/span&gt; 
&lt;br /&gt;
&lt;div style="background: #222222"&gt;&lt;span style="color: teal"&gt;&amp;#160; 1 &lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160;&amp;#160;
p&lt;/span&gt;&lt;span style="color: #c0c0c0"&gt;.&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;IntProperty &lt;/span&gt;&lt;span style="color: #c0c0c0"&gt;=&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: #00ffff"&gt;1&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;;&lt;/span&gt;
&lt;/div&gt;
&lt;span style="color: teal"&gt;&amp;#160; 2 &lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160;&amp;#160;
p&lt;/span&gt;&lt;span style="color: #c0c0c0"&gt;.&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;StringProperty &lt;/span&gt;&lt;span style="color: #c0c0c0"&gt;=&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: #00ffff"&gt;&amp;quot;Ruurd&amp;quot;&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;;&lt;/span&gt; 
&lt;br /&gt;
&lt;div style="background: #222222"&gt;&lt;span style="color: teal"&gt;&amp;#160; 3 &lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160;&amp;#160;
p&lt;/span&gt;&lt;span style="color: #c0c0c0"&gt;.&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;StringProperty2 &lt;/span&gt;&lt;span style="color: #c0c0c0"&gt;=&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: #00ffff"&gt;&amp;quot;Boeke&amp;quot;&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;;&lt;/span&gt;
&lt;/div&gt;
&lt;span style="color: teal"&gt;&amp;#160; 4 &lt;/span&gt; 
&lt;br /&gt;
&lt;div style="background: #222222"&gt;&lt;span style="color: teal"&gt;&amp;#160; 5 &lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160;&amp;#160;
p&lt;/span&gt;&lt;span style="color: #c0c0c0"&gt;.&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;StringLijst&lt;/span&gt;&lt;span style="color: #c0c0c0"&gt;.&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;Add(&lt;/span&gt;&lt;span style="color: #00ffff"&gt;&amp;quot;a&amp;quot;&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;);&lt;/span&gt;
&lt;/div&gt;
&lt;span style="color: teal"&gt;&amp;#160; 6 &lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160;&amp;#160;
p&lt;/span&gt;&lt;span style="color: #c0c0c0"&gt;.&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;IntLijst&lt;/span&gt;&lt;span style="color: #c0c0c0"&gt;.&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;Add(&lt;/span&gt;&lt;span style="color: #00ffff"&gt;1&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;);&lt;/span&gt; 
&lt;br /&gt;
&lt;div style="background: #222222"&gt;&lt;span style="color: teal"&gt;&amp;#160; 7 &lt;/span&gt;
&lt;/div&gt;
&lt;span style="color: teal"&gt;&amp;#160; 8 &lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160;&amp;#160;
(p &lt;/span&gt;&lt;span style="color: #90ee90"&gt;as&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: #ff80c0"&gt;IEditableBusinessObject&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;)&lt;/span&gt;&lt;span style="color: #c0c0c0"&gt;.&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;CopyCurrentToLoaded();&lt;/span&gt; 
&lt;br /&gt;
&lt;div style="background: #222222"&gt;&lt;span style="color: teal"&gt;&amp;#160; 9 &lt;/span&gt;
&lt;/div&gt;
&lt;span style="color: teal"&gt;&amp;#160; 10 &lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160;&amp;#160;
(p &lt;/span&gt;&lt;span style="color: #90ee90"&gt;as&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: #ff80c0"&gt;IEditableBusinessObject&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;)&lt;/span&gt;&lt;span style="color: #c0c0c0"&gt;.&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;BeginEdit();&lt;/span&gt; 
&lt;br /&gt;
&lt;div style="background: #222222"&gt;&lt;span style="color: teal"&gt;&amp;#160; 11 &lt;/span&gt;
&lt;/div&gt;
&lt;span style="color: teal"&gt;&amp;#160; 12 &lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160;&amp;#160;
p&lt;/span&gt;&lt;span style="color: #c0c0c0"&gt;.&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;IntLijst&lt;/span&gt;&lt;span style="color: #c0c0c0"&gt;.&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;Add(&lt;/span&gt;&lt;span style="color: #00ffff"&gt;2&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;);&lt;/span&gt; 
&lt;br /&gt;
&lt;div style="background: #222222"&gt;&lt;span style="color: teal"&gt;&amp;#160; 13 &lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160;&amp;#160;
p&lt;/span&gt;&lt;span style="color: #c0c0c0"&gt;.&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;StringLijst&lt;/span&gt;&lt;span style="color: #c0c0c0"&gt;.&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;Add(&lt;/span&gt;&lt;span style="color: #00ffff"&gt;&amp;quot;b&amp;quot;&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;);&lt;/span&gt;
&lt;/div&gt;
&lt;span style="color: teal"&gt;&amp;#160; 14 &lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160;&amp;#160;
p&lt;/span&gt;&lt;span style="color: #c0c0c0"&gt;.&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;StringProperty &lt;/span&gt;&lt;span style="color: #c0c0c0"&gt;=&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: #00ffff"&gt;&amp;quot;Ruurd
Boeke&amp;quot;&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;;&lt;/span&gt; 
&lt;br /&gt;
&lt;div style="background: #222222"&gt;&lt;span style="color: teal"&gt;&amp;#160; 15 &lt;/span&gt;
&lt;/div&gt;
&lt;span style="color: teal"&gt;&amp;#160; 16 &lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160;&amp;#160;
(p &lt;/span&gt;&lt;span style="color: #90ee90"&gt;as&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: #ff80c0"&gt;IEditableBusinessObject&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;)&lt;/span&gt;&lt;span style="color: #c0c0c0"&gt;.End&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;Edit();&lt;/span&gt; 
&lt;br /&gt;
&lt;div style="background: #222222"&gt;&lt;span style="color: teal"&gt;&amp;#160; 17 &lt;/span&gt;
&lt;/div&gt;
&lt;span style="color: teal"&gt;&amp;#160; 18 &lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: #ff0080"&gt;DataContractSerializer&lt;/span&gt;&lt;span style="color: #eeeeee"&gt; s &lt;/span&gt;&lt;span style="color: #c0c0c0"&gt;=&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: #90ee90"&gt;new&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: #ff0080"&gt;DataContractSerializer&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;(p&lt;/span&gt;&lt;span style="color: #c0c0c0"&gt;.&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;GetType(), &lt;/span&gt;&lt;span style="color: #90ee90"&gt;null&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;, &lt;/span&gt;&lt;span style="color: #90ee90"&gt;int&lt;/span&gt;&lt;span style="color: #c0c0c0"&gt;.&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;MaxValue, &lt;/span&gt;&lt;span style="color: #90ee90"&gt;false&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;, &lt;/span&gt;&lt;span style="color: #90ee90"&gt;false&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;, &lt;/span&gt;&lt;span style="color: #90ee90"&gt;new&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: #ff0080"&gt;SubstituteDomainDataContractSurrogate&lt;/span&gt;&lt;span style="color: #eeeeee"&gt;());&lt;/span&gt; 
&lt;br /&gt;
&lt;div style="background: #222222"&gt;&lt;span style="color: teal"&gt;&amp;#160; 19 &lt;/span&gt;
&lt;/div&gt;
&lt;span style="color: teal"&gt;&amp;#160; 20 &lt;/span&gt;&lt;span style="color: #eeeeee"&gt;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: #90ee90"&gt;string&lt;/span&gt;&lt;span style="color: #eeeeee"&gt; outMessage &lt;/span&gt;&lt;span style="color: #c0c0c0"&gt;=&lt;/span&gt;&lt;span style="color: #eeeeee"&gt; GetWellFormedToContract(p,
s);&lt;/span&gt; 
&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
And the &lt;strong&gt;generated xml&lt;/strong&gt;: 
&lt;br /&gt;
(notice how the lists and 'StringProperty' are changed, and see the original value).
&lt;/p&gt;
&lt;pre&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;PersonSurrogate&lt;/span&gt; &lt;span style="color: red"&gt;xmlns:i&lt;/span&gt;=&amp;quot;&lt;span style="color: blue"&gt;http://www.w3.org/2001/XMLSchema-instance&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;xmlns&lt;/span&gt;=&amp;quot;&lt;span style="color: blue"&gt;myNamespace&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;    &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;IntLijst&lt;/span&gt; &lt;span style="color: red"&gt;xmlns:d2p1&lt;/span&gt;=&amp;quot;&lt;span style="color: blue"&gt;http://schemas.microsoft.com/2003/10/Serialization/Arrays&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;        &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;d2p1:int&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;1&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;/&lt;span style="color: maroon"&gt;d2p1:int&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;        &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;d2p1:int&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;2&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;/&lt;span style="color: maroon"&gt;d2p1:int&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;    &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;/&lt;span style="color: maroon"&gt;IntLijst&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;    &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;IntProperty&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;1&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;/&lt;span style="color: maroon"&gt;IntProperty&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;    &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;SerializationID&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;0&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;/&lt;span style="color: maroon"&gt;SerializationID&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;    &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;StringLijst&lt;/span&gt; &lt;span style="color: red"&gt;xmlns:d2p1&lt;/span&gt;=&amp;quot;&lt;span style="color: blue"&gt;http://schemas.microsoft.com/2003/10/Serialization/Arrays&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;        &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;d2p1:string&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;a&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;/&lt;span style="color: maroon"&gt;d2p1:string&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;        &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;d2p1:string&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;b&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;/&lt;span style="color: maroon"&gt;d2p1:string&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;    &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;/&lt;span style="color: maroon"&gt;StringLijst&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;    &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;StringProperty&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;Ruurd
Boeke&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;/&lt;span style="color: maroon"&gt;StringProperty&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;    &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;StringProperty2&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;Boeke&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;/&lt;span style="color: maroon"&gt;StringProperty2&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;    &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;OriginalValue_IntLijst&lt;/span&gt; &lt;span style="color: red"&gt;xmlns:d2p1&lt;/span&gt;=&amp;quot;&lt;span style="color: blue"&gt;http://schemas.microsoft.com/2003/10/Serialization/Arrays&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;        &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;d2p1:int&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;1&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;/&lt;span style="color: maroon"&gt;d2p1:int&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;    &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;/&lt;span style="color: maroon"&gt;OriginalValue_IntLijst&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;    &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;OriginalValue_IntProperty&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;1&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;/&lt;span style="color: maroon"&gt;OriginalValue_IntProperty&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;    &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;OriginalValue_StringLijst&lt;/span&gt; &lt;span style="color: red"&gt;xmlns:d2p1&lt;/span&gt;=&amp;quot;&lt;span style="color: blue"&gt;http://schemas.microsoft.com/2003/10/Serialization/Arrays&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;        &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;d2p1:string&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;a&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;/&lt;span style="color: maroon"&gt;d2p1:string&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;    &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;/&lt;span style="color: maroon"&gt;OriginalValue_StringLijst&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;    &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;OriginalValue_StringProperty&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;Ruurd&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;/&lt;span style="color: maroon"&gt;OriginalValue_StringProperty&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt; &lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;    &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;OriginalValue_StringProperty2&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;Boeke&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;/&lt;span style="color: maroon"&gt;OriginalValue_StringProperty2&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt; &lt;/pre&gt;
&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;/&lt;span style="color: maroon"&gt;PersonSurrogate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
What is left, is deserializing, maybe propagating the beginedit commands to all children
and then create the serverside EF variant. 
&lt;br /&gt;
Oh, and I don't like the originalValue representation. Maybe I'll generate a OriginalValue
class to keep it tidy.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.sitechno.com/Blog/aggbug.ashx?id=1432c859-cadf-4b16-9552-c0c2a34d49b4" /&gt;</description>
      <comments>http://www.sitechno.com/Blog/CommentView,guid,1432c859-cadf-4b16-9552-c0c2a34d49b4.aspx</comments>
      <category>Code;EF-Contrib;WCF (Indigo)</category>
    </item>
    <item>
      <trackback:ping>http://www.sitechno.com/Blog/Trackback.aspx?guid=0ae96e5f-3d3a-48d7-b928-eeabb035fa2e</trackback:ping>
      <pingback:server>http://www.sitechno.com/Blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.sitechno.com/Blog/PermaLink,guid,0ae96e5f-3d3a-48d7-b928-eeabb035fa2e.aspx</pingback:target>
      <dc:creator>Ruurd Boeke</dc:creator>
      <wfw:comment>http://www.sitechno.com/Blog/CommentView,guid,0ae96e5f-3d3a-48d7-b928-eeabb035fa2e.aspx</wfw:comment>
      <wfw:commentRss>http://www.sitechno.com/Blog/SyndicationService.asmx/GetEntryCommentsRss?guid=0ae96e5f-3d3a-48d7-b928-eeabb035fa2e</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
[<strong>update</strong>: I've updated my project quite a bit, and moved the state
to another object. So, the code you are about to see is old!]
</p>
        <p>
In the grand scheme of things, I'm building toward a set of tools that will enable
me to use EntityFramework on the server and use the same businessobjects on the client-side,
without having to reference EntityFramework at all. 
<br />
We already have a great <a href="http://www.codeplex.com/efcontrib" target="_blank">domain
layer supporting EF</a>, <a href="http://www.sitechno.com/Blog/ComplexTypesInEFHowTheyWorkAndSupportInEFContrib.aspx" target="_blank">without
baseclasses</a>. To use these objects on the client, we will need to take care of
changetracking ourselves. When we are done with that, we'll just have to write a custom
serializer, that will know how to serialize xml representations of the objects on
the client-side, and deserialize on the server and vice versa.
</p>
        <p>
I'll follow up in some post that describes how you can create different versions of
your domain layer for use on either client-side or server-side. 
</p>
        <h5>The end result
</h5>
        <p>
Let's skip to the end result straight away. This is a little test that runs fine:
</p>
        <p>
        </p>
        <div style="BACKGROUND: #000000; COLOR: #f2f0df; FONT-FAMILY: monospace">
          <span style="COLOR: teal"> 
0 </span>
          <span style="COLOR: #eeeeee">   </span>
          <span style="COLOR: #ff0080">Person</span>
          <span style="COLOR: #eeeeee"> p </span>
          <span style="COLOR: #c0c0c0">=</span>
          <span style="COLOR: #eeeeee"> </span>
          <span style="COLOR: #90ee90">new</span>
          <span style="COLOR: #eeeeee"> </span>
          <span style="COLOR: #ff0080">Person</span>
          <span style="COLOR: #eeeeee">();</span>
          <br />
          <div style="BACKGROUND: #222222">
            <span style="COLOR: teal">  1 </span>
            <span style="COLOR: #eeeeee">  
p</span>
            <span style="COLOR: #c0c0c0">.</span>
            <span style="COLOR: #eeeeee">Name </span>
            <span style="COLOR: #c0c0c0">=</span>
            <span style="COLOR: #eeeeee"> </span>
            <span style="COLOR: #00ffff">"Ruurd"</span>
            <span style="COLOR: #eeeeee">;</span>
          </div>
          <span style="COLOR: teal">  2 </span>
          <span style="COLOR: #eeeeee">  
p</span>
          <span style="COLOR: #c0c0c0">.</span>
          <span style="COLOR: #eeeeee">MyProperty </span>
          <span style="COLOR: #c0c0c0">=</span>
          <span style="COLOR: #eeeeee"> </span>
          <span style="COLOR: #00ffff">10</span>
          <span style="COLOR: #eeeeee">;</span>
          <br />
          <div style="BACKGROUND: #222222">
            <span style="COLOR: teal">  3 </span>
            <span style="COLOR: #eeeeee">  
p</span>
            <span style="COLOR: #c0c0c0">.</span>
            <span style="COLOR: #eeeeee">orders</span>
            <span style="COLOR: #c0c0c0">.</span>
            <span style="COLOR: #eeeeee">Add(</span>
            <span style="COLOR: #00ffff">"234"</span>
            <span style="COLOR: #eeeeee">);</span>
          </div>
          <span style="COLOR: teal">  4 </span>
          <span style="COLOR: #eeeeee">  
p</span>
          <span style="COLOR: #c0c0c0">.</span>
          <span style="COLOR: #eeeeee">orders</span>
          <span style="COLOR: #c0c0c0">.</span>
          <span style="COLOR: #eeeeee">Add(</span>
          <span style="COLOR: #00ffff">"23asdf4"</span>
          <span style="COLOR: #eeeeee">);</span>
          <br />
          <div style="BACKGROUND: #222222">
            <span style="COLOR: teal">  5 </span>
            <span style="COLOR: #eeeeee">  
p</span>
            <span style="COLOR: #c0c0c0">.</span>
            <span style="COLOR: #eeeeee">orders</span>
            <span style="COLOR: #c0c0c0">.</span>
            <span style="COLOR: #eeeeee">Add(</span>
            <span style="COLOR: #00ffff">"234345zs"</span>
            <span style="COLOR: #eeeeee">);</span>
          </div>
          <span style="COLOR: teal">  6 </span>
          <br />
          <div style="BACKGROUND: #222222">
            <span style="COLOR: teal">  7 </span>
          </div>
          <span style="COLOR: teal">  8 </span>
          <span style="COLOR: #eeeeee">   </span>
          <span style="COLOR: #ff80c0">IEditableBusinessObject</span>
          <span style="COLOR: #eeeeee"> editablePerson </span>
          <span style="COLOR: #c0c0c0">=</span>
          <span style="COLOR: #eeeeee"> p </span>
          <span style="COLOR: #90ee90">as</span>
          <span style="COLOR: #eeeeee"> </span>
          <span style="COLOR: #ff80c0">IEditableBusinessObject</span>
          <span style="COLOR: #eeeeee">;</span>
          <br />
          <div style="BACKGROUND: #222222">
            <span style="COLOR: teal">  9 </span>
          </div>
          <span style="COLOR: teal">  10 </span>
          <span style="COLOR: #eeeeee">  
editablePerson</span>
          <span style="COLOR: #c0c0c0">.</span>
          <span style="COLOR: #eeeeee">CopyCurrentToLoaded();</span>
          <br />
          <div style="BACKGROUND: #222222">
            <span style="COLOR: teal">  11 </span>
          </div>
          <span style="COLOR: teal">  12 </span>
          <span style="COLOR: #eeeeee">  
editablePerson</span>
          <span style="COLOR: #c0c0c0">.</span>
          <span style="COLOR: #eeeeee">BeginEdit();</span>
          <br />
          <div style="BACKGROUND: #222222">
            <span style="COLOR: teal">  13 </span>
          </div>
          <span style="COLOR: teal">  14 </span>
          <span style="COLOR: #eeeeee">  
p</span>
          <span style="COLOR: #c0c0c0">.</span>
          <span style="COLOR: #eeeeee">Name </span>
          <span style="COLOR: #c0c0c0">=</span>
          <span style="COLOR: #eeeeee"> </span>
          <span style="COLOR: #00ffff">"Boeke"</span>
          <span style="COLOR: #eeeeee">;</span>
          <br />
          <div style="BACKGROUND: #222222">
            <span style="COLOR: teal">  15 </span>
            <span style="COLOR: #eeeeee">  
p</span>
            <span style="COLOR: #c0c0c0">.</span>
            <span style="COLOR: #eeeeee">orders</span>
            <span style="COLOR: #c0c0c0">.</span>
            <span style="COLOR: #eeeeee">Add(</span>
            <span style="COLOR: #00ffff">"zxcvzxcvzxcvzxcv"</span>
            <span style="COLOR: #eeeeee">);</span>
          </div>
          <span style="COLOR: teal">  16 </span>
          <br />
          <div style="BACKGROUND: #222222">
            <span style="COLOR: teal">  17 </span>
            <span style="COLOR: #eeeeee">   </span>
            <span style="COLOR: #ff0080">Assert</span>
            <span style="COLOR: #c0c0c0">.</span>
            <span style="COLOR: #eeeeee">IsTrue(p</span>
            <span style="COLOR: #c0c0c0">.</span>
            <span style="COLOR: #eeeeee">Name </span>
            <span style="COLOR: #c0c0c0">==</span>
            <span style="COLOR: #eeeeee"> </span>
            <span style="COLOR: #00ffff">"Boeke"</span>
            <span style="COLOR: #eeeeee">);</span>
          </div>
          <span style="COLOR: teal">  18 </span>
          <span style="COLOR: #eeeeee">   </span>
          <span style="COLOR: #ff0080">Assert</span>
          <span style="COLOR: #c0c0c0">.</span>
          <span style="COLOR: #eeeeee">IsTrue(p</span>
          <span style="COLOR: #c0c0c0">.</span>
          <span style="COLOR: #eeeeee">orders</span>
          <span style="COLOR: #c0c0c0">.</span>
          <span style="COLOR: #eeeeee">Count </span>
          <span style="COLOR: #c0c0c0">==</span>
          <span style="COLOR: #eeeeee"> </span>
          <span style="COLOR: #00ffff">4</span>
          <span style="COLOR: #eeeeee">);</span>
          <br />
          <div style="BACKGROUND: #222222">
            <span style="COLOR: teal">  19 </span>
          </div>
          <span style="COLOR: teal">  20 </span>
          <span style="COLOR: #eeeeee">  
editablePerson</span>
          <span style="COLOR: #c0c0c0">.</span>
          <span style="COLOR: #eeeeee">CancelEdit();</span>
          <br />
          <div style="BACKGROUND: #222222">
            <span style="COLOR: teal">  21 </span>
          </div>
          <span style="COLOR: teal">  22 </span>
          <span style="COLOR: #eeeeee">   </span>
          <span style="COLOR: #ff0080">Assert</span>
          <span style="COLOR: #c0c0c0">.</span>
          <span style="COLOR: #eeeeee">IsTrue(p</span>
          <span style="COLOR: #c0c0c0">.</span>
          <span style="COLOR: #eeeeee">orders</span>
          <span style="COLOR: #c0c0c0">.</span>
          <span style="COLOR: #eeeeee">Count </span>
          <span style="COLOR: #c0c0c0">==</span>
          <span style="COLOR: #eeeeee"> </span>
          <span style="COLOR: #00ffff">3</span>
          <span style="COLOR: #eeeeee">);</span>
          <br />
          <div style="BACKGROUND: #222222">
            <span style="COLOR: teal">  23 </span>
            <span style="COLOR: #eeeeee">   </span>
            <span style="COLOR: #ff0080">Assert</span>
            <span style="COLOR: #c0c0c0">.</span>
            <span style="COLOR: #eeeeee">IsTrue(p</span>
            <span style="COLOR: #c0c0c0">.</span>
            <span style="COLOR: #eeeeee">Name </span>
            <span style="COLOR: #c0c0c0">==</span>
            <span style="COLOR: #eeeeee"> </span>
            <span style="COLOR: #00ffff">"Ruurd"</span>
            <span style="COLOR: #eeeeee">);</span>
          </div>
        </div>
        <p>
Just so we are on the same page, we did not have to implement anything on the business
object itself. Only use an attribute: the EditableBusinessObjectAttribute. It will
take care of everything for ya.
</p>
        <p>
        </p>
        <div style="BACKGROUND: #000000; COLOR: #f2f0df; FONT-FAMILY: monospace">
          <span style="COLOR: teal"> 
0 </span>
          <span style="COLOR: #eeeeee">[</span>
          <span style="COLOR: #ff0080">EditableBusinessObject</span>
          <span style="COLOR: #eeeeee">]</span>
          <br />
          <div style="BACKGROUND: #222222">
            <span style="COLOR: teal">  1 </span>
            <span style="COLOR: #eeeeee">[</span>
            <span style="COLOR: #ff0080">Serializable</span>
            <span style="COLOR: #eeeeee">]</span>
          </div>
          <span style="COLOR: teal">  2 </span>
          <span style="COLOR: #eeeeee"> </span>
          <span style="COLOR: #90ee90">public</span>
          <span style="COLOR: #eeeeee"> </span>
          <span style="COLOR: #90ee90">class</span>
          <span style="COLOR: #eeeeee"> </span>
          <span style="COLOR: #ff0080">Person</span>
          <br />
          <div style="BACKGROUND: #222222">
            <span style="COLOR: teal">  3 </span>
            <span style="COLOR: #eeeeee">{</span>
          </div>
          <span style="COLOR: teal">  4 </span>
          <span style="COLOR: #eeeeee">  </span>
          <span style="COLOR: #90ee90">public</span>
          <span style="COLOR: #eeeeee"> </span>
          <span style="COLOR: #90ee90">int</span>
          <span style="COLOR: #eeeeee"> MyProperty
{ </span>
          <span style="COLOR: #90ee90">get</span>
          <span style="COLOR: #eeeeee">; </span>
          <span style="COLOR: #90ee90">set</span>
          <span style="COLOR: #eeeeee">;
}</span>
          <br />
          <div style="BACKGROUND: #222222">
            <span style="COLOR: teal">  5 </span>
          </div>
          <span style="COLOR: teal">  6 </span>
          <span style="COLOR: #eeeeee">  </span>
          <span style="COLOR: #90ee90">public</span>
          <span style="COLOR: #eeeeee"> </span>
          <span style="COLOR: #90ee90">string</span>
          <span style="COLOR: #eeeeee"> Name
{ </span>
          <span style="COLOR: #90ee90">get</span>
          <span style="COLOR: #eeeeee">; </span>
          <span style="COLOR: #90ee90">set</span>
          <span style="COLOR: #eeeeee">;
}</span>
          <br />
          <div style="BACKGROUND: #222222">
            <span style="COLOR: teal">  7 </span>
          </div>
          <span style="COLOR: teal">  8 </span>
          <span style="COLOR: #eeeeee">  </span>
          <span style="COLOR: #90ee90">public</span>
          <span style="COLOR: #eeeeee"> </span>
          <span style="COLOR: #ff0080">List</span>
          <span style="COLOR: #c0c0c0">&lt;</span>
          <span style="COLOR: #90ee90">string</span>
          <span style="COLOR: #c0c0c0">&gt;</span>
          <span style="COLOR: #eeeeee"> orders
{ </span>
          <span style="COLOR: #90ee90">get</span>
          <span style="COLOR: #eeeeee">; </span>
          <span style="COLOR: #90ee90">set</span>
          <span style="COLOR: #eeeeee">;
}</span>
          <br />
          <div style="BACKGROUND: #222222">
            <span style="COLOR: teal">  9 </span>
          </div>
          <span style="COLOR: teal">  10 </span>
          <span style="COLOR: #eeeeee">  </span>
          <span style="COLOR: #90ee90">public</span>
          <span style="COLOR: #eeeeee"> Person()</span>
          <br />
          <div style="BACKGROUND: #222222">
            <span style="COLOR: teal">  11 </span>
            <span style="COLOR: #eeeeee"> 
{</span>
          </div>
          <span style="COLOR: teal">  12 </span>
          <span style="COLOR: #eeeeee">  
orders </span>
          <span style="COLOR: #c0c0c0">=</span>
          <span style="COLOR: #eeeeee"> </span>
          <span style="COLOR: #90ee90">new</span>
          <span style="COLOR: #eeeeee"> </span>
          <span style="COLOR: #ff0080">List</span>
          <span style="COLOR: #c0c0c0">&lt;</span>
          <span style="COLOR: #90ee90">string</span>
          <span style="COLOR: #c0c0c0">&gt;</span>
          <span style="COLOR: #eeeeee">();</span>
          <br />
          <div style="BACKGROUND: #222222">
            <span style="COLOR: teal">  13 </span>
            <span style="COLOR: #eeeeee"> 
}</span>
          </div>
          <span style="COLOR: teal">  14 </span>
          <br />
          <div style="BACKGROUND: #222222">
            <span style="COLOR: teal">  15 </span>
            <span style="COLOR: #eeeeee">}</span>
          </div>
        </div>
        <p>
        </p>
        <h5>Editable business objects
</h5>
        <p>
There is already a great usersample available on how to use <a href="http://www.postsharp.org/" target="_blank">PostSharp</a> to
implement this interface. I took a different route, but you should still <a href="http://code.google.com/p/postsharp-user-samples/wiki/DataBindingSupport" target="_blank">check
out</a> the sample, because it is actually quite well put together. 
</p>
        <p>
My scenario has the following requirements:
</p>
        <ul>
          <li>
implement IEditableObject (obviously) 
</li>
          <li>
Have a way to copy values to a 'Loaded' state: necessary to be able to send the 'original
values' to Entity Framework 
</li>
          <li>
Retrieve that loaded state: will be used by the serializer, to actually create the
original value serialization 
</li>
        </ul>
        <p>
So, I created the following interface that we will implement using PostSharp:
</p>
        <p>
        </p>
        <div style="BACKGROUND: #000000; COLOR: #f2f0df; FONT-FAMILY: monospace">
          <span style="COLOR: teal"> 
0 </span>
          <span style="COLOR: #eeeeee"> </span>
          <span style="COLOR: #90ee90">public</span>
          <span style="COLOR: #eeeeee"> </span>
          <span style="COLOR: #90ee90">interface</span>
          <span style="COLOR: #eeeeee"> </span>
          <span style="COLOR: #ff80c0">IEditableBusinessObject</span>
          <span style="COLOR: #eeeeee"> : </span>
          <span style="COLOR: #ff80c0">IEditableObject</span>
          <br />
          <div style="BACKGROUND: #222222">
            <span style="COLOR: teal">  1 </span>
            <span style="COLOR: #eeeeee">{</span>
          </div>
          <span style="COLOR: teal">  2 </span>
          <span style="COLOR: #eeeeee">  </span>
          <span style="COLOR: #90ee90">void</span>
          <span style="COLOR: #eeeeee"> RegisterFieldAccessAspect(</span>
          <span style="COLOR: #ff0080">FieldInterceptionAspect</span>
          <span style="COLOR: #eeeeee"> aspect);</span>
          <br />
          <div style="BACKGROUND: #222222">
            <span style="COLOR: teal">  3 </span>
          </div>
          <span style="COLOR: teal">  4 </span>
          <span style="COLOR: #eeeeee">  </span>
          <span style="COLOR: #90ee90">void</span>
          <span style="COLOR: #eeeeee"> CopyCurrentToLoaded();</span>
          <br />
          <div style="BACKGROUND: #222222">
            <span style="COLOR: teal">  5 </span>
          </div>
          <span style="COLOR: teal">  6 </span>
          <span style="COLOR: #eeeeee">  </span>
          <span style="COLOR: #90ee90">object</span>
          <span style="COLOR: #eeeeee"> RetrieveLoadedState(</span>
          <span style="COLOR: #90ee90">string</span>
          <span style="COLOR: #eeeeee"> FieldName);</span>
          <br />
          <div style="BACKGROUND: #222222">
            <span style="COLOR: teal">  7 </span>
          </div>
          <span style="COLOR: teal">  8 </span>
          <span style="COLOR: #eeeeee">  </span>
          <span style="COLOR: #90ee90">bool</span>
          <span style="COLOR: #eeeeee"> HasPendingTransaction();</span>
          <br />
          <div style="BACKGROUND: #222222">
            <span style="COLOR: teal">  9 </span>
            <span style="COLOR: #eeeeee">} </span>
          </div>
          <span style="COLOR: teal">  10 </span>
          <span style="COLOR: #000000">
          </span>
          <br />
        </div>
        <p>
        </p>
        <p>
To implement, we use the familiar CompositionAspect. 
</p>
        <p>
For the real magic, we need to intercept all gets and sets of all fields in the business
object.
</p>
        <h5>Intercept field access
</h5>
        <p>
A very strong feature of PostSharp is the OnFieldAccessAspect. It allows you to actually
intercept field access and route it to something different. 
<br />
The implementation of IEditableBusinessObject knows when the businessobject is set
to beginedit and should notify all fieldaspects. We do this by 'registering' the fieldaspect
at the editableBusinessObject. This way, when our object is going to beginEdit mode,
all we have to do is iterate our fieldaspects and let them know.
</p>
        <p>
At that point the fieldaspect makes a copy of it's value to the corresponding statebag.
If our value was not a value type, we make a deepcopy. I'm contemplating adding support
for ICloneable, so we can possibly skip that step.
</p>
        <p>
So, the begin, cancel and endedit methods on the fieldaspect look something like this:
</p>
        <p>
        </p>
        <div style="BACKGROUND: #000000; COLOR: #f2f0df; FONT-FAMILY: monospace">
          <span style="COLOR: teal"> 
0 </span>
          <span style="COLOR: #eeeeee">  </span>
          <span style="COLOR: #90ee90">internal</span>
          <span style="COLOR: #eeeeee"> </span>
          <span style="COLOR: #90ee90">void</span>
          <span style="COLOR: #eeeeee"> BeginEdit()</span>
          <br />
          <div style="BACKGROUND: #222222">
            <span style="COLOR: teal">  1 </span>
            <span style="COLOR: #eeeeee"> 
{</span>
          </div>
          <span style="COLOR: teal">  2 </span>
          <span style="COLOR: #eeeeee">   </span>
          <span style="COLOR: #90ee90">if</span>
          <span style="COLOR: #eeeeee"> (needsBinaryCopy)</span>
          <br />
          <div style="BACKGROUND: #222222">
            <span style="COLOR: teal">  3 </span>
            <span style="COLOR: #eeeeee">  
{</span>
          </div>
          <span style="COLOR: teal">  4 </span>
          <span style="COLOR: #eeeeee">    </span>
          <span style="COLOR: #ff0080">MemoryStream</span>
          <span style="COLOR: #eeeeee"> m </span>
          <span style="COLOR: #c0c0c0">=</span>
          <span style="COLOR: #eeeeee"> </span>
          <span style="COLOR: #90ee90">new</span>
          <span style="COLOR: #eeeeee"> </span>
          <span style="COLOR: #ff0080">MemoryStream</span>
          <span style="COLOR: #eeeeee">();</span>
          <br />
          <div style="BACKGROUND: #222222">
            <span style="COLOR: teal">  5 </span>
            <span style="COLOR: #eeeeee">    </span>
            <span style="COLOR: #ff0080">BinaryFormatter</span>
            <span style="COLOR: #eeeeee"> b </span>
            <span style="COLOR: #c0c0c0">=</span>
            <span style="COLOR: #eeeeee"> </span>
            <span style="COLOR: #90ee90">new</span>
            <span style="COLOR: #eeeeee"> </span>
            <span style="COLOR: #ff0080">BinaryFormatter</span>
            <span style="COLOR: #eeeeee">();</span>
          </div>
          <span style="COLOR: teal">  6 </span>
          <span style="COLOR: #eeeeee">   
b</span>
          <span style="COLOR: #c0c0c0">.</span>
          <span style="COLOR: #eeeeee">Serialize(m,
CurrentState);</span>
          <br />
          <div style="BACKGROUND: #222222">
            <span style="COLOR: teal">  7 </span>
            <span style="COLOR: #eeeeee">   
m</span>
            <span style="COLOR: #c0c0c0">.</span>
            <span style="COLOR: #eeeeee">Position </span>
            <span style="COLOR: #c0c0c0">=</span>
            <span style="COLOR: #eeeeee"> </span>
            <span style="COLOR: #00ffff">0</span>
            <span style="COLOR: #eeeeee">;</span>
          </div>
          <span style="COLOR: teal">  8 </span>
          <span style="COLOR: #eeeeee">   
PendingState </span>
          <span style="COLOR: #c0c0c0">=</span>
          <span style="COLOR: #eeeeee"> b</span>
          <span style="COLOR: #c0c0c0">.</span>
          <span style="COLOR: #eeeeee">Deserialize(m);</span>
          <br />
          <div style="BACKGROUND: #222222">
            <span style="COLOR: teal">  9 </span>
            <span style="COLOR: #eeeeee">  
}</span>
          </div>
          <span style="COLOR: teal">  10 </span>
          <span style="COLOR: #eeeeee">   </span>
          <span style="COLOR: #90ee90">else</span>
          <br />
          <div style="BACKGROUND: #222222">
            <span style="COLOR: teal">  11 </span>
            <span style="COLOR: #eeeeee">  
{</span>
          </div>
          <span style="COLOR: teal">  12 </span>
          <span style="COLOR: #eeeeee">   
PendingState </span>
          <span style="COLOR: #c0c0c0">=</span>
          <span style="COLOR: #eeeeee"> CurrentState;</span>
          <br />
          <div style="BACKGROUND: #222222">
            <span style="COLOR: teal">  13 </span>
            <span style="COLOR: #eeeeee">  
}</span>
          </div>
          <span style="COLOR: teal">  14 </span>
          <span style="COLOR: #eeeeee">  }  </span>
          <br />
          <div style="BACKGROUND: #222222">
            <span style="COLOR: teal">  15 </span>
            <span style="COLOR: #eeeeee">  </span>
          </div>
          <span style="COLOR: teal">  16 </span>
          <span style="COLOR: #eeeeee">  </span>
          <span style="COLOR: #90ee90">internal</span>
          <span style="COLOR: #eeeeee"> </span>
          <span style="COLOR: #90ee90">void</span>
          <span style="COLOR: #eeeeee"> CancelEdit()</span>
          <br />
          <div style="BACKGROUND: #222222">
            <span style="COLOR: teal">  17 </span>
            <span style="COLOR: #eeeeee"> 
{</span>
          </div>
          <span style="COLOR: teal">  18 </span>
          <span style="COLOR: #eeeeee">  
PendingState </span>
          <span style="COLOR: #c0c0c0">=</span>
          <span style="COLOR: #eeeeee"> </span>
          <span style="COLOR: #90ee90">null</span>
          <span style="COLOR: #eeeeee">;</span>
          <br />
          <div style="BACKGROUND: #222222">
            <span style="COLOR: teal">  19 </span>
            <span style="COLOR: #eeeeee"> 
}</span>
          </div>
          <span style="COLOR: teal">  20 </span>
          <br />
          <div style="BACKGROUND: #222222">
            <span style="COLOR: teal">  21 </span>
            <span style="COLOR: #eeeeee">  </span>
            <span style="COLOR: #90ee90">internal</span>
            <span style="COLOR: #eeeeee"> </span>
            <span style="COLOR: #90ee90">void</span>
            <span style="COLOR: #eeeeee"> EndEdit()</span>
          </div>
          <span style="COLOR: teal">  22 </span>
          <span style="COLOR: #eeeeee">  {</span>
          <br />
          <div style="BACKGROUND: #222222">
            <span style="COLOR: teal">  23 </span>
            <span style="COLOR: #eeeeee">  
CurrentState </span>
            <span style="COLOR: #c0c0c0">=</span>
            <span style="COLOR: #eeeeee"> PendingState;</span>
          </div>
          <span style="COLOR: teal">  24 </span>
          <span style="COLOR: #eeeeee">  
PendingState </span>
          <span style="COLOR: #c0c0c0">=</span>
          <span style="COLOR: #eeeeee"> </span>
          <span style="COLOR: #90ee90">null</span>
          <span style="COLOR: #eeeeee">;</span>
          <br />
          <div style="BACKGROUND: #222222">
            <span style="COLOR: teal">  25 </span>
            <span style="COLOR: #eeeeee"> 
}</span>
          </div>
        </div>
        <p>
        </p>
        <p>
And the get and set methods of the field look like this:
</p>
        <p>
        </p>
        <div style="BACKGROUND: #000000; COLOR: #f2f0df; FONT-FAMILY: monospace">
          <span style="COLOR: teal"> 
0 </span>
          <span style="COLOR: #eeeeee">  </span>
          <span style="COLOR: #90ee90">public</span>
          <span style="COLOR: #eeeeee"> </span>
          <span style="COLOR: #90ee90">override</span>
          <span style="COLOR: #eeeeee"> </span>
          <span style="COLOR: #90ee90">void</span>
          <span style="COLOR: #eeeeee"> OnGetValue(</span>
          <span style="COLOR: #ff0080">FieldAccessEventArgs</span>
          <span style="COLOR: #eeeeee"> eventArgs)</span>
          <br />
          <div style="BACKGROUND: #222222">
            <span style="COLOR: teal">  1 </span>
            <span style="COLOR: #eeeeee"> 
{</span>
          </div>
          <span style="COLOR: teal">  2 </span>
          <span style="COLOR: #eeeeee">   </span>
          <span style="COLOR: #ff80c0">IEditableBusinessObject</span>
          <span style="COLOR: #eeeeee"> editableObjectImpl </span>
          <span style="COLOR: #c0c0c0">=</span>
          <span style="COLOR: #eeeeee"> (</span>
          <span style="COLOR: #ff80c0">IEditableBusinessObject</span>
          <span style="COLOR: #eeeeee">)eventArgs</span>
          <span style="COLOR: #c0c0c0">.</span>
          <span style="COLOR: #eeeeee">Instance;</span>
          <br />
          <div style="BACKGROUND: #222222">
            <span style="COLOR: teal">  3 </span>
            <span style="COLOR: #eeeeee">  
editableObjectImpl</span>
            <span style="COLOR: #c0c0c0">.</span>
            <span style="COLOR: #eeeeee">RegisterFieldAccessAspect(</span>
            <span style="COLOR: #90ee90">this</span>
            <span style="COLOR: #eeeeee">);</span>
          </div>
          <span style="COLOR: teal">  4 </span>
          <br />
          <div style="BACKGROUND: #222222">
            <span style="COLOR: teal">  5 </span>
            <span style="COLOR: #eeeeee">  
eventArgs</span>
            <span style="COLOR: #c0c0c0">.</span>
            <span style="COLOR: #eeeeee">ExposedFieldValue </span>
            <span style="COLOR: #c0c0c0">=</span>
            <span style="COLOR: #eeeeee"> editableObjectImpl</span>
            <span style="COLOR: #c0c0c0">.</span>
            <span style="COLOR: #eeeeee">HasPendingTransaction() </span>
            <span style="COLOR: #c0c0c0">?</span>
            <span style="COLOR: #eeeeee"> PendingState
: CurrentState;</span>
          </div>
          <span style="COLOR: teal">  6 </span>
          <span style="COLOR: #eeeeee">  }</span>
          <br />
          <div style="BACKGROUND: #222222">
            <span style="COLOR: teal">  7 </span>
          </div>
          <span style="COLOR: teal">  8 </span>
          <span style="COLOR: #eeeeee">  </span>
          <span style="COLOR: #90ee90">public</span>
          <span style="COLOR: #eeeeee"> </span>
          <span style="COLOR: #90ee90">override</span>
          <span style="COLOR: #eeeeee"> </span>
          <span style="COLOR: #90ee90">void</span>
          <span style="COLOR: #eeeeee"> OnSetValue(</span>
          <span style="COLOR: #ff0080">FieldAccessEventArgs</span>
          <span style="COLOR: #eeeeee"> eventArgs)</span>
          <br />
          <div style="BACKGROUND: #222222">
            <span style="COLOR: teal">  9 </span>
            <span style="COLOR: #eeeeee"> 
{</span>
          </div>
          <span style="COLOR: teal">  10 </span>
          <span style="COLOR: #eeeeee">   </span>
          <span style="COLOR: #ff80c0">IEditableBusinessObject</span>
          <span style="COLOR: #eeeeee"> editableObjectImpl </span>
          <span style="COLOR: #c0c0c0">=</span>
          <span style="COLOR: #eeeeee"> (</span>
          <span style="COLOR: #ff80c0">IEditableBusinessObject</span>
          <span style="COLOR: #eeeeee">)eventArgs</span>
          <span style="COLOR: #c0c0c0">.</span>
          <span style="COLOR: #eeeeee">Instance;</span>
          <br />
          <div style="BACKGROUND: #222222">
            <span style="COLOR: teal">  11 </span>
            <span style="COLOR: #eeeeee">  
editableObjectImpl</span>
            <span style="COLOR: #c0c0c0">.</span>
            <span style="COLOR: #eeeeee">RegisterFieldAccessAspect(</span>
            <span style="COLOR: #90ee90">this</span>
            <span style="COLOR: #eeeeee">);</span>
          </div>
          <span style="COLOR: teal">  12 </span>
          <br />
          <div style="BACKGROUND: #222222">
            <span style="COLOR: teal">  13 </span>
          </div>
          <span style="COLOR: teal">  14 </span>
          <br />
          <div style="BACKGROUND: #222222">
            <span style="COLOR: teal">  15 </span>
            <span style="COLOR: #eeeeee">   </span>
            <span style="COLOR: #90ee90">if</span>
            <span style="COLOR: #eeeeee"> (editableObjectImpl</span>
            <span style="COLOR: #c0c0c0">.</span>
            <span style="COLOR: #eeeeee">HasPendingTransaction())</span>
          </div>
          <span style="COLOR: teal">  16 </span>
          <span style="COLOR: #eeeeee">  
{</span>
          <br />
          <div style="BACKGROUND: #222222">
            <span style="COLOR: teal">  17 </span>
            <span style="COLOR: #eeeeee">   
PendingState </span>
            <span style="COLOR: #c0c0c0">=</span>
            <span style="COLOR: #eeeeee"> eventArgs</span>
            <span style="COLOR: #c0c0c0">.</span>
            <span style="COLOR: #eeeeee">ExposedFieldValue;</span>
          </div>
          <span style="COLOR: teal">  18 </span>
          <span style="COLOR: #eeeeee">  
}</span>
          <br />
          <div style="BACKGROUND: #222222">
            <span style="COLOR: teal">  19 </span>
            <span style="COLOR: #eeeeee">   </span>
            <span style="COLOR: #90ee90">else</span>
          </div>
          <span style="COLOR: teal">  20 </span>
          <span style="COLOR: #eeeeee">  
{</span>
          <br />
          <div style="BACKGROUND: #222222">
            <span style="COLOR: teal">  21 </span>
            <span style="COLOR: #eeeeee">   
CurrentState </span>
            <span style="COLOR: #c0c0c0">=</span>
            <span style="COLOR: #eeeeee"> eventArgs</span>
            <span style="COLOR: #c0c0c0">.</span>
            <span style="COLOR: #eeeeee">ExposedFieldValue;</span>
          </div>
          <span style="COLOR: teal">  22 </span>
          <span style="COLOR: #eeeeee">  
}</span>
          <br />
          <div style="BACKGROUND: #222222">
            <span style="COLOR: teal">  23 </span>
            <span style="COLOR: #eeeeee"> 
}</span>
          </div>
        </div>
        <p>
        </p>
        <p>
As you can see, it checks with the instance, whether we have a pending transaction
(we have started beginedit). If we do, we write to the pendingstate object, instead
of the current state.
</p>
        <p>
I don't feel too comfortable with the code at this point, because I took quite a bit
of shortcuts. So I'm not putting that online at this point. However, if you are really
interested, let me know in the comments, and I'll clean it up.
</p>
        <p>
Stay tuned, because the next step will be to get this to serialize nicely, with originalvalues
and such.
</p>
        <img width="0" height="0" src="http://www.sitechno.com/Blog/aggbug.ashx?id=0ae96e5f-3d3a-48d7-b928-eeabb035fa2e" />
      </body>
      <title>Adding Edit support to businessobjects</title>
      <guid isPermaLink="false">http://www.sitechno.com/Blog/PermaLink,guid,0ae96e5f-3d3a-48d7-b928-eeabb035fa2e.aspx</guid>
      <link>http://www.sitechno.com/Blog/AddingEditSupportToBusinessobjects.aspx</link>
      <pubDate>Sun, 16 Mar 2008 14:16:14 GMT</pubDate>
      <description>&lt;p&gt;
[&lt;strong&gt;update&lt;/strong&gt;: I've updated my project quite a bit, and moved the state
to another object. So, the code you are about to see is old!]
&lt;/p&gt;
&lt;p&gt;
In the grand scheme of things, I'm building toward a set of tools that will enable
me to use EntityFramework on the server and use the same businessobjects on the client-side,
without having to reference EntityFramework at all. 
&lt;br&gt;
We already have a great &lt;a href="http://www.codeplex.com/efcontrib" target=_blank&gt;domain
layer supporting EF&lt;/a&gt;, &lt;a href="http://www.sitechno.com/Blog/ComplexTypesInEFHowTheyWorkAndSupportInEFContrib.aspx" target=_blank&gt;without
baseclasses&lt;/a&gt;. To use these objects on the client, we will need to take care of
changetracking ourselves. When we are done with that, we'll just have to write a custom
serializer, that will know how to serialize xml representations of the objects on
the client-side, and deserialize on the server and vice versa.
&lt;/p&gt;
&lt;p&gt;
I'll follow up in some post that describes how you can create different versions of
your domain layer for use on either client-side or server-side. 
&lt;/p&gt;
&lt;h5&gt;The end result
&lt;/h5&gt;
&lt;p&gt;
Let's skip to the end result straight away. This is a little test that runs fine:
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;div style="BACKGROUND: #000000; COLOR: #f2f0df; FONT-FAMILY: monospace"&gt;&lt;span style="COLOR: teal"&gt;&amp;nbsp;
0 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: #ff0080"&gt;Person&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt; p &lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;=&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="COLOR: #90ee90"&gt;new&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="COLOR: #ff0080"&gt;Person&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;();&lt;/span&gt; 
&lt;br&gt;
&lt;div style="BACKGROUND: #222222"&gt;&lt;span style="COLOR: teal"&gt;&amp;nbsp; 1 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&amp;nbsp;
p&lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;.&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;Name &lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;=&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="COLOR: #00ffff"&gt;"Ruurd"&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;;&lt;/span&gt;
&lt;/div&gt;
&lt;span style="COLOR: teal"&gt;&amp;nbsp; 2 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&amp;nbsp;
p&lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;.&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;MyProperty &lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;=&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="COLOR: #00ffff"&gt;10&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;;&lt;/span&gt; 
&lt;br&gt;
&lt;div style="BACKGROUND: #222222"&gt;&lt;span style="COLOR: teal"&gt;&amp;nbsp; 3 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&amp;nbsp;
p&lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;.&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;orders&lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;.&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;Add(&lt;/span&gt;&lt;span style="COLOR: #00ffff"&gt;"234"&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;);&lt;/span&gt;
&lt;/div&gt;
&lt;span style="COLOR: teal"&gt;&amp;nbsp; 4 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&amp;nbsp;
p&lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;.&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;orders&lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;.&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;Add(&lt;/span&gt;&lt;span style="COLOR: #00ffff"&gt;"23asdf4"&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;);&lt;/span&gt; 
&lt;br&gt;
&lt;div style="BACKGROUND: #222222"&gt;&lt;span style="COLOR: teal"&gt;&amp;nbsp; 5 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&amp;nbsp;
p&lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;.&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;orders&lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;.&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;Add(&lt;/span&gt;&lt;span style="COLOR: #00ffff"&gt;"234345zs"&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;);&lt;/span&gt;
&lt;/div&gt;
&lt;span style="COLOR: teal"&gt;&amp;nbsp; 6 &lt;/span&gt;
&lt;br&gt;
&lt;div style="BACKGROUND: #222222"&gt;&lt;span style="COLOR: teal"&gt;&amp;nbsp; 7 &lt;/span&gt;
&lt;/div&gt;
&lt;span style="COLOR: teal"&gt;&amp;nbsp; 8 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: #ff80c0"&gt;IEditableBusinessObject&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt; editablePerson &lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;=&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt; p &lt;/span&gt;&lt;span style="COLOR: #90ee90"&gt;as&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="COLOR: #ff80c0"&gt;IEditableBusinessObject&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;;&lt;/span&gt; 
&lt;br&gt;
&lt;div style="BACKGROUND: #222222"&gt;&lt;span style="COLOR: teal"&gt;&amp;nbsp; 9 &lt;/span&gt;
&lt;/div&gt;
&lt;span style="COLOR: teal"&gt;&amp;nbsp; 10 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&amp;nbsp;
editablePerson&lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;.&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;CopyCurrentToLoaded();&lt;/span&gt; 
&lt;br&gt;
&lt;div style="BACKGROUND: #222222"&gt;&lt;span style="COLOR: teal"&gt;&amp;nbsp; 11 &lt;/span&gt;
&lt;/div&gt;
&lt;span style="COLOR: teal"&gt;&amp;nbsp; 12 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&amp;nbsp;
editablePerson&lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;.&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;BeginEdit();&lt;/span&gt; 
&lt;br&gt;
&lt;div style="BACKGROUND: #222222"&gt;&lt;span style="COLOR: teal"&gt;&amp;nbsp; 13 &lt;/span&gt;
&lt;/div&gt;
&lt;span style="COLOR: teal"&gt;&amp;nbsp; 14 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&amp;nbsp;
p&lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;.&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;Name &lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;=&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="COLOR: #00ffff"&gt;"Boeke"&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;;&lt;/span&gt; 
&lt;br&gt;
&lt;div style="BACKGROUND: #222222"&gt;&lt;span style="COLOR: teal"&gt;&amp;nbsp; 15 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&amp;nbsp;
p&lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;.&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;orders&lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;.&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;Add(&lt;/span&gt;&lt;span style="COLOR: #00ffff"&gt;"zxcvzxcvzxcvzxcv"&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;);&lt;/span&gt;
&lt;/div&gt;
&lt;span style="COLOR: teal"&gt;&amp;nbsp; 16 &lt;/span&gt;
&lt;br&gt;
&lt;div style="BACKGROUND: #222222"&gt;&lt;span style="COLOR: teal"&gt;&amp;nbsp; 17 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: #ff0080"&gt;Assert&lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;.&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;IsTrue(p&lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;.&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;Name &lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;==&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="COLOR: #00ffff"&gt;"Boeke"&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;);&lt;/span&gt;
&lt;/div&gt;
&lt;span style="COLOR: teal"&gt;&amp;nbsp; 18 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: #ff0080"&gt;Assert&lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;.&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;IsTrue(p&lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;.&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;orders&lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;.&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;Count &lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;==&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="COLOR: #00ffff"&gt;4&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;);&lt;/span&gt; 
&lt;br&gt;
&lt;div style="BACKGROUND: #222222"&gt;&lt;span style="COLOR: teal"&gt;&amp;nbsp; 19 &lt;/span&gt;
&lt;/div&gt;
&lt;span style="COLOR: teal"&gt;&amp;nbsp; 20 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&amp;nbsp;
editablePerson&lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;.&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;CancelEdit();&lt;/span&gt; 
&lt;br&gt;
&lt;div style="BACKGROUND: #222222"&gt;&lt;span style="COLOR: teal"&gt;&amp;nbsp; 21 &lt;/span&gt;
&lt;/div&gt;
&lt;span style="COLOR: teal"&gt;&amp;nbsp; 22 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: #ff0080"&gt;Assert&lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;.&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;IsTrue(p&lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;.&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;orders&lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;.&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;Count &lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;==&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="COLOR: #00ffff"&gt;3&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;);&lt;/span&gt; 
&lt;br&gt;
&lt;div style="BACKGROUND: #222222"&gt;&lt;span style="COLOR: teal"&gt;&amp;nbsp; 23 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: #ff0080"&gt;Assert&lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;.&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;IsTrue(p&lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;.&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;Name &lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;==&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="COLOR: #00ffff"&gt;"Ruurd"&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;);&lt;/span&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
Just so we are on the same page, we did not have to implement anything on the business
object itself. Only use an attribute: the EditableBusinessObjectAttribute. It will
take care of everything for ya.
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;div style="BACKGROUND: #000000; COLOR: #f2f0df; FONT-FAMILY: monospace"&gt;&lt;span style="COLOR: teal"&gt;&amp;nbsp;
0 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;[&lt;/span&gt;&lt;span style="COLOR: #ff0080"&gt;EditableBusinessObject&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;]&lt;/span&gt; 
&lt;br&gt;
&lt;div style="BACKGROUND: #222222"&gt;&lt;span style="COLOR: teal"&gt;&amp;nbsp; 1 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;[&lt;/span&gt;&lt;span style="COLOR: #ff0080"&gt;Serializable&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;]&lt;/span&gt;
&lt;/div&gt;
&lt;span style="COLOR: teal"&gt;&amp;nbsp; 2 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="COLOR: #90ee90"&gt;public&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="COLOR: #90ee90"&gt;class&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="COLOR: #ff0080"&gt;Person&lt;/span&gt; 
&lt;br&gt;
&lt;div style="BACKGROUND: #222222"&gt;&lt;span style="COLOR: teal"&gt;&amp;nbsp; 3 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;{&lt;/span&gt;
&lt;/div&gt;
&lt;span style="COLOR: teal"&gt;&amp;nbsp; 4 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: #90ee90"&gt;public&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="COLOR: #90ee90"&gt;int&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt; MyProperty
{ &lt;/span&gt;&lt;span style="COLOR: #90ee90"&gt;get&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;; &lt;/span&gt;&lt;span style="COLOR: #90ee90"&gt;set&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;;
}&lt;/span&gt; 
&lt;br&gt;
&lt;div style="BACKGROUND: #222222"&gt;&lt;span style="COLOR: teal"&gt;&amp;nbsp; 5 &lt;/span&gt;
&lt;/div&gt;
&lt;span style="COLOR: teal"&gt;&amp;nbsp; 6 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: #90ee90"&gt;public&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="COLOR: #90ee90"&gt;string&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt; Name
{ &lt;/span&gt;&lt;span style="COLOR: #90ee90"&gt;get&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;; &lt;/span&gt;&lt;span style="COLOR: #90ee90"&gt;set&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;;
}&lt;/span&gt; 
&lt;br&gt;
&lt;div style="BACKGROUND: #222222"&gt;&lt;span style="COLOR: teal"&gt;&amp;nbsp; 7 &lt;/span&gt;
&lt;/div&gt;
&lt;span style="COLOR: teal"&gt;&amp;nbsp; 8 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: #90ee90"&gt;public&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="COLOR: #ff0080"&gt;List&lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #90ee90"&gt;string&lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;&amp;gt;&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt; orders
{ &lt;/span&gt;&lt;span style="COLOR: #90ee90"&gt;get&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;; &lt;/span&gt;&lt;span style="COLOR: #90ee90"&gt;set&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;;
}&lt;/span&gt; 
&lt;br&gt;
&lt;div style="BACKGROUND: #222222"&gt;&lt;span style="COLOR: teal"&gt;&amp;nbsp; 9 &lt;/span&gt;
&lt;/div&gt;
&lt;span style="COLOR: teal"&gt;&amp;nbsp; 10 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: #90ee90"&gt;public&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt; Person()&lt;/span&gt; 
&lt;br&gt;
&lt;div style="BACKGROUND: #222222"&gt;&lt;span style="COLOR: teal"&gt;&amp;nbsp; 11 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;
{&lt;/span&gt;
&lt;/div&gt;
&lt;span style="COLOR: teal"&gt;&amp;nbsp; 12 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&amp;nbsp;
orders &lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;=&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="COLOR: #90ee90"&gt;new&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="COLOR: #ff0080"&gt;List&lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #90ee90"&gt;string&lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;&amp;gt;&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;();&lt;/span&gt; 
&lt;br&gt;
&lt;div style="BACKGROUND: #222222"&gt;&lt;span style="COLOR: teal"&gt;&amp;nbsp; 13 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;
}&lt;/span&gt;
&lt;/div&gt;
&lt;span style="COLOR: teal"&gt;&amp;nbsp; 14 &lt;/span&gt;
&lt;br&gt;
&lt;div style="BACKGROUND: #222222"&gt;&lt;span style="COLOR: teal"&gt;&amp;nbsp; 15 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;}&lt;/span&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;h5&gt;Editable business objects
&lt;/h5&gt;
&lt;p&gt;
There is already a great usersample available on how to use &lt;a href="http://www.postsharp.org/" target=_blank&gt;PostSharp&lt;/a&gt; to
implement this interface. I took a different route, but you should still &lt;a href="http://code.google.com/p/postsharp-user-samples/wiki/DataBindingSupport" target=_blank&gt;check
out&lt;/a&gt; the sample, because it is actually quite well put together. 
&lt;/p&gt;
&lt;p&gt;
My scenario has the following requirements:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
implement IEditableObject (obviously) 
&lt;li&gt;
Have a way to copy values to a 'Loaded' state: necessary to be able to send the 'original
values' to Entity Framework 
&lt;li&gt;
Retrieve that loaded state: will be used by the serializer, to actually create the
original value serialization 
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
So, I created the following interface that we will implement using PostSharp:
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;div style="BACKGROUND: #000000; COLOR: #f2f0df; FONT-FAMILY: monospace"&gt;&lt;span style="COLOR: teal"&gt;&amp;nbsp;
0 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="COLOR: #90ee90"&gt;public&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="COLOR: #90ee90"&gt;interface&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="COLOR: #ff80c0"&gt;IEditableBusinessObject&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt; : &lt;/span&gt;&lt;span style="COLOR: #ff80c0"&gt;IEditableObject&lt;/span&gt; 
&lt;br&gt;
&lt;div style="BACKGROUND: #222222"&gt;&lt;span style="COLOR: teal"&gt;&amp;nbsp; 1 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;{&lt;/span&gt;
&lt;/div&gt;
&lt;span style="COLOR: teal"&gt;&amp;nbsp; 2 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: #90ee90"&gt;void&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt; RegisterFieldAccessAspect(&lt;/span&gt;&lt;span style="COLOR: #ff0080"&gt;FieldInterceptionAspect&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt; aspect);&lt;/span&gt; 
&lt;br&gt;
&lt;div style="BACKGROUND: #222222"&gt;&lt;span style="COLOR: teal"&gt;&amp;nbsp; 3 &lt;/span&gt;
&lt;/div&gt;
&lt;span style="COLOR: teal"&gt;&amp;nbsp; 4 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: #90ee90"&gt;void&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt; CopyCurrentToLoaded();&lt;/span&gt; 
&lt;br&gt;
&lt;div style="BACKGROUND: #222222"&gt;&lt;span style="COLOR: teal"&gt;&amp;nbsp; 5 &lt;/span&gt;
&lt;/div&gt;
&lt;span style="COLOR: teal"&gt;&amp;nbsp; 6 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: #90ee90"&gt;object&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt; RetrieveLoadedState(&lt;/span&gt;&lt;span style="COLOR: #90ee90"&gt;string&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt; FieldName);&lt;/span&gt; 
&lt;br&gt;
&lt;div style="BACKGROUND: #222222"&gt;&lt;span style="COLOR: teal"&gt;&amp;nbsp; 7 &lt;/span&gt;
&lt;/div&gt;
&lt;span style="COLOR: teal"&gt;&amp;nbsp; 8 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: #90ee90"&gt;bool&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt; HasPendingTransaction();&lt;/span&gt; 
&lt;br&gt;
&lt;div style="BACKGROUND: #222222"&gt;&lt;span style="COLOR: teal"&gt;&amp;nbsp; 9 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;} &lt;/span&gt;
&lt;/div&gt;
&lt;span style="COLOR: teal"&gt;&amp;nbsp; 10 &lt;/span&gt;&lt;span style="COLOR: #000000"&gt;&lt;/span&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
To implement, we use the familiar CompositionAspect. 
&lt;/p&gt;
&lt;p&gt;
For the real magic, we need to intercept all gets and sets of all fields in the business
object.
&lt;/p&gt;
&lt;h5&gt;Intercept field access
&lt;/h5&gt;
&lt;p&gt;
A very strong feature of PostSharp is the OnFieldAccessAspect. It allows you to actually
intercept field access and route it to something different. 
&lt;br&gt;
The implementation of IEditableBusinessObject knows when the businessobject is set
to beginedit and should notify all fieldaspects. We do this by 'registering' the fieldaspect
at the editableBusinessObject. This way, when our object is going to beginEdit mode,
all we have to do is iterate our fieldaspects and let them know.
&lt;/p&gt;
&lt;p&gt;
At that point the fieldaspect makes a copy of it's value to the corresponding statebag.
If our value was not a value type, we make a deepcopy. I'm contemplating adding support
for ICloneable, so we can possibly skip that step.
&lt;/p&gt;
&lt;p&gt;
So, the begin, cancel and endedit methods on the fieldaspect look something like this:
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;div style="BACKGROUND: #000000; COLOR: #f2f0df; FONT-FAMILY: monospace"&gt;&lt;span style="COLOR: teal"&gt;&amp;nbsp;
0 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: #90ee90"&gt;internal&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="COLOR: #90ee90"&gt;void&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt; BeginEdit()&lt;/span&gt; 
&lt;br&gt;
&lt;div style="BACKGROUND: #222222"&gt;&lt;span style="COLOR: teal"&gt;&amp;nbsp; 1 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;
{&lt;/span&gt;
&lt;/div&gt;
&lt;span style="COLOR: teal"&gt;&amp;nbsp; 2 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: #90ee90"&gt;if&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt; (needsBinaryCopy)&lt;/span&gt; 
&lt;br&gt;
&lt;div style="BACKGROUND: #222222"&gt;&lt;span style="COLOR: teal"&gt;&amp;nbsp; 3 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&amp;nbsp;
{&lt;/span&gt;
&lt;/div&gt;
&lt;span style="COLOR: teal"&gt;&amp;nbsp; 4 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: #ff0080"&gt;MemoryStream&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt; m &lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;=&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="COLOR: #90ee90"&gt;new&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="COLOR: #ff0080"&gt;MemoryStream&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;();&lt;/span&gt; 
&lt;br&gt;
&lt;div style="BACKGROUND: #222222"&gt;&lt;span style="COLOR: teal"&gt;&amp;nbsp; 5 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: #ff0080"&gt;BinaryFormatter&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt; b &lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;=&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="COLOR: #90ee90"&gt;new&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="COLOR: #ff0080"&gt;BinaryFormatter&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;();&lt;/span&gt;
&lt;/div&gt;
&lt;span style="COLOR: teal"&gt;&amp;nbsp; 6 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;
b&lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;.&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;Serialize(m,
CurrentState);&lt;/span&gt; 
&lt;br&gt;
&lt;div style="BACKGROUND: #222222"&gt;&lt;span style="COLOR: teal"&gt;&amp;nbsp; 7 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;
m&lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;.&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;Position &lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;=&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="COLOR: #00ffff"&gt;0&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;;&lt;/span&gt;
&lt;/div&gt;
&lt;span style="COLOR: teal"&gt;&amp;nbsp; 8 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;
PendingState &lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;=&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt; b&lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;.&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;Deserialize(m);&lt;/span&gt; 
&lt;br&gt;
&lt;div style="BACKGROUND: #222222"&gt;&lt;span style="COLOR: teal"&gt;&amp;nbsp; 9 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&amp;nbsp;
}&lt;/span&gt;
&lt;/div&gt;
&lt;span style="COLOR: teal"&gt;&amp;nbsp; 10 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: #90ee90"&gt;else&lt;/span&gt; 
&lt;br&gt;
&lt;div style="BACKGROUND: #222222"&gt;&lt;span style="COLOR: teal"&gt;&amp;nbsp; 11 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&amp;nbsp;
{&lt;/span&gt;
&lt;/div&gt;
&lt;span style="COLOR: teal"&gt;&amp;nbsp; 12 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;
PendingState &lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;=&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt; CurrentState;&lt;/span&gt; 
&lt;br&gt;
&lt;div style="BACKGROUND: #222222"&gt;&lt;span style="COLOR: teal"&gt;&amp;nbsp; 13 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&amp;nbsp;
}&lt;/span&gt;
&lt;/div&gt;
&lt;span style="COLOR: teal"&gt;&amp;nbsp; 14 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp; }&amp;nbsp; &lt;/span&gt;
&lt;br&gt;
&lt;div style="BACKGROUND: #222222"&gt;&lt;span style="COLOR: teal"&gt;&amp;nbsp; 15 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp; &lt;/span&gt;
&lt;/div&gt;
&lt;span style="COLOR: teal"&gt;&amp;nbsp; 16 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: #90ee90"&gt;internal&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="COLOR: #90ee90"&gt;void&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt; CancelEdit()&lt;/span&gt; 
&lt;br&gt;
&lt;div style="BACKGROUND: #222222"&gt;&lt;span style="COLOR: teal"&gt;&amp;nbsp; 17 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;
{&lt;/span&gt;
&lt;/div&gt;
&lt;span style="COLOR: teal"&gt;&amp;nbsp; 18 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&amp;nbsp;
PendingState &lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;=&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="COLOR: #90ee90"&gt;null&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;;&lt;/span&gt; 
&lt;br&gt;
&lt;div style="BACKGROUND: #222222"&gt;&lt;span style="COLOR: teal"&gt;&amp;nbsp; 19 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;
}&lt;/span&gt;
&lt;/div&gt;
&lt;span style="COLOR: teal"&gt;&amp;nbsp; 20 &lt;/span&gt;
&lt;br&gt;
&lt;div style="BACKGROUND: #222222"&gt;&lt;span style="COLOR: teal"&gt;&amp;nbsp; 21 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: #90ee90"&gt;internal&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="COLOR: #90ee90"&gt;void&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt; EndEdit()&lt;/span&gt;
&lt;/div&gt;
&lt;span style="COLOR: teal"&gt;&amp;nbsp; 22 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp; {&lt;/span&gt; 
&lt;br&gt;
&lt;div style="BACKGROUND: #222222"&gt;&lt;span style="COLOR: teal"&gt;&amp;nbsp; 23 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&amp;nbsp;
CurrentState &lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;=&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt; PendingState;&lt;/span&gt;
&lt;/div&gt;
&lt;span style="COLOR: teal"&gt;&amp;nbsp; 24 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&amp;nbsp;
PendingState &lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;=&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="COLOR: #90ee90"&gt;null&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;;&lt;/span&gt; 
&lt;br&gt;
&lt;div style="BACKGROUND: #222222"&gt;&lt;span style="COLOR: teal"&gt;&amp;nbsp; 25 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;
}&lt;/span&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
And the get and set methods of the field look like this:
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;div style="BACKGROUND: #000000; COLOR: #f2f0df; FONT-FAMILY: monospace"&gt;&lt;span style="COLOR: teal"&gt;&amp;nbsp;
0 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: #90ee90"&gt;public&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="COLOR: #90ee90"&gt;override&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="COLOR: #90ee90"&gt;void&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt; OnGetValue(&lt;/span&gt;&lt;span style="COLOR: #ff0080"&gt;FieldAccessEventArgs&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt; eventArgs)&lt;/span&gt; 
&lt;br&gt;
&lt;div style="BACKGROUND: #222222"&gt;&lt;span style="COLOR: teal"&gt;&amp;nbsp; 1 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;
{&lt;/span&gt;
&lt;/div&gt;
&lt;span style="COLOR: teal"&gt;&amp;nbsp; 2 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: #ff80c0"&gt;IEditableBusinessObject&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt; editableObjectImpl &lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;=&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt; (&lt;/span&gt;&lt;span style="COLOR: #ff80c0"&gt;IEditableBusinessObject&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;)eventArgs&lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;.&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;Instance;&lt;/span&gt; 
&lt;br&gt;
&lt;div style="BACKGROUND: #222222"&gt;&lt;span style="COLOR: teal"&gt;&amp;nbsp; 3 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&amp;nbsp;
editableObjectImpl&lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;.&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;RegisterFieldAccessAspect(&lt;/span&gt;&lt;span style="COLOR: #90ee90"&gt;this&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;);&lt;/span&gt;
&lt;/div&gt;
&lt;span style="COLOR: teal"&gt;&amp;nbsp; 4 &lt;/span&gt;
&lt;br&gt;
&lt;div style="BACKGROUND: #222222"&gt;&lt;span style="COLOR: teal"&gt;&amp;nbsp; 5 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&amp;nbsp;
eventArgs&lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;.&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;ExposedFieldValue &lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;=&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt; editableObjectImpl&lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;.&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;HasPendingTransaction() &lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;?&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt; PendingState
: CurrentState;&lt;/span&gt;
&lt;/div&gt;
&lt;span style="COLOR: teal"&gt;&amp;nbsp; 6 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp; }&lt;/span&gt; 
&lt;br&gt;
&lt;div style="BACKGROUND: #222222"&gt;&lt;span style="COLOR: teal"&gt;&amp;nbsp; 7 &lt;/span&gt;
&lt;/div&gt;
&lt;span style="COLOR: teal"&gt;&amp;nbsp; 8 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: #90ee90"&gt;public&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="COLOR: #90ee90"&gt;override&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="COLOR: #90ee90"&gt;void&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt; OnSetValue(&lt;/span&gt;&lt;span style="COLOR: #ff0080"&gt;FieldAccessEventArgs&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt; eventArgs)&lt;/span&gt; 
&lt;br&gt;
&lt;div style="BACKGROUND: #222222"&gt;&lt;span style="COLOR: teal"&gt;&amp;nbsp; 9 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;
{&lt;/span&gt;
&lt;/div&gt;
&lt;span style="COLOR: teal"&gt;&amp;nbsp; 10 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: #ff80c0"&gt;IEditableBusinessObject&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt; editableObjectImpl &lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;=&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt; (&lt;/span&gt;&lt;span style="COLOR: #ff80c0"&gt;IEditableBusinessObject&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;)eventArgs&lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;.&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;Instance;&lt;/span&gt; 
&lt;br&gt;
&lt;div style="BACKGROUND: #222222"&gt;&lt;span style="COLOR: teal"&gt;&amp;nbsp; 11 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&amp;nbsp;
editableObjectImpl&lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;.&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;RegisterFieldAccessAspect(&lt;/span&gt;&lt;span style="COLOR: #90ee90"&gt;this&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;);&lt;/span&gt;
&lt;/div&gt;
&lt;span style="COLOR: teal"&gt;&amp;nbsp; 12 &lt;/span&gt;
&lt;br&gt;
&lt;div style="BACKGROUND: #222222"&gt;&lt;span style="COLOR: teal"&gt;&amp;nbsp; 13 &lt;/span&gt;
&lt;/div&gt;
&lt;span style="COLOR: teal"&gt;&amp;nbsp; 14 &lt;/span&gt;
&lt;br&gt;
&lt;div style="BACKGROUND: #222222"&gt;&lt;span style="COLOR: teal"&gt;&amp;nbsp; 15 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: #90ee90"&gt;if&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt; (editableObjectImpl&lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;.&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;HasPendingTransaction())&lt;/span&gt;
&lt;/div&gt;
&lt;span style="COLOR: teal"&gt;&amp;nbsp; 16 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&amp;nbsp;
{&lt;/span&gt; 
&lt;br&gt;
&lt;div style="BACKGROUND: #222222"&gt;&lt;span style="COLOR: teal"&gt;&amp;nbsp; 17 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;
PendingState &lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;=&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt; eventArgs&lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;.&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;ExposedFieldValue;&lt;/span&gt;
&lt;/div&gt;
&lt;span style="COLOR: teal"&gt;&amp;nbsp; 18 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&amp;nbsp;
}&lt;/span&gt; 
&lt;br&gt;
&lt;div style="BACKGROUND: #222222"&gt;&lt;span style="COLOR: teal"&gt;&amp;nbsp; 19 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: #90ee90"&gt;else&lt;/span&gt;
&lt;/div&gt;
&lt;span style="COLOR: teal"&gt;&amp;nbsp; 20 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&amp;nbsp;
{&lt;/span&gt; 
&lt;br&gt;
&lt;div style="BACKGROUND: #222222"&gt;&lt;span style="COLOR: teal"&gt;&amp;nbsp; 21 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;
CurrentState &lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;=&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt; eventArgs&lt;/span&gt;&lt;span style="COLOR: #c0c0c0"&gt;.&lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;ExposedFieldValue;&lt;/span&gt;
&lt;/div&gt;
&lt;span style="COLOR: teal"&gt;&amp;nbsp; 22 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;&amp;nbsp;
}&lt;/span&gt; 
&lt;br&gt;
&lt;div style="BACKGROUND: #222222"&gt;&lt;span style="COLOR: teal"&gt;&amp;nbsp; 23 &lt;/span&gt;&lt;span style="COLOR: #eeeeee"&gt;&amp;nbsp;
}&lt;/span&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
As you can see, it checks with the instance, whether we have a pending transaction
(we have started beginedit). If we do, we write to the pendingstate object, instead
of the current state.
&lt;/p&gt;
&lt;p&gt;
I don't feel too comfortable with the code at this point, because I took quite a bit
of shortcuts. So I'm not putting that online at this point. However, if you are really
interested, let me know in the comments, and I'll clean it up.
&lt;/p&gt;
&lt;p&gt;
Stay tuned, because the next step will be to get this to serialize nicely, with originalvalues
and such.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.sitechno.com/Blog/aggbug.ashx?id=0ae96e5f-3d3a-48d7-b928-eeabb035fa2e" /&gt;</description>
      <comments>http://www.sitechno.com/Blog/CommentView,guid,0ae96e5f-3d3a-48d7-b928-eeabb035fa2e.aspx</comments>
      <category>Code;EF (Entity Framework)</category>
    </item>
    <item>
      <trackback:ping>http://www.sitechno.com/Blog/Trackback.aspx?guid=793af762-4993-435e-8159-28c5bb9c8b74</trackback:ping>
      <pingback:server>http://www.sitechno.com/Blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.sitechno.com/Blog/PermaLink,guid,793af762-4993-435e-8159-28c5bb9c8b74.aspx</pingback:target>
      <dc:creator>Ruurd Boeke</dc:creator>
      <wfw:comment>http://www.sitechno.com/Blog/CommentView,guid,793af762-4993-435e-8159-28c5bb9c8b74.aspx</wfw:comment>
      <wfw:commentRss>http://www.sitechno.com/Blog/SyndicationService.asmx/GetEntryCommentsRss?guid=793af762-4993-435e-8159-28c5bb9c8b74</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
the Oredev-conference posted video's of it's sessions online <a href="http://www.oredev.org/toppmeny/video.4.3f1ff754117a0ed3480800013788.html" target="_blank">here</a>.
</p>
        <p>
I've just browsed the sessions that were held at this big conference, and it looks
interesting. Many famous names, like Erik Meijer, Joe Duffy, Jimmy Nilsson (I read
his book), Mats Helander and many others. 
</p>
        <p>
The conference has specific tracks: Java, .Net, Methods &amp; Tools, Test, Project
Management, Embedded System, Architecture and User Experience. 
</p>
        <p>
So sit back, relax, have a beer and hear great people explain important topics to
you.
</p>
        <p>
Just a quick tip: you can only watch the video's inside a browser. If you try to download,
you will get a very small file. Open that with notepad and look for the rts: address
at the very end. Copy paste the url into a good media player like VLC which knows
how to deal with streams, and you will be able to watch more comfortably. I did this,
because I could not scale the webversion and I had no way of scrubbing through the
video.
</p>
        <p>
          <a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fwww.sitechno.com%2fBlog%2fSitBackWatchVideosAndLearnStuff.aspx">
            <img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.sitechno.com%2fBlog%2fSitBackWatchVideosAndLearnStuff.aspx" border="0" alt="kick it on DotNetKicks.com" />
          </a>
        </p>
        <img width="0" height="0" src="http://www.sitechno.com/Blog/aggbug.ashx?id=793af762-4993-435e-8159-28c5bb9c8b74" />
      </body>
      <title>Sit back, watch videos and learn stuff</title>
      <guid isPermaLink="false">http://www.sitechno.com/Blog/PermaLink,guid,793af762-4993-435e-8159-28c5bb9c8b74.aspx</guid>
      <link>http://www.sitechno.com/Blog/SitBackWatchVideosAndLearnStuff.aspx</link>
      <pubDate>Wed, 05 Mar 2008 16:48:13 GMT</pubDate>
      <description>&lt;p&gt;
the Oredev-conference posted video's of it's sessions online &lt;a href="http://www.oredev.org/toppmeny/video.4.3f1ff754117a0ed3480800013788.html" target=_blank&gt;here&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
I've just browsed the sessions that were held at this big conference, and it looks
interesting. Many famous names, like Erik Meijer, Joe Duffy, Jimmy Nilsson (I read
his book), Mats Helander and many others. 
&lt;/p&gt;
&lt;p&gt;
The conference has specific tracks: Java, .Net, Methods &amp;amp; Tools, Test, Project
Management, Embedded System, Architecture and User Experience. 
&lt;/p&gt;
&lt;p&gt;
So sit back, relax, have a beer and hear great people explain important topics to
you.
&lt;/p&gt;
&lt;p&gt;
Just a quick tip: you can only watch the video's inside a browser. If you try to download,
you will get a very small file. Open that with notepad and look for the rts: address
at the very end. Copy paste the url into a good media player like VLC which knows
how to deal with streams, and you will be able to watch more comfortably. I did this,
because I could not scale the webversion and I had no way of scrubbing through the
video.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fwww.sitechno.com%2fBlog%2fSitBackWatchVideosAndLearnStuff.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.sitechno.com%2fBlog%2fSitBackWatchVideosAndLearnStuff.aspx" border="0" alt="kick it on DotNetKicks.com" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.sitechno.com/Blog/aggbug.ashx?id=793af762-4993-435e-8159-28c5bb9c8b74" /&gt;</description>
      <comments>http://www.sitechno.com/Blog/CommentView,guid,793af762-4993-435e-8159-28c5bb9c8b74.aspx</comments>
      <category>Code</category>
    </item>
    <item>
      <trackback:ping>http://www.sitechno.com/Blog/Trackback.aspx?guid=bc8a80e7-5157-455f-9e8b-6245269cc393</trackback:ping>
      <pingback:server>http://www.sitechno.com/Blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.sitechno.com/Blog/PermaLink,guid,bc8a80e7-5157-455f-9e8b-6245269cc393.aspx</pingback:target>
      <dc:creator>Ruurd Boeke</dc:creator>
      <wfw:comment>http://www.sitechno.com/Blog/CommentView,guid,bc8a80e7-5157-455f-9e8b-6245269cc393.aspx</wfw:comment>
      <wfw:commentRss>http://www.sitechno.com/Blog/SyndicationService.asmx/GetEntryCommentsRss?guid=bc8a80e7-5157-455f-9e8b-6245269cc393</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Just a random piece of code that I thought is handy: when you are experimenting with
xml, you probably want to see the xml quickly and easily. For instance, when you are
using the DataContractSerializer to serialize a type, you want to see how it looks.
But it get's printed on one line!! That's not useful. 
</p>
        <p>
Use something like the following code:
</p>
        <div style="font-family: courier new">
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">            MemoryStream m = <span style="color: blue">new</span> MemoryStream();</pre>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">            XmlTextWriter tw = <span style="color: blue">new</span> XmlTextWriter(m,
Encoding.UTF8);</pre>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">            tw.Formatting = Formatting.Indented;</pre>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">            tw.Indentation = <span style="color: maroon">4</span>;</pre>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">            tw.IndentChar = <span style="color: maroon">"
"</span>.ToCharArray()[<span style="color: maroon">0</span>];</pre>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">            s.WriteObject(tw, p);</pre>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">            tw.Flush();</pre>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">            m.Position = <span style="color: maroon">0</span>;</pre>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">            StreamReader sr = <span style="color: blue">new</span> StreamReader(m);</pre>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">            <span style="color: blue">string</span> strOutput
= sr.ReadToEnd();</pre>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">            Debug.WriteLine(strOutput);</pre>
        </div>
        <div style="font-family: courier new"> 
</div>
        <div style="font-family: courier new">Where s represents your datacontract serializer. 
</div>
        <div style="font-family: courier new">This outputs glorious xml to the debug.output
window:
</div>
        <div style="font-family: courier new">
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">&lt;Person xmlns<span style="color: blue">:</span>i=<span style="color: maroon">"http://www.w3.org/2001/XMLSchema-instance"</span> xmlns=<span style="color: maroon">"http://schemas.datacontract.org/2004/07/DomainModel"</span>&gt;</pre>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    &lt;FirstName&gt;Ruurd&lt;/FirstName&gt;</pre>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">    &lt;LastName&gt;Boeke&lt;/LastName&gt;</pre>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">    &lt;Orders&gt;</pre>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">        &lt;Order&gt;</pre>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">            &lt;Amount&gt;<span style="color: maroon">5</span>&lt;/Amount&gt;</pre>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">            &lt;ProductID&gt;<span style="color: maroon">10</span>&lt;/ProductID&gt;</pre>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">        &lt;/Order&gt;</pre>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">        &lt;Order&gt;</pre>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">            &lt;Amount&gt;<span style="color: maroon">12</span>&lt;/Amount&gt;</pre>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">            &lt;ProductID&gt;<span style="color: maroon">11</span>&lt;/ProductID&gt;</pre>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">        &lt;/Order&gt;</pre>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">        &lt;Order&gt;</pre>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">            &lt;Amount&gt;<span style="color: maroon">2</span>&lt;/Amount&gt;</pre>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">            &lt;ProductID&gt;<span style="color: maroon">1</span>&lt;/ProductID&gt;</pre>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">        &lt;/Order&gt;</pre>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">    &lt;/Orders&gt;</pre>
&lt;/Person&gt;
</div>
        <div style="font-family: courier new">
        </div>
        <img width="0" height="0" src="http://www.sitechno.com/Blog/aggbug.ashx?id=bc8a80e7-5157-455f-9e8b-6245269cc393" />
      </body>
      <title>Writing well-formed xml to the debug output window</title>
      <guid isPermaLink="false">http://www.sitechno.com/Blog/PermaLink,guid,bc8a80e7-5157-455f-9e8b-6245269cc393.aspx</guid>
      <link>http://www.sitechno.com/Blog/WritingWellformedXmlToTheDebugOutputWindow.aspx</link>
      <pubDate>Thu, 28 Feb 2008 14:06:40 GMT</pubDate>
      <description>&lt;p&gt;
Just a random piece of code that I thought is handy: when you are experimenting with
xml, you probably want to see the xml quickly and easily. For instance, when you are
using the DataContractSerializer to serialize a type, you want to see how it looks.
But it get's printed on one line!! That's not useful. 
&lt;/p&gt;
&lt;p&gt;
Use something like the following code:
&lt;/p&gt;
&lt;div style="font-family: courier new"&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; MemoryStream m = &lt;span style="color: blue"&gt;new&lt;/span&gt; MemoryStream();&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; XmlTextWriter tw = &lt;span style="color: blue"&gt;new&lt;/span&gt; XmlTextWriter(m,
Encoding.UTF8);&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; tw.Formatting = Formatting.Indented;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; tw.Indentation = &lt;span style="color: maroon"&gt;4&lt;/span&gt;;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; tw.IndentChar = &lt;span style="color: maroon"&gt;&amp;quot;
&amp;quot;&lt;/span&gt;.ToCharArray()[&lt;span style="color: maroon"&gt;0&lt;/span&gt;];&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; s.WriteObject(tw, p);&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; tw.Flush();&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; m.Position = &lt;span style="color: maroon"&gt;0&lt;/span&gt;;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; StreamReader sr = &lt;span style="color: blue"&gt;new&lt;/span&gt; StreamReader(m);&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: blue"&gt;string&lt;/span&gt; strOutput
= sr.ReadToEnd();&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Debug.WriteLine(strOutput);&lt;/pre&gt;
&lt;/div&gt;
&lt;div style="font-family: courier new"&gt;&amp;#160;
&lt;/div&gt;
&lt;div style="font-family: courier new"&gt;Where s represents your datacontract serializer. 
&lt;/div&gt;
&lt;div style="font-family: courier new"&gt;This outputs glorious xml to the debug.output
window:
&lt;/div&gt;
&lt;div style="font-family: courier new"&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;lt;Person xmlns&lt;span style="color: blue"&gt;:&lt;/span&gt;i=&lt;span style="color: maroon"&gt;&amp;quot;http://www.w3.org/2001/XMLSchema-instance&amp;quot;&lt;/span&gt; xmlns=&lt;span style="color: maroon"&gt;&amp;quot;http://schemas.datacontract.org/2004/07/DomainModel&amp;quot;&lt;/span&gt;&amp;gt;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;FirstName&amp;gt;Ruurd&amp;lt;/FirstName&amp;gt;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;LastName&amp;gt;Boeke&amp;lt;/LastName&amp;gt;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Orders&amp;gt;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Order&amp;gt;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Amount&amp;gt;&lt;span style="color: maroon"&gt;5&lt;/span&gt;&amp;lt;/Amount&amp;gt;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;ProductID&amp;gt;&lt;span style="color: maroon"&gt;10&lt;/span&gt;&amp;lt;/ProductID&amp;gt;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/Order&amp;gt;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Order&amp;gt;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Amount&amp;gt;&lt;span style="color: maroon"&gt;12&lt;/span&gt;&amp;lt;/Amount&amp;gt;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;ProductID&amp;gt;&lt;span style="color: maroon"&gt;11&lt;/span&gt;&amp;lt;/ProductID&amp;gt;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/Order&amp;gt;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Order&amp;gt;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;Amount&amp;gt;&lt;span style="color: maroon"&gt;2&lt;/span&gt;&amp;lt;/Amount&amp;gt;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;ProductID&amp;gt;&lt;span style="color: maroon"&gt;1&lt;/span&gt;&amp;lt;/ProductID&amp;gt;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/Order&amp;gt;&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/Orders&amp;gt;&lt;/pre&gt;
&amp;lt;/Person&amp;gt;
&lt;/div&gt;
&lt;div style="font-family: courier new"&gt;
&lt;/div&gt;
&lt;img width="0" height="0" src="http://www.sitechno.com/Blog/aggbug.ashx?id=bc8a80e7-5157-455f-9e8b-6245269cc393" /&gt;</description>
      <comments>http://www.sitechno.com/Blog/CommentView,guid,bc8a80e7-5157-455f-9e8b-6245269cc393.aspx</comments>
      <category>Code</category>
    </item>
    <item>
      <trackback:ping>http://www.sitechno.com/Blog/Trackback.aspx?guid=1f773d3c-cf57-466a-b893-d09acc709f3e</trackback:ping>
      <pingback:server>http://www.sitechno.com/Blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.sitechno.com/Blog/PermaLink,guid,1f773d3c-cf57-466a-b893-d09acc709f3e.aspx</pingback:target>
      <dc:creator>Ruurd Boeke</dc:creator>
      <wfw:comment>http://www.sitechno.com/Blog/CommentView,guid,1f773d3c-cf57-466a-b893-d09acc709f3e.aspx</wfw:comment>
      <wfw:commentRss>http://www.sitechno.com/Blog/SyndicationService.asmx/GetEntryCommentsRss?guid=1f773d3c-cf57-466a-b893-d09acc709f3e</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I'm a big reflection fan. However, reflection is slow and (for certain actions) requires
full-trust. That's a big issue, since that means you can not use it in an unsigned
xbap or whatever. 
</p>
        <p>
People are finding some cool ways to work around reflection where they can.
</p>
        <p>
Ayende talks about the performance implications of creating objects <a href="http://www.ayende.com/Blog/archive/2008/02/27/Creating-objects--Perf-implications.aspx" target="_blank">here</a>,
and concludes that reflection might be slow, but you should ask yourself if you really
care. If you do, he shows how to use dynamic methods to do the creation for you.
</p>
        <p>
Roger Alsing takes it one step further, and uses Linq to build an expression tree
to access <strong>private</strong> fields. Radical!! I love it. Read it <a href="http://rogeralsing.com/2008/02/26/linq-expressions-access-private-fields/" target="_blank">here</a>. 
<br />
Also note his performance gains:
</p>
        <blockquote>
          <p>
This approach is also much faster than Reflection.FieldInfo. 
<br />
I made a little benchmark where I accessed the same field a million times.
</p>
        </blockquote>
        <blockquote>
          <p>
The Reflection.FieldInfo approach took <strong>6.2 seconds</strong> to complete. 
<br />
The Compiled lambda approach took <strong>0.013 seconds</strong> to complete. 
<br />
That’s quit a big difference.
</p>
        </blockquote>
        <p>
But keep in mind that actually compiling the expression is many times slower than
reflection. 
</p>
        <img width="0" height="0" src="http://www.sitechno.com/Blog/aggbug.ashx?id=1f773d3c-cf57-466a-b893-d09acc709f3e" />
      </body>
      <title>The downfall of reflection</title>
      <guid isPermaLink="false">http://www.sitechno.com/Blog/PermaLink,guid,1f773d3c-cf57-466a-b893-d09acc709f3e.aspx</guid>
      <link>http://www.sitechno.com/Blog/TheDownfallOfReflection.aspx</link>
      <pubDate>Thu, 28 Feb 2008 00:41:48 GMT</pubDate>
      <description>&lt;p&gt;
I'm a big reflection fan. However, reflection is slow and (for certain actions) requires
full-trust. That's a big issue, since that means you can not use it in an unsigned
xbap or whatever. 
&lt;/p&gt;
&lt;p&gt;
People are finding some cool ways to work around reflection where they can.
&lt;/p&gt;
&lt;p&gt;
Ayende talks about the performance implications of creating objects &lt;a href="http://www.ayende.com/Blog/archive/2008/02/27/Creating-objects--Perf-implications.aspx" target="_blank"&gt;here&lt;/a&gt;,
and concludes that reflection might be slow, but you should ask yourself if you really
care. If you do, he shows how to use dynamic methods to do the creation for you.
&lt;/p&gt;
&lt;p&gt;
Roger Alsing takes it one step further, and uses Linq to build an expression tree
to access &lt;strong&gt;private&lt;/strong&gt; fields. Radical!! I love it. Read it &lt;a href="http://rogeralsing.com/2008/02/26/linq-expressions-access-private-fields/" target="_blank"&gt;here&lt;/a&gt;. 
&lt;br /&gt;
Also note his performance gains:
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
This approach is also much faster than Reflection.FieldInfo. 
&lt;br /&gt;
I made a little benchmark where I accessed the same field a million times.
&lt;/p&gt;
&lt;/blockquote&gt; &lt;blockquote&gt; 
&lt;p&gt;
The Reflection.FieldInfo approach took &lt;strong&gt;6.2 seconds&lt;/strong&gt; to complete. 
&lt;br /&gt;
The Compiled lambda approach took &lt;strong&gt;0.013 seconds&lt;/strong&gt; to complete. 
&lt;br /&gt;
That&amp;#8217;s quit a big difference.
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
But keep in mind that actually compiling the expression is many times slower than
reflection. 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.sitechno.com/Blog/aggbug.ashx?id=1f773d3c-cf57-466a-b893-d09acc709f3e" /&gt;</description>
      <comments>http://www.sitechno.com/Blog/CommentView,guid,1f773d3c-cf57-466a-b893-d09acc709f3e.aspx</comments>
      <category>Code</category>
    </item>
  </channel>
</rss>