<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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/" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" version="2.0">
  <channel>
    <title>Manuel Abadia's ASP.NET stuff - Microsoft .NET Framework</title>
    <link>http://www.manuelabadia.com/blog/</link>
    <description />
    <language>en-us</language>
    <copyright>Manuel Abadia</copyright>
    <lastBuildDate>Tue, 31 Aug 2010 16:27:46 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 1.9.6264.0</generator>
    <managingEditor>blogcomments@manuelabadia.com</managingEditor>
    <webMaster>blogcomments@manuelabadia.com</webMaster>
    <item>
      <trackback:ping>http://www.manuelabadia.com/blog/Trackback.aspx?guid=04ac6c0f-dde0-4960-ba68-d5e8fbf09148</trackback:ping>
      <pingback:server>http://www.manuelabadia.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.manuelabadia.com/blog/PermaLink,guid,04ac6c0f-dde0-4960-ba68-d5e8fbf09148.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://www.manuelabadia.com/blog/CommentView,guid,04ac6c0f-dde0-4960-ba68-d5e8fbf09148.aspx</wfw:comment>
      <wfw:commentRss>http://www.manuelabadia.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=04ac6c0f-dde0-4960-ba68-d5e8fbf09148</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I have finally updated the Linq Expressions DebuggerVisualizer to work in VS 2010.
</p>
        <p>
There were a lot of new kind of Expressions introduced so I added support for them
too.
</p>
        <p>
You can see it in action with data from the MSDN samples for the SwitchExpression
class and the TryExpression class.
</p>
        <p>
          <img border="0" src="http://www.manuelabadia.com/blog/content/binary/linqdebviz1.PNG" />
          <br />
          <img border="0" src="http://www.manuelabadia.com/blog/content/binary/linqdebviz2.PNG" />
          <br />
        </p>
        <p>
You can download the Visualizer <a href="http://www.manuelabadia.com/blog/PermaLink,guid,9160035f-490f-46bd-ab55-516b5c7545af.aspx">here</a></p>
        <img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=04ac6c0f-dde0-4960-ba68-d5e8fbf09148" />
      </body>
      <title>Linq Expressions DebuggerVisualizer updated to work in VS2010</title>
      <guid isPermaLink="false">http://www.manuelabadia.com/blog/PermaLink,guid,04ac6c0f-dde0-4960-ba68-d5e8fbf09148.aspx</guid>
      <link>http://www.manuelabadia.com/blog/PermaLink,guid,04ac6c0f-dde0-4960-ba68-d5e8fbf09148.aspx</link>
      <pubDate>Tue, 31 Aug 2010 16:27:46 GMT</pubDate>
      <description>&lt;p&gt;
I have finally updated the Linq Expressions DebuggerVisualizer to work in VS 2010.
&lt;/p&gt;
&lt;p&gt;
There were a lot of new kind of Expressions introduced so I added support for them
too.
&lt;/p&gt;
&lt;p&gt;
You can see it in action with data from the MSDN samples for the SwitchExpression
class and the TryExpression class.
&lt;/p&gt;
&lt;p&gt;
&lt;img border="0" src="http://www.manuelabadia.com/blog/content/binary/linqdebviz1.PNG"&gt;
&lt;br /&gt;
&lt;img border="0" src="http://www.manuelabadia.com/blog/content/binary/linqdebviz2.PNG"&gt;
&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;
You can download the Visualizer &lt;a href="http://www.manuelabadia.com/blog/PermaLink,guid,9160035f-490f-46bd-ab55-516b5c7545af.aspx"&gt;here&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=04ac6c0f-dde0-4960-ba68-d5e8fbf09148" /&gt;</description>
      <comments>http://www.manuelabadia.com/blog/CommentView,guid,04ac6c0f-dde0-4960-ba68-d5e8fbf09148.aspx</comments>
      <category>Linq;Microsoft .NET Framework;Visual Studio</category>
    </item>
    <item>
      <trackback:ping>http://www.manuelabadia.com/blog/Trackback.aspx?guid=0606d95f-56ae-4dd7-8458-69cd550fa356</trackback:ping>
      <pingback:server>http://www.manuelabadia.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.manuelabadia.com/blog/PermaLink,guid,0606d95f-56ae-4dd7-8458-69cd550fa356.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://www.manuelabadia.com/blog/CommentView,guid,0606d95f-56ae-4dd7-8458-69cd550fa356.aspx</wfw:comment>
      <wfw:commentRss>http://www.manuelabadia.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=0606d95f-56ae-4dd7-8458-69cd550fa356</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
All controls that inherit from ListControl (BulletedList, CheckBoxList, DropDownList,
ListBox and RadioButtonList) have some annoying behavior in common: 
</p>
        <p>
You can only bind the control to a single property using the DataTextField property.
For example, if you have a Customer class with properties Id, Name, Surname, etc and
you want to show the full name of a customer in any of the ListControls, you have
several options:
</p>
        <ol>
          <li>
When you get the data from the database, return another column with the name and surname. 
</li>
          <li>
Create a property (f.e. FullName) that returns what you want to show. 
</li>
          <li>
Use a DataSet and add a computed column. 
</li>
          <li>
Manually add ListItems with the appropriate values performing the data bind manually. 
</li>
          <li>
Create a simple class that will be bound (instead of the original one) just to fix
the problem.</li>
        </ol>
        <p>
The truth is that I don’t like any of those options, all of them are hacks. 
</p>
        <p>
For nested properties you have the similar problems. You can bind to Id or Name, but
you can’t bind to Address.City or Address.Zip.
</p>
        <p>
Today I faced this problem again and I decided to investigate a more innovative solution.
The problem itself is in the controls that inherit from ListControl that are very
strict in the binding options. So I took a look of how the controls perform the binding
to see if I could do anything to overcome those limitations. At first sight I thought
I was loosing my time but after a deeper study I found that it was amazingly easy
to fix those problems in a very sleek way.
</p>
        <p>
The data binding of the controls is performed in the PerformDataBinding method. The
code at ListControl.PerformDataBinding uses DataBinder.GetPropertyValue to retrieve
the value to show in the control if you set the DataTextField property. However, DataBinder.GetPropertyValue
doesn’t handle nested properties. DataBinder.Eval is a better choice because it does
handle nested properties. So using it we solve one problem. The other problem can
be solved easily as well. As we have two properties that control how the Text of each
ListItem will be extracted and shown from the data source, with a bit more of effort
we can handle the new functionality. I have come up with a very intuitive solution:
</p>
        <ul>
          <li>
DataTextField allows one or more properties (that can be nested if needed) separated
by commas. 
</li>
          <li>
DataTextFormatString can be used to control the formatting of the items, using {0},
{1}, {2}, {3}… as the value of the properties specified with DataTextField.</li>
        </ul>
        <p>
The code that performs the data binding is:
</p>
        <div class="csharp" style="BORDER-RIGHT: #d0d0d0 1px solid; BORDER-TOP: #d0d0d0 1px solid; BORDER-LEFT: #d0d0d0 1px solid; COLOR: #006; BORDER-BOTTOM: #d0d0d0 1px solid; FONT-FAMILY: monospace; BACKGROUND-COLOR: #f0f0f0">
          <span style="COLOR: #008080; FONT-STYLE: italic">///
&lt;summary&gt;Binds the data to the control.&lt;/summary&gt;</span>
          <br />
          <span style="COLOR: #008080; FONT-STYLE: italic">/// &lt;param name="ctrl"&gt;control
to bind.&lt;/param&gt;</span>
          <br />
          <span style="COLOR: #008080; FONT-STYLE: italic">/// &lt;param name="dataSource"&gt;data
to bind to the control.&lt;/param&gt;</span>
          <br />
          <span style="COLOR: #0600ff">public</span>
          <span style="COLOR: #0600ff">static</span>
          <span style="COLOR: #0600ff">void</span> PerformDataBinding<span style="COLOR: #000000">(</span>ListControl
ctrl, IEnumerable dataSource<span style="COLOR: #000000">)</span><br /><span style="COLOR: #000000">{</span><br />
    <span style="COLOR: #008080; FONT-STYLE: italic">// resets the selected
item</span><br />
    ctrl.<span style="COLOR: #0000ff">SelectedIndex</span><span style="COLOR: #008000">=</span><span style="COLOR: #008000">-</span><span style="COLOR: #ff0000">1</span><span style="COLOR: #008000">;</span><br />
    ctrl.<span style="COLOR: #0000ff">SelectedValue</span><span style="COLOR: #008000">=</span> null<span style="COLOR: #008000">;</span><br /><br />
    <span style="COLOR: #0600ff">if</span><span style="COLOR: #000000">(</span>dataSource <span style="COLOR: #008000">!=</span><span style="COLOR: #0600ff">null</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">{</span><br />
        <span style="COLOR: #ff0000">bool</span> fieldInfoSet <span style="COLOR: #008000">=</span> false<span style="COLOR: #008000">;</span><br />
        <span style="COLOR: #ff0000">bool</span> dataTextFormatStringSet <span style="COLOR: #008000">=</span> false<span style="COLOR: #008000">;</span><br /><br />
        <span style="COLOR: #008080; FONT-STYLE: italic">// checks
if we have to clear the existing items</span><br />
        <span style="COLOR: #0600ff">if</span><span style="COLOR: #000000">(</span><span style="COLOR: #008000">!</span>ctrl.<span style="COLOR: #0000ff">AppendDataBoundItems</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">{</span><br />
            ctrl.<span style="COLOR: #0000ff">Items</span>.<span style="COLOR: #0000ff">Clear</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span><span style="COLOR: #008000">;</span><br />
        <span style="COLOR: #000000">}</span><br /><br />
        <span style="COLOR: #008080; FONT-STYLE: italic">// if
the data source is a collection, sets the capacity</span><br />
        ICollection soureceCollection <span style="COLOR: #008000">=</span> dataSource <span style="COLOR: #0600ff">as</span> ICollection<span style="COLOR: #008000">;</span><br />
        <span style="COLOR: #0600ff">if</span><span style="COLOR: #000000">(</span>soureceCollection <span style="COLOR: #008000">!=</span><span style="COLOR: #0600ff">null</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">{</span><br />
            ctrl.<span style="COLOR: #0000ff">Items</span>.<span style="COLOR: #0000ff">Capacity</span><span style="COLOR: #008000">=</span> soureceCollection.<span style="COLOR: #0000ff">Count</span><span style="COLOR: #008000">+</span> ctrl.<span style="COLOR: #0000ff">Items</span>.<span style="COLOR: #0000ff">Count</span><span style="COLOR: #008000">;</span><br />
        <span style="COLOR: #000000">}</span><br /><br />
        <span style="COLOR: #008080; FONT-STYLE: italic">// save
if the data text field of data value field has been set</span><br />
        <span style="COLOR: #0600ff">if</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">(</span>ctrl.<span style="COLOR: #0000ff">DataTextField</span>.<span style="COLOR: #0000ff">Length</span><span style="COLOR: #008000">!=</span><span style="COLOR: #ff0000">0</span><span style="COLOR: #000000">)</span><span style="COLOR: #008000">||</span><span style="COLOR: #000000">(</span>ctrl.<span style="COLOR: #0000ff">DataValueField</span>.<span style="COLOR: #0000ff">Length</span><span style="COLOR: #008000">!=</span><span style="COLOR: #ff0000">0</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">{</span><br />
            fieldInfoSet <span style="COLOR: #008000">=</span> true<span style="COLOR: #008000">;</span><br />
        <span style="COLOR: #000000">}</span><br /><br />
        <span style="COLOR: #008080; FONT-STYLE: italic">// save
if the data text format string has been set</span><br />
        <span style="COLOR: #0600ff">if</span><span style="COLOR: #000000">(</span>ctrl.<span style="COLOR: #0000ff">DataTextFormatString</span>.<span style="COLOR: #0000ff">Length</span><span style="COLOR: #008000">!=</span><span style="COLOR: #ff0000">0</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">{</span><br />
            dataTextFormatStringSet <span style="COLOR: #008000">=</span> true<span style="COLOR: #008000">;</span><br />
        <span style="COLOR: #000000">}</span><br /><br />
        <span style="COLOR: #008080; FONT-STYLE: italic">// iterates
through the data source creating the ListItems</span><br />
        <span style="COLOR: #0600ff">foreach</span><span style="COLOR: #000000">(</span><span style="COLOR: #ff0000">object</span> obj <span style="COLOR: #0600ff">in</span> dataSource<span style="COLOR: #000000">)</span><span style="COLOR: #000000">{</span><br />
            ListItem item <span style="COLOR: #008000">=</span><a style="COLOR: #000060" href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="COLOR: #008000">new</span></a> ListItem<span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span><span style="COLOR: #008000">;</span><br /><br />
            <span style="COLOR: #0600ff">if</span><span style="COLOR: #000000">(</span>fieldInfoSet<span style="COLOR: #000000">)</span><span style="COLOR: #000000">{</span><br />
                <span style="COLOR: #0600ff">if</span><span style="COLOR: #000000">(</span>ctrl.<span style="COLOR: #0000ff">DataTextField</span>.<span style="COLOR: #0000ff">Length</span><span style="COLOR: #008000">&gt;</span><span style="COLOR: #ff0000">0</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">{</span><br />
                    <span style="COLOR: #0600ff">if</span><span style="COLOR: #000000">(</span>ctrl.<span style="COLOR: #0000ff">DataTextField</span>.<span style="COLOR: #0000ff">IndexOf</span><span style="COLOR: #000000">(</span><span style="COLOR: #666666">','</span><span style="COLOR: #000000">)</span><span style="COLOR: #008000">==</span><span style="COLOR: #008000">-</span><span style="COLOR: #ff0000">1</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">{</span><br />
                       
item.<span style="COLOR: #0000ff">Text</span><span style="COLOR: #008000">=</span> DataBinder.<span style="COLOR: #0000ff">Eval</span><span style="COLOR: #000000">(</span>obj,
ctrl.<span style="COLOR: #0000ff">DataTextField</span>, ctrl.<span style="COLOR: #0000ff">DataTextFormatString</span><span style="COLOR: #000000">)</span><span style="COLOR: #008000">;</span><br />
                    <span style="COLOR: #000000">}</span><span style="COLOR: #0600ff">else</span><span style="COLOR: #000000">{</span><br />
                        <span style="COLOR: #008080; FONT-STYLE: italic">//
if the DataTextField property has a list of fields, get them to create the text of
the item</span><br />
                        <span style="COLOR: #ff0000">string</span><span style="COLOR: #000000">[</span><span style="COLOR: #000000">]</span> fields <span style="COLOR: #008000">=</span> ctrl.<span style="COLOR: #0000ff">DataTextField</span>.<span style="COLOR: #0000ff">Split</span><span style="COLOR: #000000">(</span><a style="COLOR: #000060" href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="COLOR: #008000">new</span></a><span style="COLOR: #ff0000">string</span><span style="COLOR: #000000">[</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">{</span><span style="COLOR: #666666">","</span><span style="COLOR: #000000">}</span>,
StringSplitOptions.<span style="COLOR: #0000ff">RemoveEmptyEntries</span><span style="COLOR: #000000">)</span><span style="COLOR: #008000">;</span><br />
                        <span style="COLOR: #ff0000">object</span><span style="COLOR: #000000">[</span><span style="COLOR: #000000">]</span> values <span style="COLOR: #008000">=</span><a style="COLOR: #000060" href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="COLOR: #008000">new</span></a><span style="COLOR: #ff0000">object</span><span style="COLOR: #000000">[</span>fields.<span style="COLOR: #0000ff">Length</span><span style="COLOR: #000000">]</span><span style="COLOR: #008000">;</span><br /><br />
                        <span style="COLOR: #0600ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #ff0000">int</span> i <span style="COLOR: #008000">=</span><span style="COLOR: #ff0000">0</span><span style="COLOR: #008000">;</span> i <span style="COLOR: #008000">&lt;</span> fields.<span style="COLOR: #0000ff">Length</span><span style="COLOR: #008000">;</span> i<span style="COLOR: #008000">++</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">{</span><br />
                       
    <span style="COLOR: #ff0000">string</span> field <span style="COLOR: #008000">=</span> fields<span style="COLOR: #000000">[</span>i<span style="COLOR: #000000">]</span><span style="COLOR: #008000">;</span><br />
                       
    values<span style="COLOR: #000000">[</span>i<span style="COLOR: #000000">]</span><span style="COLOR: #008000">=</span> DataBinder.<span style="COLOR: #0000ff">Eval</span><span style="COLOR: #000000">(</span>obj,
field<span style="COLOR: #000000">)</span><span style="COLOR: #008000">;</span><br />
                        <span style="COLOR: #000000">}</span><br /><br />
                       
item.<span style="COLOR: #0000ff">Text</span><span style="COLOR: #008000">=</span><span style="COLOR: #ff0000">String</span>.<span style="COLOR: #0000ff">Format</span><span style="COLOR: #000000">(</span>ctrl.<span style="COLOR: #0000ff">DataTextFormatString</span>,
values<span style="COLOR: #000000">)</span><span style="COLOR: #008000">;</span><br />
                    <span style="COLOR: #000000">}</span><br />
                <span style="COLOR: #000000">}</span><br />
                <span style="COLOR: #0600ff">if</span><span style="COLOR: #000000">(</span>ctrl.<span style="COLOR: #0000ff">DataValueField</span>.<span style="COLOR: #0000ff">Length</span><span style="COLOR: #008000">&gt;</span><span style="COLOR: #ff0000">0</span><span style="COLOR: #000000">)</span><span style="COLOR: #000000">{</span><br />
                    item.<span style="COLOR: #0000ff">Value</span><span style="COLOR: #008000">=</span> DataBinder.<span style="COLOR: #0000ff">Eval</span><span style="COLOR: #000000">(</span>obj,
ctrl.<span style="COLOR: #0000ff">DataValueField</span>, <span style="COLOR: #0600ff">null</span><span style="COLOR: #000000">)</span><span style="COLOR: #008000">;</span><br />
                <span style="COLOR: #000000">}</span><br />
            <span style="COLOR: #000000">}</span><span style="COLOR: #0600ff">else</span><span style="COLOR: #000000">{</span><br />
                <span style="COLOR: #0600ff">if</span><span style="COLOR: #000000">(</span>dataTextFormatStringSet<span style="COLOR: #000000">)</span><span style="COLOR: #000000">{</span><br />
                    item.<span style="COLOR: #0000ff">Text</span><span style="COLOR: #008000">=</span><span style="COLOR: #ff0000">string</span>.<span style="COLOR: #0000ff">Format</span><span style="COLOR: #000000">(</span>CultureInfo.<span style="COLOR: #0000ff">CurrentCulture</span>,
ctrl.<span style="COLOR: #0000ff">DataTextFormatString</span>, <a style="COLOR: #000060" href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="COLOR: #008000">new</span></a><span style="COLOR: #ff0000">object</span><span style="COLOR: #000000">[</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">{</span> obj <span style="COLOR: #000000">}</span><span style="COLOR: #000000">)</span><span style="COLOR: #008000">;</span><br />
                <span style="COLOR: #000000">}</span><span style="COLOR: #0600ff">else</span><span style="COLOR: #000000">{</span><br />
                    item.<span style="COLOR: #0000ff">Text</span><span style="COLOR: #008000">=</span> obj.<span style="COLOR: #0000ff">ToString</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span><span style="COLOR: #008000">;</span><br />
                <span style="COLOR: #000000">}</span><br />
                item.<span style="COLOR: #0000ff">Value</span><span style="COLOR: #008000">=</span> obj.<span style="COLOR: #0000ff">ToString</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">)</span><span style="COLOR: #008000">;</span><br />
            <span style="COLOR: #000000">}</span><br />
            
<br />
            ctrl.<span style="COLOR: #0000ff">Items</span>.<span style="COLOR: #0000ff">Add</span><span style="COLOR: #000000">(</span>item<span style="COLOR: #000000">)</span><span style="COLOR: #008000">;</span><br />
        <span style="COLOR: #000000">}</span><br />
    <span style="COLOR: #000000">}</span><br /><span style="COLOR: #000000">}</span></div>
        <p>
 
</p>
        <p>
As we need to call this data binding code instead of the one from ListControl I needed
to subclass all controls that inherit from ListControl in order to fix them. So now
I have BulletedListEx, CheckBoxListEx, DropDownListEx, ListBoxEx and RadioButtonListEx.
</p>
        <p>
I have created a simple example showing how to use them. Imagine that an Item can
be supplied by a set of suppliers, and each supplier sells the item with a different
price. The following image shows the properties of the 3 entities of the sample:
</p>
        <p>
          <img src="http://www.manuelabadia.com/blog/content/binary/listcontrolex_sample.png" border="0" />
        </p>
        <p>
I have created a web page with a DropDownList with some items, and when you select
an item in the DropDownList you will see a ListBox with the all suppliers of that
item with the associated price for the item. Notice how I show the Id and the Name
in the DropDownList and how I show the price, supplier Id and supplier name in the
ListBox:
</p>
        <p>
          <img src="http://www.manuelabadia.com/blog/content/binary/listcontrolex_sample2.png" border="0" />
        </p>
        <p>
The ASPX of the page follows:
</p>
        <div class="xml" style="BORDER-RIGHT: #d0d0d0 1px solid; BORDER-TOP: #d0d0d0 1px solid; BORDER-LEFT: #d0d0d0 1px solid; COLOR: #006; BORDER-BOTTOM: #d0d0d0 1px solid; FONT-FAMILY: monospace; BACKGROUND-COLOR: #f0f0f0">
          <span style="COLOR: #009900">
            <span style="FONT-WEIGHT: bold; COLOR: #000000">&lt;body<span style="FONT-WEIGHT: bold; COLOR: #000000">&gt;</span></span>
          </span>
          <br />
    <span style="COLOR: #009900"><span style="FONT-WEIGHT: bold; COLOR: #000000">&lt;form</span><span style="COLOR: #000066">id</span>=<span style="COLOR: #ff0000">"form1"</span><span style="COLOR: #000066">runat</span>=<span style="COLOR: #ff0000">"server"</span><span style="FONT-WEIGHT: bold; COLOR: #000000">&gt;</span></span><br />
    <span style="COLOR: #009900"><span style="FONT-WEIGHT: bold; COLOR: #000000">&lt;div<span style="FONT-WEIGHT: bold; COLOR: #000000">&gt;</span></span></span><br />
    <span style="COLOR: #009900"><span style="FONT-WEIGHT: bold; COLOR: #000000">&lt;/div<span style="FONT-WEIGHT: bold; COLOR: #000000">&gt;</span></span></span><br />
        Choose an item to see the suppliers:<span style="COLOR: #009900"><span style="FONT-WEIGHT: bold; COLOR: #000000">&lt;br</span><span style="FONT-WEIGHT: bold; COLOR: #000000">/&gt;</span></span><br />
        Items:<span style="COLOR: #009900"><span style="FONT-WEIGHT: bold; COLOR: #000000">&lt;br</span><span style="FONT-WEIGHT: bold; COLOR: #000000">/&gt;</span></span><br />
        <span style="COLOR: #009900"><span style="FONT-WEIGHT: bold; COLOR: #000000">&lt;manu:DropDownListEx</span><span style="COLOR: #000066">ID</span>=<span style="COLOR: #ff0000">"DropDownListEx1"</span><span style="COLOR: #000066">runat</span>=<span style="COLOR: #ff0000">"server"</span><span style="COLOR: #000066">AutoPostBack</span>=<span style="COLOR: #ff0000">"True"</span><span style="COLOR: #000066">Width</span>=<span style="COLOR: #ff0000">"300px"</span></span><br /><span style="COLOR: #009900">            <span style="COLOR: #000066">DataTextField</span>=<span style="COLOR: #ff0000">"Id,
Name"</span></span><br /><span style="COLOR: #009900">            <span style="COLOR: #000066">DataTextFormatString</span>=<span style="COLOR: #ff0000">"[{0}]
- {1}"</span></span><br /><span style="COLOR: #009900">            <span style="COLOR: #000066">DataValueField</span>=<span style="COLOR: #ff0000">"Id"</span></span><br /><span style="COLOR: #009900">            <span style="COLOR: #000066">OnSelectedIndexChanged</span>=<span style="COLOR: #ff0000">"DropDownListEx1_SelectedIndexChanged"</span><span style="COLOR: #000066">AppendDataBoundItems</span>=<span style="COLOR: #ff0000">"True"</span><span style="FONT-WEIGHT: bold; COLOR: #000000">&gt;</span></span><br />
            <span style="COLOR: #009900"><span style="FONT-WEIGHT: bold; COLOR: #000000">&lt;asp:ListItem</span><span style="COLOR: #000066">Selected</span>=<span style="COLOR: #ff0000">"True"</span><span style="COLOR: #000066">Value</span>=<span style="COLOR: #ff0000">"0"</span><span style="FONT-WEIGHT: bold; COLOR: #000000">&gt;</span></span>Select
an Item<span style="COLOR: #009900"><span style="FONT-WEIGHT: bold; COLOR: #000000">&lt;/asp:ListItem<span style="FONT-WEIGHT: bold; COLOR: #000000">&gt;</span></span></span><br />
        <span style="COLOR: #009900"><span style="FONT-WEIGHT: bold; COLOR: #000000">&lt;/manu:DropDownListEx<span style="FONT-WEIGHT: bold; COLOR: #000000">&gt;</span></span><span style="FONT-WEIGHT: bold; COLOR: #000000">&lt;br</span><span style="FONT-WEIGHT: bold; COLOR: #000000">/&gt;</span></span><br />
        
<br />
        Price and suppliers:<span style="COLOR: #009900"><span style="FONT-WEIGHT: bold; COLOR: #000000">&lt;br</span><span style="FONT-WEIGHT: bold; COLOR: #000000">/&gt;</span></span><br />
        
<br />
        <span style="COLOR: #009900"><span style="FONT-WEIGHT: bold; COLOR: #000000">&lt;manu:ListBoxEx</span><span style="COLOR: #000066">ID</span>=<span style="COLOR: #ff0000">"ListBoxEx1"</span><span style="COLOR: #000066">runat</span>=<span style="COLOR: #ff0000">"server"</span><span style="COLOR: #000066">Width</span>=<span style="COLOR: #ff0000">"300px"</span></span><br /><span style="COLOR: #009900">            <span style="COLOR: #000066">DataTextField</span>=<span style="COLOR: #ff0000">"Price,
Supplier.Id, Supplier.Name"</span></span><br /><span style="COLOR: #009900">            <span style="COLOR: #000066">DataTextFormatString</span>=<span style="COLOR: #ff0000">"{0}
- [{1}] {2}"</span></span><br /><span style="COLOR: #009900">            <span style="COLOR: #000066">DataValueField</span>=<span style="COLOR: #ff0000">"Supplier.Id"</span><span style="FONT-WEIGHT: bold; COLOR: #000000">&gt;</span></span><br />
        <span style="COLOR: #009900"><span style="FONT-WEIGHT: bold; COLOR: #000000">&lt;/manu:ListBoxEx<span style="FONT-WEIGHT: bold; COLOR: #000000">&gt;</span></span></span><br />
    <span style="COLOR: #009900"><span style="FONT-WEIGHT: bold; COLOR: #000000">&lt;/form<span style="FONT-WEIGHT: bold; COLOR: #000000">&gt;</span></span></span><br /><span style="COLOR: #009900"><span style="FONT-WEIGHT: bold; COLOR: #000000">&lt;/body<span style="FONT-WEIGHT: bold; COLOR: #000000">&gt;</span></span></span></div>
        <p>
 
</p>
        <p>
As you can see, the solution is really clean and elegant, and backward compatible
with the current controls that inherit from ListControl.
</p>
        <p>
That’s all for now,<br />
Merry christmas!
</p>
        <p>
          <a href="http://www.manuelabadia.com/blog/content/binary/ListControlsEx_bin.zip">ListControlsEx_bin.zip
(6.53 KB)</a>
        </p>
        <a href="http://www.manuelabadia.com/blog/content/binary/ListControlsEx_sample.zip">ListControlsEx_sample.zip
(33.75 KB)</a>
        <img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=0606d95f-56ae-4dd7-8458-69cd550fa356" />
      </body>
      <title>Binding a DropDownList to multiple properties and to nested properties</title>
      <guid isPermaLink="false">http://www.manuelabadia.com/blog/PermaLink,guid,0606d95f-56ae-4dd7-8458-69cd550fa356.aspx</guid>
      <link>http://www.manuelabadia.com/blog/PermaLink,guid,0606d95f-56ae-4dd7-8458-69cd550fa356.aspx</link>
      <pubDate>Mon, 22 Dec 2008 23:35:20 GMT</pubDate>
      <description>&lt;p&gt;
All controls that inherit from ListControl (BulletedList, CheckBoxList, DropDownList,
ListBox and RadioButtonList) have some annoying behavior in common: 
&lt;/p&gt;
&lt;p&gt;
You can only bind the control to a single property using the DataTextField property.
For example, if you have a Customer class with properties Id, Name, Surname, etc and
you want to show the full name of a customer in any of the ListControls, you have
several options:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
When you get the data from the database, return another column with the name and surname. 
&lt;li&gt;
Create a property (f.e. FullName) that returns what you want to show. 
&lt;li&gt;
Use a DataSet and add a computed column. 
&lt;li&gt;
Manually add ListItems with the appropriate values performing the data bind manually. 
&lt;li&gt;
Create a simple class that will be bound (instead of the original one) just to fix
the problem.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
The truth is that I don’t like any of those options, all of them are hacks. 
&lt;/p&gt;
&lt;p&gt;
For nested properties you have the similar problems. You can bind to Id or Name, but
you can’t bind to Address.City or Address.Zip.
&lt;/p&gt;
&lt;p&gt;
Today I faced this problem again and I decided to investigate a more innovative solution.
The problem itself is in the controls that inherit from ListControl that are very
strict in the binding options. So I took a look of how the controls perform the binding
to see if I could do anything to overcome those limitations. At first sight I thought
I was loosing my time but after a deeper study I found that it was amazingly easy
to fix those problems in a very sleek way.
&lt;/p&gt;
&lt;p&gt;
The data binding of the controls is performed in the PerformDataBinding method. The
code at ListControl.PerformDataBinding uses DataBinder.GetPropertyValue to retrieve
the value to show in the control if you set the DataTextField property. However, DataBinder.GetPropertyValue
doesn’t handle nested properties. DataBinder.Eval is a better choice because it does
handle nested properties. So using it we solve one problem. The other problem can
be solved easily as well. As we have two properties that control how the Text of each
ListItem will be extracted and shown from the data source, with a bit more of effort
we can handle the new functionality. I have come up with a very intuitive solution:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
DataTextField allows one or more properties (that can be nested if needed) separated
by commas. 
&lt;li&gt;
DataTextFormatString can be used to control the formatting of the items, using {0},
{1}, {2}, {3}… as the value of the properties specified with DataTextField.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
The code that performs the data binding is:
&lt;/p&gt;
&lt;div class=csharp style="BORDER-RIGHT: #d0d0d0 1px solid; BORDER-TOP: #d0d0d0 1px solid; BORDER-LEFT: #d0d0d0 1px solid; COLOR: #006; BORDER-BOTTOM: #d0d0d0 1px solid; FONT-FAMILY: monospace; BACKGROUND-COLOR: #f0f0f0"&gt;&lt;span style="COLOR: #008080; FONT-STYLE: italic"&gt;///
&amp;lt;summary&amp;gt;Binds the data to the control.&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="COLOR: #008080; FONT-STYLE: italic"&gt;/// &amp;lt;param name="ctrl"&amp;gt;control
to bind.&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="COLOR: #008080; FONT-STYLE: italic"&gt;/// &amp;lt;param name="dataSource"&amp;gt;data
to bind to the control.&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="COLOR: #0600ff"&gt;public&lt;/span&gt; &lt;span style="COLOR: #0600ff"&gt;static&lt;/span&gt; &lt;span style="COLOR: #0600ff"&gt;void&lt;/span&gt; PerformDataBinding&lt;span style="COLOR: #000000"&gt;(&lt;/span&gt;ListControl
ctrl, IEnumerable dataSource&lt;span style="COLOR: #000000"&gt;)&lt;/span&gt;
&lt;br&gt;
&lt;span style="COLOR: #000000"&gt;{&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #008080; FONT-STYLE: italic"&gt;// resets the selected
item&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; ctrl.&lt;span style="COLOR: #0000ff"&gt;SelectedIndex&lt;/span&gt; &lt;span style="COLOR: #008000"&gt;=&lt;/span&gt; &lt;span style="COLOR: #008000"&gt;-&lt;/span&gt;&lt;span style="COLOR: #ff0000"&gt;1&lt;/span&gt;&lt;span style="COLOR: #008000"&gt;;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; ctrl.&lt;span style="COLOR: #0000ff"&gt;SelectedValue&lt;/span&gt; &lt;span style="COLOR: #008000"&gt;=&lt;/span&gt; null&lt;span style="COLOR: #008000"&gt;;&lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #0600ff"&gt;if&lt;/span&gt; &lt;span style="COLOR: #000000"&gt;(&lt;/span&gt;dataSource &lt;span style="COLOR: #008000"&gt;!=&lt;/span&gt; &lt;span style="COLOR: #0600ff"&gt;null&lt;/span&gt;&lt;span style="COLOR: #000000"&gt;)&lt;/span&gt; &lt;span style="COLOR: #000000"&gt;{&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #ff0000"&gt;bool&lt;/span&gt; fieldInfoSet &lt;span style="COLOR: #008000"&gt;=&lt;/span&gt; false&lt;span style="COLOR: #008000"&gt;;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #ff0000"&gt;bool&lt;/span&gt; dataTextFormatStringSet &lt;span style="COLOR: #008000"&gt;=&lt;/span&gt; false&lt;span style="COLOR: #008000"&gt;;&lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #008080; FONT-STYLE: italic"&gt;// checks
if we have to clear the existing items&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #0600ff"&gt;if&lt;/span&gt; &lt;span style="COLOR: #000000"&gt;(&lt;/span&gt;&lt;span style="COLOR: #008000"&gt;!&lt;/span&gt;ctrl.&lt;span style="COLOR: #0000ff"&gt;AppendDataBoundItems&lt;/span&gt;&lt;span style="COLOR: #000000"&gt;)&lt;/span&gt; &lt;span style="COLOR: #000000"&gt;{&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ctrl.&lt;span style="COLOR: #0000ff"&gt;Items&lt;/span&gt;.&lt;span style="COLOR: #0000ff"&gt;Clear&lt;/span&gt;&lt;span style="COLOR: #000000"&gt;(&lt;/span&gt;&lt;span style="COLOR: #000000"&gt;)&lt;/span&gt;&lt;span style="COLOR: #008000"&gt;;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #000000"&gt;}&lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #008080; FONT-STYLE: italic"&gt;// if
the data source is a collection, sets the capacity&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ICollection soureceCollection &lt;span style="COLOR: #008000"&gt;=&lt;/span&gt; dataSource &lt;span style="COLOR: #0600ff"&gt;as&lt;/span&gt; ICollection&lt;span style="COLOR: #008000"&gt;;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #0600ff"&gt;if&lt;/span&gt; &lt;span style="COLOR: #000000"&gt;(&lt;/span&gt;soureceCollection &lt;span style="COLOR: #008000"&gt;!=&lt;/span&gt; &lt;span style="COLOR: #0600ff"&gt;null&lt;/span&gt;&lt;span style="COLOR: #000000"&gt;)&lt;/span&gt; &lt;span style="COLOR: #000000"&gt;{&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ctrl.&lt;span style="COLOR: #0000ff"&gt;Items&lt;/span&gt;.&lt;span style="COLOR: #0000ff"&gt;Capacity&lt;/span&gt; &lt;span style="COLOR: #008000"&gt;=&lt;/span&gt; soureceCollection.&lt;span style="COLOR: #0000ff"&gt;Count&lt;/span&gt; &lt;span style="COLOR: #008000"&gt;+&lt;/span&gt; ctrl.&lt;span style="COLOR: #0000ff"&gt;Items&lt;/span&gt;.&lt;span style="COLOR: #0000ff"&gt;Count&lt;/span&gt;&lt;span style="COLOR: #008000"&gt;;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #000000"&gt;}&lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #008080; FONT-STYLE: italic"&gt;// save
if the data text field of data value field has been set&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #0600ff"&gt;if&lt;/span&gt; &lt;span style="COLOR: #000000"&gt;(&lt;/span&gt;&lt;span style="COLOR: #000000"&gt;(&lt;/span&gt;ctrl.&lt;span style="COLOR: #0000ff"&gt;DataTextField&lt;/span&gt;.&lt;span style="COLOR: #0000ff"&gt;Length&lt;/span&gt; &lt;span style="COLOR: #008000"&gt;!=&lt;/span&gt; &lt;span style="COLOR: #ff0000"&gt;0&lt;/span&gt;&lt;span style="COLOR: #000000"&gt;)&lt;/span&gt; &lt;span style="COLOR: #008000"&gt;||&lt;/span&gt; &lt;span style="COLOR: #000000"&gt;(&lt;/span&gt;ctrl.&lt;span style="COLOR: #0000ff"&gt;DataValueField&lt;/span&gt;.&lt;span style="COLOR: #0000ff"&gt;Length&lt;/span&gt; &lt;span style="COLOR: #008000"&gt;!=&lt;/span&gt; &lt;span style="COLOR: #ff0000"&gt;0&lt;/span&gt;&lt;span style="COLOR: #000000"&gt;)&lt;/span&gt;&lt;span style="COLOR: #000000"&gt;)&lt;/span&gt; &lt;span style="COLOR: #000000"&gt;{&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; fieldInfoSet &lt;span style="COLOR: #008000"&gt;=&lt;/span&gt; true&lt;span style="COLOR: #008000"&gt;;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #000000"&gt;}&lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #008080; FONT-STYLE: italic"&gt;// save
if the data text format string has been set&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #0600ff"&gt;if&lt;/span&gt; &lt;span style="COLOR: #000000"&gt;(&lt;/span&gt;ctrl.&lt;span style="COLOR: #0000ff"&gt;DataTextFormatString&lt;/span&gt;.&lt;span style="COLOR: #0000ff"&gt;Length&lt;/span&gt; &lt;span style="COLOR: #008000"&gt;!=&lt;/span&gt; &lt;span style="COLOR: #ff0000"&gt;0&lt;/span&gt;&lt;span style="COLOR: #000000"&gt;)&lt;/span&gt; &lt;span style="COLOR: #000000"&gt;{&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dataTextFormatStringSet &lt;span style="COLOR: #008000"&gt;=&lt;/span&gt; true&lt;span style="COLOR: #008000"&gt;;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #000000"&gt;}&lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #008080; FONT-STYLE: italic"&gt;// iterates
through the data source creating the ListItems&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #0600ff"&gt;foreach&lt;/span&gt; &lt;span style="COLOR: #000000"&gt;(&lt;/span&gt;&lt;span style="COLOR: #ff0000"&gt;object&lt;/span&gt; obj &lt;span style="COLOR: #0600ff"&gt;in&lt;/span&gt; dataSource&lt;span style="COLOR: #000000"&gt;)&lt;/span&gt; &lt;span style="COLOR: #000000"&gt;{&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ListItem item &lt;span style="COLOR: #008000"&gt;=&lt;/span&gt; &lt;a style="COLOR: #000060" href="http://www.google.com/search?q=new+msdn.microsoft.com"&gt;&lt;span style="COLOR: #008000"&gt;new&lt;/span&gt;&lt;/a&gt; ListItem&lt;span style="COLOR: #000000"&gt;(&lt;/span&gt;&lt;span style="COLOR: #000000"&gt;)&lt;/span&gt;&lt;span style="COLOR: #008000"&gt;;&lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #0600ff"&gt;if&lt;/span&gt; &lt;span style="COLOR: #000000"&gt;(&lt;/span&gt;fieldInfoSet&lt;span style="COLOR: #000000"&gt;)&lt;/span&gt; &lt;span style="COLOR: #000000"&gt;{&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #0600ff"&gt;if&lt;/span&gt; &lt;span style="COLOR: #000000"&gt;(&lt;/span&gt;ctrl.&lt;span style="COLOR: #0000ff"&gt;DataTextField&lt;/span&gt;.&lt;span style="COLOR: #0000ff"&gt;Length&lt;/span&gt; &lt;span style="COLOR: #008000"&gt;&amp;gt;&lt;/span&gt; &lt;span style="COLOR: #ff0000"&gt;0&lt;/span&gt;&lt;span style="COLOR: #000000"&gt;)&lt;/span&gt; &lt;span style="COLOR: #000000"&gt;{&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #0600ff"&gt;if&lt;/span&gt; &lt;span style="COLOR: #000000"&gt;(&lt;/span&gt;ctrl.&lt;span style="COLOR: #0000ff"&gt;DataTextField&lt;/span&gt;.&lt;span style="COLOR: #0000ff"&gt;IndexOf&lt;/span&gt;&lt;span style="COLOR: #000000"&gt;(&lt;/span&gt;&lt;span style="COLOR: #666666"&gt;','&lt;/span&gt;&lt;span style="COLOR: #000000"&gt;)&lt;/span&gt; &lt;span style="COLOR: #008000"&gt;==&lt;/span&gt; &lt;span style="COLOR: #008000"&gt;-&lt;/span&gt;&lt;span style="COLOR: #ff0000"&gt;1&lt;/span&gt;&lt;span style="COLOR: #000000"&gt;)&lt;/span&gt; &lt;span style="COLOR: #000000"&gt;{&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;
item.&lt;span style="COLOR: #0000ff"&gt;Text&lt;/span&gt; &lt;span style="COLOR: #008000"&gt;=&lt;/span&gt; DataBinder.&lt;span style="COLOR: #0000ff"&gt;Eval&lt;/span&gt;&lt;span style="COLOR: #000000"&gt;(&lt;/span&gt;obj,
ctrl.&lt;span style="COLOR: #0000ff"&gt;DataTextField&lt;/span&gt;, ctrl.&lt;span style="COLOR: #0000ff"&gt;DataTextFormatString&lt;/span&gt;&lt;span style="COLOR: #000000"&gt;)&lt;/span&gt;&lt;span style="COLOR: #008000"&gt;;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #000000"&gt;}&lt;/span&gt; &lt;span style="COLOR: #0600ff"&gt;else&lt;/span&gt; &lt;span style="COLOR: #000000"&gt;{&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #008080; FONT-STYLE: italic"&gt;//
if the DataTextField property has a list of fields, get them to create the text of
the item&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #ff0000"&gt;string&lt;/span&gt;&lt;span style="COLOR: #000000"&gt;[&lt;/span&gt;&lt;span style="COLOR: #000000"&gt;]&lt;/span&gt; fields &lt;span style="COLOR: #008000"&gt;=&lt;/span&gt; ctrl.&lt;span style="COLOR: #0000ff"&gt;DataTextField&lt;/span&gt;.&lt;span style="COLOR: #0000ff"&gt;Split&lt;/span&gt;&lt;span style="COLOR: #000000"&gt;(&lt;/span&gt;&lt;a style="COLOR: #000060" href="http://www.google.com/search?q=new+msdn.microsoft.com"&gt;&lt;span style="COLOR: #008000"&gt;new&lt;/span&gt;&lt;/a&gt; &lt;span style="COLOR: #ff0000"&gt;string&lt;/span&gt;&lt;span style="COLOR: #000000"&gt;[&lt;/span&gt;&lt;span style="COLOR: #000000"&gt;]&lt;/span&gt; &lt;span style="COLOR: #000000"&gt;{&lt;/span&gt; &lt;span style="COLOR: #666666"&gt;","&lt;/span&gt; &lt;span style="COLOR: #000000"&gt;}&lt;/span&gt;,
StringSplitOptions.&lt;span style="COLOR: #0000ff"&gt;RemoveEmptyEntries&lt;/span&gt;&lt;span style="COLOR: #000000"&gt;)&lt;/span&gt;&lt;span style="COLOR: #008000"&gt;;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #ff0000"&gt;object&lt;/span&gt;&lt;span style="COLOR: #000000"&gt;[&lt;/span&gt;&lt;span style="COLOR: #000000"&gt;]&lt;/span&gt; values &lt;span style="COLOR: #008000"&gt;=&lt;/span&gt; &lt;a style="COLOR: #000060" href="http://www.google.com/search?q=new+msdn.microsoft.com"&gt;&lt;span style="COLOR: #008000"&gt;new&lt;/span&gt;&lt;/a&gt; &lt;span style="COLOR: #ff0000"&gt;object&lt;/span&gt;&lt;span style="COLOR: #000000"&gt;[&lt;/span&gt;fields.&lt;span style="COLOR: #0000ff"&gt;Length&lt;/span&gt;&lt;span style="COLOR: #000000"&gt;]&lt;/span&gt;&lt;span style="COLOR: #008000"&gt;;&lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #0600ff"&gt;for&lt;/span&gt; &lt;span style="COLOR: #000000"&gt;(&lt;/span&gt;&lt;span style="COLOR: #ff0000"&gt;int&lt;/span&gt; i &lt;span style="COLOR: #008000"&gt;=&lt;/span&gt; &lt;span style="COLOR: #ff0000"&gt;0&lt;/span&gt;&lt;span style="COLOR: #008000"&gt;;&lt;/span&gt; i &lt;span style="COLOR: #008000"&gt;&amp;lt;&lt;/span&gt; fields.&lt;span style="COLOR: #0000ff"&gt;Length&lt;/span&gt;&lt;span style="COLOR: #008000"&gt;;&lt;/span&gt; i&lt;span style="COLOR: #008000"&gt;++&lt;/span&gt;&lt;span style="COLOR: #000000"&gt;)&lt;/span&gt; &lt;span style="COLOR: #000000"&gt;{&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;
&amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #ff0000"&gt;string&lt;/span&gt; field &lt;span style="COLOR: #008000"&gt;=&lt;/span&gt; fields&lt;span style="COLOR: #000000"&gt;[&lt;/span&gt;i&lt;span style="COLOR: #000000"&gt;]&lt;/span&gt;&lt;span style="COLOR: #008000"&gt;;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;
&amp;nbsp; &amp;nbsp; values&lt;span style="COLOR: #000000"&gt;[&lt;/span&gt;i&lt;span style="COLOR: #000000"&gt;]&lt;/span&gt; &lt;span style="COLOR: #008000"&gt;=&lt;/span&gt; DataBinder.&lt;span style="COLOR: #0000ff"&gt;Eval&lt;/span&gt;&lt;span style="COLOR: #000000"&gt;(&lt;/span&gt;obj,
field&lt;span style="COLOR: #000000"&gt;)&lt;/span&gt;&lt;span style="COLOR: #008000"&gt;;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #000000"&gt;}&lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;
item.&lt;span style="COLOR: #0000ff"&gt;Text&lt;/span&gt; &lt;span style="COLOR: #008000"&gt;=&lt;/span&gt; &lt;span style="COLOR: #ff0000"&gt;String&lt;/span&gt;.&lt;span style="COLOR: #0000ff"&gt;Format&lt;/span&gt;&lt;span style="COLOR: #000000"&gt;(&lt;/span&gt;ctrl.&lt;span style="COLOR: #0000ff"&gt;DataTextFormatString&lt;/span&gt;,
values&lt;span style="COLOR: #000000"&gt;)&lt;/span&gt;&lt;span style="COLOR: #008000"&gt;;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #000000"&gt;}&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #000000"&gt;}&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #0600ff"&gt;if&lt;/span&gt; &lt;span style="COLOR: #000000"&gt;(&lt;/span&gt;ctrl.&lt;span style="COLOR: #0000ff"&gt;DataValueField&lt;/span&gt;.&lt;span style="COLOR: #0000ff"&gt;Length&lt;/span&gt; &lt;span style="COLOR: #008000"&gt;&amp;gt;&lt;/span&gt; &lt;span style="COLOR: #ff0000"&gt;0&lt;/span&gt;&lt;span style="COLOR: #000000"&gt;)&lt;/span&gt; &lt;span style="COLOR: #000000"&gt;{&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; item.&lt;span style="COLOR: #0000ff"&gt;Value&lt;/span&gt; &lt;span style="COLOR: #008000"&gt;=&lt;/span&gt; DataBinder.&lt;span style="COLOR: #0000ff"&gt;Eval&lt;/span&gt;&lt;span style="COLOR: #000000"&gt;(&lt;/span&gt;obj,
ctrl.&lt;span style="COLOR: #0000ff"&gt;DataValueField&lt;/span&gt;, &lt;span style="COLOR: #0600ff"&gt;null&lt;/span&gt;&lt;span style="COLOR: #000000"&gt;)&lt;/span&gt;&lt;span style="COLOR: #008000"&gt;;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #000000"&gt;}&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #000000"&gt;}&lt;/span&gt; &lt;span style="COLOR: #0600ff"&gt;else&lt;/span&gt; &lt;span style="COLOR: #000000"&gt;{&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #0600ff"&gt;if&lt;/span&gt; &lt;span style="COLOR: #000000"&gt;(&lt;/span&gt;dataTextFormatStringSet&lt;span style="COLOR: #000000"&gt;)&lt;/span&gt; &lt;span style="COLOR: #000000"&gt;{&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; item.&lt;span style="COLOR: #0000ff"&gt;Text&lt;/span&gt; &lt;span style="COLOR: #008000"&gt;=&lt;/span&gt; &lt;span style="COLOR: #ff0000"&gt;string&lt;/span&gt;.&lt;span style="COLOR: #0000ff"&gt;Format&lt;/span&gt;&lt;span style="COLOR: #000000"&gt;(&lt;/span&gt;CultureInfo.&lt;span style="COLOR: #0000ff"&gt;CurrentCulture&lt;/span&gt;,
ctrl.&lt;span style="COLOR: #0000ff"&gt;DataTextFormatString&lt;/span&gt;, &lt;a style="COLOR: #000060" href="http://www.google.com/search?q=new+msdn.microsoft.com"&gt;&lt;span style="COLOR: #008000"&gt;new&lt;/span&gt;&lt;/a&gt; &lt;span style="COLOR: #ff0000"&gt;object&lt;/span&gt;&lt;span style="COLOR: #000000"&gt;[&lt;/span&gt;&lt;span style="COLOR: #000000"&gt;]&lt;/span&gt; &lt;span style="COLOR: #000000"&gt;{&lt;/span&gt; obj &lt;span style="COLOR: #000000"&gt;}&lt;/span&gt;&lt;span style="COLOR: #000000"&gt;)&lt;/span&gt;&lt;span style="COLOR: #008000"&gt;;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #000000"&gt;}&lt;/span&gt; &lt;span style="COLOR: #0600ff"&gt;else&lt;/span&gt; &lt;span style="COLOR: #000000"&gt;{&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; item.&lt;span style="COLOR: #0000ff"&gt;Text&lt;/span&gt; &lt;span style="COLOR: #008000"&gt;=&lt;/span&gt; obj.&lt;span style="COLOR: #0000ff"&gt;ToString&lt;/span&gt;&lt;span style="COLOR: #000000"&gt;(&lt;/span&gt;&lt;span style="COLOR: #000000"&gt;)&lt;/span&gt;&lt;span style="COLOR: #008000"&gt;;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #000000"&gt;}&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; item.&lt;span style="COLOR: #0000ff"&gt;Value&lt;/span&gt; &lt;span style="COLOR: #008000"&gt;=&lt;/span&gt; obj.&lt;span style="COLOR: #0000ff"&gt;ToString&lt;/span&gt;&lt;span style="COLOR: #000000"&gt;(&lt;/span&gt;&lt;span style="COLOR: #000000"&gt;)&lt;/span&gt;&lt;span style="COLOR: #008000"&gt;;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #000000"&gt;}&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ctrl.&lt;span style="COLOR: #0000ff"&gt;Items&lt;/span&gt;.&lt;span style="COLOR: #0000ff"&gt;Add&lt;/span&gt;&lt;span style="COLOR: #000000"&gt;(&lt;/span&gt;item&lt;span style="COLOR: #000000"&gt;)&lt;/span&gt;&lt;span style="COLOR: #008000"&gt;;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #000000"&gt;}&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #000000"&gt;}&lt;/span&gt;
&lt;br&gt;
&lt;span style="COLOR: #000000"&gt;}&lt;/span&gt;
&lt;/div&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
As we need to call this data binding code instead of the one from ListControl I needed
to subclass all controls that inherit from ListControl in order to fix them. So now
I have BulletedListEx, CheckBoxListEx, DropDownListEx, ListBoxEx and RadioButtonListEx.
&lt;/p&gt;
&lt;p&gt;
I have created a simple example showing how to use them. Imagine that an Item can
be supplied by a set of suppliers, and each supplier sells the item with a different
price. The following image shows the properties of the 3 entities of the sample:
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://www.manuelabadia.com/blog/content/binary/listcontrolex_sample.png" border=0&gt;
&lt;/p&gt;
&lt;p&gt;
I have created a web page with a DropDownList with some items, and when you select
an item in the DropDownList you will see a ListBox with the all suppliers of that
item with the associated price for the item. Notice how I show the Id and the Name
in the DropDownList and how I show the price, supplier Id and supplier name in the
ListBox:
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://www.manuelabadia.com/blog/content/binary/listcontrolex_sample2.png" border=0&gt;
&lt;/p&gt;
&lt;p&gt;
The ASPX of the page follows:
&lt;/p&gt;
&lt;div class=xml style="BORDER-RIGHT: #d0d0d0 1px solid; BORDER-TOP: #d0d0d0 1px solid; BORDER-LEFT: #d0d0d0 1px solid; COLOR: #006; BORDER-BOTTOM: #d0d0d0 1px solid; FONT-FAMILY: monospace; BACKGROUND-COLOR: #f0f0f0"&gt;&lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;body&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;form&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;id&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"form1"&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;runat&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"server"&lt;/span&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;div&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;/div&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Choose an item to see the suppliers:&lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;br&lt;/span&gt; &lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Items:&lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;br&lt;/span&gt; &lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;manu:DropDownListEx&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;ID&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"DropDownListEx1"&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;runat&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"server"&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;AutoPostBack&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"True"&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;Width&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"300px"&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="COLOR: #009900"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #000066"&gt;DataTextField&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"Id,
Name"&lt;/span&gt; &lt;/span&gt;
&lt;br&gt;
&lt;span style="COLOR: #009900"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #000066"&gt;DataTextFormatString&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"[{0}]
- {1}"&lt;/span&gt; &lt;/span&gt;
&lt;br&gt;
&lt;span style="COLOR: #009900"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #000066"&gt;DataValueField&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"Id"&lt;/span&gt; &lt;/span&gt;
&lt;br&gt;
&lt;span style="COLOR: #009900"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #000066"&gt;OnSelectedIndexChanged&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"DropDownListEx1_SelectedIndexChanged"&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;AppendDataBoundItems&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"True"&lt;/span&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;asp:ListItem&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;Selected&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"True"&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;Value&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"0"&lt;/span&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;Select
an Item&lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;/asp:ListItem&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;/manu:DropDownListEx&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;br&lt;/span&gt; &lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Price and suppliers:&lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;br&lt;/span&gt; &lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;manu:ListBoxEx&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;ID&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"ListBoxEx1"&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;runat&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"server"&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;Width&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"300px"&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="COLOR: #009900"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #000066"&gt;DataTextField&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"Price,
Supplier.Id, Supplier.Name"&lt;/span&gt; &lt;/span&gt;
&lt;br&gt;
&lt;span style="COLOR: #009900"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #000066"&gt;DataTextFormatString&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"{0}
- [{1}] {2}"&lt;/span&gt; &lt;/span&gt;
&lt;br&gt;
&lt;span style="COLOR: #009900"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #000066"&gt;DataValueField&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"Supplier.Id"&lt;/span&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;/manu:ListBoxEx&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;/form&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;/body&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
As you can see, the solution is really clean and elegant, and backward compatible
with the current controls that inherit from ListControl.
&lt;/p&gt;
&lt;p&gt;
That’s all for now,&lt;br&gt;
Merry christmas!
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.manuelabadia.com/blog/content/binary/ListControlsEx_bin.zip"&gt;ListControlsEx_bin.zip
(6.53 KB)&lt;/a&gt;
&lt;/p&gt;
&lt;a href="http://www.manuelabadia.com/blog/content/binary/ListControlsEx_sample.zip"&gt;ListControlsEx_sample.zip
(33.75 KB)&lt;/a&gt;&lt;img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=0606d95f-56ae-4dd7-8458-69cd550fa356" /&gt;</description>
      <comments>http://www.manuelabadia.com/blog/CommentView,guid,0606d95f-56ae-4dd7-8458-69cd550fa356.aspx</comments>
      <category>ASP.NET;Microsoft .NET Framework</category>
    </item>
    <item>
      <trackback:ping>http://www.manuelabadia.com/blog/Trackback.aspx?guid=7924eaf8-b406-43af-9444-b816f6dfa246</trackback:ping>
      <pingback:server>http://www.manuelabadia.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.manuelabadia.com/blog/PermaLink,guid,7924eaf8-b406-43af-9444-b816f6dfa246.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://www.manuelabadia.com/blog/CommentView,guid,7924eaf8-b406-43af-9444-b816f6dfa246.aspx</wfw:comment>
      <wfw:commentRss>http://www.manuelabadia.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=7924eaf8-b406-43af-9444-b816f6dfa246</wfw:commentRss>
      <slash:comments>12</slash:comments>
      <title>Search Engine Optimization - Moving View State to the bottom of the page</title>
      <guid isPermaLink="false">http://www.manuelabadia.com/blog/PermaLink,guid,7924eaf8-b406-43af-9444-b816f6dfa246.aspx</guid>
      <link>http://www.manuelabadia.com/blog/PermaLink,guid,7924eaf8-b406-43af-9444-b816f6dfa246.aspx</link>
      <pubDate>Thu, 04 Dec 2008 19:26:16 GMT</pubDate>
      <description>&lt;p&gt;
One of the greatest problems when trying to optimize an ASP.NET page to be more search
engine friendly is the view state hidden field. Most search engines give more score
to the content of the firsts thousands of bytes of the document so if your first 2
KB are view state junk your pages are penalized. So the goal here is to move the view
state data as down as possible. 
&lt;/p&gt;
&lt;p&gt;
I have seen some approaches to solve this problem rewriting the final HTML code of
the response. While this approach works I think that it wastes some precious processor
cycles that can be used to do other things. So I needed a way to do the same thing
without wasting that CPU time. After some large reflector sessions I found a way to
do it. My method uses the ASP.NET Control Adapter Architecture. 
&lt;/p&gt;
&lt;p&gt;
A control adapter is a class that can be used to control the HTML generated by the
control it adapts. Since the Page class is the responsible of rendering the view state
hidden field (Page.BeginFormRender calls Page.RenderViewStateFields), an adapter for
the Page is needed. However, the view state hidden field plays a key role in the ASP.NET
infrastructure (for example, the Page.IsPostBack property checks if the view state
hidden field has been posted) and it is difficult to modify the associated HTML. 
&lt;/p&gt;
&lt;p&gt;
A PageAdapter has a method called GetStatePersister() that returns an object that
inherits from PageStatePersister. The PageStatePersister is called when it is time
to load and save the view state. There are 2 classes that inherit from PageStatePersister:
HiddenFieldPageStatePersister and SessionPageStatePersister. The first one is the
default, which stores the view state in the hidden field called __VIEWSTATE. The second
one stores the view state in the session. So, we can easily create a custom PageStatePersister
to control the view state load and save process. The big problem is how to create
the hidden view state field before the closing form tag while being a fully transparent
solution. After some tries I came up with a solution that I was happy with. 
&lt;/p&gt;
&lt;p&gt;
I realized that it was impossible to completely remove the view state hidden field
from the top of the page, because it plays a key role in the ASP.NET infrastructure.
However, with any custom page state persister the ASP.NET infrastructure renders at
least an empty view state hidden field of only 70 bytes: 
&lt;/p&gt;
&lt;div class=html4strict style="BORDER-RIGHT: #d0d0d0 1px solid; BORDER-TOP: #d0d0d0 1px solid; BORDER-LEFT: #d0d0d0 1px solid; COLOR: #006; BORDER-BOTTOM: #d0d0d0 1px solid; FONT-FAMILY: monospace; BACKGROUND-COLOR: #f0f0f0"&gt;&lt;span style="COLOR: #009900"&gt;&amp;lt;&lt;a style="COLOR: #000060" href="http://december.com/html/4/element/input.html"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;input&lt;/span&gt;&lt;/a&gt; &lt;span style="COLOR: #000066"&gt;type&lt;/span&gt;&lt;span style="COLOR: #66cc66"&gt;=&lt;/span&gt;&lt;span style="COLOR: #ff0000"&gt;"hidden"&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;name&lt;/span&gt;&lt;span style="COLOR: #66cc66"&gt;=&lt;/span&gt;&lt;span style="COLOR: #ff0000"&gt;"__VIEWSTATE"&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;id&lt;/span&gt;&lt;span style="COLOR: #66cc66"&gt;=&lt;/span&gt;&lt;span style="COLOR: #ff0000"&gt;"__VIEWSTATE"&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;value&lt;/span&gt;&lt;span style="COLOR: #66cc66"&gt;=&lt;/span&gt;&lt;span style="COLOR: #ff0000"&gt;""&lt;/span&gt; &lt;span style="COLOR: #66cc66"&gt;/&lt;/span&gt;&amp;gt;&lt;/span&gt;
&lt;/div&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
My page adapter adds a hidden field to the bottom of the form called __SEOVIEWSTATE
with the actual view state data, and the only limitation that it has it is that you
can not use &lt;% %&gt;expressions directly inside the asp.net form. However, this restriction
can be easily avoided putting the &lt;% %&gt;expression in a PlaceHolder control or inside
another control. For an in-depth explanation of this limitation take a look &lt;a href="http://www.west-wind.com/WebLog/posts/6148.aspx"&gt;here&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
Let’s see an example of the adapter in action. The following ASP.NET page: 
&lt;/p&gt;
&lt;div class=xml style="BORDER-RIGHT: #d0d0d0 1px solid; BORDER-TOP: #d0d0d0 1px solid; BORDER-LEFT: #d0d0d0 1px solid; COLOR: #006; BORDER-BOTTOM: #d0d0d0 1px solid; FONT-FAMILY: monospace; BACKGROUND-COLOR: #f0f0f0"&gt;&lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;&lt;/span&gt;%@
Page &lt;span style="COLOR: #000066"&gt;Language&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"C#"&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;AutoEventWireup&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"true"&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;CodeBehind&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"Default.aspx.cs"&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;Inherits&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"SEOViewStateAdapterTest._Default"&lt;/span&gt; %&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="COLOR: #00bbdd"&gt;&amp;lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
&lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;html&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;xmlns&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"http://www.w3.org/1999/xhtml"&lt;/span&gt; &lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;head&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;runat&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"server"&lt;/span&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;title&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;/title&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;/head&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;body&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;form&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;id&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"form1"&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;runat&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"server"&lt;/span&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;div&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Enter a message: &lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;br&lt;/span&gt; &lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;asp:TextBox&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;ID&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"txtMessage"&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;runat&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"server"&lt;/span&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;/asp:TextBox&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;br&lt;/span&gt; &lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;asp:Button&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;ID&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"bSaveMessage"&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;runat&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"server"&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;Text&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"Save
Message"&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;onclick&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"bSaveMessage_Click"&lt;/span&gt; &lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;/&amp;gt;&lt;/span&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;br&lt;/span&gt; &lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;asp:Label&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;ID&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"lMessage"&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;runat&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"server"&lt;/span&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;/asp:Label&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;br&lt;/span&gt; &lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;p&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;Page
generated at &lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;asp:PlaceHolder&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;ID&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"PlaceHolder1"&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;runat&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"server"&lt;/span&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;&lt;/span&gt;%=
DateTime.Now.ToString&lt;span style="COLOR: #66cc66"&gt;(&lt;/span&gt;&lt;span style="COLOR: #ff0000"&gt;"hh:mm
dd/MM/yyy"&lt;/span&gt;&lt;span style="COLOR: #66cc66"&gt;)&lt;/span&gt; %&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;/asp:PlaceHolder&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;/p&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;/div&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;/form&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;/body&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;/html&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;
&lt;/div&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
With the associated code: 
&lt;/p&gt;
&lt;div class=csharp style="BORDER-RIGHT: #d0d0d0 1px solid; BORDER-TOP: #d0d0d0 1px solid; BORDER-LEFT: #d0d0d0 1px solid; COLOR: #006; BORDER-BOTTOM: #d0d0d0 1px solid; FONT-FAMILY: monospace; BACKGROUND-COLOR: #f0f0f0"&gt;&lt;span style="COLOR: #0600ff"&gt;using&lt;/span&gt; &lt;span style="COLOR: #008080"&gt;System&lt;/span&gt;&lt;span style="COLOR: #008000"&gt;;&lt;/span&gt;
&lt;br&gt;
&lt;span style="COLOR: #0600ff"&gt;using&lt;/span&gt; &lt;span style="COLOR: #008080"&gt;System.Collections.Generic&lt;/span&gt;&lt;span style="COLOR: #008000"&gt;;&lt;/span&gt;
&lt;br&gt;
&lt;span style="COLOR: #0600ff"&gt;using&lt;/span&gt; &lt;span style="COLOR: #008080"&gt;System.Web&lt;/span&gt;&lt;span style="COLOR: #008000"&gt;;&lt;/span&gt;
&lt;br&gt;
&lt;span style="COLOR: #0600ff"&gt;using&lt;/span&gt; &lt;span style="COLOR: #008080"&gt;System.Web.UI&lt;/span&gt;&lt;span style="COLOR: #008000"&gt;;&lt;/span&gt;
&lt;br&gt;
&lt;span style="COLOR: #0600ff"&gt;using&lt;/span&gt; &lt;span style="COLOR: #008080"&gt;System.Web.UI.WebControls&lt;/span&gt;&lt;span style="COLOR: #008000"&gt;;&lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
&lt;span style="COLOR: #0600ff"&gt;namespace&lt;/span&gt; SEOViewStateAdapterTest&lt;br&gt;
&lt;span style="COLOR: #000000"&gt;{&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #0600ff"&gt;public&lt;/span&gt; &lt;span style="COLOR: #0600ff"&gt;partial&lt;/span&gt; &lt;span style="COLOR: #ff0000"&gt;class&lt;/span&gt; _Default &lt;span style="COLOR: #008000"&gt;:&lt;/span&gt; &lt;span style="COLOR: #000000"&gt;System.&lt;span style="COLOR: #0000ff"&gt;Web&lt;/span&gt;.&lt;span style="COLOR: #0000ff"&gt;UI&lt;/span&gt;&lt;/span&gt;.&lt;span style="COLOR: #0000ff"&gt;Page&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #000000"&gt;{&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #0600ff"&gt;protected&lt;/span&gt; &lt;span style="COLOR: #0600ff"&gt;void&lt;/span&gt; Page_Load&lt;span style="COLOR: #000000"&gt;(&lt;/span&gt;&lt;span style="COLOR: #ff0000"&gt;object&lt;/span&gt; sender,
EventArgs e&lt;span style="COLOR: #000000"&gt;)&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #000000"&gt;{&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #0600ff"&gt;if&lt;/span&gt; &lt;span style="COLOR: #000000"&gt;(&lt;/span&gt;&lt;span style="COLOR: #008000"&gt;!&lt;/span&gt;Page.&lt;span style="COLOR: #0000ff"&gt;IsPostBack&lt;/span&gt;&lt;span style="COLOR: #000000"&gt;)&lt;/span&gt; &lt;span style="COLOR: #000000"&gt;{&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ViewState&lt;span style="COLOR: #000000"&gt;[&lt;/span&gt;&lt;span style="COLOR: #666666"&gt;"previousMessage"&lt;/span&gt;&lt;span style="COLOR: #000000"&gt;]&lt;/span&gt; &lt;span style="COLOR: #008000"&gt;=&lt;/span&gt; txtMessage.&lt;span style="COLOR: #0000ff"&gt;Text&lt;/span&gt;&lt;span style="COLOR: #008000"&gt;;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #000000"&gt;}&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #000000"&gt;}&lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #0600ff"&gt;protected&lt;/span&gt; &lt;span style="COLOR: #0600ff"&gt;void&lt;/span&gt; bSaveMessage_Click&lt;span style="COLOR: #000000"&gt;(&lt;/span&gt;&lt;span style="COLOR: #ff0000"&gt;object&lt;/span&gt; sender,
EventArgs e&lt;span style="COLOR: #000000"&gt;)&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #000000"&gt;{&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; lMessage.&lt;span style="COLOR: #0000ff"&gt;Text&lt;/span&gt; &lt;span style="COLOR: #008000"&gt;=&lt;/span&gt; &lt;span style="COLOR: #ff0000"&gt;String&lt;/span&gt;.&lt;span style="COLOR: #0000ff"&gt;Format&lt;/span&gt;&lt;span style="COLOR: #000000"&gt;(&lt;/span&gt;&lt;span style="COLOR: #666666"&gt;"The
current message is '{0}'. The previous message was '{1}'"&lt;/span&gt;, txtMessage.&lt;span style="COLOR: #0000ff"&gt;Text&lt;/span&gt;, &lt;span style="COLOR: #000000"&gt;(&lt;/span&gt;&lt;span style="COLOR: #ff0000"&gt;string&lt;/span&gt;&lt;span style="COLOR: #000000"&gt;)&lt;/span&gt;ViewState&lt;span style="COLOR: #000000"&gt;[&lt;/span&gt;&lt;span style="COLOR: #666666"&gt;"previousMessage"&lt;/span&gt;&lt;span style="COLOR: #000000"&gt;]&lt;/span&gt;&lt;span style="COLOR: #000000"&gt;)&lt;/span&gt;&lt;span style="COLOR: #008000"&gt;;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ViewState&lt;span style="COLOR: #000000"&gt;[&lt;/span&gt;&lt;span style="COLOR: #666666"&gt;"previousMessage"&lt;/span&gt;&lt;span style="COLOR: #000000"&gt;]&lt;/span&gt; &lt;span style="COLOR: #008000"&gt;=&lt;/span&gt; txtMessage.&lt;span style="COLOR: #0000ff"&gt;Text&lt;/span&gt;&lt;span style="COLOR: #008000"&gt;;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #000000"&gt;}&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #000000"&gt;}&lt;/span&gt;
&lt;br&gt;
&lt;span style="COLOR: #000000"&gt;}&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;
&lt;/div&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
after a couple of postbacks, without using the adapter, the HTML looks like this: 
&lt;/p&gt;
&lt;div class=xml style="BORDER-RIGHT: #d0d0d0 1px solid; BORDER-TOP: #d0d0d0 1px solid; BORDER-LEFT: #d0d0d0 1px solid; COLOR: #006; BORDER-BOTTOM: #d0d0d0 1px solid; FONT-FAMILY: monospace; BACKGROUND-COLOR: #f0f0f0"&gt;&lt;span style="COLOR: #00bbdd"&gt;&amp;lt;!DOCTYPE
html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
&lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;html&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;xmlns&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"http://www.w3.org/1999/xhtml"&lt;/span&gt; &lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;head&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;title&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
&lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;/title&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;/head&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;body&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;form&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;name&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"form1"&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;method&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"post"&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;action&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"Default.aspx"&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;id&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"form1"&lt;/span&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;div&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;input&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;type&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"hidden"&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;name&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"__VIEWSTATE"&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;id&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"__VIEWSTATE"&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;value&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"/wEPDwUJc01l[...]VwP+cfdSWI6Q=="&lt;/span&gt; &lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;/div&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
&lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;div&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;input&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;type&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"hidden"&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;name&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"__EVENTVALIDATION"&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;id&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"__EVENTVALIDATION"&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;value&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"/wEWAwKb4uenCgK/1s7/DwKf8MMPfiUvZtKPSXk//XdxkLooz8QDI0Y="&lt;/span&gt; &lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;/div&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;div&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Enter a message: &lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;br&lt;/span&gt; &lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;input&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;name&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"txtMessage"&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;type&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"text"&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;value&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"Message
2"&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;id&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"txtMessage"&lt;/span&gt; &lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;/&amp;gt;&lt;/span&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;br&lt;/span&gt; &lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;input&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;type&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"submit"&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;name&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"bSaveMessage"&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;value&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"Save
Message"&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;id&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"bSaveMessage"&lt;/span&gt; &lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;/&amp;gt;&lt;/span&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;br&lt;/span&gt; &lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;span&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;id&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"lMessage"&lt;/span&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;The
current message is 'Message 2'. The previous message was 'Message 1'&lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;/span&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;br&lt;/span&gt; &lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;p&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;Page
generated at 08:13 04/12/2008&lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;/p&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;/div&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;/form&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;/body&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;/html&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
and after a couple of postbacks, using the adapter, the HTML looks like this: 
&lt;/p&gt;
&lt;div class=xml style="BORDER-RIGHT: #d0d0d0 1px solid; BORDER-TOP: #d0d0d0 1px solid; BORDER-LEFT: #d0d0d0 1px solid; COLOR: #006; BORDER-BOTTOM: #d0d0d0 1px solid; FONT-FAMILY: monospace; BACKGROUND-COLOR: #f0f0f0"&gt;&lt;span style="COLOR: #00bbdd"&gt;&amp;lt;!DOCTYPE
html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
&lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;html&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;xmlns&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"http://www.w3.org/1999/xhtml"&lt;/span&gt; &lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;head&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;title&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
&lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;/title&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;/head&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;body&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;form&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;name&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"form1"&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;method&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"post"&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;action&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"Default.aspx"&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;id&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"form1"&lt;/span&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;div&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;input&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;type&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"hidden"&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;name&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"__VIEWSTATE"&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;id&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"__VIEWSTATE"&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;value&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;""&lt;/span&gt; &lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;/div&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
&lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;div&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;input&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;type&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"hidden"&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;name&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"__EVENTVALIDATION"&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;id&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"__EVENTVALIDATION"&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;value&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"/wEWAwL+raDpAgK/1s7/DwKf8MMPyF7nqN1AbwNwFBq8OAjEAQorsyo="&lt;/span&gt; &lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;/div&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;div&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Enter a message: &lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;br&lt;/span&gt; &lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;input&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;name&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"txtMessage"&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;type&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"text"&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;value&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"Message
2"&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;id&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"txtMessage"&lt;/span&gt; &lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;/&amp;gt;&lt;/span&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;br&lt;/span&gt; &lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;input&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;type&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"submit"&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;name&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"bSaveMessage"&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;value&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"Save
Message"&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;id&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"bSaveMessage"&lt;/span&gt; &lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;/&amp;gt;&lt;/span&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;br&lt;/span&gt; &lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;span&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;id&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"lMessage"&lt;/span&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;The
current message is 'Message 2'. The previous message was 'Message 1'&lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;/span&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;br&lt;/span&gt; &lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;p&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;Page
generated at 08:11 04/12/2008&lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;/p&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;/div&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;input&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;type&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"hidden"&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;name&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"__SEOVIEWSTATE"&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;id&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"__SEOVIEWSTATE"&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;value&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"/wEPc01lc3[...]CdNY6AtgigHvU="&lt;/span&gt; &lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;/&amp;gt;&lt;/span&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;/form&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;/body&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;/html&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
In order to use the adapter, you have to add a reference to the assembly and add a
file called SEOViewStateAdapter.browser (the name of the file does not matter. The
extension needs to be the same. Or also you could merge the contents to another file
if you already have one) to the App_Browsers folder. The content of the file should
be: 
&lt;/p&gt;
&lt;div class=xml style="BORDER-RIGHT: #d0d0d0 1px solid; BORDER-TOP: #d0d0d0 1px solid; BORDER-LEFT: #d0d0d0 1px solid; COLOR: #006; BORDER-BOTTOM: #d0d0d0 1px solid; FONT-FAMILY: monospace; BACKGROUND-COLOR: #f0f0f0"&gt;&lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;browsers&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #808080; FONT-STYLE: italic"&gt;&amp;lt;!-- use the adapters
for all browsers --&amp;gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;browser&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;refID&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"Default"&lt;/span&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;controlAdapters&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #808080; FONT-STYLE: italic"&gt;&amp;lt;!--
ths adapter is used to save the view and control state at the bottom of the form so
the page is more friendly to search engines --&amp;gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;adapter&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;controlType&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"System.Web.UI.Page"&lt;/span&gt; &lt;span style="COLOR: #000066"&gt;adapterType&lt;/span&gt;=&lt;span style="COLOR: #ff0000"&gt;"Manu.Web.Adapters.SEOFriendlyViewStatePageAdapter,
SEOViewStateAdapter"&lt;/span&gt; &lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;/controlAdapters&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp; &amp;nbsp; &lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;/browser&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="COLOR: #009900"&gt;&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;lt;/browsers&lt;span style="FONT-WEIGHT: bold; COLOR: #000000"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;
&lt;/div&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
That’s all. Enjoy!
&lt;/p&gt;
&lt;a href="http://www.manuelabadia.com/blog/content/binary/SEOViewState.zip"&gt;SEOViewState.zip
(29.67 KB)&lt;/a&gt;&lt;img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=7924eaf8-b406-43af-9444-b816f6dfa246" /&gt;</description>
      <comments>http://www.manuelabadia.com/blog/CommentView,guid,7924eaf8-b406-43af-9444-b816f6dfa246.aspx</comments>
      <category>ASP.NET;Microsoft .NET Framework;SEO</category>
    </item>
    <item>
      <trackback:ping>http://www.manuelabadia.com/blog/Trackback.aspx?guid=1265968d-573a-42f2-8382-9a35e2226272</trackback:ping>
      <pingback:server>http://www.manuelabadia.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.manuelabadia.com/blog/PermaLink,guid,1265968d-573a-42f2-8382-9a35e2226272.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://www.manuelabadia.com/blog/CommentView,guid,1265968d-573a-42f2-8382-9a35e2226272.aspx</wfw:comment>
      <wfw:commentRss>http://www.manuelabadia.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=1265968d-573a-42f2-8382-9a35e2226272</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Probably most of you have heard about AdSense, the ad serving program run by Google.
It is very simple to have a website to display ads using AdSense, as you only need
to include an external script with a few parameters (that mainly configure the size
and colors of the ads). For each click in a banner of the website, the associated
AdSense account gets a bit of money.
</p>
        <p>
However, this is not the only way to get AdSense in your pages. Google has the "<a href="http://code.google.com/apis/adsense/">AdSense
API</a>", which consists in several web services that allow sharing the revenue of
the banners between the website owner and the content publisher. That way, website
with user generated content can pay their users if their content is useful.
</p>
        <p>
A customer asked me to modify their website so they can share some of the benefits
of their banners with the creators of the articles in their site using the AdSense
API. I’ll detail some of my experiences with the integration of the AdSense API in
the webpage.
</p>
        <p>
As I had to deal with web services, and I was comfortable with the web service support
present in the .NET Framework 2.0, the easiest thing to do for me was to follow that
route. However, I always try to learn new stuff when I can, so it was an excellent
chance for me to learn WCF. Creating a proxy for a web service in WCF is as easy as
in .NET Framework 2.0. However, the problems started really soon. For some unknown
reason, the Google guys require some SOAP headers in the web service calls that are
not exposed in the AdSense’s WSDL. Reading some of the comments in the AdSense Group
revealed that the SOAP headers were exposed previously but they were removed without
giving any reason. I found this to be really annoying and. It can be fixed adding
the headers to the OutgoingMessageHeaders in the current OperationScope. Only for
this detail the Adsense API can be labeled as unfriendly for the developers.
</p>
        <p>
Once you set the headers manually, it is easy to call to the different methods to
create AdSense accounts, associate them with a publisher and generate the code to
display ads. However, I found very confusing some parts of the documentation, specially
all the ids available (you end up using clientId, publisherId,  synServiceId,
developerId, and in some methods having to pass the same id twice).
</p>
        <p>
Inspecting the generated code for the WCF proxy, I found one thing I didn’t like about
WCF. The DataContractSerializer does not handle bare arrays, so the generated code
was using the XmlSerializer for a lot of things that need directly or indirectly to
handle bare arrays in the AdSense API. The official statement of Microsoft about this
seems to be that bare arrays do not support the distinction between null arrays and
empty arrays, so the best is to use a wrapped collection.
</p>
        <p>
The AdSense API has a technical requirements page that informs you how to proceed
in some interactions with the users and how to react to error conditions. The AdSense
API methods expose the fault details as specified in the AdSenseApiException. When
an error happens when your WCF proxy is calling to the AdSense API, a FaultException
is generated. I was expecting the proxy to receive a FaultException&lt; AdSenseApiException&gt;
instead so I could easily access to the exception details but that wasn’t the case
(maybe that only works in WCF to WCF scenarios?). I tried to create a generic error
handler in order to convert the SOAP faults to the FaultException&lt;AdSenseApiException&gt;
type, but the information I found about WCF error handling in the web was only talking
about server side error handling using the IErrorHandler interface. It was clear that
I needed more in depth knowledge of WCF in order to do that. After some research I
bought Inside Windows Communication Foundation:
</p>
        <iframe style="WIDTH: 120px; HEIGHT: 240px" marginwidth="0" marginheight="0" src="http://rcm.amazon.com/e/cm?t=manuelabadias-20&amp;o=1&amp;p=8&amp;l=as1&amp;asins=0735623066&amp;fc1=000000&amp;IS2=1&amp;lt1=_blank&amp;lc1=0000FF&amp;bc1=000000&amp;bg1=FFFFFF&amp;f=ifr" frameborder="0" scrolling="no">
        </iframe>
        <p>
The book was exactly what I was looking for. Good and detailed internal information
about how WCF worked.
</p>
        <p>
Thanks to the book I was able to make my proxy generate the FaultException&lt;AdSenseApiException&gt;
transparently, but it wasn’t easy. Well, it is not difficult but you have to create
a lot of classes to do something simple.
</p>
        <p>
A channel exposes a method called GetProperty&lt;T&gt;. When an exception is generated
in the channel, the GetProperty&lt;T&gt; method is called with a parameter of type
FaultConverter. The method should return an an instance of a FaultConverter, which
creates the appropriate exception/fault type. To solve my problem I created an AdSenseFaultConverter:
</p>
        <p>
          <img src="http://www.manuelabadia.com/blog/content/binary/adsenseapi1.gif" border="0" />
        </p>
        <p>
However, in order to expose the AdSenseFaultConverter I had to create a ChannelFactory
(AdSenseChannelFactory), a channel (AdSenseChannelBase and AdSenseRequestChannel),
a Binding (AdSenseHttpBinding), and a BindingElement (AdSenseBindingElement). A lot
of classes with little added value just to override the GetProperty&lt;T&gt; method
in the channel. Also, to be able to use the configuration instead of setting up the
communication programmatically, I had to create a configuration BindingElement(AdSenseHttpBindingElement)
and a CollectionBindingElement (AdSenseHttpBindingCollectionElement). As I said before,
it is a lot of code.
</p>
        <p>
One thing that I haven’t commented yet is that your AdSense API implementation needs
to be reviewed in order to be able to serve live ads, and you need to follow some
policy requirements that you need to carefully study as they want to control even
the help pages you put in your web site. One of the requirements to be eligible to
participate in the AdSense API program is to have more than 100000 daily page views.
This is a showstopper for most of the web sites making the AdSense API useless for
99.9% of the people.
</p>
        <p>
Another negative point of the AdSense API is that the WSDL has been broken for more
than a month. I planned to write this article a couple of months ago so I don’t know
if the WSDL of the AdSense API is still invalid or not, but having it broken for more
than a month can give you an idea of the overall satisfaction I have with the AdSense
API.
</p>
        <p>
To finish talking about the AdSense API, I have to mention the Sandbox. The development
web services don’t behave exactly as the live web services (something that I hate),
so some methods need to have additional headers when testing the API to work properly.
Why? Well, basically because they do not have a decent sandbox. They just have the
development version of the web services and you have to live with that. No GUI for
managing the developers accounts, payments or something similar to the AdSense account
webpage. If you compare this to other sandboxes like the paypal one where you can
even receive the IPN confirmation messages you can clearly see the difference.
</p>
        <p>
And the last rant of the post is about Google policies regarding to AdWords and AdSense.
If you are an European citizen and you want to advertise using AdWords, Google forces
you to pay in Euros. However, when you have AdSense in your page, Google will pay
you in dollars. Judging by the prices of the ads in AdWords and the money you receive
with AdSense, Google is taking advantage of the European citizens by charging a 60%
more for an ad in AdWords and paying a 60% less for it (the exchange rate is approximately
1 euro = 1.60 dollars). Is the European commission too busy fining Microsoft for including
free products with Windows to investigate things like this?
</p>
        <p>
To sum up, I’m completely disappointed with Google and their AdSense API. If some
people ever had the illusion that Google was a non evil company that did the things
the right way, they need to wake up.<br /></p>
        <img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=1265968d-573a-42f2-8382-9a35e2226272" />
      </body>
      <title>Google and AdSense</title>
      <guid isPermaLink="false">http://www.manuelabadia.com/blog/PermaLink,guid,1265968d-573a-42f2-8382-9a35e2226272.aspx</guid>
      <link>http://www.manuelabadia.com/blog/PermaLink,guid,1265968d-573a-42f2-8382-9a35e2226272.aspx</link>
      <pubDate>Mon, 28 Apr 2008 21:25:28 GMT</pubDate>
      <description>&lt;p&gt;
Probably most of you have heard about AdSense, the ad serving program run by Google.
It is very simple to have a website to display ads using AdSense, as you only need
to include an external script with a few parameters (that mainly configure the size
and colors of the ads). For each click in a banner of the website, the associated
AdSense account gets a bit of money.
&lt;/p&gt;
&lt;p&gt;
However, this is not the only way to get AdSense in your pages. Google has the "&lt;a href="http://code.google.com/apis/adsense/"&gt;AdSense
API&lt;/a&gt;", which consists in several web services that allow sharing the revenue of
the banners between the website owner and the content publisher. That way, website
with user generated content can pay their users if their content is useful.
&lt;/p&gt;
&lt;p&gt;
A customer asked me to modify their website so they can share some of the benefits
of their banners with the creators of the articles in their site using the AdSense
API. I’ll detail some of my experiences with the integration of the AdSense API in
the webpage.
&lt;/p&gt;
&lt;p&gt;
As I had to deal with web services, and I was comfortable with the web service support
present in the .NET Framework 2.0, the easiest thing to do for me was to follow that
route. However, I always try to learn new stuff when I can, so it was an excellent
chance for me to learn WCF. Creating a proxy for a web service in WCF is as easy as
in .NET Framework 2.0. However, the problems started really soon. For some unknown
reason, the Google guys require some SOAP headers in the web service calls that are
not exposed in the AdSense’s WSDL. Reading some of the comments in the AdSense Group
revealed that the SOAP headers were exposed previously but they were removed without
giving any reason. I found this to be really annoying and. It can be fixed adding
the headers to the OutgoingMessageHeaders in the current OperationScope. Only for
this detail the Adsense API can be labeled as unfriendly for the developers.
&lt;/p&gt;
&lt;p&gt;
Once you set the headers manually, it is easy to call to the different methods to
create AdSense accounts, associate them with a publisher and generate the code to
display ads. However, I found very confusing some parts of the documentation, specially
all the ids available (you end up using clientId, publisherId,&amp;nbsp; synServiceId,
developerId, and in some methods having to pass the same id twice).
&lt;/p&gt;
&lt;p&gt;
Inspecting the generated code for the WCF proxy, I found one thing I didn’t like about
WCF. The DataContractSerializer does not handle bare arrays, so the generated code
was using the XmlSerializer for a lot of things that need directly or indirectly to
handle bare arrays in the AdSense API. The official statement of Microsoft about this
seems to be that bare arrays do not support the distinction between null arrays and
empty arrays, so the best is to use a wrapped collection.
&lt;/p&gt;
&lt;p&gt;
The AdSense API has a technical requirements page that informs you how to proceed
in some interactions with the users and how to react to error conditions. The AdSense
API methods expose the fault details as specified in the AdSenseApiException. When
an error happens when your WCF proxy is calling to the AdSense API, a FaultException
is generated. I was expecting the proxy to receive a FaultException&amp;lt; AdSenseApiException&amp;gt;
instead so I could easily access to the exception details but that wasn’t the case
(maybe that only works in WCF to WCF scenarios?). I tried to create a generic error
handler in order to convert the SOAP faults to the FaultException&amp;lt;AdSenseApiException&amp;gt;
type, but the information I found about WCF error handling in the web was only talking
about server side error handling using the IErrorHandler interface. It was clear that
I needed more in depth knowledge of WCF in order to do that. After some research I
bought Inside Windows Communication Foundation:
&lt;/p&gt;
&lt;iframe style="WIDTH: 120px; HEIGHT: 240px" marginwidth=0 marginheight=0 src="http://rcm.amazon.com/e/cm?t=manuelabadias-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=as1&amp;amp;asins=0735623066&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" frameborder=0 scrolling=no&gt;
&lt;/iframe&gt;
&lt;p&gt;
The book was exactly what I was looking for. Good and detailed internal information
about how WCF worked.
&lt;/p&gt;
&lt;p&gt;
Thanks to the book I was able to make my proxy generate the FaultException&amp;lt;AdSenseApiException&amp;gt;
transparently, but it wasn’t easy. Well, it is not difficult but you have to create
a lot of classes to do something simple.
&lt;/p&gt;
&lt;p&gt;
A channel exposes a method called GetProperty&amp;lt;T&amp;gt;. When an exception is generated
in the channel, the GetProperty&amp;lt;T&amp;gt; method is called with a parameter of type
FaultConverter. The method should return an an instance of a FaultConverter, which
creates the appropriate exception/fault type. To solve my problem I created an AdSenseFaultConverter:
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://www.manuelabadia.com/blog/content/binary/adsenseapi1.gif" border=0&gt;
&lt;/p&gt;
&lt;p&gt;
However, in order to expose the AdSenseFaultConverter I had to create a ChannelFactory
(AdSenseChannelFactory), a channel (AdSenseChannelBase and AdSenseRequestChannel),
a Binding (AdSenseHttpBinding), and a BindingElement (AdSenseBindingElement). A lot
of classes with little added value just to override the GetProperty&amp;lt;T&amp;gt; method
in the channel. Also, to be able to use the configuration instead of setting up the
communication programmatically, I had to create a configuration BindingElement(AdSenseHttpBindingElement)
and a CollectionBindingElement (AdSenseHttpBindingCollectionElement). As I said before,
it is a lot of code.
&lt;/p&gt;
&lt;p&gt;
One thing that I haven’t commented yet is that your AdSense API implementation needs
to be reviewed in order to be able to serve live ads, and you need to follow some
policy requirements that you need to carefully study as they want to control even
the help pages you put in your web site. One of the requirements to be eligible to
participate in the AdSense API program is to have more than 100000 daily page views.
This is a showstopper for most of the web sites making the AdSense API useless for
99.9% of the people.
&lt;/p&gt;
&lt;p&gt;
Another negative point of the AdSense API is that the WSDL has been broken for more
than a month. I planned to write this article a couple of months ago so I don’t know
if the WSDL of the AdSense API is still invalid or not, but having it broken for more
than a month can give you an idea of the overall satisfaction I have with the AdSense
API.
&lt;/p&gt;
&lt;p&gt;
To finish talking about the AdSense API, I have to mention the Sandbox. The development
web services don’t behave exactly as the live web services (something that I hate),
so some methods need to have additional headers when testing the API to work properly.
Why? Well, basically because they do not have a decent sandbox. They just have the
development version of the web services and you have to live with that. No GUI for
managing the developers accounts, payments or something similar to the AdSense account
webpage. If you compare this to other sandboxes like the paypal one where you can
even receive the IPN confirmation messages you can clearly see the difference.
&lt;/p&gt;
&lt;p&gt;
And the last rant of the post is about Google policies regarding to AdWords and AdSense.
If you are an European citizen and you want to advertise using AdWords, Google forces
you to pay in Euros. However, when you have AdSense in your page, Google will pay
you in dollars. Judging by the prices of the ads in AdWords and the money you receive
with AdSense, Google is taking advantage of the European citizens by charging a 60%
more for an ad in AdWords and paying a 60% less for it (the exchange rate is approximately
1 euro = 1.60 dollars). Is the European commission too busy fining Microsoft for including
free products with Windows to investigate things like this?
&lt;/p&gt;
&lt;p&gt;
To sum up, I’m completely disappointed with Google and their AdSense API. If some
people ever had the illusion that Google was a non evil company that did the things
the right way, they need to wake up.&lt;br&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=1265968d-573a-42f2-8382-9a35e2226272" /&gt;</description>
      <comments>http://www.manuelabadia.com/blog/CommentView,guid,1265968d-573a-42f2-8382-9a35e2226272.aspx</comments>
      <category>General;Microsoft .NET Framework;AdSense;WCF</category>
    </item>
    <item>
      <trackback:ping>http://www.manuelabadia.com/blog/Trackback.aspx?guid=a073bf47-5324-4884-9e2f-730fb8d78f7b</trackback:ping>
      <pingback:server>http://www.manuelabadia.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.manuelabadia.com/blog/PermaLink,guid,a073bf47-5324-4884-9e2f-730fb8d78f7b.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://www.manuelabadia.com/blog/CommentView,guid,a073bf47-5324-4884-9e2f-730fb8d78f7b.aspx</wfw:comment>
      <wfw:commentRss>http://www.manuelabadia.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=a073bf47-5324-4884-9e2f-730fb8d78f7b</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
        </p>
        <p>
One of the tools I’m using is NDepend (<a href="http://www.ndepend.com/">http://www.ndepend.com/</a>).
It is a cool application that can be used for a lot of things, as will be detailed
later. 
</p>
        <p>
To use NDepend you have to feed it with a set of assemblies. After that, it will analyze
those assemblies and their reference assemblies. If the PDBs of the assemblies are
available it will use them so more data is analyzed, although the PDBs are not needed
for NDepend to work.
</p>
        <p>
After the analysis has been completed, NDepend looks like this:
</p>
        <img src="http://www.manuelabadia.com/blog/content/binary/ndepend1.png" border="0" />
        <p>
          <br />
I have used version 1.1 of Spring.NET Framework (<a href="http://www.springframework.net/">http://www.springframework.net/</a>)
for the sample. As you can see the application has a beautiful GUI. I’ll talk a bit
about the main windows of the tool:
</p>
        <blockquote dir="ltr" style="MARGIN-RIGHT: 0px">
          <p>
• Metrics: this window gives a graphical high level view of the project. You
can see a lot of ellipses and some of them that are made of smaller ellipses. The
big ellipses are types of the project. If a big ellipse is made of several smaller
ellipses, those smaller ellipses are the methods of the type. The types of the same
namespace are distributed in the same rectangular region, separated by a small yellow
line. The assemblies are separated by a thicker yellow line. 
</p>
          <p>
By watching this window you can get an idea of which assemblies contain more code,
which types are big, which types have a lot of methods, etc. The window was in “Method
Level”. The available levels are Assembly, Namespace, Type, Method and Field.
</p>
          <p>
• Class Browser: this is where the assemblies of the project and its referenced
assemblies are shown. You can expand the assembly up to the field level. While you
hover over an item in most windows, the Metrics window gets updated highlighting the
hovered item. 
</p>
          <p>
What it’s really cool about the Class Browser is that for the referenced assemblies,
only the namespaces, types, methods and other items that are used by the project are
shown.
</p>
          <p>
• Info: When you hover over an item the information about it is displayed here,
with some metrics if applicable. There are a lot of metrics so it can take time to
interiorize them and judge their value appropriately.
</p>
          <p>
• Dependencies: this window is a bit intimidating at first but like a lot of
things, with a bit of effort you can master it. The window displays very important
information of the dependencies in a matrix form. As in other windows, the detail
level is selectable, from the assembly level to the field level. 
</p>
          <p>
A cell can have 3 colors. Blue means that the associated item in the top header uses
the associated item in the left header. Green means that the associated item in the
left header is using the associated item in the top header. Black means a cyclic dependency.
The blue and green cells express the same dependency using opposite points of view. 
</p>
          <p>
You can see a diagram of the dependencies clicking on a cell. For example, if you
click in the cell corresponding to System.Web.Extensions and System.Web you get this:
</p>
          <img src="http://www.manuelabadia.com/blog/content/binary/BoxAndArrowGraph.PNG" border="0" />
          <p>
To read more about the theory of dependencies take a look here:
</p>
          <p>
            <a href="http://www.theserverside.net/tt/articles/showarticle.tss?id=ControllingDependencies">ttp://www.theserverside.net/tt/articles/showarticle.tss?id=ControllingDependencies</a>
          </p>
          <p>
• CQL Queries: CQL stands for Code Query Language and it is a central piece of
NDepend. Being able to ask questions about the code is great. If you like using the
Analyzer window in Reflector you’ll love this. You can create new queries and modify
the existing ones.
</p>
        </blockquote>
        <p dir="ltr">
I have presented the main NDepend windows, but the main question is: what you can
do with NDepend?
</p>
        <p dir="ltr">
There are several uses that I can think of:
</p>
        <blockquote dir="ltr" style="MARGIN-RIGHT: 0px">
          <p dir="ltr">
• It is an excellent tool to check differences between different builds of an
assembly. You can use it as a diff tool, as it will show in the Class Browser which
types, methods, etc have been added, removed or changed. This information is also
available for CQL Queries, with the power that it implies.
</p>
          <p>
• It can be used to understand code. When you are thrown with code that you have
no clue about how it works you have several options to accomplish that task:
</p>
          <ol dir="ltr" style="MARGIN-RIGHT: 0px">
            <li>
Look at the source code directly. 
</li>
            <li>
Make some diagrams from the source code (for example, using View Class Diagram in
Visual Studio). 
</li>
            <li>
Use NDepend.</li>
          </ol>
          <p dir="ltr">
These methods are not exclusive, and probably you’ll use a combination of them to
understand how the code works. However, the abstraction level is higher when you use
NDepend is higher than when you use a Class Diagram (and a Class Diagram is a high
level view compared to raw source code).  I’d use NDepend to have a global vision
of the main assemblies, type most used, dependencies between namespaces, more complex
methods, etc. and then focus my attention in the most important parts of the application,
going to a lower level of detail.
</p>
          <p dir="ltr">
• It can be used in the refactoring process, to see the impact of a change, and
to keep dependencies to a minimum, in order to have a project that is easier to understand
and maintain.
</p>
          <p>
• Integrating NDepend in the software development process. IMHO this is a key
point, as using NDepend regulary will certainly improve the quality of the software
that is being developed.  NDepend can generate a report of a project. A sample
report is available here:
</p>
          <p>
            <a href="http://www.ndepend.com/SampleReports/OnNUnit/NDependReport.html">http://www.ndepend.com/SampleReports/OnNUnit/NDependReport.html</a>
          </p>
          <p>
There are a lot of sections in the report, but I’ll concentrate on the section called
“CQL Queries and Constraints”. That section is really important as it shows a list
of items that can be problematic or don’t follow the standards of your company (methods
with a lot of lines of code, very complex methods, poorly commented methods, types
or methods or properties or fields with incorrect naming conventions, etc). This way
the project leader can make periodic checks of those problems and report them to the
people that are responsible for them. 
<br />
This also allows you to know more the people you’re working with. Some developers
don’t comment code, others like to make very long methods, and others tend to write
complex logic that is difficult to understand by others. With the review of the report,
they can be instructed so the resulting code and comments is better and more uniform.
</p>
          <p>
However, there are times where a method with more than 30 lines of code is necessary.
Or a method with a cyclomatic complexity of 25 is needed. So it is up to the project
leader to review the suspicious method and inform the developers of the problem or
simply acknowledge that it is necessary. 
</p>
          <p>
Unfortunately, NDepend does not provide built in support for this level of detail
of project management. I have been told that in a future version it will provide hooks
so custom scenarios like the exposed above are fully supported.
</p>
        </blockquote>
        <p dir="ltr">
So, after what I have said about NDepend, you can be thinking, is it for me? Well,
that depends on a lot of factors. I know a lot of companies that have no interest
in achieving high quality products and that they only care about having a project
done as soon as possible. If the maintenance of that project is a nightmare, well,
that is another problem for another moment. However, there are some companies that
actually spend time and effort to produce excellent products, so they may be interested
in what NDepend can add for them.
</p>
        <p dir="ltr">
I have used NDepend in several projects that are widely used when learning about it,
and I found something curious:
</p>
        <p dir="ltr">
          <img src="http://www.manuelabadia.com/blog/content/binary/nhibernate_dependencies.png" border="0" />
        </p>
        <p dir="ltr">
The image shows that almost all of the NHibernate code has a big dependency cycle.
I wish them good luck making the transition to ASTs.
</p>
        <p dir="ltr">
          <em>To finish this post, I have to say that I have received a free professional version
of NDepend. This has not conditioned my post about it. If I think it was a useless
product I will not have posted about it.<br /></em>
        </p>
        <img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=a073bf47-5324-4884-9e2f-730fb8d78f7b" />
      </body>
      <title>NDepend</title>
      <guid isPermaLink="false">http://www.manuelabadia.com/blog/PermaLink,guid,a073bf47-5324-4884-9e2f-730fb8d78f7b.aspx</guid>
      <link>http://www.manuelabadia.com/blog/PermaLink,guid,a073bf47-5324-4884-9e2f-730fb8d78f7b.aspx</link>
      <pubDate>Fri, 08 Feb 2008 12:22:13 GMT</pubDate>
      <description>&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
One of the tools I’m using is NDepend (&lt;a href="http://www.ndepend.com/"&gt;http://www.ndepend.com/&lt;/a&gt;).
It is a cool application that can be used for a lot of things, as will be detailed
later. 
&lt;/p&gt;
&lt;p&gt;
To use NDepend you have to feed it with a set of assemblies. After that, it will analyze
those assemblies and their reference assemblies. If the PDBs of the assemblies are
available it will use them so more data is analyzed, although the PDBs are not needed
for NDepend to work.
&lt;/p&gt;
&lt;p&gt;
After the analysis has been completed, NDepend looks like this:
&lt;/p&gt;
&lt;img src="http://www.manuelabadia.com/blog/content/binary/ndepend1.png" border=0&gt; 
&lt;p&gt;
&lt;br&gt;
I have used version 1.1 of Spring.NET Framework (&lt;a href="http://www.springframework.net/"&gt;http://www.springframework.net/&lt;/a&gt;)
for the sample. As you can see the application has a beautiful GUI. I’ll talk a bit
about the main windows of the tool:
&lt;/p&gt;
&lt;blockquote dir=ltr style="MARGIN-RIGHT: 0px"&gt; 
&lt;p&gt;
•&amp;nbsp;Metrics: this window gives a graphical high level view of the project. You
can see a lot of ellipses and some of them that are made of smaller ellipses. The
big ellipses are types of the project. If a big ellipse is made of several smaller
ellipses, those smaller ellipses are the methods of the type. The types of the same
namespace are distributed in the same rectangular region, separated by a small yellow
line. The assemblies are separated by a thicker yellow line. 
&lt;/p&gt;
&lt;p&gt;
By watching this window you can get an idea of which assemblies contain more code,
which types are big, which types have a lot of methods, etc. The window was in “Method
Level”. The available levels are Assembly, Namespace, Type, Method and Field.
&lt;/p&gt;
&lt;p&gt;
•&amp;nbsp;Class Browser: this is where the assemblies of the project and its referenced
assemblies are shown. You can expand the assembly up to the field level. While you
hover over an item in most windows, the Metrics window gets updated highlighting the
hovered item. 
&lt;/p&gt;
&lt;p&gt;
What it’s really cool about the Class Browser is that for the referenced assemblies,
only the namespaces, types, methods and other items that are used by the project are
shown.
&lt;/p&gt;
&lt;p&gt;
•&amp;nbsp;Info: When you hover over an item the information about it is displayed here,
with some metrics if applicable. There are a lot of metrics so it can take time to
interiorize them and judge their value appropriately.
&lt;/p&gt;
&lt;p&gt;
•&amp;nbsp;Dependencies: this window is a bit intimidating at first but like a lot of
things, with a bit of effort you can master it. The window displays very important
information of the dependencies in a matrix form. As in other windows, the detail
level is selectable, from the assembly level to the field level. 
&lt;/p&gt;
&lt;p&gt;
A cell can have 3 colors. Blue means that the associated item in the top header uses
the associated item in the left header. Green means that the associated item in the
left header is using the associated item in the top header. Black means a cyclic dependency.
The blue and green cells express the same dependency using opposite points of view. 
&lt;/p&gt;
&lt;p&gt;
You can see a diagram of the dependencies clicking on a cell. For example, if you
click in the cell corresponding to System.Web.Extensions and System.Web you get this:
&lt;/p&gt;
&lt;img src="http://www.manuelabadia.com/blog/content/binary/BoxAndArrowGraph.PNG" border=0&gt; 
&lt;p&gt;
To read more about the theory of dependencies take a look here:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.theserverside.net/tt/articles/showarticle.tss?id=ControllingDependencies"&gt;ttp://www.theserverside.net/tt/articles/showarticle.tss?id=ControllingDependencies&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
•&amp;nbsp;CQL Queries: CQL stands for Code Query Language and it is a central piece of
NDepend. Being able to ask questions about the code is great. If you like using the
Analyzer window in Reflector you’ll love this. You can create new queries and modify
the existing ones.
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p dir=ltr&gt;
I have presented the main NDepend windows, but the main question is: what you can
do with NDepend?
&lt;/p&gt;
&lt;p dir=ltr&gt;
There are several uses that I can think of:
&lt;/p&gt;
&lt;blockquote dir=ltr style="MARGIN-RIGHT: 0px"&gt; 
&lt;p dir=ltr&gt;
•&amp;nbsp;It is an excellent tool to check differences between different builds of an
assembly. You can use it as a diff tool, as it will show in the Class Browser which
types, methods, etc have been added, removed or changed. This information is also
available for CQL Queries, with the power that it implies.
&lt;/p&gt;
&lt;p&gt;
•&amp;nbsp;It can be used to understand code. When you are thrown with code that you have
no clue about how it works you have several options to accomplish that task:
&lt;/p&gt;
&lt;ol dir=ltr style="MARGIN-RIGHT: 0px"&gt;
&lt;li&gt;
Look at the source code directly. 
&lt;li&gt;
Make some diagrams from the source code (for example, using View Class Diagram in
Visual Studio). 
&lt;li&gt;
Use NDepend.&lt;/li&gt;
&lt;/ol&gt;
&lt;p dir=ltr&gt;
These methods are not exclusive, and probably you’ll use a combination of them to
understand how the code works. However, the abstraction level is higher when you use
NDepend is higher than when you use a Class Diagram (and a Class Diagram is a high
level view compared to raw source code).&amp;nbsp; I’d use NDepend to have a global vision
of the main assemblies, type most used, dependencies between namespaces, more complex
methods, etc. and then focus my attention in the most important parts of the application,
going to a lower level of detail.
&lt;/p&gt;
&lt;p dir=ltr&gt;
•&amp;nbsp;It can be used in the refactoring process, to see the impact of a change, and
to keep dependencies to a minimum, in order to have a project that is easier to understand
and maintain.
&lt;/p&gt;
&lt;p&gt;
•&amp;nbsp;Integrating NDepend in the software development process. IMHO this is a key
point, as using NDepend regulary will certainly improve the quality of the software
that is being developed.&amp;nbsp; NDepend can generate a report of a project. A sample
report is available here:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.ndepend.com/SampleReports/OnNUnit/NDependReport.html"&gt;http://www.ndepend.com/SampleReports/OnNUnit/NDependReport.html&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
There are a lot of sections in the report, but I’ll concentrate on the section called
“CQL Queries and Constraints”. That section is really important as it shows a list
of items that can be problematic or don’t follow the standards of your company (methods
with a lot of lines of code, very complex methods, poorly commented methods, types
or methods or properties or fields with incorrect naming conventions, etc). This way
the project leader can make periodic checks of those problems and report them to the
people that are responsible for them. 
&lt;br&gt;
This also allows you to know more the people you’re working with. Some developers
don’t comment code, others like to make very long methods, and others tend to write
complex logic that is difficult to understand by others. With the review of the report,
they can be instructed so the resulting code and comments is better and more uniform.
&lt;/p&gt;
&lt;p&gt;
However, there are times where a method with more than 30 lines of code is necessary.
Or a method with a cyclomatic complexity of 25 is needed. So it is up to the project
leader to review the suspicious method and inform the developers of the problem or
simply acknowledge that it is necessary. 
&lt;/p&gt;
&lt;p&gt;
Unfortunately, NDepend does not provide built in support for this level of detail
of project management. I have been told that in a future version it will provide hooks
so custom scenarios like the exposed above are fully supported.
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p dir=ltr&gt;
So, after what I have said about NDepend, you can be thinking, is it for me? Well,
that depends on a lot of factors. I know a lot of companies that have no interest
in achieving high quality products and that they only care about having a project
done as soon as possible. If the maintenance of that project is a nightmare, well,
that is another problem for another moment. However, there are some companies that
actually spend time and effort to produce excellent products, so they may be interested
in what NDepend can add for them.
&lt;/p&gt;
&lt;p dir=ltr&gt;
I have used NDepend in several projects that are widely used when learning about it,
and I found something curious:
&lt;/p&gt;
&lt;p dir=ltr&gt;
&lt;img src="http://www.manuelabadia.com/blog/content/binary/nhibernate_dependencies.png" border=0&gt;
&lt;/p&gt;
&lt;p dir=ltr&gt;
The image shows that almost all of the NHibernate code has a big dependency cycle.
I wish them good luck making the transition to ASTs.
&lt;/p&gt;
&lt;p dir=ltr&gt;
&lt;em&gt;To finish this post, I have to say that I have received a free professional version
of NDepend. This has not conditioned my post about it. If I think it was a useless
product I will not have posted about it.&lt;br&gt;
&lt;/em&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=a073bf47-5324-4884-9e2f-730fb8d78f7b" /&gt;</description>
      <comments>http://www.manuelabadia.com/blog/CommentView,guid,a073bf47-5324-4884-9e2f-730fb8d78f7b.aspx</comments>
      <category>ASP.NET;Microsoft .NET Framework;NHibernate</category>
    </item>
    <item>
      <trackback:ping>http://www.manuelabadia.com/blog/Trackback.aspx?guid=870abdd7-ec3d-4760-8513-287151782f1f</trackback:ping>
      <pingback:server>http://www.manuelabadia.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.manuelabadia.com/blog/PermaLink,guid,870abdd7-ec3d-4760-8513-287151782f1f.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://www.manuelabadia.com/blog/CommentView,guid,870abdd7-ec3d-4760-8513-287151782f1f.aspx</wfw:comment>
      <wfw:commentRss>http://www.manuelabadia.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=870abdd7-ec3d-4760-8513-287151782f1f</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Some time ago I created a DebuggerVisualizer for LINQ expressions. I have finally
updated the DebuggerVisualizer for Visual Studio 2008 RTM version. You can download
it <a href="http://www.manuelabadia.com/blog/PermaLink,guid,9160035f-490f-46bd-ab55-516b5c7545af.aspx">here</a>.
</p>
        <p>
The main changes are that Funclets and LiftExpressions were removed after Beta 1.
For more information check <a href="http://sgdotnet.org/blogs/chuawenching/archive/2007/09/27/Missing-FuncletExpression-and-LiftExpression-in-Visual-Studio-2008-Beta-2.aspx">this
post</a>.
</p>
        <p>
I have tested it only in a couple of expressions so let me know if you find any problem.
</p>
        <img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=870abdd7-ec3d-4760-8513-287151782f1f" />
      </body>
      <title>LINQ Expressions DebuggerVisualizer Update</title>
      <guid isPermaLink="false">http://www.manuelabadia.com/blog/PermaLink,guid,870abdd7-ec3d-4760-8513-287151782f1f.aspx</guid>
      <link>http://www.manuelabadia.com/blog/PermaLink,guid,870abdd7-ec3d-4760-8513-287151782f1f.aspx</link>
      <pubDate>Sun, 13 Jan 2008 10:08:02 GMT</pubDate>
      <description>&lt;p&gt;
Some time ago I created a DebuggerVisualizer for LINQ expressions. I have finally
updated the DebuggerVisualizer for Visual Studio 2008 RTM version. You can download
it &lt;a href="http://www.manuelabadia.com/blog/PermaLink,guid,9160035f-490f-46bd-ab55-516b5c7545af.aspx"&gt;here&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
The main changes are that Funclets and LiftExpressions were removed after Beta 1.
For more information check &lt;a href="http://sgdotnet.org/blogs/chuawenching/archive/2007/09/27/Missing-FuncletExpression-and-LiftExpression-in-Visual-Studio-2008-Beta-2.aspx"&gt;this
post&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
I have tested it only in a couple of expressions so let me know if you find any problem.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=870abdd7-ec3d-4760-8513-287151782f1f" /&gt;</description>
      <comments>http://www.manuelabadia.com/blog/CommentView,guid,870abdd7-ec3d-4760-8513-287151782f1f.aspx</comments>
      <category>Linq;Microsoft .NET Framework;Visual Studio</category>
    </item>
    <item>
      <trackback:ping>http://www.manuelabadia.com/blog/Trackback.aspx?guid=1d9cf157-2c6c-4ec4-b45a-7dc724543c28</trackback:ping>
      <pingback:server>http://www.manuelabadia.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.manuelabadia.com/blog/PermaLink,guid,1d9cf157-2c6c-4ec4-b45a-7dc724543c28.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://www.manuelabadia.com/blog/CommentView,guid,1d9cf157-2c6c-4ec4-b45a-7dc724543c28.aspx</wfw:comment>
      <wfw:commentRss>http://www.manuelabadia.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=1d9cf157-2c6c-4ec4-b45a-7dc724543c28</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
If you have worked with the design time infrastructure you will know that there are
parts of it that are poorly documented.
</p>
        <p>
To complement MSDN help and internet searches you can try another source of information: <strong>patents</strong>.
</p>
        <p>
Most big companies like to patent a lot of stuff so I stumbled upon <a href="http://www.freepatentsonline.com/20050251380.html">this
patent</a> that has some good information about design time. The inventors of
the patent are:
</p>
        <ul>
          <li>
            <em>Andrew Cheng-Min Lin</em>
          </li>
          <li>
            <em>Bulusu Krishna Mohan</em>
          </li>
          <li>
            <em>Nikhil Kothari</em>
          </li>
          <li>
            <em>Simon Calvert</em>
          </li>
        </ul>
        <p>
Does any one sound familiar to you?<br /><br />
Anyway, nothing beats using reflector to figure out some of the more obscure interfaces.
Unfortunately, it is also the slowest method. 
</p>
        <img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=1d9cf157-2c6c-4ec4-b45a-7dc724543c28" />
      </body>
      <title>Unexpected source of information</title>
      <guid isPermaLink="false">http://www.manuelabadia.com/blog/PermaLink,guid,1d9cf157-2c6c-4ec4-b45a-7dc724543c28.aspx</guid>
      <link>http://www.manuelabadia.com/blog/PermaLink,guid,1d9cf157-2c6c-4ec4-b45a-7dc724543c28.aspx</link>
      <pubDate>Sat, 24 Nov 2007 09:56:41 GMT</pubDate>
      <description>&lt;p&gt;
If you have worked with the design time infrastructure you will know that there are
parts of it that are poorly documented.
&lt;/p&gt;
&lt;p&gt;
To complement MSDN&amp;nbsp;help and internet searches you can try another source of information: &lt;strong&gt;patents&lt;/strong&gt;.
&lt;/p&gt;
&lt;p&gt;
Most big companies like to patent a lot of stuff so I stumbled upon &lt;a href="http://www.freepatentsonline.com/20050251380.html"&gt;this
patent&lt;/a&gt; that has some good information about design time. The&amp;nbsp;inventors of
the patent are:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;Andrew Cheng-Min Lin&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Bulusu Krishna Mohan&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Nikhil Kothari&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Simon Calvert&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Does any one&amp;nbsp;sound familiar to you?&lt;br&gt;
&lt;br&gt;
Anyway, nothing beats using reflector to figure out some of the more obscure interfaces.
Unfortunately, it is also the slowest method. 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=1d9cf157-2c6c-4ec4-b45a-7dc724543c28" /&gt;</description>
      <comments>http://www.manuelabadia.com/blog/CommentView,guid,1d9cf157-2c6c-4ec4-b45a-7dc724543c28.aspx</comments>
      <category>ASP.NET;Microsoft .NET Framework</category>
    </item>
    <item>
      <trackback:ping>http://www.manuelabadia.com/blog/Trackback.aspx?guid=80742d4d-e250-44cb-8488-6b7cf4b63986</trackback:ping>
      <pingback:server>http://www.manuelabadia.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.manuelabadia.com/blog/PermaLink,guid,80742d4d-e250-44cb-8488-6b7cf4b63986.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://www.manuelabadia.com/blog/CommentView,guid,80742d4d-e250-44cb-8488-6b7cf4b63986.aspx</wfw:comment>
      <wfw:commentRss>http://www.manuelabadia.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=80742d4d-e250-44cb-8488-6b7cf4b63986</wfw:commentRss>
      <slash:comments>3</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
One of the coolest tools I have been using for the lasts months is DocProject:
</p>
        <p>
          <a href="http://www.codeplex.com/DocProject/">http://www.codeplex.com/DocProject/</a>
        </p>
        <p>
DocProject generates documentation from an xml comment file using sandcastle. The
generated documentation can be a precompiled help file (help 1.x or help 2.x) or a
web site. 
</p>
        <p>
There are other tools that serve as a friendly GUI for sandcastle but DocProject integrates
great with Visual Studio 2005 (and 2008) and lets you create and maintain the documentation
without effort.
</p>
        <p>
When DocProject is installed, two new project types will show in the “New Project
Dialog”:
</p>
        <p>
• Project Documentation: that lets you generate a precompiled help file.<br />
• DocSite Web Application: that creates a web site with the documentation.<br /></p>
        <p>
          <img src="http://www.manuelabadia.com/blog/content/binary/docproject1.png" border="0" />
        </p>
        <p>
When you select one of those project types, it will ask you for which projects you
want to generate the documentation, and basically that is all that you need to get
DocProject working (of course you need to generate the xml comment file for the projects
you want to document, so be sure to have the checkbox at “Build -&gt; Output -&gt;
XML documentation file” enabled in the project properties.
</p>
        <p>
You can configure a lot of options when generating the documentation. To do that you
have to click in Tool-&gt;Options-&gt;DocProject. I won’t detail the options, but
it is really straightforward to use. The only thing I miss is that this can’t be done
in the project properties for the projects created by DocProject.
</p>
        <p>
There are several styles available for the generated documentation. Here is a pic
of a precompiled help file of the one I’m using:
</p>
        <p>
          <img src="http://www.manuelabadia.com/blog/content/binary/docproject2.png" border="0" />
        </p>
        <p>
You can take a look at a website that uses DocProject here:
</p>
        <p>
          <a href="http://docs.mbunit.com/">http://docs.mbunit.com/</a>
        </p>
        <p>
If you compile often (as I do) you will see that generating the documentation takes
a long time so probably you’ll want to exclude the generation of the documentation
when you compile (Build-&gt;Configuration Manager-&gt;uncheck the build from the documentation
project) and build it when you really need it or if you have use a continuous integration
server, let it do the work for you.
</p>
        <p>
So the only excuse now to not have good documentation for your projects is being lazy.
</p>
        <img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=80742d4d-e250-44cb-8488-6b7cf4b63986" />
      </body>
      <title>DocProject</title>
      <guid isPermaLink="false">http://www.manuelabadia.com/blog/PermaLink,guid,80742d4d-e250-44cb-8488-6b7cf4b63986.aspx</guid>
      <link>http://www.manuelabadia.com/blog/PermaLink,guid,80742d4d-e250-44cb-8488-6b7cf4b63986.aspx</link>
      <pubDate>Thu, 15 Nov 2007 22:58:43 GMT</pubDate>
      <description>&lt;p&gt;
One of the coolest tools I have been using for the lasts months is DocProject:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.codeplex.com/DocProject/"&gt;http://www.codeplex.com/DocProject/&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
DocProject generates documentation from an xml comment file using sandcastle. The
generated documentation can be a precompiled help file (help 1.x or help 2.x) or a
web site. 
&lt;/p&gt;
&lt;p&gt;
There are other tools that serve as a friendly GUI for sandcastle but DocProject integrates
great with Visual Studio 2005 (and 2008) and lets you create and maintain the documentation
without effort.
&lt;/p&gt;
&lt;p&gt;
When DocProject is installed, two new project types will show in the “New Project
Dialog”:
&lt;/p&gt;
&lt;p&gt;
•&amp;nbsp;Project Documentation: that lets you generate a precompiled help file.&lt;br&gt;
•&amp;nbsp;DocSite Web Application: that creates a web site with the documentation.&lt;br&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://www.manuelabadia.com/blog/content/binary/docproject1.png" border=0&gt;
&lt;/p&gt;
&lt;p&gt;
When you select one of those project types, it will ask you for which projects you
want to generate the documentation, and basically that is all that you need to get
DocProject working (of course you need to generate the xml comment file for the projects
you want to document, so be sure to have the checkbox at “Build -&amp;gt; Output -&amp;gt;
XML documentation file” enabled in the project properties.
&lt;/p&gt;
&lt;p&gt;
You can configure a lot of options when generating the documentation. To do that you
have to click in Tool-&amp;gt;Options-&amp;gt;DocProject. I won’t detail the options, but
it is really straightforward to use. The only thing I miss is that this can’t be done
in the project properties for the projects created by DocProject.
&lt;/p&gt;
&lt;p&gt;
There are several styles available for the generated documentation. Here is a pic
of a precompiled help file of the one I’m using:
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://www.manuelabadia.com/blog/content/binary/docproject2.png" border=0&gt;
&lt;/p&gt;
&lt;p&gt;
You can take a look at a website that uses DocProject here:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://docs.mbunit.com/"&gt;http://docs.mbunit.com/&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
If you compile often (as I do) you will see that generating the documentation takes
a long time so probably you’ll want to exclude the generation of the documentation
when you compile (Build-&amp;gt;Configuration Manager-&amp;gt;uncheck the build from the documentation
project) and build it when you really need it or if you have use a continuous integration
server, let it do the work for you.
&lt;/p&gt;
&lt;p&gt;
So the only excuse now to not have good documentation for your projects is being lazy.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=80742d4d-e250-44cb-8488-6b7cf4b63986" /&gt;</description>
      <comments>http://www.manuelabadia.com/blog/CommentView,guid,80742d4d-e250-44cb-8488-6b7cf4b63986.aspx</comments>
      <category>Microsoft .NET Framework;Visual Studio</category>
    </item>
    <item>
      <trackback:ping>http://www.manuelabadia.com/blog/Trackback.aspx?guid=6933d7ba-0d2b-4e3f-b5f2-8e1514a2b938</trackback:ping>
      <pingback:server>http://www.manuelabadia.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.manuelabadia.com/blog/PermaLink,guid,6933d7ba-0d2b-4e3f-b5f2-8e1514a2b938.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://www.manuelabadia.com/blog/CommentView,guid,6933d7ba-0d2b-4e3f-b5f2-8e1514a2b938.aspx</wfw:comment>
      <wfw:commentRss>http://www.manuelabadia.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=6933d7ba-0d2b-4e3f-b5f2-8e1514a2b938</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
From time to time I like to evaluate the way I’m working, investigate on new alternatives,
try other approaches, etc. in order to improve the way I do things. Other times, I
have to change the way I do some things by necessity. This time was a bit of both.
The number of components I’m selling on my web page <a href="http://www.manuelabadia.com">www.manuelabadia.com</a> is
growing slowly and some things I was doing by hand were a pain to maintain and started
to take too much time, so a change was really needed. Also, in the development area,
things were also getting more complex.
</p>
        <p>
Distribution of the components by mail is a lot less reliable than I thought as some
companies have really strict firewall/attachment policies. Implementing a decent LicenseProvider
based on digital signature was more complex than I thought, has some hurdles with
ASP.NET and works a bit different between web site projects and web application projects.
However, having the LicenseProvider implemented has freed me of all component distribution
and signing, saving a lot of time and headaches.
</p>
        <p>
Maintaining and developing new components was also getting more complicated, because
components were starting to share code, and having to maintain two versions of the
same code is problematic and error prone. However, splitting the components in several
projects and then using ILMerge seems to work great. Improving my subversion merge/branch
skills was also necessary as I end with a lot of releases with a very similar codebase
but with little differences between them. Better tool integration for ordinary tasks
with Visual Studio has also helped a lot. I’ll comment about a few of these tools
in a future.
</p>
        <p>
There seem to be a lot of good tools emerging with a goal to improve the quality and
reliability of our code. Microsoft research is also trying some things with Spec#
and Pex. Maybe I’ll blog about those when Pex becomes available to the masses.
</p>
        <p>
So what about the future? Well, I have a lot of ideas for new components and new features
for the existing ones. As always, the biggest problem is time. There’s no time to
do all the stuff I have in mind or the cool things I want to try (has anybody tried <a href="http://www.codeplex.com/SharpMap">SharpMap</a>?)
I have a component in the works that has been nearly finished for a couple of months.
I hope to finish it at the end of the year or in January 2008. After that probably
I’ll concentrate on further improving the existing components and checking if something
new can be added if the version of ASP.NET shipped Visual Studio 2008 has a couple
of significant changes. After that probably I won’t release more components because
I can’t be sure to be able to provide a good service if I release more components.<br />
 <br />
As I said before, the sales are growing slowly, and the components are being used
in most of the “important” countries:
</p>
        <p>
          <img src="http://www.manuelabadia.com/blog/content/binary/products_in_the_world.png" border="0" />
        </p>
        <p>
This shows me that I’m doing things well and encourages me to work harder and keep
improving my skills.
</p>
        <img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=6933d7ba-0d2b-4e3f-b5f2-8e1514a2b938" />
      </body>
      <title>Continuous Evolution</title>
      <guid isPermaLink="false">http://www.manuelabadia.com/blog/PermaLink,guid,6933d7ba-0d2b-4e3f-b5f2-8e1514a2b938.aspx</guid>
      <link>http://www.manuelabadia.com/blog/PermaLink,guid,6933d7ba-0d2b-4e3f-b5f2-8e1514a2b938.aspx</link>
      <pubDate>Thu, 01 Nov 2007 23:04:32 GMT</pubDate>
      <description>&lt;p&gt;
From time to time I like to evaluate the way I’m working, investigate on new alternatives,
try other approaches, etc. in order to improve the way I do things. Other times, I
have to change the way I do some things by necessity. This time was a bit of both.
The number of components I’m selling on my web page &lt;a href="http://www.manuelabadia.com"&gt;www.manuelabadia.com&lt;/a&gt; is
growing slowly and some things I was doing by hand were a pain to maintain and started
to take too much time, so a change was really needed. Also, in the development area,
things were also getting more complex.
&lt;/p&gt;
&lt;p&gt;
Distribution of the components by mail is a lot less reliable than I thought as some
companies have really strict firewall/attachment policies. Implementing a decent LicenseProvider
based on digital signature was more complex than I thought, has some hurdles with
ASP.NET and works a bit different between web site projects and web application projects.
However, having the LicenseProvider implemented has freed me of all component distribution
and signing, saving a lot of time and headaches.
&lt;/p&gt;
&lt;p&gt;
Maintaining and developing new components was also getting more complicated, because
components were starting to share code, and having to maintain two versions of the
same code is problematic and error prone. However, splitting the components in several
projects and then using ILMerge seems to work great. Improving my subversion merge/branch
skills was also necessary as I end with a lot of releases with a very similar codebase
but with little differences between them. Better tool integration for ordinary tasks
with Visual Studio has also helped a lot. I’ll comment about a few of these tools
in a future.
&lt;/p&gt;
&lt;p&gt;
There seem to be a lot of good tools emerging with a goal to improve the quality and
reliability of our code. Microsoft research is also trying some things with Spec#
and Pex. Maybe I’ll blog about those when Pex becomes available to the masses.
&lt;/p&gt;
&lt;p&gt;
So what about the future? Well, I have a lot of ideas for new components and new features
for the existing ones. As always, the biggest problem is time. There’s no time to
do all the stuff I have in mind or the cool things I want to try (has anybody tried &lt;a href="http://www.codeplex.com/SharpMap"&gt;SharpMap&lt;/a&gt;?)
I have a component in the works that has been nearly finished for a couple of months.
I hope to finish it at the end of the year or in January 2008. After that probably
I’ll concentrate on further improving the existing components and checking if something
new can be added if the version of ASP.NET shipped Visual Studio 2008 has a couple
of significant changes. After that probably I won’t release more components because
I can’t be sure to be able to provide a good service if I release more components.&lt;br&gt;
&amp;nbsp;&lt;br&gt;
As I said before, the sales are growing slowly, and the components are being used
in most of the “important” countries:
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://www.manuelabadia.com/blog/content/binary/products_in_the_world.png" border=0&gt;
&lt;/p&gt;
&lt;p&gt;
This shows me that I’m doing things well and encourages me to work harder and keep
improving my skills.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=6933d7ba-0d2b-4e3f-b5f2-8e1514a2b938" /&gt;</description>
      <comments>http://www.manuelabadia.com/blog/CommentView,guid,6933d7ba-0d2b-4e3f-b5f2-8e1514a2b938.aspx</comments>
      <category>ASP.NET;General;Microsoft .NET Framework;Visual Studio</category>
    </item>
    <item>
      <trackback:ping>http://www.manuelabadia.com/blog/Trackback.aspx?guid=27e22b2c-af95-4f4c-befd-1debc5841735</trackback:ping>
      <pingback:server>http://www.manuelabadia.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.manuelabadia.com/blog/PermaLink,guid,27e22b2c-af95-4f4c-befd-1debc5841735.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://www.manuelabadia.com/blog/CommentView,guid,27e22b2c-af95-4f4c-befd-1debc5841735.aspx</wfw:comment>
      <wfw:commentRss>http://www.manuelabadia.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=27e22b2c-af95-4f4c-befd-1debc5841735</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Due to lack of time I haven’t been able to make a sample website showing a complete
usage scenario for my NHibernate custom Membership and Role providers. However, as
there are nearly 100 downloads per month and there is some people using it I’m uploading
a new version. The changes from the latest release are:
</p>
        <ul dir="ltr">
          <li>
            <div style="MARGIN-RIGHT: 0px">Fixed an important bug that didn’t prevent locked out
users from login in.
</div>
          </li>
          <li>
            <div style="MARGIN-RIGHT: 0px">Added a CreateUserWizardEx control that allows creating
a user with extra information in an easy way.
</div>
          </li>
          <li>
            <div style="MARGIN-RIGHT: 0px">Added auto unlock support.
</div>
          </li>
          <li>
            <div style="MARGIN-RIGHT: 0px">Fixed some minor bugs/typos.
</div>
          </li>
        </ul>
        <p>
I’ll detail a bit the new features. The standard CreateUserWizard control generates
an event before creating the user (CreatingUser) and one after the user has been created
(CreatedUser). Somewhere between these two events the control calls the CreateUser
method of the membership provider. The CreateUserWizardEx control extends the CreateUserWizard
that ship with ASP.NET 2.0. It is supposed to be used when you want to insert a user
in the system without using the CreateUser method of the membership provider (for
example, because you want to store more data in the database).<br />
 <br />
The CreateUserWizardEx control adds a CreateUserEx event. You should handle this event,
retrieve all the information for the new user and make the insert in your users table
manually (as the provider interface can’t handle extra data). This event will be generated
after all the password checking and generation have been made, so you only have to
insert the user in the database. When you handle this event, you’ll be passed an instance
of the CreateUserExEventArgs class. This class has 3 properties: EncodedPassword,
EncodedPasswordSalt and EncodedPasswordAnswer that are useful if you’re not storing
the sensitive data in plain text. After the CreateUserEx event is generated, the CreatedUser
event is also generated.
</p>
        <p>
There is one little problem with the CreateUserWizardEx control. Because quite a bit
ASP.NET classes (especially controls) haven’t been designed with extensibility in
mind, it is impossible to override some of the behavior of the CreateUserWizard control
to achieve the desired result. In this particular case I can’t make the control to
skip the CreateUser call to the membership provider in any way without rewriting the
full control (the CreateUserWizard is one of the lengthiest controls in ASP.NET this
is not an option). So the only solution without compromising medium trust scenarios
is to ignore the CreateUser method calls in case you plan to insert the users manually.
To do this you have to set the provider attribute ignoreCreateUserMethod to true.
If the CreateUserWizard control is ever rewritten with extensibility in mind this
hack could be removed, but I don’t think that will happen anytime. I posted about
similar lack of extensibility problems here.
</p>
        <p>
The auto unlock feature is useful if you use locking. If a user fails entering the
password several times in a predefined period of time (specified by the maxInvalidPasswordAttempts
and passwordAttemptWindow properties) his account gets locked out. However, you need
human interaction in order to unlock the user.
</p>
        <p>
If the auto unlock feature is enabled, when a locked user tries to log on the system,
if the data supplied is correct and a certain period of time has passed since the
account was locked out, the provider automatically unlocks the account. To enable
auto unlocking you have to specify enableAutoUnlock="true" in the web.config. The
provider property autoUnlockMinutes controls the minium period of time to wait since
the last failed login to be able to auto unlock an account. The default is 30 minutes.
Note that setting this value too low can make the security benefits of having a lockout
feature disappear.
</p>
        <p>
I’m thinking in adding some code to enforce single user log on for the next version
as time permits (don’t expect this to be implemented in 2007).
</p>
        <p>
As always, feedback is welcome. As the previous version, it has been tested only in
SQL Server 2005. Let me know if you try it in other databases. 
</p>
        <p>
You can <a href="http://www.manuelabadia.com/blog/PermaLink,guid,3b6ccb3f-2f2a-4dcb-a414-605371a00618.aspx">download
the providers here</a>.
</p>
        <img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=27e22b2c-af95-4f4c-befd-1debc5841735" />
      </body>
      <title>Custom Membership and Role Providers using NHibernate Update</title>
      <guid isPermaLink="false">http://www.manuelabadia.com/blog/PermaLink,guid,27e22b2c-af95-4f4c-befd-1debc5841735.aspx</guid>
      <link>http://www.manuelabadia.com/blog/PermaLink,guid,27e22b2c-af95-4f4c-befd-1debc5841735.aspx</link>
      <pubDate>Fri, 12 Oct 2007 14:58:30 GMT</pubDate>
      <description>&lt;p&gt;
Due to lack of time I haven’t been able to make a sample website showing a complete
usage scenario for my NHibernate custom Membership and Role providers. However, as
there are nearly 100 downloads per month and there is some people using it I’m uploading
a new version. The changes from the latest release are:
&lt;/p&gt;
&lt;ul dir=ltr&gt;
&lt;li&gt;
&lt;div style="MARGIN-RIGHT: 0px"&gt;Fixed an important bug that didn’t prevent locked out
users from login in.
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;div style="MARGIN-RIGHT: 0px"&gt;Added a CreateUserWizardEx control that allows creating
a user with extra information in an easy way.
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;div style="MARGIN-RIGHT: 0px"&gt;Added auto unlock support.
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;div style="MARGIN-RIGHT: 0px"&gt;Fixed some minor bugs/typos.
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
I’ll detail a bit the new features. The standard CreateUserWizard control generates
an event before creating the user (CreatingUser) and one after the user has been created
(CreatedUser). Somewhere between these two events the control calls the CreateUser
method of the membership provider. The CreateUserWizardEx control extends the CreateUserWizard
that ship with ASP.NET 2.0. It is supposed to be used when you want to insert a user
in the system without using the CreateUser method of the membership provider (for
example, because you want to store more data in the database).&lt;br&gt;
&amp;nbsp;&lt;br&gt;
The CreateUserWizardEx control adds a CreateUserEx event. You should handle this event,
retrieve all the information for the new user and make the insert in your users table
manually (as the provider interface can’t handle extra data). This event will be generated
after all the password checking and generation have been made, so you only have to
insert the user in the database. When you handle this event, you’ll be passed an instance
of the CreateUserExEventArgs class. This class has 3 properties: EncodedPassword,
EncodedPasswordSalt and EncodedPasswordAnswer that are useful if you’re not storing
the sensitive data in plain text. After the CreateUserEx event is generated, the CreatedUser
event is also generated.
&lt;/p&gt;
&lt;p&gt;
There is one little problem with the CreateUserWizardEx control. Because quite a bit
ASP.NET classes (especially controls) haven’t been designed with extensibility in
mind, it is impossible to override some of the behavior of the CreateUserWizard control
to achieve the desired result. In this particular case I can’t make the control to
skip the CreateUser call to the membership provider in any way without rewriting the
full control (the CreateUserWizard is one of the lengthiest controls in ASP.NET this
is not an option). So the only solution without compromising medium trust scenarios
is to ignore the CreateUser method calls in case you plan to insert the users manually.
To do this you have to set the provider attribute ignoreCreateUserMethod to true.
If the CreateUserWizard control is ever rewritten with extensibility in mind this
hack could be removed, but I don’t think that will happen anytime. I posted about
similar lack of extensibility problems here.
&lt;/p&gt;
&lt;p&gt;
The auto unlock feature is useful if you use locking. If a user fails entering the
password several times in a predefined period of time (specified by the maxInvalidPasswordAttempts
and passwordAttemptWindow properties) his account gets locked out. However, you need
human interaction in order to unlock the user.
&lt;/p&gt;
&lt;p&gt;
If the auto unlock feature is enabled, when a locked user tries to log on the system,
if the data supplied is correct and a certain period of time has passed since the
account was locked out, the provider automatically unlocks the account. To enable
auto unlocking you have to specify enableAutoUnlock="true" in the web.config. The
provider property autoUnlockMinutes controls the minium period of time to wait since
the last failed login to be able to auto unlock an account. The default is 30 minutes.
Note that setting this value too low can make the security benefits of having a lockout
feature disappear.
&lt;/p&gt;
&lt;p&gt;
I’m thinking in adding some code to enforce single user log on for the next version
as time permits (don’t expect this to be implemented in 2007).
&lt;/p&gt;
&lt;p&gt;
As always, feedback is welcome. As the previous version, it has been tested only in
SQL Server 2005. Let me know if you try it in other databases. 
&lt;/p&gt;
&lt;p&gt;
You can &lt;a href="http://www.manuelabadia.com/blog/PermaLink,guid,3b6ccb3f-2f2a-4dcb-a414-605371a00618.aspx"&gt;download
the providers here&lt;/a&gt;.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=27e22b2c-af95-4f4c-befd-1debc5841735" /&gt;</description>
      <comments>http://www.manuelabadia.com/blog/CommentView,guid,27e22b2c-af95-4f4c-befd-1debc5841735.aspx</comments>
      <category>ASP.NET;Microsoft .NET Framework;NHibernate</category>
    </item>
    <item>
      <trackback:ping>http://www.manuelabadia.com/blog/Trackback.aspx?guid=7b1f65da-71b7-4d35-8680-6305c908c840</trackback:ping>
      <pingback:server>http://www.manuelabadia.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.manuelabadia.com/blog/PermaLink,guid,7b1f65da-71b7-4d35-8680-6305c908c840.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://www.manuelabadia.com/blog/CommentView,guid,7b1f65da-71b7-4d35-8680-6305c908c840.aspx</wfw:comment>
      <wfw:commentRss>http://www.manuelabadia.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=7b1f65da-71b7-4d35-8680-6305c908c840</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Something that is really annoying is the list of little bugs or problems that pollute
the .NET Framework and doesn’t seem to get fixed (mostly because of remotely backward
compatibility reasons). Others problems are simple solved as “won’t fix“, without
giving any explanation. 
</p>
        <p>
For example, take a look at this one:
</p>
        <p>
          <a href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=94108">https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=94108</a>
        </p>
        <p>
If you use a TreeView, invalid XHTML gets generated because a script tag is added
without specifying the type. They only need to add type="text/javascript" to the generated
script. It is clearly a bug and it won’t break anything. However, it is marked as
“won’t fix”. WTF?
</p>
        <p>
Sometimes one can be lucky and they actually fix the bug (or at least they told you
that they will fix it) but this seems to be the exception rather than the rule. For
example, I submitted this bug some time ago and it seems it will be fixed:
</p>
        <p>
          <a href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=265321">https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=265321</a>
        </p>
        <p>
However, the list of unresolved issues that clearly need to be fixed is big and growing,
but a lot of them aren't addressed. IMHO this should change. I prefer to have
a remote possibility of having something that works to stop working because of bug
fixes than keep going with thousand of bugs and work arounds for not solving them.
Also, I'd like to have updates more often. To wait a year for a service pack for the
framework is too much.
</p>
        <img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=7b1f65da-71b7-4d35-8680-6305c908c840" />
      </body>
      <title>Microsoft bug fixing policies</title>
      <guid isPermaLink="false">http://www.manuelabadia.com/blog/PermaLink,guid,7b1f65da-71b7-4d35-8680-6305c908c840.aspx</guid>
      <link>http://www.manuelabadia.com/blog/PermaLink,guid,7b1f65da-71b7-4d35-8680-6305c908c840.aspx</link>
      <pubDate>Wed, 13 Jun 2007 14:09:57 GMT</pubDate>
      <description>&lt;p&gt;
Something that is really annoying is the list of little bugs or problems that pollute
the .NET Framework and doesn’t seem to get fixed (mostly because of remotely backward
compatibility reasons). Others problems are simple solved as “won’t fix“, without
giving any explanation. 
&lt;/p&gt;
&lt;p&gt;
For example, take a look at this one:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=94108"&gt;https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=94108&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
If you use a TreeView, invalid XHTML gets generated because a script tag is added
without specifying the type. They only need to add type="text/javascript" to the generated
script. It is clearly a bug and it won’t break anything. However, it is marked as
“won’t fix”. WTF?
&lt;/p&gt;
&lt;p&gt;
Sometimes one can be lucky and they actually fix the bug (or at least they told you
that they will fix it) but this seems to be the exception rather than the rule. For
example, I submitted this bug some time ago and it seems it will be fixed:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=265321"&gt;https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=265321&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
However, the list of unresolved issues that clearly need to be fixed is big and growing,
but a lot of them aren't addressed. IMHO this should change.&amp;nbsp;I prefer to have
a remote possibility of having something that works to stop working because of bug
fixes than keep going with thousand of bugs and work arounds for not solving them.
Also, I'd like to have updates more often. To wait a year for a service pack for the
framework is too much.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=7b1f65da-71b7-4d35-8680-6305c908c840" /&gt;</description>
      <comments>http://www.manuelabadia.com/blog/CommentView,guid,7b1f65da-71b7-4d35-8680-6305c908c840.aspx</comments>
      <category>ASP.NET;Microsoft .NET Framework</category>
    </item>
    <item>
      <trackback:ping>http://www.manuelabadia.com/blog/Trackback.aspx?guid=9160035f-490f-46bd-ab55-516b5c7545af</trackback:ping>
      <pingback:server>http://www.manuelabadia.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.manuelabadia.com/blog/PermaLink,guid,9160035f-490f-46bd-ab55-516b5c7545af.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://www.manuelabadia.com/blog/CommentView,guid,9160035f-490f-46bd-ab55-516b5c7545af.aspx</wfw:comment>
      <wfw:commentRss>http://www.manuelabadia.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=9160035f-490f-46bd-ab55-516b5c7545af</wfw:commentRss>
      <slash:comments>11</slash:comments>
      <title>Linq Expressions DebuggerVisualizer</title>
      <guid isPermaLink="false">http://www.manuelabadia.com/blog/PermaLink,guid,9160035f-490f-46bd-ab55-516b5c7545af.aspx</guid>
      <link>http://www.manuelabadia.com/blog/PermaLink,guid,9160035f-490f-46bd-ab55-516b5c7545af.aspx</link>
      <pubDate>Tue, 24 Apr 2007 12:05:10 GMT</pubDate>
      <description>&lt;p&gt;
I have been playing a bit with Visual Studio "Orcas" Beta 1 and I really wanted to
see the Expression Trees generated by Linq, so it was a good chance to play with my &lt;a href="http://www.manuelabadia.com/products/StructsViz_features.aspx"&gt;StructsViz
component&lt;/a&gt;. In a couple of hours I got this DebuggerVisualizer working. 
&lt;/p&gt;
&lt;p&gt;
For the following expressions:
&lt;/p&gt;
&lt;p style="FONT-SIZE: 10pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;span style="COLOR: #2b91af"&gt;Expression&lt;/span&gt;&lt;&lt;SPAN style="COLOR: #2b91af"&gt;Func&gt;&lt;&lt;SPAN style="COLOR: #2b91af"&gt;Person&gt;, &lt;span style="COLOR: blue"&gt;bool&lt;/span&gt;&gt;&gt;
expr1;
&lt;/p&gt;
&lt;p dir=ltr style="FONT-SIZE: 10pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;span style="COLOR: #2b91af"&gt;Expression&lt;/span&gt;&lt;&lt;SPAN style="COLOR: #2b91af"&gt;Func&gt;&lt;&lt;SPAN style="COLOR: blue"&gt;int&gt;, &lt;span style="COLOR: blue"&gt;string&lt;/span&gt;, &lt;span style="COLOR: blue"&gt;bool&lt;/span&gt;&gt;&gt;
expr2;
&lt;/p&gt;
&lt;p dir=ltr style="FONT-SIZE: 10pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;/p&gt;
&lt;p dir=ltr style="FONT-SIZE: 10pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New"&gt;
expr1 = p =&gt; p.Name == &lt;span style="COLOR: #a31515"&gt;"Manu"&lt;/span&gt;;
&lt;/p&gt;
&lt;p dir=ltr style="FONT-SIZE: 10pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New"&gt;&lt;= 0) || (str.Length &gt;
expr2 = (idx, str) =&gt; !((idx 2));
&lt;/p&gt;
&lt;!--EndFragment--&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
The visualizer renders the following:
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://www.manuelabadia.com/blog/content/binary/expr1.PNG" border=0&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://www.manuelabadia.com/blog/content/binary/expr2.PNG" border=0&gt;
&lt;/p&gt;
&lt;p&gt;
The nodes in red are terminal expressions (constants or parameters), the nodes in
green are objects used by the expression subtree, and the other expression nodes are
blue. The properties and fields for each node are loaded on demand and can be inspected
when the node is expanded.
&lt;/p&gt;
&lt;p&gt;
As expression trees are used to do really cool things I have made a free special version
of StructsViz with only the functionaly needed to display expression trees. Due to
the crappy NVidia drivers for Vista I haven't been able to test it extensively (as
my hard disk stops from time to time, specially with Virtual PC) so let me know if
there is any problem. As always, feedback is welcome.
&lt;/p&gt;
&lt;p&gt;
To read more about Linq take a look at &lt;a href="http://msdn2.microsoft.com/en-us/library/aa479865.aspx"&gt;this
article&lt;/a&gt; or at &lt;a href="http://weblogs.asp.net/scottgu"&gt;ScottGu's excellent posts
about Linq&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
To use the DebuggerVisualizer, create a Visualizers folder inside C:\Documents and
Settings\Administrator\My Documents\Visual Studio 2008, and copy the LinqExpressionVisualizer.dll
there.
&lt;/p&gt;
&lt;p&gt;
Another option is to copy the visualizer to C:\Program FIles\Microsoft Visual Studio
9.0\Common7\Packages\Debugger\Visualizers
&lt;/p&gt;
&lt;p&gt;
Please do not distribute the visualizer from your web page. Link to this page instead.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Update 13/01/2008&lt;/strong&gt;: 
&lt;/p&gt;
&lt;p&gt;
Modified it to run on VS 2008 RTM.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.manuelabadia.com/blog/content/binary/LinqExpressionDebuggerVisualizer.zip"&gt;LinqExpressionDebuggerVisualizer.zip
(33.4 KB)&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Update 31/08/2010&lt;/strong&gt;: 
&lt;/p&gt;
&lt;p&gt;
Modified it to run on VS 2010 RTM.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.manuelabadia.com/blog/content/binary/LinqExpressionVisualizer_VS2010.zip"&gt;LinqExpressionVisualizer_VS2010.zip
(41,37 KB)&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=9160035f-490f-46bd-ab55-516b5c7545af" /&gt;</description>
      <comments>http://www.manuelabadia.com/blog/CommentView,guid,9160035f-490f-46bd-ab55-516b5c7545af.aspx</comments>
      <category>Linq;Microsoft .NET Framework</category>
    </item>
    <item>
      <trackback:ping>http://www.manuelabadia.com/blog/Trackback.aspx?guid=3b6ccb3f-2f2a-4dcb-a414-605371a00618</trackback:ping>
      <pingback:server>http://www.manuelabadia.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.manuelabadia.com/blog/PermaLink,guid,3b6ccb3f-2f2a-4dcb-a414-605371a00618.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://www.manuelabadia.com/blog/CommentView,guid,3b6ccb3f-2f2a-4dcb-a414-605371a00618.aspx</wfw:comment>
      <wfw:commentRss>http://www.manuelabadia.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=3b6ccb3f-2f2a-4dcb-a414-605371a00618</wfw:commentRss>
      <slash:comments>26</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Usually, the built-in providers for ASP.NET do not integrate very well with existing
applications. The membership provider has a very complex structure that in most cases
is not needed at all. The following diagram shows most of the tables and relations
for the built-in ASP.NET providers:
</p>
        <p>
          <img src="http://www.manuelabadia.com/blog/content/binary/providers.png" border="0" />
        </p>
        <p>
 
</p>
        <p>
The membership related tables are selected in red and the role related tables are
selected in blue. The default membership and roles provider have support to store
data for multiple applications using the aspnet_Applications table. I think this table
was introduced because some portal frameworks like dotnetnuke needed the ability to
store membership and role data for multiple users in a single store because they support
multiple portals. If you don't need this scenario (and most applications do not need
it), this only complicate things.
</p>
        <p>
Also, the built-in providers use tables that are not part of your application tables,
and some of those tables have quite a few columns, and probably some are not needed
by your application.
</p>
        <p>
If you do not use SQL Server, you can not use the default providers, so that is a
big showstopper.
</p>
        <p>
To overcome all of this problems I have created a custom membership and role provider
that use NHibernate and can be easily integrated with existing or future applications
using your own tables.
</p>
        <p>
The reference book about providers is:
</p>
        <p>
          <strong>
            <em>Professional ASP.NET 2.0 Security, Membership, and Role Management.</em>
          </strong>
        </p>
        <iframe style="WIDTH: 120px; HEIGHT: 240px" marginwidth="0" marginheight="0" src="http://rcm.amazon.com/e/cm?t=manuelabadias-20&amp;o=1&amp;p=8&amp;l=as1&amp;asins=0764596985&amp;fc1=000000&amp;IS2=1&amp;lt1=_blank&amp;lc1=0000FF&amp;bc1=000000&amp;bg1=FFFFFF&amp;f=ifr" frameborder="0" scrolling="no">
        </iframe>
        <p>
I suggest you to read it if you really want to get deep into providers as it is an
excellent book.
</p>
        <p>
The NHCustomMembershipProvider uses NHibernate to do all membership related database
operations so it should work on all databases supported by NHibernate. The membership
data will be stored and retrieved from a table configured in the provider section
in the web.config so you can map it to an existing table like users. The column names
for your user table can also be configured in the provider section. The cool thing
about the provider is that it adapts its behaviour to the number of columns supported
by your data store. For example, if you use the provider and map it to your users
table where you only have the membership data for userId, userName, password and email,
it will work without any problem. If your data store supports more advanced options
of the membership provider like account lockout, password question and answer, password
salt or last activity date, that advanced functionality will be automatically available,
but it is not required. 
</p>
        <p>
The provider knows what functionality to offer based on the number of columns that
are mapped to your data store. To support account lockout when the user do not supply
a valid password after some tries in a predefined period of time you need to map the
isLockedOutColumn, failedPasswordAttemptCountColumn and failedPasswordAttemptWindowStartColumn
to columns in your data store.
</p>
        <p>
The default configuration for the provider is to use integer identities or sequences
for the user identifier, but that can be changed using the userIdType and idGeneratorClass
properties in the provider configuration section.
</p>
        <p>
If you use the provider with an existing user table, probably you will create the
users manually without using the CreateUser method from the membership provider. The
provider exposes the methods CheckPasswordPolicy, ValidatePassword, EncodePassword
and GenerateSalt to allow manual creation of the user in case you need it, without
sacrifying password strength.
</p>
        <p>
To finish with the custom membership provider lets see an example. If you want to
use the membership provider with a table like this (that has columns for all supported
functionality):
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">CREATE TABLE </span>[dbo].[Users](
</p>
          <p style="MARGIN: 0px">
 [userId] [int] <span style="COLOR: blue">IDENTITY</span>(1,1) <span style="COLOR: blue">NOT
NULL</span>,
</p>
          <p style="MARGIN: 0px">
 [username] [nvarchar](50) <span style="COLOR: blue">NOT NULL</span>,
</p>
          <p style="MARGIN: 0px">
 [email] [nvarchar](100) <span style="COLOR: blue">NOT NULL</span>,
</p>
          <p style="MARGIN: 0px">
 [password] [nvarchar](256) <span style="COLOR: blue">NOT NULL</span>,
</p>
          <p style="MARGIN: 0px">
 [passwordSalt] [nvarchar](64) <span style="COLOR: blue">NULL</span>,
</p>
          <p style="MARGIN: 0px">
 [passwordFormat] [int] <span style="COLOR: blue">NOT NULL</span>,
</p>
          <p style="MARGIN: 0px">
 [passwordQuestion] [nvarchar](512) <span style="COLOR: blue">NOT NULL</span>,
</p>
          <p style="MARGIN: 0px">
 [passwordAnswer] [nvarchar](512) <span style="COLOR: blue">NOT NULL</span>,
</p>
          <p style="MARGIN: 0px">
 [failedPasswordAttemptCount] [int] <span style="COLOR: blue">NOT NULL</span>,
</p>
          <p style="MARGIN: 0px">
 [failedPasswordAttemptWindowStart] [smalldatetime] <span style="COLOR: blue">NULL</span>,
</p>
          <p style="MARGIN: 0px">
 [failedPasswordAnswerAttemptCount] [int] <span style="COLOR: blue">NOT NULL</span>,
</p>
          <p style="MARGIN: 0px">
 [failedPasswordAnswerAttemptWindowStart] [smalldatetime] <span style="COLOR: blue">NULL</span>,
</p>
          <p style="MARGIN: 0px">
 [lastPasswordChangedDate] [smalldatetime] <span style="COLOR: blue">NULL</span>,
</p>
          <p style="MARGIN: 0px">
 [creationDate] [smalldatetime] <span style="COLOR: blue">NOT NULL</span>,
</p>
          <p style="MARGIN: 0px">
 [lastActivityDate] [smalldatetime] <span style="COLOR: blue">NOT NULL</span>,
</p>
          <p style="MARGIN: 0px">
 [isApproved] [bit] <span style="COLOR: blue">NOT NULL</span>,
</p>
          <p style="MARGIN: 0px">
 [isLockedOut] [bit] <span style="COLOR: blue">NOT NULL</span>,
</p>
          <p style="MARGIN: 0px">
 [lastLockOutDate] [smalldatetime] <span style="COLOR: blue">NULL</span>,
</p>
          <p style="MARGIN: 0px">
 [lastLoginDate] [smalldatetime] <span style="COLOR: blue">NULL</span>,
</p>
          <p style="MARGIN: 0px">
 [name] [nvarchar](256) <span style="COLOR: blue">NULL</span>,
</p>
          <p style="MARGIN: 0px">
 [surname] [nvarchar](256) <span style="COLOR: blue">NULL</span>,
</p>
          <p style="MARGIN: 0px">
 [address] [nvarchar](256) <span style="COLOR: blue">NULL</span>,
</p>
          <p style="MARGIN: 0px">
 [phone] [nvarchar](16) <span style="COLOR: blue">NULL</span>,
</p>
          <p style="MARGIN: 0px">
 [postalCode] [nvarchar](50) <span style="COLOR: blue">NULL</span>,
</p>
          <p style="MARGIN: 0px">
 [comments] [nvarchar](<span style="COLOR: blue">max</span>) <span style="COLOR: blue">NULL</span>,
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">CONSTRAINT </span>[PK_Users] <span style="COLOR: blue">PRIMARY
KEY CLUSTERED </span></p>
          <p style="MARGIN: 0px">
    (
</p>
          <p style="MARGIN: 0px">
    [userId] <span style="COLOR: blue">ASC</span></p>
          <p style="MARGIN: 0px">
    )
</p>
          <p style="MARGIN: 0px">
)
</p>
        </div>
        <p>
          <!--EndFragment-->
        </p>
        <p>
The configuration section for the membership provider will be something like this:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">&lt;</span>
            <span style="COLOR: #a31515">membership</span>
            <span style="COLOR: blue">
            </span>
            <span style="COLOR: red">defaultProvider</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">NHCustomMembershipProvider</span>"<span style="COLOR: blue">&gt;</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">  &lt;</span>
            <span style="COLOR: #a31515">providers</span>
            <span style="COLOR: blue">&gt;</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">    &lt;</span>
            <span style="COLOR: #a31515">add</span>
            <span style="COLOR: blue">
            </span>
            <span style="COLOR: red">name</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">NHCustomMembershipProvider</span>"<span style="COLOR: blue"></span><span style="COLOR: red">type</span><span style="COLOR: blue">=</span>"<span style="COLOR: blue">NHCustomProviders.NHCustomMembershipProvider,
NHCustomProviders</span>"
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        </span>
            <span style="COLOR: red">enablePasswordReset</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">true</span>"<span style="COLOR: blue"></span><span style="COLOR: red">enablePasswordRetrieval</span><span style="COLOR: blue">=</span>"<span style="COLOR: blue">true</span>"
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        </span>
            <span style="COLOR: red">minRequiredNonAlphanumericCharacters</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">1</span>"<span style="COLOR: blue"></span><span style="COLOR: red">minRequiredPasswordLength</span><span style="COLOR: blue">=</span>"<span style="COLOR: blue">6</span>"<span style="COLOR: blue"></span><span style="COLOR: red">passwordFormat</span><span style="COLOR: blue">=</span>"<span style="COLOR: blue">Encrypted</span>"
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        </span>
            <span style="COLOR: red">maxInvalidPasswordAttempts</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">5</span>"<span style="COLOR: blue"></span><span style="COLOR: red">passwordAttemptWindow</span><span style="COLOR: blue">=</span>"<span style="COLOR: blue">5</span>"
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        </span>
            <span style="COLOR: red">requiresQuestionAndAnswer</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">true</span>"
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        </span>
            <span style="COLOR: red">requiresUniqueEmail</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">false</span>"
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        </span>
            <span style="COLOR: red">tableName</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">USERS</span>"
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        </span>
            <span style="COLOR: red">userIdColumn</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">USERID</span>"
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        </span>
            <span style="COLOR: red">userIdType</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">Int32</span>"
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        </span>
            <span style="COLOR: red">idGeneratorClass</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">native</span>"
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        </span>
            <span style="COLOR: red">userNameColumn</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">USERNAME</span>"
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        </span>
            <span style="COLOR: red">emailColumn</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">EMAIL</span>"
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        </span>
            <span style="COLOR: red">passwordColumn</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">PASSWORD</span>"
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        </span>
            <span style="COLOR: red">passwordSaltColumn</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">PASSWORDSALT</span>"
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        </span>
            <span style="COLOR: red">passwordFormatColumn</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">PASSWORDFORMAT</span>"
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        </span>
            <span style="COLOR: red">passwordQuestionColumn</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">PASSWORDQUESTION</span>"
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        </span>
            <span style="COLOR: red">passwordAnswerColumn</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">PASSWORDANSWER</span>"
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        </span>
            <span style="COLOR: red">failedPasswordAttemptCountColumn</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">FAILEDPASSWORDATTEMPTCOUNT</span>"
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        </span>
            <span style="COLOR: red">failedPasswordAttemptWindowStartColumn</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">FAILEDPASSWORDATTEMPTWINDOWSTART</span>"
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        </span>
            <span style="COLOR: red">failedPasswordAnswerAttemptCountColumn</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">FAILEDPASSWORDANSWERATTEMPTCOUNT</span>"
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        </span>
            <span style="COLOR: red">failedPasswordAnswerAttemptWindowStartColumn</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">FAILEDPASSWORDANSWERATTEMPTWINDOWSTART</span>"
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        </span>
            <span style="COLOR: red">lastPasswordChangedDateColumn</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">LASTPASSWORDCHANGEDDATE</span>"
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        </span>
            <span style="COLOR: red">creationDateColumn</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">CREATIONDATE</span>"
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        </span>
            <span style="COLOR: red">lastActivityDateColumn</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">LASTACTIVITYDATE</span>"
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        </span>
            <span style="COLOR: red">isApprovedColumn</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">ISAPPROVED</span>"
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        </span>
            <span style="COLOR: red">isLockedOutColumn</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">ISLOCKEDOUT</span>"
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        </span>
            <span style="COLOR: red">lastLockOutDateColumn</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">LASTLOCKOUTDATE</span>"
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        </span>
            <span style="COLOR: red">lastLoginDateColumn</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">LASTLOGINDATE</span>"
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        </span>
            <span style="COLOR: red">commentsColumn</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">COMMENTS</span>"
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        </span>
            <span style="COLOR: red">userNameColumnSize</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">50</span>"
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        </span>
            <span style="COLOR: red">emailColumnSize</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">50</span>"
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        </span>
            <span style="COLOR: red">passwordColumnSize</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">256</span>"
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        </span>
            <span style="COLOR: red">passwordSaltColumnSize</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">64</span>"
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        </span>
            <span style="COLOR: red">passwordQuestionColumnSize</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">512</span>"
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        </span>
            <span style="COLOR: red">passwordAnswerColumnSize</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">512</span>"
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        </span>
            <span style="COLOR: red">passwordSaltSize</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">16</span>"
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        </span>
            <span style="COLOR: red">raiseSystemEvents</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">true</span>"
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        </span>
            <span style="COLOR: red">dynamicUpdate</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">true</span>"
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">    /&gt;</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">  &lt;/</span>
            <span style="COLOR: #a31515">providers</span>
            <span style="COLOR: blue">&gt;</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">&lt;/</span>
            <span style="COLOR: #a31515">membership</span>
            <span style="COLOR: blue">&gt;</span>
          </p>
        </div>
        <p>
          <!--EndFragment-->
          <br />
    
<br />
The column sizes are optional but it is a good practice to fill them.
</p>
        <p>
The built-in provider raises events after a succesfully or a failed login. However,
ASP.NET 2.0 does not allow to create or raise built-in health monitoring events, so
I had to use reflection in a private method in order to raise the same events. That
means that the provider will not run in medium trust if it is not installed in the
GAC if you want to raise the system events. As this can be a showstopper to some people
I have added an option to disable system events generation (raiseSystemEvents).
</p>
        <p>
The provider reads the config section and programatically generates a mapping for
the specified columns in the ConfigureNHibernate method. The provider expects that
you have configured NHibernate in the web.config to work. If you need extra configuration
for the provider you can inherit from the provider and use override the ConfigureNHibernate
method, modifying the Configuration object that the base class returns.
</p>
        <p>
The NHCustomRoleProvider is also configurable in order adapt to your own tables. It
only needs a Users table with id and user name columns, a roles table with id and
role name columns, and a join table used to store the information for the many-to-many
relationship between the users and roles.
</p>
        <p>
For example, if we the previous user table with the following tables (FKs omitted
for brevity):
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">CREATE TABLE </span>[dbo].[Roles](
</p>
          <p style="MARGIN: 0px">
    [roleId] [int] <span style="COLOR: blue">IDENTITY</span>(1,1) <span style="COLOR: blue">NOT
NULL</span>,
</p>
          <p style="MARGIN: 0px">
    [name] [nvarchar](50) <span style="COLOR: blue">NOT NULL</span>,
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">CONSTRAINT </span>[PK_Roles] <span style="COLOR: blue">PRIMARY
KEY CLUSTERED </span></p>
          <p style="MARGIN: 0px">
    (
</p>
          <p style="MARGIN: 0px">
       [roleId] <span style="COLOR: blue">ASC</span></p>
          <p style="MARGIN: 0px">
    )
</p>
          <p style="MARGIN: 0px">
)
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">CREATE TABLE </span>[dbo].[Users_In_Roles](
</p>
          <p style="MARGIN: 0px">
    [userId] [int] <span style="COLOR: blue">NOT NULL</span>,
</p>
          <p style="MARGIN: 0px">
    [roleId] [int] <span style="COLOR: blue">NOT NULL</span>,
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">CONSTRAINT </span>[PK_UsersInRoles] <span style="COLOR: blue">PRIMARY
KEY CLUSTERED </span></p>
          <p style="MARGIN: 0px">
    (
</p>
          <p style="MARGIN: 0px">
       [userId] <span style="COLOR: blue">ASC</span>,
</p>
          <p style="MARGIN: 0px">
       [roleId] <span style="COLOR: blue">ASC</span></p>
          <p style="MARGIN: 0px">
    )
</p>
          <p style="MARGIN: 0px">
)
</p>
        </div>
        <!--EndFragment-->
        <p>
 
</p>
        <p>
The configuration section for the role provider will be something like this:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">&lt;</span>
            <span style="COLOR: #a31515">roleManager</span>
            <span style="COLOR: blue">
            </span>
            <span style="COLOR: red">defaultProvider</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">NHCustomRoleProvider</span>"<span style="COLOR: blue"></span><span style="COLOR: red">enabled</span><span style="COLOR: blue">=</span>"<span style="COLOR: blue">true</span>"<span style="COLOR: blue">&gt;</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">  &lt;</span>
            <span style="COLOR: #a31515">providers</span>
            <span style="COLOR: blue">&gt;</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">    &lt;</span>
            <span style="COLOR: #a31515">add</span>
            <span style="COLOR: blue">
            </span>
            <span style="COLOR: red">name</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">NHCustomRoleProvider</span>"<span style="COLOR: blue"></span><span style="COLOR: red">type</span><span style="COLOR: blue">=</span>"<span style="COLOR: blue">NHCustomProviders.NHCustomRoleProvider,
NHCustomProviders</span>"
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        </span>
            <span style="COLOR: red">userTableName</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">USERS</span>"
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        </span>
            <span style="COLOR: red">userIdColumn</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">USERID</span>"
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        </span>
            <span style="COLOR: red">userIdType</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">Int32</span>"
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        </span>
            <span style="COLOR: red">userIdGeneratorClass</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">native</span>"
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        </span>
            <span style="COLOR: red">userNameColumn</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">USERNAME</span>"
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        </span>
            <span style="COLOR: red">roleTableName</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">ROLES</span>"
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        </span>
            <span style="COLOR: red">roleIdColumn</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">ROLEID</span>"
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        </span>
            <span style="COLOR: red">roleIdType</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">Int32</span>"
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        </span>
            <span style="COLOR: red">roleIdGeneratorClass</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">native</span>"
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        </span>
            <span style="COLOR: red">roleNameColumn</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">NAME</span>"
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        </span>
            <span style="COLOR: red">joinTableName</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">USERS_IN_ROLES</span>"
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        </span>
            <span style="COLOR: red">userNameColumnSize</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">50</span>"
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        </span>
            <span style="COLOR: red">roleNameColumnSize</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">50</span>"
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">    /&gt;</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">  &lt;/</span>
            <span style="COLOR: #a31515">providers</span>
            <span style="COLOR: blue">&gt;</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">&lt;/</span>
            <span style="COLOR: #a31515">roleManager</span>
            <span style="COLOR: blue">&gt;</span>
          </p>
        </div>
        <p>
          <!--EndFragment-->
        </p>
        <p>
          <br />
Note that the id columns in the join table need be named as in their respective tables
in order to work.<br />
    
<br />
Programatically creating the mapping using the CreateMappings for something more complex
than a single table seems to be something very tied to the NHibernate implementation
so I opted to create a XmlDocument with the mapping read from the configuration settings
as it seems to be the best thing to do in complex cases.
</p>
        <p>
One of the problems I faced with the NHCustomRoleProvider is that some times I wanted
to save or delete data from one side of the many-to-many relationship but in some
cases I wanted to use the other side. If you know a bit of NHibernate you know that
the inverse attribute controls what side of the relationship has to be used in order
to have changes persisted. As I was generating the mapping dynamically I created two
session factories, one with the inverse set to true on one side and the other with
the inverse in the other side. That way I open a connection in the session factory
that has the mapping with the inverse in the side of the relationship I want.
</p>
        <p>
I'd appreciate usage feedback, suggestions, bug reports, etc. I have only tried these
providers with NHibernate 1.2.0 GA and the MsSql2005Dialect so let me know if
it works in other configurations.
</p>
        <p>
Please do not store the providers in your server. Link to this page instead. Updates
to the providers will be posted in this page. 
</p>
        <p>
          <font size="4">
            <strong>
              <em>History</em>
            </strong>
          </font>
        </p>
        <p>
          <strong>v1.0 - 08/04/2007</strong>
        </p>
        <p>
          <strong>v1.1 - 21/06/2007</strong>
        </p>
        <ul dir="ltr" style="MARGIN-RIGHT: 0px">
          <li>
Now using NHibernate 1.2.0 GA 
</li>
          <li>
Some minor fixes</li>
        </ul>
        <p>
          <strong>v1.2 - 12/10/2007:</strong>
        </p>
        <ul>
          <li>
Fixed an important bug that didn’t prevent locked out users from login in. 
</li>
          <li>
Added a CreateUserWizardEx control that allows creating a user with extra information
in an easy way. 
</li>
          <li>
Added auto unlock support. 
</li>
          <li>
Fixed some minor bugs/typos.</li>
        </ul>
        <p>
For more details about the features introduced in version 1.2 take a look <a href="http://www.manuelabadia.com/blog/PermaLink,guid,27e22b2c-af95-4f4c-befd-1debc5841735.aspx">here</a>.
</p>
        <p>
          <strong>v2.0 - 01/08/2008:</strong>
        </p>
        <p>
For more details about the features introduced in version 2.0 and a sample of its
usage take a look <a href="http://www.manuelabadia.com/blog/PermaLink,guid,a93878c1-bd98-40d1-81cb-8bbfb6f0bb63.aspx">here</a>.
</p>
        <p>
          <a href="http://www.manuelabadia.com/blog/content/binary/NHCustomProviders_bin.zip">NHCustomProviders_bin.zip
(67 KB)</a>
          <br />
          <a href="http://www.manuelabadia.com/blog/content/binary/NHCustomProviders_source.zip">NHCustomProviders_source.zip
(122 KB)</a>
        </p>
        <img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=3b6ccb3f-2f2a-4dcb-a414-605371a00618" />
      </body>
      <title>Custom Membership and Role Providers using NHibernate</title>
      <guid isPermaLink="false">http://www.manuelabadia.com/blog/PermaLink,guid,3b6ccb3f-2f2a-4dcb-a414-605371a00618.aspx</guid>
      <link>http://www.manuelabadia.com/blog/PermaLink,guid,3b6ccb3f-2f2a-4dcb-a414-605371a00618.aspx</link>
      <pubDate>Sun, 08 Apr 2007 16:21:02 GMT</pubDate>
      <description>&lt;p&gt;
Usually, the built-in providers for ASP.NET do not integrate very well with existing
applications. The membership provider has a very complex structure that in most cases
is not needed at all. The following diagram shows most of the tables and relations
for the built-in ASP.NET providers:
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://www.manuelabadia.com/blog/content/binary/providers.png" border=0&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
The membership related tables are selected in red and the role related tables are
selected in blue. The default membership and roles provider have support to store
data for multiple applications using the aspnet_Applications table. I think this table
was introduced because some portal frameworks like dotnetnuke needed the ability to
store membership and role data for multiple users in a single store because they support
multiple portals. If you don't need this scenario (and most applications do not need
it), this only complicate things.
&lt;/p&gt;
&lt;p&gt;
Also, the built-in providers use tables that are not part of your application tables,
and some of those tables have quite a few columns, and probably some are not needed
by your application.
&lt;/p&gt;
&lt;p&gt;
If you do not use SQL Server, you can not use the default providers, so that is a
big showstopper.
&lt;/p&gt;
&lt;p&gt;
To overcome all of this problems I have created a custom membership and role provider
that use NHibernate and can be easily integrated with existing or future applications
using your own tables.
&lt;/p&gt;
&lt;p&gt;
The reference book about providers is:
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;&lt;em&gt;Professional ASP.NET 2.0 Security, Membership, and Role Management.&lt;/em&gt;&lt;/strong&gt;
&lt;/p&gt;
&lt;iframe style="WIDTH: 120px; HEIGHT: 240px" marginwidth=0 marginheight=0 src="http://rcm.amazon.com/e/cm?t=manuelabadias-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=as1&amp;amp;asins=0764596985&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" frameborder=0 scrolling=no&gt;
&lt;/iframe&gt;
&lt;p&gt;
I suggest you to read it if you really want to get deep into providers as it is an
excellent book.
&lt;/p&gt;
&lt;p&gt;
The NHCustomMembershipProvider uses NHibernate to do all membership related database
operations so it should work on all databases supported by NHibernate. The membership
data will be stored and retrieved from a table configured in the provider section
in the web.config so you can map it to an existing table like users. The column names
for your user table can also be configured in the provider section. The cool thing
about the provider is that it adapts its behaviour to the number of columns supported
by your data store. For example, if you use the provider and map it to your users
table where you only have the membership data for userId, userName, password and email,
it will work without any problem. If your data store supports more advanced options
of the membership provider like account lockout, password question and answer, password
salt or last activity date, that advanced functionality will be automatically available,
but it is not required. 
&lt;/p&gt;
&lt;p&gt;
The provider knows what functionality to offer based on the number of columns that
are mapped to your data store. To support account lockout when the user do not supply
a valid password after some tries in a predefined period of time you need to map the
isLockedOutColumn, failedPasswordAttemptCountColumn and failedPasswordAttemptWindowStartColumn
to columns in your data store.
&lt;/p&gt;
&lt;p&gt;
The default configuration for the provider is to use integer identities or sequences
for the user identifier, but that can be changed using the userIdType and idGeneratorClass
properties in the provider configuration section.
&lt;/p&gt;
&lt;p&gt;
If you use the provider with an existing user table, probably you will create the
users manually without using the CreateUser method from the membership provider. The
provider exposes the methods CheckPasswordPolicy, ValidatePassword, EncodePassword
and GenerateSalt to allow manual creation of the user in case you need it, without
sacrifying password strength.
&lt;/p&gt;
&lt;p&gt;
To finish with the custom membership provider lets see an example. If you want to
use the membership provider with a table like this (that has columns for all supported
functionality):
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;CREATE TABLE &lt;/span&gt;[dbo].[Users](
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;[userId] [int] &lt;span style="COLOR: blue"&gt;IDENTITY&lt;/span&gt;(1,1) &lt;span style="COLOR: blue"&gt;NOT
NULL&lt;/span&gt;,
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;[username] [nvarchar](50) &lt;span style="COLOR: blue"&gt;NOT NULL&lt;/span&gt;,
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;[email] [nvarchar](100) &lt;span style="COLOR: blue"&gt;NOT NULL&lt;/span&gt;,
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;[password] [nvarchar](256) &lt;span style="COLOR: blue"&gt;NOT NULL&lt;/span&gt;,
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;[passwordSalt] [nvarchar](64) &lt;span style="COLOR: blue"&gt;NULL&lt;/span&gt;,
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;[passwordFormat] [int] &lt;span style="COLOR: blue"&gt;NOT NULL&lt;/span&gt;,
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;[passwordQuestion] [nvarchar](512) &lt;span style="COLOR: blue"&gt;NOT NULL&lt;/span&gt;,
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;[passwordAnswer] [nvarchar](512) &lt;span style="COLOR: blue"&gt;NOT NULL&lt;/span&gt;,
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;[failedPasswordAttemptCount] [int] &lt;span style="COLOR: blue"&gt;NOT NULL&lt;/span&gt;,
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;[failedPasswordAttemptWindowStart] [smalldatetime] &lt;span style="COLOR: blue"&gt;NULL&lt;/span&gt;,
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;[failedPasswordAnswerAttemptCount] [int] &lt;span style="COLOR: blue"&gt;NOT NULL&lt;/span&gt;,
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;[failedPasswordAnswerAttemptWindowStart] [smalldatetime] &lt;span style="COLOR: blue"&gt;NULL&lt;/span&gt;,
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;[lastPasswordChangedDate] [smalldatetime] &lt;span style="COLOR: blue"&gt;NULL&lt;/span&gt;,
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;[creationDate] [smalldatetime] &lt;span style="COLOR: blue"&gt;NOT NULL&lt;/span&gt;,
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;[lastActivityDate] [smalldatetime] &lt;span style="COLOR: blue"&gt;NOT NULL&lt;/span&gt;,
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;[isApproved] [bit] &lt;span style="COLOR: blue"&gt;NOT NULL&lt;/span&gt;,
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;[isLockedOut] [bit] &lt;span style="COLOR: blue"&gt;NOT NULL&lt;/span&gt;,
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;[lastLockOutDate] [smalldatetime] &lt;span style="COLOR: blue"&gt;NULL&lt;/span&gt;,
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;[lastLoginDate] [smalldatetime] &lt;span style="COLOR: blue"&gt;NULL&lt;/span&gt;,
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;[name] [nvarchar](256) &lt;span style="COLOR: blue"&gt;NULL&lt;/span&gt;,
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;[surname] [nvarchar](256) &lt;span style="COLOR: blue"&gt;NULL&lt;/span&gt;,
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;[address] [nvarchar](256) &lt;span style="COLOR: blue"&gt;NULL&lt;/span&gt;,
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;[phone] [nvarchar](16) &lt;span style="COLOR: blue"&gt;NULL&lt;/span&gt;,
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;[postalCode] [nvarchar](50) &lt;span style="COLOR: blue"&gt;NULL&lt;/span&gt;,
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;[comments] [nvarchar](&lt;span style="COLOR: blue"&gt;max&lt;/span&gt;) &lt;span style="COLOR: blue"&gt;NULL&lt;/span&gt;,
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;CONSTRAINT &lt;/span&gt;[PK_Users] &lt;span style="COLOR: blue"&gt;PRIMARY
KEY CLUSTERED &lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; (
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; [userId] &lt;span style="COLOR: blue"&gt;ASC&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; )
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
)
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;!--EndFragment--&gt;
&lt;/p&gt;
&lt;p&gt;
The configuration section for the membership provider will be something like this:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;membership&lt;/span&gt;&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;defaultProvider&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;NHCustomMembershipProvider&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;providers&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;add&lt;/span&gt;&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;name&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;NHCustomMembershipProvider&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;type&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;NHCustomProviders.NHCustomMembershipProvider,
NHCustomProviders&lt;/span&gt;"
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: red"&gt;enablePasswordReset&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;true&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;enablePasswordRetrieval&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;true&lt;/span&gt;"
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: red"&gt;minRequiredNonAlphanumericCharacters&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;1&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;minRequiredPasswordLength&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;6&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;passwordFormat&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;Encrypted&lt;/span&gt;"
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: red"&gt;maxInvalidPasswordAttempts&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;5&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;passwordAttemptWindow&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;5&lt;/span&gt;"
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: red"&gt;requiresQuestionAndAnswer&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;true&lt;/span&gt;"
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: red"&gt;requiresUniqueEmail&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;false&lt;/span&gt;"
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: red"&gt;tableName&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;USERS&lt;/span&gt;"
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: red"&gt;userIdColumn&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;USERID&lt;/span&gt;"
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: red"&gt;userIdType&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;Int32&lt;/span&gt;"
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: red"&gt;idGeneratorClass&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;native&lt;/span&gt;"
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: red"&gt;userNameColumn&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;USERNAME&lt;/span&gt;"
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: red"&gt;emailColumn&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;EMAIL&lt;/span&gt;"
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: red"&gt;passwordColumn&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;PASSWORD&lt;/span&gt;"
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: red"&gt;passwordSaltColumn&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;PASSWORDSALT&lt;/span&gt;"
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: red"&gt;passwordFormatColumn&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;PASSWORDFORMAT&lt;/span&gt;"
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: red"&gt;passwordQuestionColumn&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;PASSWORDQUESTION&lt;/span&gt;"
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: red"&gt;passwordAnswerColumn&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;PASSWORDANSWER&lt;/span&gt;"
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: red"&gt;failedPasswordAttemptCountColumn&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;FAILEDPASSWORDATTEMPTCOUNT&lt;/span&gt;"
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: red"&gt;failedPasswordAttemptWindowStartColumn&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;FAILEDPASSWORDATTEMPTWINDOWSTART&lt;/span&gt;"
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: red"&gt;failedPasswordAnswerAttemptCountColumn&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;FAILEDPASSWORDANSWERATTEMPTCOUNT&lt;/span&gt;"
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: red"&gt;failedPasswordAnswerAttemptWindowStartColumn&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;FAILEDPASSWORDANSWERATTEMPTWINDOWSTART&lt;/span&gt;"
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: red"&gt;lastPasswordChangedDateColumn&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;LASTPASSWORDCHANGEDDATE&lt;/span&gt;"
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: red"&gt;creationDateColumn&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;CREATIONDATE&lt;/span&gt;"
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: red"&gt;lastActivityDateColumn&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;LASTACTIVITYDATE&lt;/span&gt;"
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: red"&gt;isApprovedColumn&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;ISAPPROVED&lt;/span&gt;"
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: red"&gt;isLockedOutColumn&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;ISLOCKEDOUT&lt;/span&gt;"
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: red"&gt;lastLockOutDateColumn&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;LASTLOCKOUTDATE&lt;/span&gt;"
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: red"&gt;lastLoginDateColumn&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;LASTLOGINDATE&lt;/span&gt;"
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: red"&gt;commentsColumn&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;COMMENTS&lt;/span&gt;"
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: red"&gt;userNameColumnSize&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;50&lt;/span&gt;"
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: red"&gt;emailColumnSize&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;50&lt;/span&gt;"
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: red"&gt;passwordColumnSize&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;256&lt;/span&gt;"
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: red"&gt;passwordSaltColumnSize&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;64&lt;/span&gt;"
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: red"&gt;passwordQuestionColumnSize&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;512&lt;/span&gt;"
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: red"&gt;passwordAnswerColumnSize&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;512&lt;/span&gt;"
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: red"&gt;passwordSaltSize&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;16&lt;/span&gt;"
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: red"&gt;raiseSystemEvents&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;true&lt;/span&gt;"
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: red"&gt;dynamicUpdate&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;true&lt;/span&gt;"
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; /&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;providers&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;membership&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;!--EndFragment--&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&lt;br&gt;
The column sizes are optional but it is a good practice to fill them.
&lt;/p&gt;
&lt;p&gt;
The built-in provider raises events after a succesfully or a failed login. However,
ASP.NET 2.0 does not allow to create or raise built-in health monitoring events, so
I had to use reflection in a private method in order to raise the same events. That
means that the provider will not run in medium trust if it is not installed in the
GAC if you want to raise the system events. As this can be a showstopper to some people
I have added an option to disable system events generation (raiseSystemEvents).
&lt;/p&gt;
&lt;p&gt;
The provider reads the config section and programatically generates a mapping for
the specified columns in the ConfigureNHibernate method. The provider expects that
you have configured NHibernate in the web.config to work. If you need extra configuration
for the provider you can inherit from the provider and use override the ConfigureNHibernate
method, modifying the Configuration object that the base class returns.
&lt;/p&gt;
&lt;p&gt;
The NHCustomRoleProvider is also configurable in order adapt to your own tables. It
only needs a Users table with id and user name columns, a roles table with id and
role name columns, and a join table used to store the information for the many-to-many
relationship between the users and roles.
&lt;/p&gt;
&lt;p&gt;
For example, if we the previous user table with the following tables (FKs omitted
for brevity):
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;CREATE TABLE &lt;/span&gt;[dbo].[Roles](
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; [roleId] [int] &lt;span style="COLOR: blue"&gt;IDENTITY&lt;/span&gt;(1,1) &lt;span style="COLOR: blue"&gt;NOT
NULL&lt;/span&gt;,
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; [name] [nvarchar](50) &lt;span style="COLOR: blue"&gt;NOT NULL&lt;/span&gt;,
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;CONSTRAINT &lt;/span&gt;[PK_Roles] &lt;span style="COLOR: blue"&gt;PRIMARY
KEY CLUSTERED &lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; (
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; [roleId] &lt;span style="COLOR: blue"&gt;ASC&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; )
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;CREATE TABLE &lt;/span&gt;[dbo].[Users_In_Roles](
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; [userId] [int] &lt;span style="COLOR: blue"&gt;NOT NULL&lt;/span&gt;,
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; [roleId] [int] &lt;span style="COLOR: blue"&gt;NOT NULL&lt;/span&gt;,
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;CONSTRAINT &lt;/span&gt;[PK_UsersInRoles] &lt;span style="COLOR: blue"&gt;PRIMARY
KEY CLUSTERED &lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; (
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; [userId] &lt;span style="COLOR: blue"&gt;ASC&lt;/span&gt;,
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; [roleId] &lt;span style="COLOR: blue"&gt;ASC&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; )
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
)
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
The configuration section for the role provider will be something like this:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;roleManager&lt;/span&gt;&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;defaultProvider&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;NHCustomRoleProvider&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;enabled&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;true&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;providers&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;add&lt;/span&gt;&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;name&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;NHCustomRoleProvider&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;type&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;NHCustomProviders.NHCustomRoleProvider,
NHCustomProviders&lt;/span&gt;"
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: red"&gt;userTableName&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;USERS&lt;/span&gt;"
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: red"&gt;userIdColumn&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;USERID&lt;/span&gt;"
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: red"&gt;userIdType&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;Int32&lt;/span&gt;"
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: red"&gt;userIdGeneratorClass&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;native&lt;/span&gt;"
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: red"&gt;userNameColumn&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;USERNAME&lt;/span&gt;"
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: red"&gt;roleTableName&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;ROLES&lt;/span&gt;"
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: red"&gt;roleIdColumn&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;ROLEID&lt;/span&gt;"
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: red"&gt;roleIdType&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;Int32&lt;/span&gt;"
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: red"&gt;roleIdGeneratorClass&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;native&lt;/span&gt;"
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: red"&gt;roleNameColumn&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;NAME&lt;/span&gt;"
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: red"&gt;joinTableName&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;USERS_IN_ROLES&lt;/span&gt;"
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: red"&gt;userNameColumnSize&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;50&lt;/span&gt;"
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: red"&gt;roleNameColumnSize&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;50&lt;/span&gt;"
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; /&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;providers&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;roleManager&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;!--EndFragment--&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;br&gt;
Note that the id columns in the join table need be named as in their respective tables
in order to work.&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&lt;br&gt;
Programatically creating the mapping using the CreateMappings for something more complex
than a single table seems to be something very tied to the NHibernate implementation
so I opted to create a XmlDocument with the mapping read from the configuration settings
as it seems to be the best thing to do in complex cases.
&lt;/p&gt;
&lt;p&gt;
One of the problems I faced with the NHCustomRoleProvider is that some times I wanted
to save or delete data from one side of the many-to-many relationship but in some
cases I wanted to use the other side. If you know a bit of NHibernate you know that
the inverse attribute controls what side of the relationship has to be used in order
to have changes persisted. As I was generating the mapping dynamically I created two
session factories, one with the inverse set to true on one side and the other with
the inverse in the other side. That way I open a connection in the session factory
that has the mapping with the inverse in the side of the relationship I want.
&lt;/p&gt;
&lt;p&gt;
I'd appreciate usage feedback, suggestions, bug reports, etc. I have only tried these
providers with NHibernate 1.2.0&amp;nbsp;GA and the MsSql2005Dialect so let me know if
it works in other configurations.
&lt;/p&gt;
&lt;p&gt;
Please do not store the providers in your server. Link to this page instead. Updates
to the providers will be posted in this page. 
&lt;/p&gt;
&lt;p&gt;
&lt;font size=4&gt;&lt;strong&gt;&lt;em&gt;History&lt;/em&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;v1.0&amp;nbsp;-&amp;nbsp;08/04/2007&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;v1.1 - 21/06/2007&lt;/strong&gt;
&lt;/p&gt;
&lt;ul dir=ltr style="MARGIN-RIGHT: 0px"&gt;
&lt;li&gt;
Now using NHibernate 1.2.0 GA 
&lt;li&gt;
Some minor fixes&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&lt;strong&gt;v1.2&amp;nbsp;- 12/10/2007:&lt;/strong&gt;
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Fixed an important bug that didn’t prevent locked out users from login in. 
&lt;li&gt;
Added a CreateUserWizardEx control that allows creating a user with extra information
in an easy way. 
&lt;li&gt;
Added auto unlock support. 
&lt;li&gt;
Fixed some minor bugs/typos.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
For more details about the features introduced in version 1.2 take a look &lt;a href="http://www.manuelabadia.com/blog/PermaLink,guid,27e22b2c-af95-4f4c-befd-1debc5841735.aspx"&gt;here&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;v2.0&amp;nbsp;- 01/08/2008:&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
For more details about the features introduced in version 2.0 and a sample of its
usage&amp;nbsp;take a look &lt;a href="http://www.manuelabadia.com/blog/PermaLink,guid,a93878c1-bd98-40d1-81cb-8bbfb6f0bb63.aspx"&gt;here&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.manuelabadia.com/blog/content/binary/NHCustomProviders_bin.zip"&gt;NHCustomProviders_bin.zip
(67 KB)&lt;/a&gt;
&lt;br&gt;
&lt;a href="http://www.manuelabadia.com/blog/content/binary/NHCustomProviders_source.zip"&gt;NHCustomProviders_source.zip
(122 KB)&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=3b6ccb3f-2f2a-4dcb-a414-605371a00618" /&gt;</description>
      <comments>http://www.manuelabadia.com/blog/CommentView,guid,3b6ccb3f-2f2a-4dcb-a414-605371a00618.aspx</comments>
      <category>ASP.NET;Microsoft .NET Framework;NHibernate</category>
    </item>
    <item>
      <trackback:ping>http://www.manuelabadia.com/blog/Trackback.aspx?guid=91a1d00f-197e-4148-b4e1-cea324029dc6</trackback:ping>
      <pingback:server>http://www.manuelabadia.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.manuelabadia.com/blog/PermaLink,guid,91a1d00f-197e-4148-b4e1-cea324029dc6.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://www.manuelabadia.com/blog/CommentView,guid,91a1d00f-197e-4148-b4e1-cea324029dc6.aspx</wfw:comment>
      <wfw:commentRss>http://www.manuelabadia.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=91a1d00f-197e-4148-b4e1-cea324029dc6</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
In a previous <a href="http://www.manuelabadia.com/blog/PermaLink,guid,560b6980-d109-4047-a886-4c523f090522.aspx">post</a> I
said that the ObjectDataSource can handle generic types using the backtick (`) notation,
even if the ObjectDataSource doesn't have any design time support for this. 
</p>
        <p>
This works because the ObjectDataSource internally calls to Type.GetType to resolve
type names to Type objects. As the Type.GetType method handle generics transparently,
the ObjectDataSource does not have to do anything special to support it at runtime.
Supporting generic types at design time is more complex so they fiter out generic
types in the "Select Type" wizard step.
</p>
        <p>
For generic methods things change. There is some inconsistency in generics handling
in the .NET Framework. If you get the type of a class like List&lt;Customer&gt;, its
Name is List`1[Customer]. However, if you have a method like Customer Get&lt;Customer&gt;(int
id), the method name is Get. IMHO, to have an orthogonal implementation, the method
name should be Get`1[Customer]. Also, the GetMethod method should understand the backtick
notation for methods and retrieve the specified method properly but it isn't supported
for now. I have requested an improvement for the next version of the .NET framework <a href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=265628">here</a>.
Probably they won't fix it but it would be nice if you vote for it.
</p>
        <p>
Returning to the ObjectDataSource... When the ObjectDataSource tries to find a method,
it call the GetMethods method and compares the method name with the expected name,
filtering out generic methods.
</p>
        <p>
So, I think Microsoft didn't bother to add support for generic types or generic methods,
and if generic types work at runtime is by luck (because of the GetType behaviour).
</p>
        <p>
As more developers are using generics, there is a need to properly support generic
methods and generic types. The next version of the ExtendedObjectDataSource (that
will be released next week), will have full generics support, at design time and at
runtime.
</p>
        <p>
It wasn't easy to add design time support for generics as several problems appeared:
</p>
        <p>
* Generic type expressions and generic method expressions can be arbitrarily complex
(like MyGraph`2[[Utilities.Set, Utilities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a7a65c534534e209],[Utilities.Graph,
Utilities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a7a65c534534e209]], MyGraphLibrary,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=2134afb4534e209), so I had to write
a parser for both kinds of expressions.<br />
 <br />
* At runtime, specifying "__code" for the assembly name gets traslated to the dynamically
generated assembly (as explained in the previous post). However, at design time this
translation has to be done manually.<br />
 <br />
* I had to rewrite the select type wizard step and select method wizard step as the
code was getting harder to maintain with generics.
</p>
        <p>
* Showing and choosing generic methods and types is half of the problem, after choosing
them you have to create the generic type or the generic method based on the generic
type definition and the generic method definition.<br />
 <br />
Lets see an example of what can be accomplished now with the CompatObjectDataSource.
</p>
        <p>
Imagine that we want to be able to register some objects at the start of the application
in order to used later using a registry.
</p>
        <p>
The registry can be implemented like this:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: gray">///</span>
            <span style="COLOR: green">
            </span>
            <span style="COLOR: gray">&lt;summary&gt;</span>
            <span style="COLOR: green">Global
Registry.</span>
            <span style="COLOR: gray">&lt;/summary&gt;</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">public</span>
            <span style="COLOR: blue">class</span>
            <span style="COLOR: #2b91af">Registry</span>
          </p>
          <p style="MARGIN: 0px">
{
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">    #region</span> Fields
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">private</span><span style="COLOR: blue">static</span><span style="COLOR: #2b91af">Registry</span> _instance
= <span style="COLOR: blue">new</span><span style="COLOR: #2b91af">Registry</span>();
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">private</span><span style="COLOR: #2b91af">Hashtable</span> _registryStore
= <span style="COLOR: blue">new</span><span style="COLOR: #2b91af">Hashtable</span>();
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">    #endregion</span>
          </p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">    #region</span> Properties
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;summary&gt;</span><span style="COLOR: green">Gets
the unique instance for this class.</span><span style="COLOR: gray">&lt;/value&gt;</span></p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">static</span><span style="COLOR: #2b91af">Registry</span> Instance
</p>
          <p style="MARGIN: 0px">
    {
</p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">get</span> { <span style="COLOR: blue">return</span> _instance;
}
</p>
          <p style="MARGIN: 0px">
    }
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">    #endregion</span>
          </p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">    #region</span> Methods
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;summary&gt;</span><span style="COLOR: green">Private
constructor to avoid creating instances of this class.</span><span style="COLOR: gray">&lt;/summary&gt;</span></p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">private</span> Registry() { }
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;summary&gt;</span><span style="COLOR: green">Registers
an object.</span><span style="COLOR: gray">&lt;/summary&gt;</span></p>
          <p style="MARGIN: 0px">
    <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;param
name="key"&gt;</span><span style="COLOR: green">The key.</span><span style="COLOR: gray">&lt;/param&gt;</span></p>
          <p style="MARGIN: 0px">
    <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;param
name="obj"&gt;</span><span style="COLOR: green">The object to register.</span><span style="COLOR: gray">&lt;/param&gt;</span></p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">void</span> RegisterObject&lt;K,
T&gt;(K key, T obj)
</p>
          <p style="MARGIN: 0px">
    {
</p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">if</span> (_registryStore.Contains(key))
{
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">throw</span><span style="COLOR: blue">new</span><span style="COLOR: #2b91af">Exception</span>(<span style="COLOR: #2b91af">String</span>.Format(<span style="COLOR: #a31515">"Error,
there is an object stored using the '{0}' key"</span> + key.ToString()));
</p>
          <p style="MARGIN: 0px">
        }
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
        _registryStore[key] = obj;
</p>
          <p style="MARGIN: 0px">
    }
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;summary&gt;</span><span style="COLOR: green">Registers
an object list.</span><span style="COLOR: gray">&lt;/summary&gt;</span></p>
          <p style="MARGIN: 0px">
    <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;param
name="key"&gt;</span><span style="COLOR: green">The key.</span><span style="COLOR: gray">&lt;/param&gt;</span></p>
          <p style="MARGIN: 0px">
    <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;param
name="objects"&gt;</span><span style="COLOR: green">The object list to register.</span><span style="COLOR: gray">&lt;/param&gt;</span></p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">void</span> RegisterObjectList&lt;K,
T&gt;(K key, <span style="COLOR: #2b91af">IList</span>&lt;T&gt; objects)
</p>
          <p style="MARGIN: 0px">
    {
</p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">if</span> (_registryStore.Contains(key))
{
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">throw</span><span style="COLOR: blue">new</span><span style="COLOR: #2b91af">Exception</span>(<span style="COLOR: #2b91af">String</span>.Format(<span style="COLOR: #a31515">"Error,
there are objects stored using the '{0}' key"</span> + key.ToString()));
</p>
          <p style="MARGIN: 0px">
        }
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
        _registryStore[key] = objects;
</p>
          <p style="MARGIN: 0px">
    }
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;summary&gt;</span><span style="COLOR: green">Gets
an object from the registry.</span><span style="COLOR: gray">&lt;/summary&gt;</span></p>
          <p style="MARGIN: 0px">
    <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;param
name="key"&gt;</span><span style="COLOR: green">The key.</span><span style="COLOR: gray">&lt;/param&gt;</span></p>
          <p style="MARGIN: 0px">
    <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;returns&gt;</span><span style="COLOR: green">The
object stored on the registry or null if it wasn't found.</span><span style="COLOR: gray">&lt;/returns&gt;</span></p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span> T GetObject&lt;K, T&gt;(K
key)
</p>
          <p style="MARGIN: 0px">
    {
</p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">return</span> (T)_registryStore[key];
</p>
          <p style="MARGIN: 0px">
    }
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;summary&gt;</span><span style="COLOR: green">Gets
a list of objects from the registry.</span><span style="COLOR: gray">&lt;/summary&gt;</span></p>
          <p style="MARGIN: 0px">
    <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;param
name="key"&gt;</span><span style="COLOR: green">The key.</span><span style="COLOR: gray">&lt;/param&gt;</span></p>
          <p style="MARGIN: 0px">
    <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;returns&gt;</span><span style="COLOR: green">The
list of objects stored on the registry or null if it wasn't found.</span><span style="COLOR: gray">&lt;/returns&gt;</span></p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: #2b91af">IList</span>&lt;T&gt;
GetObjectList&lt;K, T&gt;(K key)
</p>
          <p style="MARGIN: 0px">
    {
</p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">return</span> _registryStore[key] <span style="COLOR: blue">as</span><span style="COLOR: #2b91af">IList</span>&lt;T&gt;;
</p>
          <p style="MARGIN: 0px">
    }
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">    #endregion</span>
          </p>
          <p style="MARGIN: 0px">
}
</p>
        </div>
        <p>
          <!--EndFragment-->
          <br />
    
<br />
Some of the data stored in the registry when the application starts is a list of all
available countries (for example, retrieved from the database):
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: green">// register the countries</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #2b91af">Registry</span>.Instance.RegisterObjectList&lt;<span style="COLOR: blue">string</span>, <span style="COLOR: #2b91af">Country</span>&gt;(<span style="COLOR: #a31515">"countries"</span>,
countries);
</p>
        </div>
        <p>
          <!--EndFragment-->
        </p>
        <p>
The Country class is very simple:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">namespace</span> Manu.GenericTests
</p>
          <p style="MARGIN: 0px">
{
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">class</span><span style="COLOR: #2b91af">Country</span></p>
          <p style="MARGIN: 0px">
    {
</p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">private</span><span style="COLOR: blue">int</span> _id;
</p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">private</span><span style="COLOR: blue">string</span> _name;
</p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">private</span><span style="COLOR: blue">string</span> _code;
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">public</span><span style="COLOR: blue">int</span> Id
</p>
          <p style="MARGIN: 0px">
        {
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">get</span> { <span style="COLOR: blue">return</span> _id;
}
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">set</span> {
_id = <span style="COLOR: blue">value</span>; }
</p>
          <p style="MARGIN: 0px">
        }
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">public</span><span style="COLOR: blue">string</span> Name
</p>
          <p style="MARGIN: 0px">
        {
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">get</span> { <span style="COLOR: blue">return</span> _name;
}
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">set</span> {
_name = <span style="COLOR: blue">value</span>; }
</p>
          <p style="MARGIN: 0px">
        }
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">public</span><span style="COLOR: blue">string</span> Code
</p>
          <p style="MARGIN: 0px">
        {
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">get</span> { <span style="COLOR: blue">return</span> _code;
}
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">set</span> {
_code = <span style="COLOR: blue">value</span>; }
</p>
          <p style="MARGIN: 0px">
        }
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">public</span> Country()
</p>
          <p style="MARGIN: 0px">
        {
</p>
          <p style="MARGIN: 0px">
        }
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">public</span> Country(<span style="COLOR: blue">int</span> id, <span style="COLOR: blue">string</span> name, <span style="COLOR: blue">string</span> code)
</p>
          <p style="MARGIN: 0px">
        {
</p>
          <p style="MARGIN: 0px">
            _id = id;
</p>
          <p style="MARGIN: 0px">
            _name = name;
</p>
          <p style="MARGIN: 0px">
            _code = code;
</p>
          <p style="MARGIN: 0px">
        }
</p>
          <p style="MARGIN: 0px">
    }
</p>
          <p style="MARGIN: 0px">
}
</p>
        </div>
        <p>
          <!--EndFragment-->
        </p>
        <p>
If we want to show all the countries in any webform we can use an CompatObjectDataSource.
After dropping one to the toolbox we configure the type:
</p>
        <p>
          <img src="http://www.manuelabadia.com/blog/content/binary/EODS_designer1.png" border="0" />
        </p>
        <p>
And then we can see the list of methods compatible with the Select operation (GetObject
and GetObjectList):
</p>
        <p>
          <img src="http://www.manuelabadia.com/blog/content/binary/EODS_designer2.png" border="0" />
        </p>
        <p>
As both methods are generic method definitions, after selecting one of them, we have
to specify the generic parameters. In our case, we stored the countries using a string
key, and we stored a List of Country objects so the generic parameters for the method
are System.String, Manu.GenericTests.Country. After clicking in "Make Generic Method"
we have the data source configured properly:
</p>
        <p>
          <img src="http://www.manuelabadia.com/blog/content/binary/EODS_designer3.png" border="0" />
        </p>
        <p>
If we take a look to the ASPX we can see the following code:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">&lt;</span>
            <span style="COLOR: #a31515">manu</span>
            <span style="COLOR: blue">:</span>
            <span style="COLOR: #a31515">CompatObjectDataSource</span>
            <span style="COLOR: red">ID</span>
            <span style="COLOR: blue">="CompatObjectDataSource1"</span>
            <span style="COLOR: red">runat</span>
            <span style="COLOR: blue">="server"</span>
          </p>
          <p style="MARGIN: 0px">
    <span style="COLOR: red">SelectMethod</span><span style="COLOR: blue">="GetObjectList`2[System.String,
[Manu.GenericTests.Country, __code]]"</span></p>
          <p style="MARGIN: 0px">
    <span style="COLOR: red">TypeName</span><span style="COLOR: blue">="Manu.GenericTests.Registry,
__code"</span></p>
          <p style="MARGIN: 0px">
    <span style="COLOR: red">OnObjectCreating</span><span style="COLOR: blue">="ObjectDataSource1_ObjectCreating"&gt;</span></p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">&lt;</span><span style="COLOR: #a31515">SelectParameters</span><span style="COLOR: blue">&gt;</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">&lt;</span><span style="COLOR: #a31515">asp</span><span style="COLOR: blue">:</span><span style="COLOR: #a31515">Parameter</span><span style="COLOR: red">Name</span><span style="COLOR: blue">="key"</span><span style="COLOR: red">Type</span><span style="COLOR: blue">="String"</span><span style="COLOR: blue">/&gt;</span></p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">&lt;/</span><span style="COLOR: #a31515">SelectParameters</span><span style="COLOR: blue">&gt;</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">&lt;/</span>
            <span style="COLOR: #a31515">manu</span>
            <span style="COLOR: blue">:</span>
            <span style="COLOR: #a31515">CompatObjectDataSource</span>
            <span style="COLOR: blue">&gt;</span>
          </p>
        </div>
        <!--EndFragment-->
        <p>
 
</p>
        <p>
The SelectMethod is saved as "GetObjectList`2[System.String, [Manu.GenericTests.Country,
__code]]" and the TypeName is saved as "Manu.GenericTests.Registry, __code".
</p>
        <p>
The only thing to do now is to set the DefaultValue property for the key parameter
to countries. Now the CompatObjectDataSource has enough information to call to GetObjectList&lt;string,
Country&gt;("countries") from the Registry class and retrieve the countries.
</p>
        <p>
The only thing I'm missing in the CompatObjectDataSource/ExtendedObjectDataSource
is support for Bind expressions for nested properties (&lt;%# Bind(Address.PostalCode)
%&gt;), but unfortunately, the framework can not understand those expressions so nothing
can be done ast the moment. I wrote an email to <a href="http://weblogs.asp.net/scottgu/">ScottGu</a> about
that and got this reply from <a href="http://www.shankun.com/">Shanku Niyogi</a>:
</p>
        <p>
          <em>
            <strong>"This is definitely a doable thing - we'll add it to our list of items
we're considering adding for an upcoming release."</strong>
          </em>
        </p>
        <p>
So keep your fingers crossed.
</p>
        <p>
I'm open to suggestions in what to functionality you would like to see in the ObjectDataSource/CompatObjectDataSource/ExtendedObjectDataSource.
</p>
        <img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=91a1d00f-197e-4148-b4e1-cea324029dc6" />
      </body>
      <title>ObjectDataSource and Generics (part 2)</title>
      <guid isPermaLink="false">http://www.manuelabadia.com/blog/PermaLink,guid,91a1d00f-197e-4148-b4e1-cea324029dc6.aspx</guid>
      <link>http://www.manuelabadia.com/blog/PermaLink,guid,91a1d00f-197e-4148-b4e1-cea324029dc6.aspx</link>
      <pubDate>Tue, 27 Mar 2007 22:35:22 GMT</pubDate>
      <description>&lt;p&gt;
In a previous &lt;a href="http://www.manuelabadia.com/blog/PermaLink,guid,560b6980-d109-4047-a886-4c523f090522.aspx"&gt;post&lt;/a&gt; I
said that the ObjectDataSource can handle generic types using the backtick (`) notation,
even if the ObjectDataSource doesn't have any design time support for this. 
&lt;/p&gt;
&lt;p&gt;
This works because the ObjectDataSource internally calls to Type.GetType to resolve
type names to Type objects. As the Type.GetType method handle generics transparently,
the ObjectDataSource does not have to do anything special to support it at runtime.
Supporting generic types at design time is more complex so they fiter out generic
types in the "Select Type" wizard step.
&lt;/p&gt;
&lt;p&gt;
For generic methods things change. There is some inconsistency in generics handling
in the .NET Framework. If you get the type of a class like List&amp;lt;Customer&amp;gt;, its
Name is List`1[Customer]. However, if you have a method like Customer Get&amp;lt;Customer&amp;gt;(int
id), the method name is Get. IMHO, to have an orthogonal implementation, the method
name should be Get`1[Customer]. Also, the GetMethod method should understand the backtick
notation for methods and retrieve the specified method properly but it isn't supported
for now. I have requested an improvement for the next version of the .NET framework &lt;a href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=265628"&gt;here&lt;/a&gt;.
Probably they won't fix it but it would be nice if you vote for it.
&lt;/p&gt;
&lt;p&gt;
Returning to the ObjectDataSource... When the ObjectDataSource tries to find a method,
it call the GetMethods method and compares the method name with the expected name,
filtering out generic methods.
&lt;/p&gt;
&lt;p&gt;
So, I think Microsoft didn't bother to add support for generic types or generic methods,
and if generic types work at runtime is by luck (because of the GetType behaviour).
&lt;/p&gt;
&lt;p&gt;
As more developers are using generics, there is a need to properly support generic
methods and generic types. The next version of the ExtendedObjectDataSource (that
will be released next week), will have full generics support, at design time and at
runtime.
&lt;/p&gt;
&lt;p&gt;
It wasn't easy to add design time support for generics as several problems appeared:
&lt;/p&gt;
&lt;p&gt;
* Generic type expressions and generic method expressions can be arbitrarily complex
(like MyGraph`2[[Utilities.Set, Utilities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a7a65c534534e209],[Utilities.Graph,
Utilities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a7a65c534534e209]], MyGraphLibrary,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=2134afb4534e209), so I had to write
a parser for both kinds of expressions.&lt;br&gt;
&amp;nbsp;&lt;br&gt;
* At runtime, specifying "__code" for the assembly name gets traslated to the dynamically
generated assembly (as explained in the previous post). However, at design time this
translation has to be done manually.&lt;br&gt;
&amp;nbsp;&lt;br&gt;
* I had to rewrite the select type wizard step and select method wizard step as the
code was getting harder to maintain with generics.
&lt;/p&gt;
&lt;p&gt;
* Showing and choosing generic methods and types is half of the problem, after choosing
them you have to create the generic type or the generic method based on the generic
type definition and the generic method definition.&lt;br&gt;
&amp;nbsp;&lt;br&gt;
Lets see an example of what can be accomplished now with the CompatObjectDataSource.
&lt;/p&gt;
&lt;p&gt;
Imagine that we want to be able to register some objects at the start of the application
in order to used later using a registry.
&lt;/p&gt;
&lt;p&gt;
The registry can be implemented like this:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;Global
Registry.&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;class&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;Registry&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #region&lt;/span&gt; Fields
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: blue"&gt;static&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;Registry&lt;/span&gt; _instance
= &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;Registry&lt;/span&gt;();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;Hashtable&lt;/span&gt; _registryStore
= &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;Hashtable&lt;/span&gt;();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #endregion&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #region&lt;/span&gt; Properties
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;Gets
the unique instance for this class.&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/value&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;static&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;Registry&lt;/span&gt; Instance
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;get&lt;/span&gt; { &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; _instance;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #endregion&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #region&lt;/span&gt; Methods
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;Private
constructor to avoid creating instances of this class.&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; Registry() { }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;Registers
an object.&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;param
name="key"&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;The key.&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;param
name="obj"&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;The object to register.&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; RegisterObject&amp;lt;K,
T&amp;gt;(K key, T obj)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (_registryStore.Contains(key))
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;throw&lt;/span&gt; &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;Exception&lt;/span&gt;(&lt;span style="COLOR: #2b91af"&gt;String&lt;/span&gt;.Format(&lt;span style="COLOR: #a31515"&gt;"Error,
there is an object stored using the '{0}' key"&lt;/span&gt; + key.ToString()));
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; _registryStore[key] = obj;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;Registers
an object list.&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;param
name="key"&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;The key.&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;param
name="objects"&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;The object list to register.&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; RegisterObjectList&amp;lt;K,
T&amp;gt;(K key, &lt;span style="COLOR: #2b91af"&gt;IList&lt;/span&gt;&amp;lt;T&amp;gt; objects)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (_registryStore.Contains(key))
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;throw&lt;/span&gt; &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;Exception&lt;/span&gt;(&lt;span style="COLOR: #2b91af"&gt;String&lt;/span&gt;.Format(&lt;span style="COLOR: #a31515"&gt;"Error,
there are objects stored using the '{0}' key"&lt;/span&gt; + key.ToString()));
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; _registryStore[key] = objects;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;Gets
an object from the registry.&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;param
name="key"&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;The key.&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;returns&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;The
object stored on the registry or null if it wasn't found.&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/returns&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; T GetObject&amp;lt;K, T&amp;gt;(K
key)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; (T)_registryStore[key];
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;Gets
a list of objects from the registry.&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;param
name="key"&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;The key.&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;returns&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;The
list of objects stored on the registry or null if it wasn't found.&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/returns&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;IList&lt;/span&gt;&amp;lt;T&amp;gt;
GetObjectList&amp;lt;K, T&amp;gt;(K key)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; _registryStore[key] &lt;span style="COLOR: blue"&gt;as&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;IList&lt;/span&gt;&amp;lt;T&amp;gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #endregion&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;!--EndFragment--&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&lt;br&gt;
Some of the data stored in the registry when the application starts is a list of all
available countries (for example, retrieved from the database):
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: green"&gt;// register the countries&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;Registry&lt;/span&gt;.Instance.RegisterObjectList&amp;lt;&lt;span style="COLOR: blue"&gt;string&lt;/span&gt;, &lt;span style="COLOR: #2b91af"&gt;Country&lt;/span&gt;&amp;gt;(&lt;span style="COLOR: #a31515"&gt;"countries"&lt;/span&gt;,
countries);
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;!--EndFragment--&gt;
&lt;/p&gt;
&lt;p&gt;
The Country class is very simple:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;namespace&lt;/span&gt; Manu.GenericTests
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;class&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;Country&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; _id;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; _name;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; _code;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; Id
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;get&lt;/span&gt; { &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; _id;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;set&lt;/span&gt; {
_id = &lt;span style="COLOR: blue"&gt;value&lt;/span&gt;; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; Name
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;get&lt;/span&gt; { &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; _name;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;set&lt;/span&gt; {
_name = &lt;span style="COLOR: blue"&gt;value&lt;/span&gt;; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; Code
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;get&lt;/span&gt; { &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; _code;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;set&lt;/span&gt; {
_code = &lt;span style="COLOR: blue"&gt;value&lt;/span&gt;; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; Country()
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; Country(&lt;span style="COLOR: blue"&gt;int&lt;/span&gt; id, &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; name, &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; code)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; _id = id;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; _name = name;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; _code = code;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;!--EndFragment--&gt;
&lt;/p&gt;
&lt;p&gt;
If we want to show all the countries in any webform we can use an CompatObjectDataSource.
After dropping one to the toolbox we configure the type:
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://www.manuelabadia.com/blog/content/binary/EODS_designer1.png" border=0&gt;
&lt;/p&gt;
&lt;p&gt;
And then we can see the list of methods compatible with the Select operation (GetObject
and GetObjectList):
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://www.manuelabadia.com/blog/content/binary/EODS_designer2.png" border=0&gt;
&lt;/p&gt;
&lt;p&gt;
As both methods are generic method definitions, after selecting one of them, we have
to specify the generic parameters. In our case, we stored the countries using a string
key, and we stored a List of Country objects so the generic parameters for the method
are System.String, Manu.GenericTests.Country. After clicking in "Make Generic Method"
we have the data source configured properly:
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://www.manuelabadia.com/blog/content/binary/EODS_designer3.png" border=0&gt;
&lt;/p&gt;
&lt;p&gt;
If we take a look to the ASPX we can see the following code:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;manu&lt;/span&gt;&lt;span style="COLOR: blue"&gt;:&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;CompatObjectDataSource&lt;/span&gt; &lt;span style="COLOR: red"&gt;ID&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="CompatObjectDataSource1"&lt;/span&gt; &lt;span style="COLOR: red"&gt;runat&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="server"&lt;/span&gt; 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: red"&gt;SelectMethod&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="GetObjectList`2[System.String,
[Manu.GenericTests.Country, __code]]"&lt;/span&gt; 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: red"&gt;TypeName&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="Manu.GenericTests.Registry,
__code"&lt;/span&gt; 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: red"&gt;OnObjectCreating&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="ObjectDataSource1_ObjectCreating"&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;SelectParameters&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;asp&lt;/span&gt;&lt;span style="COLOR: blue"&gt;:&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;Parameter&lt;/span&gt; &lt;span style="COLOR: red"&gt;Name&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="key"&lt;/span&gt; &lt;span style="COLOR: red"&gt;Type&lt;/span&gt;&lt;span style="COLOR: blue"&gt;="String"&lt;/span&gt; &lt;span style="COLOR: blue"&gt;/&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;SelectParameters&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;manu&lt;/span&gt;&lt;span style="COLOR: blue"&gt;:&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;CompatObjectDataSource&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
The SelectMethod is saved as "GetObjectList`2[System.String, [Manu.GenericTests.Country,
__code]]" and the TypeName is saved as "Manu.GenericTests.Registry, __code".
&lt;/p&gt;
&lt;p&gt;
The only thing to do now is to set the DefaultValue property for the key parameter
to countries. Now the CompatObjectDataSource has enough information to call to GetObjectList&amp;lt;string,
Country&amp;gt;("countries")&amp;nbsp;from the Registry class and retrieve the countries.
&lt;/p&gt;
&lt;p&gt;
The only thing I'm missing in the CompatObjectDataSource/ExtendedObjectDataSource
is support for Bind expressions for nested properties (&amp;lt;%# Bind(Address.PostalCode)
%&amp;gt;), but unfortunately, the framework can not understand those expressions so nothing
can be done ast the moment. I wrote an email to &lt;a href="http://weblogs.asp.net/scottgu/"&gt;ScottGu&lt;/a&gt; about
that and got this reply from &lt;a href="http://www.shankun.com/"&gt;Shanku Niyogi&lt;/a&gt;:
&lt;/p&gt;
&lt;p&gt;
&lt;em&gt;&lt;strong&gt;"This is definitely a doable thing - we'll add it to our list of items
we're considering adding for an upcoming release."&lt;/strong&gt;&lt;/em&gt;
&lt;/p&gt;
&lt;p&gt;
So keep your fingers crossed.
&lt;/p&gt;
&lt;p&gt;
I'm open to suggestions in what to functionality you would like to see in the ObjectDataSource/CompatObjectDataSource/ExtendedObjectDataSource.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=91a1d00f-197e-4148-b4e1-cea324029dc6" /&gt;</description>
      <comments>http://www.manuelabadia.com/blog/CommentView,guid,91a1d00f-197e-4148-b4e1-cea324029dc6.aspx</comments>
      <category>ASP.NET;Microsoft .NET Framework</category>
    </item>
    <item>
      <trackback:ping>http://www.manuelabadia.com/blog/Trackback.aspx?guid=262cce30-c688-4e79-b3cd-ac0891f70e95</trackback:ping>
      <pingback:server>http://www.manuelabadia.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.manuelabadia.com/blog/PermaLink,guid,262cce30-c688-4e79-b3cd-ac0891f70e95.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://www.manuelabadia.com/blog/CommentView,guid,262cce30-c688-4e79-b3cd-ac0891f70e95.aspx</wfw:comment>
      <wfw:commentRss>http://www.manuelabadia.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=262cce30-c688-4e79-b3cd-ac0891f70e95</wfw:commentRss>
      <slash:comments>4</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Recently I was pointed out by a friend that a new version of the Hibernate Reference
book was released. I have already read the old version of this book, called "hibernate
in action" but as it was half the size of the new book, I decided to read this one
too. Even if the content is heavily based on the previous version, a lot of parts
have been rewritten and it is a lot more clear now (or maybe it is just that I'm a
better hibernate user...). Also, I found out that someone is finally doing a book
about NHibernate:
</p>
        <p>
          <table>
            <tbody>
              <tr>
                <td>
                  <iframe style="WIDTH: 120px; HEIGHT: 240px" marginwidth="0" marginheight="0" src="http://rcm.amazon.com/e/cm?t=manuelabadias-20&amp;o=1&amp;p=8&amp;l=as1&amp;asins=1932394885&amp;fc1=000000&amp;IS2=1&amp;lt1=_blank&amp;lc1=0000FF&amp;bc1=000000&amp;bg1=FFFFFF&amp;f=ifr" frameborder="0" scrolling="no">
                  </iframe>
                </td>
                <td>
                  <iframe style="WIDTH: 120px; HEIGHT: 240px" marginwidth="0" marginheight="0" src="http://rcm.amazon.com/e/cm?t=manuelabadias-20&amp;o=1&amp;p=8&amp;l=as1&amp;asins=1932394923&amp;fc1=000000&amp;IS2=1&amp;lt1=_blank&amp;lc1=0000FF&amp;bc1=000000&amp;bg1=FFFFFF&amp;f=ifr" frameborder="0" scrolling="no">
                  </iframe>
                </td>
              </tr>
            </tbody>
          </table>
        </p>
        <p>
I didn't want to talk about the book in this post. What really caught my attention
was the improvements in the Java 1.5 language. I haven't coded anything in Java for
quite a few years (the last version I used was 1.3). In that time the Java language
didn't have any important changes but the version 1.5 has added a lot of useful things
to the language: Generics, Metadata, Boxing/Unboxing, Enumerations and variable number
of arguments. 
</p>
        <p>
Does some of this sound familiar to you? Java implemented Generics a bit before .NET
Framework 2.0 but all the other stuff was already present in the first version of
the .NET Framework. Also, something that I can't live without now is Properties and
Java doesn't has them. Simulating properties using a get_/set_ methods is nothing
more than a dirty hack (you can also simulate OOP in assembler...)
</p>
        <p>
I have been an early .NET adopter since the beginning of the .NET Framework and a
lot of my friends were jumping on me about that, because in their opinion Java was
a lot better, the .NET Framework was crap, etc. Now they have to shut up ;-)
</p>
        <p>
The local companies here are also using more .NET than Java and I have read some studies
that said that both technologies are similar but usually is less expensive to develop
with .NET (unfortunately I haven't found the links). Also, if you consider the new
features added since the release of .NET Framework v2.0 (WPF, WF, WCF, ASP.NET AJAX
Extensions, LINQ, DLINQ...) clearly Java is lagging behind .NET.<br /></p>
        <img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=262cce30-c688-4e79-b3cd-ac0891f70e95" />
      </body>
      <title>Java lagging behind .NET</title>
      <guid isPermaLink="false">http://www.manuelabadia.com/blog/PermaLink,guid,262cce30-c688-4e79-b3cd-ac0891f70e95.aspx</guid>
      <link>http://www.manuelabadia.com/blog/PermaLink,guid,262cce30-c688-4e79-b3cd-ac0891f70e95.aspx</link>
      <pubDate>Wed, 07 Mar 2007 00:04:30 GMT</pubDate>
      <description>&lt;p&gt;
Recently I was pointed out by a friend that a new version of the Hibernate Reference
book was released. I have already read the old version of this book, called "hibernate
in action" but as it was half the size of the new book, I decided to read this one
too. Even if the content is heavily based on the previous version, a lot of parts
have been rewritten and it is a lot more clear now (or maybe it is just that I'm a
better hibernate user...). Also, I found out that someone is finally doing a book
about NHibernate:
&lt;/p&gt;
&lt;p&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;iframe style="WIDTH: 120px; HEIGHT: 240px" marginwidth=0 marginheight=0 src="http://rcm.amazon.com/e/cm?t=manuelabadias-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=as1&amp;amp;asins=1932394885&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" frameborder=0 scrolling=no&gt;
&lt;/iframe&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;iframe style="WIDTH: 120px; HEIGHT: 240px" marginwidth=0 marginheight=0 src="http://rcm.amazon.com/e/cm?t=manuelabadias-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=as1&amp;amp;asins=1932394923&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" frameborder=0 scrolling=no&gt;
&lt;/iframe&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/p&gt;
&lt;p&gt;
I didn't want to talk about the book in this post. What really caught my attention
was the improvements in the Java 1.5 language. I haven't coded anything in Java for
quite a few years (the last version I used was 1.3). In that time the Java language
didn't have any important changes but the version 1.5 has added a lot of useful things
to the language: Generics, Metadata, Boxing/Unboxing, Enumerations and variable number
of arguments. 
&lt;/p&gt;
&lt;p&gt;
Does some of this sound familiar to you? Java implemented Generics a bit before .NET
Framework 2.0 but all the other stuff was already present in the first version of
the .NET Framework. Also, something that I can't live without now is Properties and
Java doesn't has them. Simulating properties using a get_/set_ methods is nothing
more than a dirty hack (you can also simulate OOP in assembler...)
&lt;/p&gt;
&lt;p&gt;
I have been an early .NET adopter since the beginning of the .NET Framework and a
lot of my friends were jumping on me about that, because in their opinion Java was
a lot better, the .NET Framework was crap, etc. Now they have to shut up ;-)
&lt;/p&gt;
&lt;p&gt;
The local companies here are also using more .NET than Java and I have read some studies
that said that both technologies are similar but usually is less expensive to develop
with .NET (unfortunately I haven't found the links). Also, if you consider the new
features added since the release of .NET Framework v2.0 (WPF, WF, WCF, ASP.NET AJAX
Extensions, LINQ, DLINQ...) clearly Java is lagging behind .NET.&lt;br&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=262cce30-c688-4e79-b3cd-ac0891f70e95" /&gt;</description>
      <comments>http://www.manuelabadia.com/blog/CommentView,guid,262cce30-c688-4e79-b3cd-ac0891f70e95.aspx</comments>
      <category>General;Java;Microsoft .NET Framework</category>
    </item>
    <item>
      <trackback:ping>http://www.manuelabadia.com/blog/Trackback.aspx?guid=560b6980-d109-4047-a886-4c523f090522</trackback:ping>
      <pingback:server>http://www.manuelabadia.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.manuelabadia.com/blog/PermaLink,guid,560b6980-d109-4047-a886-4c523f090522.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://www.manuelabadia.com/blog/CommentView,guid,560b6980-d109-4047-a886-4c523f090522.aspx</wfw:comment>
      <wfw:commentRss>http://www.manuelabadia.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=560b6980-d109-4047-a886-4c523f090522</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
The ObjectDataSource supports using generic classes in the TypeName property although
it doesn't provide any support for it. Usually you'll see that the TypeName property
stores the name of a type (i.e. CustomProject.MyDAL), but it can store the type's
full assembly qualified name (i.e. CustomProject.MyDAL, CustomProject, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=a7a65c534534e209).
</p>
        <p>
The type's full assembly qualified name can be quite complicated and it is described
by the following grammar:
</p>
        <p>
          <br />
          <font face="Courier New">TypeName := NamespaceTypeName | NamespaceTypeName ',' AssemblyNameSpec<br />
 <br />
NamespaceTypeName := NestedTypeName | NamespaceSpec '.' NestedTypeName<br />
 <br />
NestedTypeName := GenericTypeName | NestedTypeName '+' GenericTypeName</font>
        </p>
        <p>
          <font face="Courier New">GenericTypeName := IDENTIFIER | IDENTIFIER '`' Number '['
GenericTypeArgList ']' </font>
        </p>
        <p>
          <font face="Courier New">GenericTypeArgList := GenericTypeArg | GenericTypeArg ','
GenericTypeArgList</font>
        </p>
        <p>
          <font face="Courier New">GenericTypeArg := NamespaceTypeName | '[' TypeSpec ']'<br />
 <br />
NamespaceSpec := IDENTIFIER | NamespaceSpec '.' IDENTIFIER<br />
 <br />
AssemblyNameSpec := IDENTIFIER | IDENTIFIER ',' AssemblyProperties<br />
 <br />
AssemblyProperties := AssemblyProperty | AssemblyProperties ',' AssemblyProperty<br />
 <br />
AssemblyProperty := AssemblyPropertyName '=' AssemblyPropertyValue</font>
        </p>
        <p>
          <br />
For more details about the grammar for type's full assembly qualified name in .NET
Framework v1 take a look <a href="http://msdn2.microsoft.com/en-us/library/yfsftwz6(VS.80).aspx">here</a></p>
        <p>
If you look in detail the grammar, it accept generic type names, that have a '`',
then the number of generic argument and then the generic arguments inside square brackets.
</p>
        <p>
So the following are valid type names:  
</p>
        <p>
          <font face="Courier New">System.Colllections.Generic.List`1[System.Int32], mscorlib</font>
        </p>
        <p>
          <font face="Courier New">MyGraph`2[[Utilities.Set, Utilities],[Utilities.Graph, Utilities]],
MyGraphLibrary</font>
        </p>
        <p>
          <font face="Courier New">MyGraph`2[[Utilities.Set, Utilities, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=a7a65c534534e209],[Utilities.Graph, Utilities, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=a7a65c534534e209]], MyGraphLibrary, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=2134afb4534e209</font>
        </p>
        <p>
So if you want to use a generic type in the ObjectDataSource you just have to specify
it using the syntax explained above. Be sure to add the assembly names if you use
generic types.
</p>
        <p>
What happens if the generic type you want to use is in the App_Code folder? The code
in the App_Code folder gets compiled into a dynamically generated assembly with a
random name so it is impossible to know it. Fortunately, you can use __code as the
assembly name and it will work. Why does this work? When the framework can't resolve
an assembly, the AppDomain AssemblyResolve event is fired. The BuildManager class
(that is a helper class for ASP.NET compilation), captures this event and checks the
specified assembly name. If it is __code, it returns the dynamically generated assembly
for the App_Code folder. Returning App_Code also works (and you save executing a few
instructions).
</p>
        <p>
As an special case, you can use VB, C# or other .NET supported language in the same
web application if you place the code for each language in a different folder. For
example, if you want to use VB and C# you have to create these folders:<br />
App_Code/VB<br />
App_Code/CS
</p>
        <p>
and add this to the web.config:
</p>
        <p>
&lt;codeSubDirectories&gt;<br />
    &lt;add directoryName="VB"/&gt;<br />
    &lt;add directoryName="CS"/&gt;<br />
&lt;/codeSubDirectories&gt;
</p>
        <p>
If you use this configuration two assemblies will be dynamically generated for your
code behind classes, one for each folder. If you want to reference it in the TypeName
of the ObjectDataSource or where the framework expects a fully qualified name you
have to use App_SubCode_VB or App_SubCode_CS.
</p>
        <p>
Of course, the ObjectDataSource doesn't have design time support for this. In fact,
the ObjectDataSource choose type dialog filters out the generic types, the interfaces
and the types registered in the GAC.
</p>
        <p>
The <a href="http://www.manuelabadia.com/products/EODS_features.aspx">ExtendedObjectDataSource</a> will
have full design time support for generic types and more control about the types that
are filtered in the next version:
</p>
        <p>
          <img src="http://www.manuelabadia.com/blog/content/binary/EODS_generics1.png" border="0" />
        </p>
        <p>
When you select a generic type, a textbox and a button appear. You can use the textbox
to specify the type of the generic parameters and click in the button to select the
generic type. Also, there are some checkbox to have control over what types get filtered.
</p>
        <p>
The above dialog has some little positioning issues that I think are caused by Windows
Vista, because the dialog was defined as:
</p>
        <p>
          <img src="http://www.manuelabadia.com/blog/content/binary/EODS_generics2.png" border="0" />
        </p>
        <p>
In a future post I'll talk about generic methods.  
</p>
        <img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=560b6980-d109-4047-a886-4c523f090522" />
      </body>
      <title>ObjectDataSource and Generics (part 1)</title>
      <guid isPermaLink="false">http://www.manuelabadia.com/blog/PermaLink,guid,560b6980-d109-4047-a886-4c523f090522.aspx</guid>
      <link>http://www.manuelabadia.com/blog/PermaLink,guid,560b6980-d109-4047-a886-4c523f090522.aspx</link>
      <pubDate>Wed, 21 Feb 2007 23:52:54 GMT</pubDate>
      <description>&lt;p&gt;
The ObjectDataSource supports using generic classes in the TypeName property although
it doesn't provide any support for it. Usually you'll see that the TypeName property
stores the name of a type (i.e. CustomProject.MyDAL), but it can store the type's
full assembly qualified name (i.e. CustomProject.MyDAL, CustomProject, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=a7a65c534534e209).
&lt;/p&gt;
&lt;p&gt;
The type's full assembly qualified name can be quite complicated and it is described
by the following grammar:
&lt;/p&gt;
&lt;p&gt;
&lt;br&gt;
&lt;font face="Courier New"&gt;TypeName := NamespaceTypeName | NamespaceTypeName ',' AssemblyNameSpec&lt;br&gt;
&amp;nbsp;&lt;br&gt;
NamespaceTypeName := NestedTypeName | NamespaceSpec '.' NestedTypeName&lt;br&gt;
&amp;nbsp;&lt;br&gt;
NestedTypeName := GenericTypeName | NestedTypeName '+' GenericTypeName&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face="Courier New"&gt;GenericTypeName := IDENTIFIER | IDENTIFIER '`' Number '['
GenericTypeArgList ']' &lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face="Courier New"&gt;GenericTypeArgList := GenericTypeArg | GenericTypeArg ','
GenericTypeArgList&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face="Courier New"&gt;GenericTypeArg := NamespaceTypeName | '[' TypeSpec ']'&lt;br&gt;
&amp;nbsp;&lt;br&gt;
NamespaceSpec := IDENTIFIER | NamespaceSpec '.' IDENTIFIER&lt;br&gt;
&amp;nbsp;&lt;br&gt;
AssemblyNameSpec := IDENTIFIER | IDENTIFIER ',' AssemblyProperties&lt;br&gt;
&amp;nbsp;&lt;br&gt;
AssemblyProperties := AssemblyProperty | AssemblyProperties ',' AssemblyProperty&lt;br&gt;
&amp;nbsp;&lt;br&gt;
AssemblyProperty := AssemblyPropertyName '=' AssemblyPropertyValue&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;br&gt;
For more details about the grammar for type's full assembly qualified name in .NET
Framework v1 take a look &lt;a href="http://msdn2.microsoft.com/en-us/library/yfsftwz6(VS.80).aspx"&gt;here&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
If you look in detail the grammar, it accept generic type names, that have a '`',
then the number of generic argument and then the generic arguments inside square brackets.
&lt;/p&gt;
&lt;p&gt;
So the following are valid type names:&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
&lt;font face="Courier New"&gt;System.Colllections.Generic.List`1[System.Int32], mscorlib&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face="Courier New"&gt;MyGraph`2[[Utilities.Set, Utilities],[Utilities.Graph, Utilities]],
MyGraphLibrary&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face="Courier New"&gt;MyGraph`2[[Utilities.Set, Utilities, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=a7a65c534534e209],[Utilities.Graph, Utilities, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=a7a65c534534e209]], MyGraphLibrary, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=2134afb4534e209&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
So if you want to use a generic type in the ObjectDataSource you just have to specify
it using the syntax explained above. Be sure to add the assembly names if you use
generic types.
&lt;/p&gt;
&lt;p&gt;
What happens if the generic type you want to use is in the App_Code folder? The code
in the App_Code folder gets compiled into a dynamically generated assembly with a
random name so it is impossible to know it. Fortunately, you can use __code as the
assembly name and it will work. Why does this work? When the framework can't resolve
an assembly, the AppDomain AssemblyResolve event is fired. The BuildManager class
(that is a helper class for ASP.NET compilation), captures this event and checks the
specified assembly name. If it is __code, it returns the dynamically generated assembly
for the App_Code folder. Returning App_Code also works (and you save executing a few
instructions).
&lt;/p&gt;
&lt;p&gt;
As an special case, you can use VB, C# or other .NET supported language in the same
web application if you place the code for each language in a different folder. For
example, if you want to use VB and C# you have to create these folders:&lt;br&gt;
App_Code/VB&lt;br&gt;
App_Code/CS
&lt;/p&gt;
&lt;p&gt;
and add this to the web.config:
&lt;/p&gt;
&lt;p&gt;
&amp;lt;codeSubDirectories&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;add directoryName="VB"/&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;add directoryName="CS"/&amp;gt;&lt;br&gt;
&amp;lt;/codeSubDirectories&amp;gt;
&lt;/p&gt;
&lt;p&gt;
If you use this configuration two assemblies will be dynamically generated for your
code behind classes, one for each folder. If you want to reference it in the TypeName
of the ObjectDataSource or where the framework expects a fully qualified name you
have to use App_SubCode_VB or App_SubCode_CS.
&lt;/p&gt;
&lt;p&gt;
Of course, the ObjectDataSource doesn't have design time support for this. In fact,
the ObjectDataSource choose type dialog filters out the generic types, the interfaces
and the types registered in the GAC.
&lt;/p&gt;
&lt;p&gt;
The &lt;a href="http://www.manuelabadia.com/products/EODS_features.aspx"&gt;ExtendedObjectDataSource&lt;/a&gt; will
have full design time support for generic types and more control about the types that
are filtered in the next version:
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://www.manuelabadia.com/blog/content/binary/EODS_generics1.png" border=0&gt;
&lt;/p&gt;
&lt;p&gt;
When you select a generic type, a textbox and a button appear. You can use the textbox
to specify the type of the generic parameters and click in the button to select the
generic type. Also, there are some checkbox to have control over what types get filtered.
&lt;/p&gt;
&lt;p&gt;
The above dialog has some little positioning issues that I think are caused by Windows
Vista, because the dialog was defined as:
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://www.manuelabadia.com/blog/content/binary/EODS_generics2.png" border=0&gt;
&lt;/p&gt;
&lt;p&gt;
In a future post I'll talk about generic methods.&amp;nbsp; 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=560b6980-d109-4047-a886-4c523f090522" /&gt;</description>
      <comments>http://www.manuelabadia.com/blog/CommentView,guid,560b6980-d109-4047-a886-4c523f090522.aspx</comments>
      <category>ASP.NET;Microsoft .NET Framework</category>
    </item>
    <item>
      <trackback:ping>http://www.manuelabadia.com/blog/Trackback.aspx?guid=c8f39803-b507-4449-919a-462198a80645</trackback:ping>
      <pingback:server>http://www.manuelabadia.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.manuelabadia.com/blog/PermaLink,guid,c8f39803-b507-4449-919a-462198a80645.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://www.manuelabadia.com/blog/CommentView,guid,c8f39803-b507-4449-919a-462198a80645.aspx</wfw:comment>
      <wfw:commentRss>http://www.manuelabadia.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=c8f39803-b507-4449-919a-462198a80645</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <title>Microsoft ASP.NET AJAX v1.0 released!</title>
      <guid isPermaLink="false">http://www.manuelabadia.com/blog/PermaLink,guid,c8f39803-b507-4449-919a-462198a80645.aspx</guid>
      <link>http://www.manuelabadia.com/blog/PermaLink,guid,c8f39803-b507-4449-919a-462198a80645.aspx</link>
      <pubDate>Wed, 24 Jan 2007 17:17:12 GMT</pubDate>
      <description>&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;Finally the Microsoft AJAX library
1.0 has been released. Take a look to ScottGu's blog for&amp;nbsp;the details:&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;&lt;a href="http://weblogs.asp.net/scottgu/archive/2007/01/23/asp-net-ajax-1-0-released.aspx"&gt;http://weblogs.asp.net/scottgu/archive/2007/01/23/asp-net-ajax-1-0-released.aspx&lt;/a&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;&lt;?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /&gt;What
is really cool about this is that Microsoft has also released the full source code
for the 
&lt;st1:place w:st="on"&gt;
&lt;st1:City w:st="on"&gt;AJAX&lt;/st1:City&gt;
&lt;/st1:place&gt;
library. That move can give a lot of people that do not work with Microsoft related
technologies a reason to try it and use it, and for the rest of us a chance to take
a look to some of the internals if it is needed.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;It is a shame that some parts of
the initial ATLAS library like the Bindings didn’t make it in the final release. Anyway,
they’re available in the AJAX Futures CTP and someday will be part of the official
release.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;Will this mean that we will see
a lot of .NET developers working directly with the Microsoft AJAX library? IMHO, no.
Probably most developers will use the Ajax Control Toolkit and the UpdatePanel to
add 
&lt;st1:place w:st="on"&gt;
&lt;st1:City w:st="on"&gt;AJAX&lt;/st1:City&gt;
&lt;/st1:place&gt;
capabilities to their projects. 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;Creating ASP.NET components that
make use the client side of the Microsoft AJAX library is not easy: You need to know
quite a bunch of stuff: a .NET programming language, ASP.NET, Javascript, HTML, DHTML,
CSS, XML and AJAX Library internals… so I guess a lot of developers are out of luck.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;Fortunately, Nikhil’s Script# can
help a bit, and finally changed the type system to be compatible with the AJAX Library
(I asked Nikhil about this a few months ago and I wasn’t sure that he will do it,
but I’m glad he did!).&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;Also, there is a lot of other new
stuff to look as a .NET developer: WPF, WCF, WF, LINQ, DLINQ, WPF/E. And if you’re
using SQL Server 2005, there are a lot of new things to look at…&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;Personally I have to learn the Microsoft
AJAX Library in detail but I’m also interested in learning Windows Workflow Foundation,
so I’m not sure in what to center my attention at the moment.&lt;/span&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=c8f39803-b507-4449-919a-462198a80645" /&gt;</description>
      <comments>http://www.manuelabadia.com/blog/CommentView,guid,c8f39803-b507-4449-919a-462198a80645.aspx</comments>
      <category>Ajax;ASP.NET;JavaScript;Microsoft .NET Framework;WPF/E</category>
    </item>
    <item>
      <trackback:ping>http://www.manuelabadia.com/blog/Trackback.aspx?guid=6e509f70-3db8-46f4-b451-1ef9dd80740b</trackback:ping>
      <pingback:server>http://www.manuelabadia.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.manuelabadia.com/blog/PermaLink,guid,6e509f70-3db8-46f4-b451-1ef9dd80740b.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://www.manuelabadia.com/blog/CommentView,guid,6e509f70-3db8-46f4-b451-1ef9dd80740b.aspx</wfw:comment>
      <wfw:commentRss>http://www.manuelabadia.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=6e509f70-3db8-46f4-b451-1ef9dd80740b</wfw:commentRss>
      <slash:comments>5</slash:comments>
      <title>ANTLR C# Overview - Part 3</title>
      <guid isPermaLink="false">http://www.manuelabadia.com/blog/PermaLink,guid,6e509f70-3db8-46f4-b451-1ef9dd80740b.aspx</guid>
      <link>http://www.manuelabadia.com/blog/PermaLink,guid,6e509f70-3db8-46f4-b451-1ef9dd80740b.aspx</link>
      <pubDate>Mon, 08 Jan 2007 07:41:33 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a href="http://www.manuelabadia.com/blog/PermaLink,guid,ff1dc504-f854-40b4-bfe7-250ce91efad7.aspx"&gt;Click
here to see part 1 of this ANTLR Overview&lt;/a&gt;
&lt;br&gt;
&lt;a href="http://www.manuelabadia.com/blog/PermaLink,guid,5085c0cc-5256-429c-a18c-4639afa0dcc1.aspx"&gt;Click
here to see part&amp;nbsp;2 of this ANTLR Overview&lt;/a&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;To complete the overview of the
main ANTLR runtime classes, we’ll study an example.&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;The following file contains a grammar
for evaluating simple expressions:&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;&lt;font face="Times New Roman" color=#000000 size=3&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt; 
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
grammar Expr;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
options {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; language=CSharp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; output=AST;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; ASTLabelType=CommonTree;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
prog:&amp;nbsp;&amp;nbsp; ( stat 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
if ($stat.tree != null){
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Console.WriteLine($stat.tree.ToStringTree());
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
} else {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Console.WriteLine();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; } 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; )+ ;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
stat:&amp;nbsp;&amp;nbsp; expr NEWLINE&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; -&amp;gt; expr
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp; ID '=' expr NEWLINE -&amp;gt; ^('=' ID expr)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp; NEWLINE&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; -&amp;gt; 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; ;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
expr:&amp;nbsp;&amp;nbsp; multExpr (('+'^^|'-'^^) multExpr)*
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; ; 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
multExpr
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; :&amp;nbsp;&amp;nbsp; atom ('*'^^ atom)*
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; ; 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
atom:&amp;nbsp;&amp;nbsp; INT 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp; ID
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp; '('! expr ')'!
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; ;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
ID&amp;nbsp; :&amp;nbsp;&amp;nbsp; ('a'..'z'|'A'..'Z')+ ;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
INT :&amp;nbsp;&amp;nbsp; '0'..'9'+ ;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
NEWLINE:'\r'? '\n' ;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
WS&amp;nbsp; :&amp;nbsp;&amp;nbsp; (' '|'\t')+ { Skip(); } ;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;&lt;/span&gt; 
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;&lt;font size=3&gt;&lt;font color=#000000&gt;&lt;font face="Times New Roman"&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;In this file, there are parse rules
and lexer rules. Parser rules are lowercase and lexer rules are uppercase. &lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;The tokens that will be recognized
by the lexer are defined at the end of the file and are ID (identifier), INT (integer),
NEWLINE (carriage return), WS (white space). Other tokens like ‘=’ don’t have a lexer
rule but a rule will be generated implicity by ANTLR as we’ll see later.&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;The grammar start symbol is prog,
that represents a program. A program is made of one ore more statements. A statement
is:&lt;br&gt;
•&amp;nbsp;an expression following by a NEWLINE token.&lt;br&gt;
•&amp;nbsp;or an ID token, followed by an equal token and then followed by a NEWLINE token.&lt;br&gt;
•&amp;nbsp;or a NEWLINE token.&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;An expression is a multExpr that
can be followed by the addition or substraction of more multExpr. A multExpr is an
atom that can be followed by the multiplication of more atoms. Finally, an atom is
an integer, an identifier or an expression enclosed in brackets. &lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;This way of defining expressions
is very common. As the grammar supports addition, substraction and multiplication,
and the multiplication has higher precedence, the grammar rules are defined so the
multiplication will appear later in a top down parse tree.&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;When we run ANTLR, it generates
a Expr.Tokens file with the integer assigned to each token:&lt;/span&gt;
&lt;/p&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;&lt;font size=3&gt;&lt;font color=#000000&gt;&lt;font face="Times New Roman"&gt; 
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
NEWLINE=4
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
ID=5
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
INT=6
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
WS=7
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: maroon"&gt;'='&lt;/span&gt;=8
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: maroon"&gt;'+'&lt;/span&gt;=9
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: maroon"&gt;'-'&lt;/span&gt;=10
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: maroon"&gt;'*'&lt;/span&gt;=11
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: maroon"&gt;'('&lt;/span&gt;=12
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: maroon"&gt;')'&lt;/span&gt;=13
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;br&gt;
&lt;/p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt; 
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;&lt;font size=3&gt;&lt;font color=#000000&gt;&lt;font face="Times New Roman"&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;The
indexes 0 to 3 are reserved for special tokens (invalid, EOR, DOWN, UP). The tokens
explicitly defined in the .g file are the first 4 shown above, but the others were
created implicitly by ANTLR.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;The first part of the Lexer starts
defining this tokens:&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;&lt;font face="Times New Roman" color=#000000 size=3&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt; 
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;class&lt;/span&gt; &lt;span style="COLOR: teal"&gt;ExprLexer&lt;/span&gt; :
Lexer 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;const&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; T10
= 10;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;const&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; T11
= 11;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;const&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; T9
= 9;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;const&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; INT
= 6;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;const&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; EOF
= -1;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;const&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; WS
= 7;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;const&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; T12
= 12;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;const&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; Tokens
= 14;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;const&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; T8
= 8;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;const&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; T13
= 13;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;const&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; NEWLINE
= 4;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;const&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; ID
= 5;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;&lt;/span&gt; 
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;The tokens created implicitly get
a name like TXXX, where XXX is the integer used to represent that token.&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;The methods present in the ExprLexer
class are the constructors (that call a helper method called InitializeCyclicDFAs),
the mTokens method and the mXXX methods, where XXX is one of the constants defined
at the top of the class.&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;Remember that the mTokens method
is called when the NextToken method is called, and what it does is to select one of
the mXXX methods to call based on the input (using a DFA for this). The mTokens method
of the ExprLexer is:&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;&lt;font face="Times New Roman" color=#000000 size=3&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt; 
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;override&lt;/span&gt; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; mTokens() &lt;span style="COLOR: green"&gt;//
throws RecognitionException &lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;// Expr.g:1:10: (
T8 | T9 | T10 | T11 | T12 | T13 | ID | INT | NEWLINE | WS )&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; alt5 =
10;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;switch&lt;/span&gt; ( input.LA(1)
) 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'='&lt;/span&gt;:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; alt5 = 1; &lt;span style="COLOR: blue"&gt;break&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'+'&lt;/span&gt;:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; alt5 = 2; &lt;span style="COLOR: blue"&gt;break&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'-'&lt;/span&gt;:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; alt5 = 3; &lt;span style="COLOR: blue"&gt;break&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'*'&lt;/span&gt;:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; alt5 = 4; &lt;span style="COLOR: blue"&gt;break&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'('&lt;/span&gt;:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; alt5 = 5; &lt;span style="COLOR: blue"&gt;break&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;')'&lt;/span&gt;:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; alt5 = 6; &lt;span style="COLOR: blue"&gt;break&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'A'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'B'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'C'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'D'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'E'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'F'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'G'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'H'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'I'&lt;/span&gt;: 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'J'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'K'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'L'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'M'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'N'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'O'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'P'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'Q'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'R'&lt;/span&gt;: 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'S'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'T'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'U'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'V'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'W'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'X'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'Y'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'Z'&lt;/span&gt;:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'a'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'b'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'c'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'d'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'e'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'f'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'g'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'h'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'i'&lt;/span&gt;:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'j'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'k'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'l'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'m'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'n'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'o'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'p'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'q'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'r'&lt;/span&gt;:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'s'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'t'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'u'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'v'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'w'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'x'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'y'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'z'&lt;/span&gt;:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; alt5 = 7;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;break&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'0'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'1'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'2'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'3'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'4'&lt;/span&gt;: 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'5'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'6'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'7'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'8'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'9'&lt;/span&gt;:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; alt5 = 8;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;break&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'\n'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'\r'&lt;/span&gt;:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; alt5 = 9;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;break&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'\t'&lt;/span&gt;: &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;'
'&lt;/span&gt;:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; alt5 = 10;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;break&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;default&lt;/span&gt;:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; NoViableAltException
nvae_d5s0 =
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; NoViableAltException(&lt;span style="COLOR: maroon"&gt;"1:1:
Tokens : ( T8 | T9 | T10 | T11 | T12 | T13 | ID | INT | NEWLINE | WS );"&lt;/span&gt;, 5,
0, input);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;throw&lt;/span&gt; nvae_d5s0;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;switch&lt;/span&gt; (alt5) 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; 1
:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
Expr.g:1:10: T8&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; { mT8();
} &lt;span style="COLOR: blue"&gt;break&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; 2
:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
Expr.g:1:13: T9&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; { mT9();
} &lt;span style="COLOR: blue"&gt;break&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; 3
:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
Expr.g:1:16: T10&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; { mT10();
} &lt;span style="COLOR: blue"&gt;break&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; 4
:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
Expr.g:1:20: T11&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; { mT11();
} &lt;span style="COLOR: blue"&gt;break&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; 5
:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
Expr.g:1:24: T12&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; { mT12();
} &lt;span style="COLOR: blue"&gt;break&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; 6
:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
Expr.g:1:28: T13&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; { mT13();
} &lt;span style="COLOR: blue"&gt;break&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; 7
:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
Expr.g:1:32: ID&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; { mID();
} &lt;span style="COLOR: blue"&gt;break&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; 8
:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
Expr.g:1:35: INT&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; { mINT();
} &lt;span style="COLOR: blue"&gt;break&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; 9
:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
Expr.g:1:39: NEWLINE&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; { mNEWLINE();
} &lt;span style="COLOR: blue"&gt;break&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; 10
:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
Expr.g:1:47: WS&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; { mWS();
} &lt;span style="COLOR: blue"&gt;break&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;&lt;/span&gt; 
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;&lt;font face="Times New Roman" color=#000000 size=3&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;In this sample the logic is really
simple. It sets the alternative depending on the look ahead (first switch) and then
calls to the corresponding mXXX method (second switch).&lt;br&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;The code for the methods mXXX is
also straightforward. For example, the code for the mT8 method (that has to match
an equals character) is:&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;&lt;font face="Times New Roman" color=#000000 size=3&gt; 
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; mT8() &lt;span style="COLOR: green"&gt;//
throws RecognitionException [2]&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;try&lt;/span&gt; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ruleNestingLevel++;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; _type
= T8;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; _start
= CharIndex;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; _line
= Line;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; _charPosition
= CharPositionInLine;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; _channel
= Token.DEFAULT_CHANNEL;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
Expr.g:7:6: ( '=' )&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
Expr.g:7:6: '='&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Match(&lt;span style="COLOR: maroon"&gt;'='&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; ((token
== &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;) &amp;amp;&amp;amp; (ruleNestingLevel == 1)) {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Emit(_type,
_line, _charPosition, _channel, _start, CharIndex - 1);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;span style="COLOR: blue"&gt;finally&lt;/span&gt; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ruleNestingLevel--;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;br&gt;
&lt;/font&gt;&lt;/span&gt;&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;The code starts incrementing
the ruleNestingLevel variable (that is used to emit tokens only in non fragment lexer
rules) and setting the information about the token being generated using the current
token type and channel and the properties of the Lexer class (CharIndex, Line, CharPositionInLine).
Then it calls the Lexer method Match that checks if the current character is what
was expected and creates the associated token. Finally the nesting level is left unchanged.&lt;/span&gt;&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;The method mWS (that recognizes
white spaces and tabs) is:&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;&lt;font face="Times New Roman" color=#000000 size=3&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;&lt;font face="Times New Roman" color=#000000 size=3&gt; 
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; mWS() &lt;span style="COLOR: green"&gt;//
throws RecognitionException [2]&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;try&lt;/span&gt; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ruleNestingLevel++;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; _type
= WS;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; _start
= CharIndex;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; _line
= Line;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; _charPosition
= CharPositionInLine;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; _channel
= Token.DEFAULT_CHANNEL;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
Expr.g:39:9: ( ( (' '|'\\t'))+ )&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
Expr.g:39:9: ( (' '|'\\t'))+&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
Expr.g:39:9: ( (' '|'\\t'))+&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; cnt4
= 0;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;do&lt;/span&gt; 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; alt4
= 2;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; LA4_0
= input.LA(1);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (
(LA4_0 == &lt;span style="COLOR: maroon"&gt;'\t'&lt;/span&gt; || LA4_0 == &lt;span style="COLOR: maroon"&gt;'
'&lt;/span&gt;) ){
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; alt4 = 1;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;switch&lt;/span&gt; (alt4) 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; 1 :
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;// Expr.g:39:10:
(' '|'\\t')&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (
input.LA(1) == &lt;span style="COLOR: maroon"&gt;'\t'&lt;/span&gt; || input.LA(1) == &lt;span style="COLOR: maroon"&gt;'
'&lt;/span&gt; ) {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; input.Consume();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;span style="COLOR: blue"&gt;else&lt;/span&gt;&amp;nbsp;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; MismatchedSetException
mse =
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; MismatchedSetException(&lt;span style="COLOR: blue"&gt;null&lt;/span&gt;,input);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Recover(mse);&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;throw&lt;/span&gt; mse;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;break&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;default&lt;/span&gt;:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; ( cnt4 &amp;gt;=
1 ) &lt;span style="COLOR: blue"&gt;goto&lt;/span&gt; loop4;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; EarlyExitException eee =
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; EarlyExitException(4,
input);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;throw&lt;/span&gt; eee;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
cnt4++;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;span style="COLOR: blue"&gt;while&lt;/span&gt; (&lt;span style="COLOR: blue"&gt;true&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; loop4:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;// Stops C# compiler whinging that
label 'loop4' has no statements&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Skip(); 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (
(token == &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;) &amp;amp;&amp;amp; (ruleNestingLevel == 1)
){
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Emit(_type,
_line, _charPosition, _channel, _start, CharIndex-1);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;span style="COLOR: blue"&gt;finally&lt;/span&gt; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ruleNestingLevel--;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;&lt;/font&gt;&lt;/span&gt; 
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;The method has the beginning and
the end part like the previous one, but the recognition logic in the middle is a bit
more complex. It has a counter initialized to 0 because the rule must find at least
one white space or tab. It starts looking for a white space or tab and when it founds
one consumes it. When there aren’t more white spaces or tabs, the code exits the do.
If no character was consumed (the counter was 0), an execption is thrown. Otherwise,
the code that followed the lexer rule is executed.&amp;nbsp; The Skip methods assigns
the SKIP_TOKEN to the token field so no token is emmited later.&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;The other methods in the lexer class
are very similar to the ones we’ve studied.&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;Let’s move to the parser. The parser
starts with the following code:&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;&lt;font face="Times New Roman" color=#000000 size=3&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt; 
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;class&lt;/span&gt; &lt;span style="COLOR: teal"&gt;ExprParser&lt;/span&gt; :
Parser 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;static&lt;/span&gt; &lt;span style="COLOR: blue"&gt;readonly&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt;[]
tokenNames = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt;[] 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: maroon"&gt;"&amp;lt;invalid&amp;gt;"&lt;/span&gt;, 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: maroon"&gt;"&amp;lt;EOR&amp;gt;"&lt;/span&gt;, 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: maroon"&gt;"&amp;lt;DOWN&amp;gt;"&lt;/span&gt;, 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: maroon"&gt;"&amp;lt;UP&amp;gt;"&lt;/span&gt;, 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: maroon"&gt;"NEWLINE"&lt;/span&gt;, 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: maroon"&gt;"ID"&lt;/span&gt;, 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: maroon"&gt;"INT"&lt;/span&gt;, 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: maroon"&gt;"WS"&lt;/span&gt;, 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: maroon"&gt;"'='"&lt;/span&gt;, 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: maroon"&gt;"'+'"&lt;/span&gt;, 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: maroon"&gt;"'-'"&lt;/span&gt;, 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: maroon"&gt;"'*'"&lt;/span&gt;, 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: maroon"&gt;"'('"&lt;/span&gt;, 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: maroon"&gt;"')'"&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; };
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;const&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; INT
= 6;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;const&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; EOF
= -1;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;const&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; WS
= 7;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;const&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; NEWLINE
= 4;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;const&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; ID
= 5; 
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;&lt;/span&gt; 
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;&lt;font face="Times New Roman" color=#000000 size=3&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;&lt;font face="Times New Roman" color=#000000 size=3&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;that declares the tokens used in
the lexer.&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;The class continues like this:&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;&lt;font face="Times New Roman" color=#000000 size=3&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt; 
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; ExprParser(ITokenStream input) 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; : &lt;span style="COLOR: blue"&gt;base&lt;/span&gt;(input)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; InitializeCyclicDFAs();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;protected&lt;/span&gt; ITreeAdaptor adaptor
= &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; CommonTreeAdaptor();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; ITreeAdaptor TreeAdaptor
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;get&lt;/span&gt; { &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; &lt;span style="COLOR: blue"&gt;this&lt;/span&gt;.adaptor;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;set&lt;/span&gt; { &lt;span style="COLOR: blue"&gt;this&lt;/span&gt;.adaptor
= value; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;override&lt;/span&gt; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt;[]
TokenNames
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;get&lt;/span&gt; { &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; tokenNames;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;override&lt;/span&gt; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; GrammarFileName
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;get&lt;/span&gt; { &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;"Expr.g"&lt;/span&gt;;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;&lt;/span&gt; 
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;&lt;font face="Times New Roman" color=#000000 size=3&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;&lt;font face="Times New Roman" color=#000000 size=3&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;So the constructor is declared and
an ITreeAdaptor is created (because we set the option to build an AST) and exposed
as a property. The other properties expose information about this recognizer.&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;Then we have a nested class for
each parser rule and a method for each parser rule that returns the previous nested
class. For the prog rule we have:&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;&lt;font face="Times New Roman" color=#000000 size=3&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt; 
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;class&lt;/span&gt; &lt;span style="COLOR: teal"&gt;prog_return&lt;/span&gt; :
ParserRuleReturnScope 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;internal&lt;/span&gt; CommonTree
tree;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;override&lt;/span&gt; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;object&lt;/span&gt; Tree
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;get&lt;/span&gt; { &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; tree;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; };
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: green"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // $ANTLR start prog&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;// Expr.g:9:1: prog : ( stat )+ ;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; prog_return prog() &lt;span style="COLOR: green"&gt;//
throws RecognitionException [1]&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {&amp;nbsp;&amp;nbsp; 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; prog_return retval = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; prog_return();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; retval.start = input.LT(1);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; CommonTree root_0 = &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; stat_return stat1 = &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;try&lt;/span&gt; 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
Expr.g:9:9: ( ( stat )+ )&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
Expr.g:9:9: ( stat )+&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; root_0
= (CommonTree)adaptor.GetNilNode();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
Expr.g:9:9: ( stat )+&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; cnt1
= 0;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;do&lt;/span&gt; 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; alt1
= 2;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; LA1_0
= input.LA(1);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (
((LA1_0 &amp;gt;= NEWLINE &amp;amp;&amp;amp; LA1_0 &amp;lt;= INT) || LA1_0 == 12) )
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; alt1 = 1;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;switch&lt;/span&gt; (alt1) 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; 1 :
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;// Expr.g:9:11: stat&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; CommonTree root_1 = (CommonTree)adaptor.GetNilNode();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; PushFollow(FOLLOW_stat_in_prog43);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; stat1 = stat();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; followingStackPointer_--;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; adaptor.AddChild(root_1,
stat1.Tree);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (((CommonTree)stat1.tree)
!= &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;){
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Console.WriteLine(((CommonTree)stat1.tree).ToStringTree());
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;span style="COLOR: blue"&gt;else&lt;/span&gt; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Console.WriteLine();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; adaptor.AddChild(root_0,
root_1);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;break&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;default&lt;/span&gt;:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; ( cnt1 &amp;gt;=
1 ) &lt;span style="COLOR: blue"&gt;goto&lt;/span&gt; loop1;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; EarlyExitException eee =
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; EarlyExitException(1,
input);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;throw&lt;/span&gt; eee;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
cnt1++;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;span style="COLOR: blue"&gt;while&lt;/span&gt; (&lt;span style="COLOR: blue"&gt;true&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; loop1:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;// Stops C# compiler whinging that
label 'loop1' has no statements&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;catch&lt;/span&gt; (RecognitionException
re) 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ReportError(re);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Recover(input,re);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;finally&lt;/span&gt; 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; retval.stop = input.LT(-1);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; retval.tree
= (CommonTree)adaptor.RulePostProcessing(root_0);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; adaptor.SetTokenBoundaries(retval.Tree,
retval.start, retval.stop);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; retval;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;&lt;/span&gt; 
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;&lt;font face="Times New Roman" color=#000000 size=3&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;As explained in a previous article,
the return classes generated when we have set the option to generate an AST inherit
from ParserRuleReturnScope and have a Tree property with the AST generated for that
rule. &lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;The prog method starts creating
the return value and setting the initial token for the AST. The method ends setting
the last token for the AST and saves the resulting AST.&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;The core of the method starts after
the try. The code starts creating a “nil” node. As the rule is prog : ( stat )+, the
generated code is a do…while with a counter to check that at least the stat rule has
been entered at least one. The basic structure of the generated code is similar to
the one we studied in the lexer method mWS. If the token found is one of the first
tokens that appear in a stat rule, the code goes to the case 1: of the switch.&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;A new “nil” node is created, the
stat rule is invoked, and the AST generated by the stat rule is added as a child to
“nil” node created previously. The BaseRecognizer class uses a stack to store the
token types that can follow a rule invocation. Before calling a rule the follow set
is pushed in this stack (PushFollow) and after the call, the follow set is removed
from the stack(followingStackPointer_--). This is used when there is an error in the
parsing process so ANTLR can continue execution adding a token or deleting a token. &lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;The code that follows is the one
that we included in the parser rule:&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;&lt;font face="Times New Roman" color=#000000 size=3&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt; 
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
prog:&amp;nbsp;&amp;nbsp; ( stat 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
if ($stat.tree != null){
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Console.WriteLine($stat.tree.ToStringTree());
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
} else {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Console.WriteLine();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; } 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; )+ ;
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;&lt;/span&gt; 
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;&lt;font face="Times New Roman" color=#000000 size=3&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;&lt;font face="Times New Roman" color=#000000 size=3&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt; 
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;Finally the first tree created at
the top of the method (that contained a “nil” node) is combined with the tree obtained
from the stat rule.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;As the others methods are very similar
we’re going to study only the generated method for the atom rule:&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt; mso-layout-grid-align: none"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;font face="Times New Roman" color=#000000 size=3&gt;&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt; 
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
atom:&amp;nbsp;&amp;nbsp; INT 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp; ID
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp; '('! expr ')'!
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; ;
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt; 
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: green"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // $ANTLR start atom&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;// Expr.g:31:1: atom : ( INT | ID |
'('! expr ')'! );&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; atom_return atom() &lt;span style="COLOR: green"&gt;//
throws RecognitionException [1]&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {&amp;nbsp;&amp;nbsp; 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; atom_return retval = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; atom_return();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; retval.start = input.LT(1);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; CommonTree root_0 = &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; IToken INT16 = &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; IToken ID17 = &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; IToken char_literal18 = &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; IToken char_literal20 = &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; expr_return expr19 = &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; CommonTree INT16_tree=&lt;span style="COLOR: blue"&gt;null&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; CommonTree ID17_tree=&lt;span style="COLOR: blue"&gt;null&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; CommonTree char_literal18_tree=&lt;span style="COLOR: blue"&gt;null&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; CommonTree char_literal20_tree=&lt;span style="COLOR: blue"&gt;null&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;try&lt;/span&gt; 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
Expr.g:31:9: ( INT | ID | '('! expr ')'! )&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; alt6
= 3;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;switch&lt;/span&gt; (
input.LA(1) ) 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; INT:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; alt6 =
1;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;break&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; ID:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; alt6 =
2;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;break&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; 12:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; alt6 =
3;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;break&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;default&lt;/span&gt;:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
NoViableAltException nvae_d6s0 =
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; NoViableAltException(&lt;span style="COLOR: maroon"&gt;"31:1:
atom : ( INT | ID | '('! expr ')'! );"&lt;/span&gt;, 6, 0, input);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;throw&lt;/span&gt; nvae_d6s0;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;switch&lt;/span&gt; (alt6) 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; 1
:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
Expr.g:31:9: INT&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; root_0 = (CommonTree)adaptor.GetNilNode();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; INT16 = (IToken)input.LT(1);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Match(input,INT,FOLLOW_INT_in_atom191); 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; INT16_tree = (CommonTree)adaptor.Create(INT16);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; adaptor.AddChild(root_0, INT16_tree);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;break&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; 2
:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
Expr.g:32:9: ID&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; root_0 = (CommonTree)adaptor.GetNilNode();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; ID17 = (IToken)input.LT(1);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Match(input,ID,FOLLOW_ID_in_atom202); 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; ID17_tree = (CommonTree)adaptor.Create(ID17);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; adaptor.AddChild(root_0, ID17_tree);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;break&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; 3
:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
Expr.g:33:9: '('! expr ')'!&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; root_0 = (CommonTree)adaptor.GetNilNode();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; char_literal18 = (IToken)input.LT(1);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Match(input,12,FOLLOW_12_in_atom212); 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; PushFollow(FOLLOW_expr_in_atom215);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; expr19 = expr();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; followingStackPointer_--;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; adaptor.AddChild(root_0, expr19.Tree);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; char_literal20 = (IToken)input.LT(1);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Match(input,13,FOLLOW_13_in_atom217); 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;break&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;catch&lt;/span&gt; (RecognitionException
re) 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ReportError(re);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Recover(input,re);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;finally&lt;/span&gt; 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; retval.stop = input.LT(-1);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; retval.tree
= (CommonTree)adaptor.RulePostProcessing(root_0);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; adaptor.SetTokenBoundaries(retval.Tree,
retval.start, retval.stop);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; retval;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;/font&gt; 
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
The start and the end of the method is similar to the prog method, although this one
declares a lot of variables that will be used later.
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
The core of the method starts in the first switch. Based on the next token an alternative
is choosen. If it isn’t one of the expected tokens (INT, ID or ‘(‘) and error is thrown.
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
The second switch has the code to execute based on the selected alternative. The first
two alternatives are atom : INT | ID, and what the code does is to create a “nil”
node, match the token with the expected one, and add the token as a child of the “nil”
node.
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
The last alternative, atom: '('! expr ')'!, create a “nil” node, matches the ‘(‘ token,
calls to the expr method, adds the AST generated by the expression as a child of the
“nil” node, and matches the ‘)’ token. In this alternative the matched tokens haven’t
been added to the AST because the ! operator specifies to not add them.
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
The parse tree generated for the input&lt;br&gt;
a=3&lt;br&gt;
a+5
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
is:
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;img height=408 alt=example_parseTree.PNG src="http://www.manuelabadia.com/blog/content/binary/example_parseTree.PNG" width=558 border=0&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
The atom rule is called 3 times (for 3, for a and for 5).
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;br&gt;
The AST generation for the atom 3 is (before and after the finally keyword):
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;img height=199 alt=atom_pre1.PNG src="http://www.manuelabadia.com/blog/content/binary/atom_pre1.PNG" width=214 border=0&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;img height=143 alt=atom1.PNG src="http://www.manuelabadia.com/blog/content/binary/atom1.PNG" width=220 border=0&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
The “nil” node was optimized in the RulePostProcessing method.
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
The expr rule is called twice (for 3 and for a+5).
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
The optimized AST for the a+5 expression is:
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;img height=184 alt=expr.PNG src="http://www.manuelabadia.com/blog/content/binary/expr.PNG" width=211 border=0&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
The final AST generated is:
&lt;/p&gt;
&lt;font face="Times New Roman" color=#000000 size=3&gt; 
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;img height=229 alt=prog.PNG src="http://www.manuelabadia.com/blog/content/binary/prog.PNG" width=247 border=0&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;br&gt;
&lt;/font&gt;The images of the trees have been created using&amp;nbsp;the &lt;a href="http://www.manuelabadia.com/products/StructsViz_features.aspx"&gt;StructsViz
DebuggerVisualizers&lt;/a&gt;.&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
To finish, lets see the code generated for the tree parser. The input to the tree
parser based on the example AST is:
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;img height=248 alt=example_treeNodeStream.PNG src="http://www.manuelabadia.com/blog/content/binary/example_treeNodeStream.PNG" width=617 border=0&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
The code generated for the tree parser starts like this:
&lt;/p&gt;
&lt;font face="Times New Roman" color=#000000 size=3&gt; 
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;class&lt;/span&gt; &lt;span style="COLOR: teal"&gt;EvalTreeParser&lt;/span&gt; :
TreeParser 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;static&lt;/span&gt; &lt;span style="COLOR: blue"&gt;readonly&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt;[]
tokenNames = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt;[] 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: maroon"&gt;"&amp;lt;invalid&amp;gt;"&lt;/span&gt;, 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: maroon"&gt;"&amp;lt;EOR&amp;gt;"&lt;/span&gt;, 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: maroon"&gt;"&amp;lt;DOWN&amp;gt;"&lt;/span&gt;, 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: maroon"&gt;"&amp;lt;UP&amp;gt;"&lt;/span&gt;, 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: maroon"&gt;"NEWLINE"&lt;/span&gt;, 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: maroon"&gt;"ID"&lt;/span&gt;, 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: maroon"&gt;"INT"&lt;/span&gt;, 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: maroon"&gt;"WS"&lt;/span&gt;, 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: maroon"&gt;"'='"&lt;/span&gt;, 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: maroon"&gt;"'+'"&lt;/span&gt;, 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: maroon"&gt;"'-'"&lt;/span&gt;, 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: maroon"&gt;"'*'"&lt;/span&gt;, 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: maroon"&gt;"'('"&lt;/span&gt;, 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: maroon"&gt;"')'"&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; };
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;const&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; INT
= 6;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;const&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; EOF
= -1;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;const&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; WS
= 7;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;const&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; NEWLINE
= 4;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;const&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; ID
= 5;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; EvalTreeParser(ITreeNodeStream
input) 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; : &lt;span style="COLOR: blue"&gt;base&lt;/span&gt;(input)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; InitializeCyclicDFAs();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;override&lt;/span&gt; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt;[]
TokenNames
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;get&lt;/span&gt; { &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; tokenNames;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;override&lt;/span&gt; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; GrammarFileName
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;get&lt;/span&gt; { &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; &lt;span style="COLOR: maroon"&gt;"Eval.g"&lt;/span&gt;;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;/** Map variable name to Integer object
holding value */&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; Hashtable memory = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; Hashtable();
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;/font&gt; 
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
If you compare this code with the parser we studied before you can see that is identical
to it but it doesn’t has the tree adaptor (because the tree parser does not generate
an AST). If we compare the code generated for the rules, we’ll find out that it is
very similar to the code generated for the methods studied earlier in the parser (but
without the code for AST generation). For example, the code for the expr rule is:
&lt;/p&gt;
&lt;font face="Times New Roman" color=#000000 size=3&gt; 
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: green"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // $ANTLR start expr&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;// Eval.g:24:1: expr returns [int value]
: ( ^( '+' a= expr b= expr ) | ^( '-' a= expr b= expr ) | ^( '*' a= expr b= expr )
| ID | integer= INT );&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; expr() &lt;span style="COLOR: green"&gt;//
throws RecognitionException [1]&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {&amp;nbsp;&amp;nbsp; 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; value =
0;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; CommonTree integer = &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; CommonTree ID4 = &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; a = 0;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; b = 0;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;try&lt;/span&gt; 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
Eval.g:25:9: ( ^( '+' a= expr b= expr ) | ^( '-' a= expr b= expr ) | ^( '*' a= expr
b= expr ) | ID | integer= INT )&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; alt3
= 5;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;switch&lt;/span&gt; (
input.LA(1) ) 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; 9:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; alt3 =
1;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;break&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; 10:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; alt3 =
2;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;break&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; 11:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; alt3 =
3;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;break&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; ID:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; alt3 =
4;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;break&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; INT:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; alt3 =
5;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;break&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;default&lt;/span&gt;:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
NoViableAltException nvae_d3s0 =
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; NoViableAltException(&lt;span style="COLOR: maroon"&gt;"24:1:
expr returns [int value] : ( ^( '+' a= expr b= expr ) | ^( '-' a= expr b= expr ) |
^( '*' a= expr b= expr ) | ID | integer= INT );"&lt;/span&gt;, 3, 0, input);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;throw&lt;/span&gt; nvae_d3s0;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;switch&lt;/span&gt; (alt3) 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; 1
:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
Eval.g:25:9: ^( '+' a= expr b= expr )&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Match(input,9,FOLLOW_9_in_expr109); 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Match(input, Token.DOWN, &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;); 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; PushFollow(FOLLOW_expr_in_expr113);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; a = expr();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; followingStackPointer_--;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; PushFollow(FOLLOW_expr_in_expr117);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; b = expr();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; followingStackPointer_--;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Match(input, Token.UP, &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;); 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; value =&amp;nbsp; a+b; 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;break&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; 2
:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
Eval.g:26:9: ^( '-' a= expr b= expr )&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Match(input,10,FOLLOW_10_in_expr132); 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Match(input, Token.DOWN, &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;); 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; PushFollow(FOLLOW_expr_in_expr136);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; a = expr();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; followingStackPointer_--;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; PushFollow(FOLLOW_expr_in_expr140);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; b = expr();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; followingStackPointer_--;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Match(input, Token.UP, &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;); 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; value =&amp;nbsp; a-b; 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;break&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; 3
:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
Eval.g:27:9: ^( '*' a= expr b= expr )&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Match(input,11,FOLLOW_11_in_expr158); 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Match(input, Token.DOWN, &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;); 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; PushFollow(FOLLOW_expr_in_expr162);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; a = expr();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; followingStackPointer_--;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; PushFollow(FOLLOW_expr_in_expr166);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; b = expr();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; followingStackPointer_--;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Match(input, Token.UP, &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;); 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; value =&amp;nbsp; a*b; 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;break&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; 4
:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
Eval.g:28:9: ID&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; ID4 = (CommonTree)input.LT(1);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Match(input,ID,FOLLOW_ID_in_expr180); 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;object&lt;/span&gt; obj
= memory[ID4.Text];
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (obj
!= &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;){
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
value =&amp;nbsp; (&lt;span style="COLOR: blue"&gt;int&lt;/span&gt;)obj;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;span style="COLOR: blue"&gt;else&lt;/span&gt; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
Console.WriteLine(&lt;span style="COLOR: maroon"&gt;"undefined variable "&lt;/span&gt; + ID4.Text);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;break&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; 5
:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
Eval.g:37:9: integer= INT&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; integer = (CommonTree)input.LT(1);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Match(input,INT,FOLLOW_INT_in_expr203); 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; value =&amp;nbsp; Int32.Parse(integer.Text); &lt;span style="COLOR: green"&gt;/*
fix for 3.0b5 bug (will be fixed in next version so integer.Text works) */&lt;/span&gt; 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;break&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;catch&lt;/span&gt; (RecognitionException
re) 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ReportError(re);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Recover(input,re);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;finally&lt;/span&gt; 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; value;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;/font&gt; 
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
The method starts declaring the variables used in the alternatives and the variable
used to hold the return vale.
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
The first switch decides what alternative to select based on the next token of the
input stream. Recall that the rule expr was:
&lt;/p&gt;
&lt;font face="Times New Roman" color=#000000 size=3&gt; 
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
expr returns [int value]
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; :&amp;nbsp;&amp;nbsp; ^('+' a=expr b=expr)&amp;nbsp; { $value = a+b; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp; ^('-' a=expr b=expr)&amp;nbsp; { $value = a-b; }&amp;nbsp;&amp;nbsp; 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp; ^('*' a=expr b=expr)&amp;nbsp; { $value = a*b; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp; ID 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; object obj = memory[$ID.text];
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if (obj != null){
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; $value
= (int)obj;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; } else {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Console.WriteLine("undefined
variable " + $ID.text);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp; integer=INT&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; { $value = Int32.Parse($integer.text);
/* fix for 3.0b5 bug (will be fixed in next version so $INT.text works) */ }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; ;
&lt;/p&gt;
&lt;/div&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;!--EndFragment--&gt;
&lt;br&gt;
&lt;/p&gt;
&lt;/font&gt; 
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
The code associated to each alternative is inside the second switch. The first 3 alternatives
have the same structure but differ in a token and in the operation to perform, so
we’ll focus only on the first one. As what we want to match is a tree that has a ‘+’
token (token number 9) as the root, and two expressions as its childs, the code first
has a Match to check that the token ‘+’ is present, then a Match to check that the
ficticious DOWN token is present (so it is walking to the childs of the root). Then
it calls two expr rules (saving the follow information in the stack as we explained
earlier), and saving the return value in the variables a and b. Finally, the ficticious
UP token is matched so it verifies that there are no more child nodes.
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
The alternatives 4 and 5 are straightforward as they only match a token and have the
code inserted in the rule.
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
And that’s it. You can see that a tree parser is very very similar to a parser.
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
The code used to connect the lexer, the parser and the tree parser is:
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: green"&gt;// sets the input string&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
ANTLRStringStream strStream = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; ANTLRStringStream(
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: maroon"&gt;@"&amp;nbsp;&amp;nbsp;&amp;nbsp; a=3&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: maroon"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; a+5&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: maroon"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: green"&gt;// creates the lexer&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
ExprLexer lexer = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; ExprLexer(strStream);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: green"&gt;// creates the parser with a stream of tokens that will
be extracted from the lexer to it&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
CommonTokenStream tokStream = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; CommonTokenStream(lexer);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
ExprParser parser = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; ExprParser(tokStream);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: green"&gt;// parse the input string and get the results&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
ExprParser.prog_return returnValue = parser.prog();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: green"&gt;// creates the tree parser with a stream of tokens that
will be extracted from the AST&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
CommonTreeNodeStream treeNodeStream = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; CommonTreeNodeStream((CommonTree)returnValue.Tree);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
EvalTreeParser treeWalker = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; EvalTreeParser(treeNodeStream);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: green"&gt;// walk the AST executing any associated code&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
treeWalker.prog();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: green"&gt;// get the AST and wrap it in our tree node class in order
to visualize it with StructsViz when debugging&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: green"&gt;// you can download an evaluation version of StructsViz
here: http://www.manuelabadia.com/products&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
AntlrDebugCommonTree AST = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; AntlrDebugCommonTree((CommonTree)returnValue.Tree);
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
The parse tree used to evaluate the sample expression in the tree parser grammar is:
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;img height=313 alt=example_parseTree2.PNG src="http://www.manuelabadia.com/blog/content/binary/example_parseTree2.PNG" width=237 border=0&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
I hope this tutorial about ANTLR has been useful to clarify some gray areas and have
a general view of the main classes involved.
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
To learn more about ANTLR refer to the upcoming book:
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;iframe style="WIDTH: 120px; HEIGHT: 240px" marginwidth=0 marginheight=0 src="http://rcm.amazon.com/e/cm?t=manuelabadias-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=as1&amp;amp;asins=0978739256&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" frameborder=0 scrolling=no&gt;
&lt;/iframe&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;/span&gt;&lt;a href="http://www.manuelabadia.com/blog/content/binary/ANTLR_tutorial.zip"&gt;Download
article source code (16.47 KB)&lt;/a&gt;&lt;img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=6e509f70-3db8-46f4-b451-1ef9dd80740b" /&gt;</description>
      <comments>http://www.manuelabadia.com/blog/CommentView,guid,6e509f70-3db8-46f4-b451-1ef9dd80740b.aspx</comments>
      <category>ANTLR;Microsoft .NET Framework</category>
    </item>
    <item>
      <trackback:ping>http://www.manuelabadia.com/blog/Trackback.aspx?guid=5085c0cc-5256-429c-a18c-4639afa0dcc1</trackback:ping>
      <pingback:server>http://www.manuelabadia.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.manuelabadia.com/blog/PermaLink,guid,5085c0cc-5256-429c-a18c-4639afa0dcc1.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://www.manuelabadia.com/blog/CommentView,guid,5085c0cc-5256-429c-a18c-4639afa0dcc1.aspx</wfw:comment>
      <wfw:commentRss>http://www.manuelabadia.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=5085c0cc-5256-429c-a18c-4639afa0dcc1</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a href="http://www.manuelabadia.com/blog/PermaLink,guid,ff1dc504-f854-40b4-bfe7-250ce91efad7.aspx">Click
here for Part 1 of this overview</a>
          <br />
          <a href="http://www.manuelabadia.com/blog/PermaLink,guid,6e509f70-3db8-46f4-b451-1ef9dd80740b.aspx">Click
here for Part 3 of this overview</a>
        </p>
        <p>
IMHO the more awkward thing in ANTLR is the tree implementation. A tree is implemented
as a tree node and all the operations related to trees are moved to another class.
Also, there can be “nil” nodes, that are fake nodes used as parent for childs (this
is used to create flat lists).
</p>
        <p>
In ANTLR a tree has to implement the ITree interface:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">public</span>
            <span style="COLOR: blue">interface</span>
            <span style="COLOR: teal">ITree</span>
          </p>
          <p style="MARGIN: 0px">
{
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">int</span> CharPositionInLine { <span style="COLOR: blue">get</span>;
}
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">int</span> ChildCount { <span style="COLOR: blue">get</span>;
}
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">int</span> Line { <span style="COLOR: blue">get</span>;
}
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">bool</span> Nil { <span style="COLOR: blue">get</span>;
}
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">string</span> Text { <span style="COLOR: blue">get</span>;
}
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">int</span> Type { <span style="COLOR: blue">get</span>;
}
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">void</span> AddChild(<span style="COLOR: teal">ITree</span> t);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: teal">ITree</span> DupNode();
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: teal">ITree</span> DupTree();
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: teal">ITree</span> GetChild(<span style="COLOR: blue">int</span> i);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">string</span> ToString();
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">string</span> ToStringTree();
</p>
          <p style="MARGIN: 0px">
}
</p>
        </div>
        <p>
          <!--EndFragment-->
        </p>
        <p>
In the ITree interface there are some properties that are also present in the IToken
interface (Line, CharPositionInLine, Type and Text) in order to associate a position
with the current tree for errors and because it is also needed for parsing.
</p>
        <p>
The Nil property is used to check if this node is a “nil” node.
</p>
        <p>
The property ChildCount and the method GetChild are used to navigate the tree.
</p>
        <p>
The DupNode methods clones the current node and the DupTree method clones the whole
tree.
</p>
        <p>
In a normal implmentation of a tree node, the method AddChild doesn’t need more comments
but in ANTLR the methods that operate on trees are not orthogonal and usually differ
if one of the operands is a “nil” node. In this case, if the tree node passed to the
AddChild is a “nil” node, all the children of that “nil” node are added as children
of the tree. Otherwise works as expected.
</p>
        <p>
The ITree interface is implemented by the abstract class BaseTree that implements
the tree using a list of child nodes, and the node doesn’t have any payload.
</p>
        <p>
The concrete classes that implement BaseTree in ANTLR are:<br />
• CommonTree: that adds a token as the payload.<br />
• ParseTree: that stores strings and tokens as the payload.
</p>
        <p>
To operate on the tree you have to use a class that implements the ITreeAdaptor interface:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">public</span>
            <span style="COLOR: blue">interface</span>
            <span style="COLOR: teal">ITreeAdaptor</span>
          </p>
          <p style="MARGIN: 0px">
{
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">void</span> AddChild(<span style="COLOR: blue">object</span> t, <span style="COLOR: teal">IToken</span> child);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">void</span> AddChild(<span style="COLOR: blue">object</span> t, <span style="COLOR: blue">object</span> child);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">object</span> BecomeRoot(<span style="COLOR: teal">IToken</span> newRoot, <span style="COLOR: blue">object</span> oldRoot);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">object</span> BecomeRoot(<span style="COLOR: blue">object</span> newRoot, <span style="COLOR: blue">object</span> oldRoot);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">object</span> Create(<span style="COLOR: teal">IToken</span> payload);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">object</span> Create(<span style="COLOR: blue">int</span> tokenType, <span style="COLOR: teal">IToken</span> fromToken);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">object</span> Create(<span style="COLOR: blue">int</span> tokenType, <span style="COLOR: blue">string</span> text);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">object</span> Create(<span style="COLOR: blue">int</span> tokenType, <span style="COLOR: teal">IToken</span> fromToken, <span style="COLOR: blue">string</span> text);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">object</span> DupNode(<span style="COLOR: blue">object</span> treeNode);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">object</span> DupTree(<span style="COLOR: blue">object</span> tree);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">object</span> GetChild(<span style="COLOR: blue">object</span> t, <span style="COLOR: blue">int</span> i);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">int</span> GetChildCount(<span style="COLOR: blue">object</span> t);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">object</span> GetNilNode();
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">string</span> GetNodeText(<span style="COLOR: blue">object</span> t);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">int</span> GetNodeType(<span style="COLOR: blue">object</span> t);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">int</span> GetTokenStartIndex(<span style="COLOR: blue">object</span> t);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">int</span> GetTokenStopIndex(<span style="COLOR: blue">object</span> t);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">int</span> GetUniqueID(<span style="COLOR: blue">object</span> node);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">object</span> RulePostProcessing(<span style="COLOR: blue">object</span> root);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">void</span> SetNodeText(<span style="COLOR: blue">object</span> t, <span style="COLOR: blue">string</span> text);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">void</span> SetNodeType(<span style="COLOR: blue">object</span> t, <span style="COLOR: blue">int</span> type);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">void</span> SetTokenBoundaries(<span style="COLOR: blue">object</span> t, <span style="COLOR: teal">IToken</span> startToken, <span style="COLOR: teal">IToken</span> stopToken);
</p>
          <p style="MARGIN: 0px">
}
</p>
        </div>
        <!--EndFragment-->
        <p>
 
</p>
        <p>
The AddChild and Dup methods do the same as the ITree counterparts.
</p>
        <p>
The Create methods are used to create a tree node from a token.
</p>
        <p>
The method GetNilNode is used to obtain a “nil” node.
</p>
        <p>
The GetChildCound and GetChild methods are used to traverse the tree.
</p>
        <p>
The BecomeRoot method returns a tree where the newRoot is the root of the resulting
tree and the oldRoot is a child of the resulting tree. There is special handling for
“nil” nodes (see the ANTLR code for details).
</p>
        <p>
The RulePostProcessing method is called after a rule has been processed in order to
optimize the resulting tree. After this method, the SetTokenBoundaries is called in
order to set the bounds in the input token stream of this tree (including all the
children).
</p>
        <p>
The other methods are for getting/setting the node type and text when doing tree parsing.
</p>
        <p>
The abstract class BaseTreeAdaptor implements the ITreeAdaptor interface and adds
an abstract method called createToken. The concrete class that is used in ANTLR
is the CommonTreeAdaptor class, that inherits from BaseTreeAdaptor. The CommonTreeAdaptor
class creates CommonTree and CommonToken objects.
</p>
        <p>
When ANTLR generates a Parser that builds the AST, the generated class has a protected
field called adaptor (and the associated property Adaptor) which is used in the rules
to create the AST.  Also a return type of each method created for each rule changes
to a new generated class (with a name rulename_return) that inherits from the ParserRuleReturnScope:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">public</span>
            <span style="COLOR: blue">class</span>
            <span style="COLOR: teal">ParserRuleReturnScope</span> : <span style="COLOR: teal">RuleReturnScope</span></p>
          <p style="MARGIN: 0px">
{
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: teal">IToken</span> start;
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: teal">IToken</span> stop;
</p>
          <p style="MARGIN: 0px">
}
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">public</span>
            <span style="COLOR: blue">class</span>
            <span style="COLOR: teal">RuleReturnScope</span>
          </p>
          <p style="MARGIN: 0px">
{
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">virtual</span><span style="COLOR: blue">object</span> Start
{ <span style="COLOR: blue">get</span>; }
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">virtual</span><span style="COLOR: blue">object</span> Stop
{ <span style="COLOR: blue">get</span>; }
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">virtual</span> Antlr.StringTemplate.<span style="COLOR: teal">StringTemplate</span> Template
{ <span style="COLOR: blue">get</span>; }
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">virtual</span><span style="COLOR: blue">object</span> Tree
{ <span style="COLOR: blue">get</span>; }
</p>
          <p style="MARGIN: 0px">
}
</p>
        </div>
        <!--EndFragment-->
        <p>
 
</p>
        <p>
The RuleReturnScope class is used to provide start and stop information (token or
tree) as well as the AST or the template when output=AST or when output=template is
used.
</p>
        <p>
The generated class that inherits from ParserRuleReturnScope stores the resulting
AST and any return value defined in the rule.
</p>
        <p>
You may be wondering why to generate an AST and then create a Tree Parser for the
generated AST to do more work if you can add attributes and logic to the rules in
the parser to do what you want to do. The reason is that there are a lot of rules
in the grammar that are just for precedence or to make the grammar cleaner and also
there are some tokens (for example the brackets) that are not needed after parsing.
The resulting AST has only the data need to perform our task without garbage. For
example, consider a grammar for evaluating expressions with support for relational
expressions and bit operators. The expression ((i &gt;= 0) AND (i &lt;= n)) OR ((index
&amp; 2) = 1) produces this parse tree:
</p>
        <img src="http://www.manuelabadia.com/blog/content/binary/expressionParseTree.PNG" border="0" />
        <p>
 
</p>
        <p>
The generated AST from that expression is:
</p>
        <img src="http://www.manuelabadia.com/blog/content/binary/expressionAST.PNG" border="0" />
        <p>
 
</p>
        <p>
So the AST is a lot easier (and clearer) to use.
</p>
        <p>
I have used my <a href="http://www.manuelabadia.com/products/StructsViz_features.aspx">StructsViz
DebuggerVisualizer pack</a> to generate those tree diagrams in the Visual Studio.NET
2005 debugger. 
</p>
        <p>
After studying the tree related classes and the Parser class it is time to start with
Tree Parsers. The TreeParser class inherits from BaseRecognizer and will consume tree
nodes from an ITree. The input of a tree parser will be a class implementing the ITreeNodeStream
interface. This interface is an specialization of the IIntStream interface to operate
on tree nodes:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">public</span>
            <span style="COLOR: blue">interface</span>
            <span style="COLOR: teal">ITreeNodeStream</span> : <span style="COLOR: teal">IIntStream</span></p>
          <p style="MARGIN: 0px">
{
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">bool</span> HasUniqueNavigationNodes
{ <span style="COLOR: blue">set</span>; }
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: teal">ITreeAdaptor</span> TreeAdaptor { <span style="COLOR: blue">get</span>;
}
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">object</span> TreeSource { <span style="COLOR: blue">get</span>;
}
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">object</span> LT(<span style="COLOR: blue">int</span> k);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">string</span> ToString(<span style="COLOR: blue">object</span> start, <span style="COLOR: blue">object</span> stop);
</p>
          <p style="MARGIN: 0px">
}
</p>
        </div>
        <!--EndFragment-->
        <p>
 
</p>
        <p>
As you can see, the interface can return any tree node with the LT method, and with
the TreeSource and TreeAdaptor properties you can access to the tree providing the
data and to the associated adaptor.
</p>
        <p>
The ToString method prints the text of the specified nodes.
</p>
        <p>
The HasUniqueNavigationNodes is used in debugging mode and specifies if the UP and
DOWN nodes are reused or created each time they’re needed. The meaning of the UP and
DOWN nodes will be explained later.
</p>
        <p>
The CommonTreeNodeStream implements the ITreeNodeStream interface, and also the IEnumerable
interface (so the nodes can be accessed sequentially using the IEnumerable related
methods and properties, that is, Reset, MoveNext, Current). The class has 3 static
tree nodes defined: the UP node, the DOWN node and the EOF node. To traverse the tree
sequentially the class uses two stacks, the node stack and the index stack. The node
stack is used to track the parent node when we’re walking down the tree. The index
stack is used to know which child node we’re currently visiting. The tree is visited
using a depth first traversal. When the first child of a node is visited, a ficticious
DOWN node is added to the lookahead buffer and when the last child of a node is visited,
a ficticious UP node is added to the lookahead buffer. After all nodes have been visited,
the ficticious EOF node is always returned. When the nodes are accessed sequentially
using the IEnumerable interface, the ficticious nodes are not returned. The ficticious
nodes are returned only when the LT method of the ItreeNodeStream interface is called.
</p>
        <p>
For completeness here are all the methods and properties of the CommonTreeNodeStream
class:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">public</span>
            <span style="COLOR: blue">class</span>
            <span style="COLOR: teal">CommonTreeNodeStream</span> : <span style="COLOR: teal">ITreeNodeStream</span>, <span style="COLOR: teal">IIntStream</span>,
IEnumerator
</p>
          <p style="MARGIN: 0px">
{
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span> CommonTreeNodeStream(<span style="COLOR: teal">ITree</span> tree);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span> CommonTreeNodeStream(<span style="COLOR: teal">ITreeAdaptor</span> adaptor, <span style="COLOR: teal">ITree</span> tree);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">virtual</span><span style="COLOR: blue">object</span> Current
{ <span style="COLOR: blue">get</span>; }
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">virtual</span><span style="COLOR: blue">void</span> Reset();
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">virtual</span><span style="COLOR: blue">bool</span> MoveNext();
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">virtual</span><span style="COLOR: blue">void</span> Consume();
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">virtual</span><span style="COLOR: blue">int</span> Index();
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">virtual</span><span style="COLOR: blue">int</span> LA(<span style="COLOR: blue">int</span> i);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">virtual</span><span style="COLOR: blue">int</span> Mark();
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">virtual</span><span style="COLOR: blue">void</span> Release(<span style="COLOR: blue">int</span> marker);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">void</span> Rewind();
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">virtual</span><span style="COLOR: blue">void</span> Rewind(<span style="COLOR: blue">int</span> marker);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">virtual</span><span style="COLOR: blue">void</span> Seek(<span style="COLOR: blue">int</span> index);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">virtual</span><span style="COLOR: blue">int</span> Size();
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">bool</span> HasUniqueNavigationNodes
{ <span style="COLOR: blue">get</span>; <span style="COLOR: blue">set</span>; }
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: teal">ITreeAdaptor</span> TreeAdaptor
{ <span style="COLOR: blue">get</span>; }
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">virtual</span><span style="COLOR: blue">object</span> TreeSource
{ <span style="COLOR: blue">get</span>; }
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">virtual</span><span style="COLOR: blue">object</span> LT(<span style="COLOR: blue">int</span> k);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">virtual</span><span style="COLOR: blue">string</span> ToString(<span style="COLOR: blue">object</span> start, <span style="COLOR: blue">object</span> stop);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">protected</span><span style="COLOR: blue">int</span> LookaheadSize
{ <span style="COLOR: blue">get</span>; }
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">protected</span><span style="COLOR: blue">internal</span><span style="COLOR: blue">virtual</span><span style="COLOR: blue">void</span> AddLookahead(<span style="COLOR: teal">ITree</span> node);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">protected</span><span style="COLOR: blue">internal</span><span style="COLOR: blue">virtual</span><span style="COLOR: blue">void</span> AddNavigationNode(<span style="COLOR: blue">int</span> ttype);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">protected</span><span style="COLOR: blue">internal</span><span style="COLOR: blue">virtual</span><span style="COLOR: blue">void</span> fill(<span style="COLOR: blue">int</span> k);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">protected</span><span style="COLOR: blue">internal</span><span style="COLOR: blue">virtual</span><span style="COLOR: teal">ITree</span> handleRootNode();
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">override</span><span style="COLOR: blue">string</span> ToString();
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">virtual</span><span style="COLOR: blue">string</span> ToNodesOnlyString();
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">protected</span><span style="COLOR: blue">internal</span><span style="COLOR: blue">virtual</span><span style="COLOR: blue">void</span> ToStringWork(<span style="COLOR: teal">ITree</span> p, <span style="COLOR: teal">ITree</span> stop, <span style="COLOR: teal">StringBuilder</span> buf);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">protected</span><span style="COLOR: blue">internal</span><span style="COLOR: blue">virtual</span><span style="COLOR: teal">ITree</span> VisitChild(<span style="COLOR: blue">int</span> child);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">protected</span><span style="COLOR: blue">internal</span><span style="COLOR: blue">virtual</span><span style="COLOR: blue">void</span> WalkBackToMostRecentNodeWithUnvisitedChildren();
</p>
          <p style="MARGIN: 0px">
}
</p>
        </div>
        <!--EndFragment-->
        <p>
 
</p>
        <p>
After the constructors, you can see the method and properties of the IEnumerable interface,
followed by the methods and properties of the IIntStream interface, and then the methods
of the ITreeNodeStream interface.
</p>
        <p>
The other methods and properties are used to maintain a circular lookahead buffer
of tree nodes and to handle the navigation taking the ficticious nodes into account.
</p>
        <p>
Nothing better than a couple of images here. For the following AST:
</p>
        <p>
          <br />
 
</p>
        <img src="http://www.manuelabadia.com/blog/content/binary/expressionAST.PNG" border="0" />
        <p>
 
</p>
        <p>
The lookahead buffer with the ficticious tokens included looks like:
</p>
        <img src="http://www.manuelabadia.com/blog/content/binary/CommonTreeNodeStream.PNG" border="0" />
        <p>
 
</p>
        <p>
The TreeParser class inherits from BaseRecognizer and gets tree nodes from a class
implementing the ITreeNodeStream interface:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">public</span>
            <span style="COLOR: blue">class</span>
            <span style="COLOR: teal">TreeParser</span> : <span style="COLOR: teal">BaseRecognizer</span></p>
          <p style="MARGIN: 0px">
{
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span> TreeParser(<span style="COLOR: teal">ITreeNodeStream</span> input);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">override</span><span style="COLOR: teal">IIntStream</span> Input
{ <span style="COLOR: blue">get</span>; }
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">virtual</span><span style="COLOR: teal">ITreeNodeStream</span> TreeNodeStream
{ <span style="COLOR: blue">get</span>; <span style="COLOR: blue">set</span>; }
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">protected</span><span style="COLOR: blue">internal</span><span style="COLOR: blue">override</span><span style="COLOR: blue">void</span> Mismatch(<span style="COLOR: teal">IIntStream</span> input, <span style="COLOR: blue">int</span> ttype, <span style="COLOR: teal">BitSet</span> follow);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">override</span> IList
ToTemplates(IList retvals);
</p>
          <p style="MARGIN: 0px">
}
</p>
        </div>
        <!--EndFragment-->
        <p>
 
</p>
        <p>
As you can see, the TreeParser is a very simple class that has properties for the
input stream and overrides 2 methods of the BaseRecognizer class.
</p>
        <p>
When ANTLR creates a TreeParser, it generates a class that inherits from the TreeParser
class. The generated class has a method for each rule in a similar way as the parsers. 
</p>
        <p>
Thanks to the smart idea behind ITreeNodeStream, a Parser and a TreeParser are very
similar if you take a look at the generated code. The Parser consumes tokens from
an ITokenStream in a linear way (one dimension) and the TreeParser consumes tokens
in a hierarchical way (two dimensions), but serialized to one dimension thanks to
the ficticious UP and DOWN tree nodes.
</p>
        <p>
To complete this ANTLR overview, I’ll post an example of a lexer, a parser and a tree
parser and the generated code in a few days.<br /></p>
        <img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=5085c0cc-5256-429c-a18c-4639afa0dcc1" />
      </body>
      <title>ANTLR C# Overview - Part 2</title>
      <guid isPermaLink="false">http://www.manuelabadia.com/blog/PermaLink,guid,5085c0cc-5256-429c-a18c-4639afa0dcc1.aspx</guid>
      <link>http://www.manuelabadia.com/blog/PermaLink,guid,5085c0cc-5256-429c-a18c-4639afa0dcc1.aspx</link>
      <pubDate>Tue, 02 Jan 2007 10:13:38 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a href="http://www.manuelabadia.com/blog/PermaLink,guid,ff1dc504-f854-40b4-bfe7-250ce91efad7.aspx"&gt;Click
here for Part 1 of this overview&lt;/a&gt;
&lt;br&gt;
&lt;a href="http://www.manuelabadia.com/blog/PermaLink,guid,6e509f70-3db8-46f4-b451-1ef9dd80740b.aspx"&gt;Click
here for Part&amp;nbsp;3 of this overview&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
IMHO the more awkward thing in ANTLR is the tree implementation. A tree is implemented
as a tree node and all the operations related to trees are moved to another class.
Also, there can be “nil” nodes, that are fake nodes used as parent for childs (this
is used to create flat lists).
&lt;/p&gt;
&lt;p&gt;
In ANTLR a tree has to implement the ITree interface:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;interface&lt;/span&gt; &lt;span style="COLOR: teal"&gt;ITree&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; CharPositionInLine { &lt;span style="COLOR: blue"&gt;get&lt;/span&gt;;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; ChildCount { &lt;span style="COLOR: blue"&gt;get&lt;/span&gt;;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; Line { &lt;span style="COLOR: blue"&gt;get&lt;/span&gt;;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;bool&lt;/span&gt; Nil { &lt;span style="COLOR: blue"&gt;get&lt;/span&gt;;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; Text { &lt;span style="COLOR: blue"&gt;get&lt;/span&gt;;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; Type { &lt;span style="COLOR: blue"&gt;get&lt;/span&gt;;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; AddChild(&lt;span style="COLOR: teal"&gt;ITree&lt;/span&gt; t);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: teal"&gt;ITree&lt;/span&gt; DupNode();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: teal"&gt;ITree&lt;/span&gt; DupTree();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: teal"&gt;ITree&lt;/span&gt; GetChild(&lt;span style="COLOR: blue"&gt;int&lt;/span&gt; i);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; ToString();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; ToStringTree();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;!--EndFragment--&gt;
&lt;/p&gt;
&lt;p&gt;
In the ITree interface there are some properties that are also present in the IToken
interface (Line, CharPositionInLine, Type and Text) in order to associate a position
with the current tree for errors and because it is also needed for parsing.
&lt;/p&gt;
&lt;p&gt;
The Nil property is used to check if this node is a “nil” node.
&lt;/p&gt;
&lt;p&gt;
The property ChildCount and the method GetChild are used to navigate the tree.
&lt;/p&gt;
&lt;p&gt;
The DupNode methods clones the current node and the DupTree method clones the whole
tree.
&lt;/p&gt;
&lt;p&gt;
In a normal implmentation of a tree node, the method AddChild doesn’t need more comments
but in ANTLR the methods that operate on trees are not orthogonal and usually differ
if one of the operands is a “nil” node. In this case, if the tree node passed to the
AddChild is a “nil” node, all the children of that “nil” node are added as children
of the tree. Otherwise works as expected.
&lt;/p&gt;
&lt;p&gt;
The ITree interface is implemented by the abstract class BaseTree that implements
the tree using a list of child nodes, and the node doesn’t have any payload.
&lt;/p&gt;
&lt;p&gt;
The concrete classes that implement BaseTree in ANTLR are:&lt;br&gt;
•&amp;nbsp;CommonTree: that adds a token as the payload.&lt;br&gt;
•&amp;nbsp;ParseTree: that stores strings and tokens as the payload.
&lt;/p&gt;
&lt;p&gt;
To operate on the tree you have to use a class that implements the ITreeAdaptor interface:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;interface&lt;/span&gt; &lt;span style="COLOR: teal"&gt;ITreeAdaptor&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; AddChild(&lt;span style="COLOR: blue"&gt;object&lt;/span&gt; t, &lt;span style="COLOR: teal"&gt;IToken&lt;/span&gt; child);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; AddChild(&lt;span style="COLOR: blue"&gt;object&lt;/span&gt; t, &lt;span style="COLOR: blue"&gt;object&lt;/span&gt; child);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;object&lt;/span&gt; BecomeRoot(&lt;span style="COLOR: teal"&gt;IToken&lt;/span&gt; newRoot, &lt;span style="COLOR: blue"&gt;object&lt;/span&gt; oldRoot);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;object&lt;/span&gt; BecomeRoot(&lt;span style="COLOR: blue"&gt;object&lt;/span&gt; newRoot, &lt;span style="COLOR: blue"&gt;object&lt;/span&gt; oldRoot);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;object&lt;/span&gt; Create(&lt;span style="COLOR: teal"&gt;IToken&lt;/span&gt; payload);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;object&lt;/span&gt; Create(&lt;span style="COLOR: blue"&gt;int&lt;/span&gt; tokenType, &lt;span style="COLOR: teal"&gt;IToken&lt;/span&gt; fromToken);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;object&lt;/span&gt; Create(&lt;span style="COLOR: blue"&gt;int&lt;/span&gt; tokenType, &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; text);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;object&lt;/span&gt; Create(&lt;span style="COLOR: blue"&gt;int&lt;/span&gt; tokenType, &lt;span style="COLOR: teal"&gt;IToken&lt;/span&gt; fromToken, &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; text);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;object&lt;/span&gt; DupNode(&lt;span style="COLOR: blue"&gt;object&lt;/span&gt; treeNode);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;object&lt;/span&gt; DupTree(&lt;span style="COLOR: blue"&gt;object&lt;/span&gt; tree);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;object&lt;/span&gt; GetChild(&lt;span style="COLOR: blue"&gt;object&lt;/span&gt; t, &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; i);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; GetChildCount(&lt;span style="COLOR: blue"&gt;object&lt;/span&gt; t);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;object&lt;/span&gt; GetNilNode();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; GetNodeText(&lt;span style="COLOR: blue"&gt;object&lt;/span&gt; t);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; GetNodeType(&lt;span style="COLOR: blue"&gt;object&lt;/span&gt; t);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; GetTokenStartIndex(&lt;span style="COLOR: blue"&gt;object&lt;/span&gt; t);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; GetTokenStopIndex(&lt;span style="COLOR: blue"&gt;object&lt;/span&gt; t);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; GetUniqueID(&lt;span style="COLOR: blue"&gt;object&lt;/span&gt; node);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;object&lt;/span&gt; RulePostProcessing(&lt;span style="COLOR: blue"&gt;object&lt;/span&gt; root);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; SetNodeText(&lt;span style="COLOR: blue"&gt;object&lt;/span&gt; t, &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; text);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; SetNodeType(&lt;span style="COLOR: blue"&gt;object&lt;/span&gt; t, &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; type);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; SetTokenBoundaries(&lt;span style="COLOR: blue"&gt;object&lt;/span&gt; t, &lt;span style="COLOR: teal"&gt;IToken&lt;/span&gt; startToken, &lt;span style="COLOR: teal"&gt;IToken&lt;/span&gt; stopToken);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
The AddChild and Dup methods do the same as the ITree counterparts.
&lt;/p&gt;
&lt;p&gt;
The Create methods are used to create a tree node from a token.
&lt;/p&gt;
&lt;p&gt;
The method GetNilNode is used to obtain a “nil” node.
&lt;/p&gt;
&lt;p&gt;
The GetChildCound and GetChild methods are used to traverse the tree.
&lt;/p&gt;
&lt;p&gt;
The BecomeRoot method returns a tree where the newRoot is the root of the resulting
tree and the oldRoot is a child of the resulting tree. There is special handling for
“nil” nodes (see the ANTLR code for details).
&lt;/p&gt;
&lt;p&gt;
The RulePostProcessing method is called after a rule has been processed in order to
optimize the resulting tree. After this method, the SetTokenBoundaries is called in
order to set the bounds in the input token stream of this tree (including all the
children).
&lt;/p&gt;
&lt;p&gt;
The other methods are for getting/setting the node type and text when doing tree parsing.
&lt;/p&gt;
&lt;p&gt;
The abstract class BaseTreeAdaptor implements the ITreeAdaptor interface and adds
an abstract method called createToken.&amp;nbsp;The concrete class that is used in ANTLR
is the CommonTreeAdaptor class, that inherits from BaseTreeAdaptor. The CommonTreeAdaptor
class creates CommonTree and CommonToken objects.
&lt;/p&gt;
&lt;p&gt;
When ANTLR generates a Parser that builds the AST, the generated class has a protected
field called adaptor (and the associated property Adaptor) which is used in the rules
to create the AST.&amp;nbsp; Also a return type of each method created for each rule changes
to a new generated class (with a name rulename_return) that inherits from the ParserRuleReturnScope:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;class&lt;/span&gt; &lt;span style="COLOR: teal"&gt;ParserRuleReturnScope&lt;/span&gt; : &lt;span style="COLOR: teal"&gt;RuleReturnScope&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: teal"&gt;IToken&lt;/span&gt; start;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: teal"&gt;IToken&lt;/span&gt; stop;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;class&lt;/span&gt; &lt;span style="COLOR: teal"&gt;RuleReturnScope&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;virtual&lt;/span&gt; &lt;span style="COLOR: blue"&gt;object&lt;/span&gt; Start
{ &lt;span style="COLOR: blue"&gt;get&lt;/span&gt;; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;virtual&lt;/span&gt; &lt;span style="COLOR: blue"&gt;object&lt;/span&gt; Stop
{ &lt;span style="COLOR: blue"&gt;get&lt;/span&gt;; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;virtual&lt;/span&gt; Antlr.StringTemplate.&lt;span style="COLOR: teal"&gt;StringTemplate&lt;/span&gt; Template
{ &lt;span style="COLOR: blue"&gt;get&lt;/span&gt;; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;virtual&lt;/span&gt; &lt;span style="COLOR: blue"&gt;object&lt;/span&gt; Tree
{ &lt;span style="COLOR: blue"&gt;get&lt;/span&gt;; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
The RuleReturnScope class is used to provide start and stop information (token or
tree) as well as the AST or the template when output=AST or when output=template is
used.
&lt;/p&gt;
&lt;p&gt;
The generated class that inherits from ParserRuleReturnScope stores the resulting
AST and any return value defined in the rule.
&lt;/p&gt;
&lt;p&gt;
You may be wondering why to generate an AST and then create a Tree Parser for the
generated AST to do more work if you can add attributes and logic to the rules in
the parser to do what you want to do. The reason is that there are a lot of rules
in the grammar that are just for precedence or to make the grammar cleaner and also
there are some tokens (for example the brackets) that are not needed after parsing.
The resulting AST has only the data need to perform our task without garbage. For
example, consider a grammar for evaluating expressions with support for relational
expressions and bit operators. The expression ((i &amp;gt;= 0) AND (i &amp;lt;= n)) OR ((index
&amp;amp; 2) = 1) produces this parse tree:
&lt;/p&gt;
&lt;img src="http://www.manuelabadia.com/blog/content/binary/expressionParseTree.PNG" border=0&gt; 
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
The generated AST from that expression is:
&lt;/p&gt;
&lt;img src="http://www.manuelabadia.com/blog/content/binary/expressionAST.PNG" border=0&gt; 
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
So the AST is a lot easier (and clearer) to use.
&lt;/p&gt;
&lt;p&gt;
I have used my &lt;a href="http://www.manuelabadia.com/products/StructsViz_features.aspx"&gt;StructsViz
DebuggerVisualizer pack&lt;/a&gt; to generate those tree diagrams in the Visual Studio.NET
2005 debugger. 
&lt;/p&gt;
&lt;p&gt;
After studying the tree related classes and the Parser class it is time to start with
Tree Parsers. The TreeParser class inherits from BaseRecognizer and will consume tree
nodes from an ITree. The input of a tree parser will be a class implementing the ITreeNodeStream
interface. This interface is an specialization of the IIntStream interface to operate
on tree nodes:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;interface&lt;/span&gt; &lt;span style="COLOR: teal"&gt;ITreeNodeStream&lt;/span&gt; : &lt;span style="COLOR: teal"&gt;IIntStream&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;bool&lt;/span&gt; HasUniqueNavigationNodes
{ &lt;span style="COLOR: blue"&gt;set&lt;/span&gt;; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: teal"&gt;ITreeAdaptor&lt;/span&gt; TreeAdaptor { &lt;span style="COLOR: blue"&gt;get&lt;/span&gt;;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;object&lt;/span&gt; TreeSource { &lt;span style="COLOR: blue"&gt;get&lt;/span&gt;;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;object&lt;/span&gt; LT(&lt;span style="COLOR: blue"&gt;int&lt;/span&gt; k);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; ToString(&lt;span style="COLOR: blue"&gt;object&lt;/span&gt; start, &lt;span style="COLOR: blue"&gt;object&lt;/span&gt; stop);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
As you can see, the interface can return any tree node with the LT method, and with
the TreeSource and TreeAdaptor properties you can access to the tree providing the
data and to the associated adaptor.
&lt;/p&gt;
&lt;p&gt;
The ToString method prints the text of the specified nodes.
&lt;/p&gt;
&lt;p&gt;
The HasUniqueNavigationNodes is used in debugging mode and specifies if the UP and
DOWN nodes are reused or created each time they’re needed. The meaning of the UP and
DOWN nodes will be explained later.
&lt;/p&gt;
&lt;p&gt;
The CommonTreeNodeStream implements the ITreeNodeStream interface, and also the IEnumerable
interface (so the nodes can be accessed sequentially using the IEnumerable related
methods and properties, that is, Reset, MoveNext, Current). The class has 3 static
tree nodes defined: the UP node, the DOWN node and the EOF node. To traverse the tree
sequentially the class uses two stacks, the node stack and the index stack. The node
stack is used to track the parent node when we’re walking down the tree. The index
stack is used to know which child node we’re currently visiting. The tree is visited
using a depth first traversal. When the first child of a node is visited, a ficticious
DOWN node is added to the lookahead buffer and when the last child of a node is visited,
a ficticious UP node is added to the lookahead buffer. After all nodes have been visited,
the ficticious EOF node is always returned. When the nodes are accessed sequentially
using the IEnumerable interface, the ficticious nodes are not returned. The ficticious
nodes are returned only when the LT method of the ItreeNodeStream interface is called.
&lt;/p&gt;
&lt;p&gt;
For completeness here are all the methods and properties of the CommonTreeNodeStream
class:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;class&lt;/span&gt; &lt;span style="COLOR: teal"&gt;CommonTreeNodeStream&lt;/span&gt; : &lt;span style="COLOR: teal"&gt;ITreeNodeStream&lt;/span&gt;, &lt;span style="COLOR: teal"&gt;IIntStream&lt;/span&gt;,
IEnumerator
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; CommonTreeNodeStream(&lt;span style="COLOR: teal"&gt;ITree&lt;/span&gt; tree);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; CommonTreeNodeStream(&lt;span style="COLOR: teal"&gt;ITreeAdaptor&lt;/span&gt; adaptor, &lt;span style="COLOR: teal"&gt;ITree&lt;/span&gt; tree);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;virtual&lt;/span&gt; &lt;span style="COLOR: blue"&gt;object&lt;/span&gt; Current
{ &lt;span style="COLOR: blue"&gt;get&lt;/span&gt;; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;virtual&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; Reset();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;virtual&lt;/span&gt; &lt;span style="COLOR: blue"&gt;bool&lt;/span&gt; MoveNext();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;virtual&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; Consume();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;virtual&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; Index();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;virtual&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; LA(&lt;span style="COLOR: blue"&gt;int&lt;/span&gt; i);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;virtual&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; Mark();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;virtual&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; Release(&lt;span style="COLOR: blue"&gt;int&lt;/span&gt; marker);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; Rewind();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;virtual&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; Rewind(&lt;span style="COLOR: blue"&gt;int&lt;/span&gt; marker);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;virtual&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; Seek(&lt;span style="COLOR: blue"&gt;int&lt;/span&gt; index);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;virtual&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; Size();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;bool&lt;/span&gt; HasUniqueNavigationNodes
{ &lt;span style="COLOR: blue"&gt;get&lt;/span&gt;; &lt;span style="COLOR: blue"&gt;set&lt;/span&gt;; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: teal"&gt;ITreeAdaptor&lt;/span&gt; TreeAdaptor
{ &lt;span style="COLOR: blue"&gt;get&lt;/span&gt;; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;virtual&lt;/span&gt; &lt;span style="COLOR: blue"&gt;object&lt;/span&gt; TreeSource
{ &lt;span style="COLOR: blue"&gt;get&lt;/span&gt;; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;virtual&lt;/span&gt; &lt;span style="COLOR: blue"&gt;object&lt;/span&gt; LT(&lt;span style="COLOR: blue"&gt;int&lt;/span&gt; k);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;virtual&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; ToString(&lt;span style="COLOR: blue"&gt;object&lt;/span&gt; start, &lt;span style="COLOR: blue"&gt;object&lt;/span&gt; stop);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;protected&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; LookaheadSize
{ &lt;span style="COLOR: blue"&gt;get&lt;/span&gt;; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;protected&lt;/span&gt; &lt;span style="COLOR: blue"&gt;internal&lt;/span&gt; &lt;span style="COLOR: blue"&gt;virtual&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; AddLookahead(&lt;span style="COLOR: teal"&gt;ITree&lt;/span&gt; node);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;protected&lt;/span&gt; &lt;span style="COLOR: blue"&gt;internal&lt;/span&gt; &lt;span style="COLOR: blue"&gt;virtual&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; AddNavigationNode(&lt;span style="COLOR: blue"&gt;int&lt;/span&gt; ttype);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;protected&lt;/span&gt; &lt;span style="COLOR: blue"&gt;internal&lt;/span&gt; &lt;span style="COLOR: blue"&gt;virtual&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; fill(&lt;span style="COLOR: blue"&gt;int&lt;/span&gt; k);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;protected&lt;/span&gt; &lt;span style="COLOR: blue"&gt;internal&lt;/span&gt; &lt;span style="COLOR: blue"&gt;virtual&lt;/span&gt; &lt;span style="COLOR: teal"&gt;ITree&lt;/span&gt; handleRootNode();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;override&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; ToString();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;virtual&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; ToNodesOnlyString();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;protected&lt;/span&gt; &lt;span style="COLOR: blue"&gt;internal&lt;/span&gt; &lt;span style="COLOR: blue"&gt;virtual&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; ToStringWork(&lt;span style="COLOR: teal"&gt;ITree&lt;/span&gt; p, &lt;span style="COLOR: teal"&gt;ITree&lt;/span&gt; stop, &lt;span style="COLOR: teal"&gt;StringBuilder&lt;/span&gt; buf);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;protected&lt;/span&gt; &lt;span style="COLOR: blue"&gt;internal&lt;/span&gt; &lt;span style="COLOR: blue"&gt;virtual&lt;/span&gt; &lt;span style="COLOR: teal"&gt;ITree&lt;/span&gt; VisitChild(&lt;span style="COLOR: blue"&gt;int&lt;/span&gt; child);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;protected&lt;/span&gt; &lt;span style="COLOR: blue"&gt;internal&lt;/span&gt; &lt;span style="COLOR: blue"&gt;virtual&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; WalkBackToMostRecentNodeWithUnvisitedChildren();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
After the constructors, you can see the method and properties of the IEnumerable interface,
followed by the methods and properties of the IIntStream interface, and then the methods
of the ITreeNodeStream interface.
&lt;/p&gt;
&lt;p&gt;
The other methods and properties are used to maintain a circular lookahead buffer
of tree nodes and to handle the navigation taking the ficticious nodes into account.
&lt;/p&gt;
&lt;p&gt;
Nothing better than a couple of images here. For the following AST:
&lt;/p&gt;
&lt;p&gt;
&lt;br&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;img src="http://www.manuelabadia.com/blog/content/binary/expressionAST.PNG" border=0&gt; 
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
The lookahead buffer with the ficticious tokens included looks like:
&lt;/p&gt;
&lt;img src="http://www.manuelabadia.com/blog/content/binary/CommonTreeNodeStream.PNG" border=0&gt; 
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
The TreeParser class inherits from BaseRecognizer and gets tree nodes from a class
implementing the ITreeNodeStream interface:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;class&lt;/span&gt; &lt;span style="COLOR: teal"&gt;TreeParser&lt;/span&gt; : &lt;span style="COLOR: teal"&gt;BaseRecognizer&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; TreeParser(&lt;span style="COLOR: teal"&gt;ITreeNodeStream&lt;/span&gt; input);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;override&lt;/span&gt; &lt;span style="COLOR: teal"&gt;IIntStream&lt;/span&gt; Input
{ &lt;span style="COLOR: blue"&gt;get&lt;/span&gt;; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;virtual&lt;/span&gt; &lt;span style="COLOR: teal"&gt;ITreeNodeStream&lt;/span&gt; TreeNodeStream
{ &lt;span style="COLOR: blue"&gt;get&lt;/span&gt;; &lt;span style="COLOR: blue"&gt;set&lt;/span&gt;; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;protected&lt;/span&gt; &lt;span style="COLOR: blue"&gt;internal&lt;/span&gt; &lt;span style="COLOR: blue"&gt;override&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; Mismatch(&lt;span style="COLOR: teal"&gt;IIntStream&lt;/span&gt; input, &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; ttype, &lt;span style="COLOR: teal"&gt;BitSet&lt;/span&gt; follow);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;override&lt;/span&gt; IList
ToTemplates(IList retvals);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
As you can see, the TreeParser is a very simple class that has properties for the
input stream and overrides 2 methods of the BaseRecognizer class.
&lt;/p&gt;
&lt;p&gt;
When ANTLR creates a TreeParser, it generates a class that inherits from the TreeParser
class. The generated class has a method for each rule in a similar way as the parsers. 
&lt;/p&gt;
&lt;p&gt;
Thanks to the smart idea behind ITreeNodeStream, a Parser and a TreeParser are very
similar if you take a look at the generated code. The Parser consumes tokens from
an ITokenStream in a linear way (one dimension) and the TreeParser consumes tokens
in a hierarchical way (two dimensions), but serialized to one dimension thanks to
the ficticious UP and DOWN tree nodes.
&lt;/p&gt;
&lt;p&gt;
To complete this ANTLR overview, I’ll post an example of a lexer, a parser and a tree
parser and the generated code in a few days.&lt;br&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=5085c0cc-5256-429c-a18c-4639afa0dcc1" /&gt;</description>
      <comments>http://www.manuelabadia.com/blog/CommentView,guid,5085c0cc-5256-429c-a18c-4639afa0dcc1.aspx</comments>
      <category>ANTLR;Microsoft .NET Framework</category>
    </item>
    <item>
      <trackback:ping>http://www.manuelabadia.com/blog/Trackback.aspx?guid=1981d708-5949-4d87-b7f4-ae60df47b298</trackback:ping>
      <pingback:server>http://www.manuelabadia.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.manuelabadia.com/blog/PermaLink,guid,1981d708-5949-4d87-b7f4-ae60df47b298.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://www.manuelabadia.com/blog/CommentView,guid,1981d708-5949-4d87-b7f4-ae60df47b298.aspx</wfw:comment>
      <wfw:commentRss>http://www.manuelabadia.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=1981d708-5949-4d87-b7f4-ae60df47b298</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Another year ends and a new one comes. Life goes as fast as usual and we’re keep
on our way. It’s time to think about it… our actions, hopes, wishes, mistakes,
etc. 
</p>
        <p>
I usually listen to a special song a few minutes after the start of the year.
In the last few years I have been choosing "Aerosmith – Full Circle" because it has
special connotations for me. 
</p>
        <p>
I wish you the best in the coming year.
</p>
        <img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=1981d708-5949-4d87-b7f4-ae60df47b298" />
      </body>
      <title>Happy 2007!</title>
      <guid isPermaLink="false">http://www.manuelabadia.com/blog/PermaLink,guid,1981d708-5949-4d87-b7f4-ae60df47b298.aspx</guid>
      <link>http://www.manuelabadia.com/blog/PermaLink,guid,1981d708-5949-4d87-b7f4-ae60df47b298.aspx</link>
      <pubDate>Mon, 01 Jan 2007 23:36:54 GMT</pubDate>
      <description>&lt;p&gt;
Another year ends and a new one comes. Life goes as fast as usual and we’re&amp;nbsp;keep
on&amp;nbsp;our way. It’s time to think about it… our actions, hopes, wishes, mistakes,
etc. 
&lt;/p&gt;
&lt;p&gt;
I usually listen to a special song&amp;nbsp;a few minutes after the start of the year.
In the last few years I have been choosing "Aerosmith – Full Circle" because it has
special connotations for me. 
&lt;/p&gt;
&lt;p&gt;
I wish you the best in the coming year.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=1981d708-5949-4d87-b7f4-ae60df47b298" /&gt;</description>
      <comments>http://www.manuelabadia.com/blog/CommentView,guid,1981d708-5949-4d87-b7f4-ae60df47b298.aspx</comments>
      <category>Ajax;ANTLR;ASP.NET;CSS;Games;General;JavaScript;Microsoft .NET Framework;Music;WPF/E</category>
    </item>
    <item>
      <trackback:ping>http://www.manuelabadia.com/blog/Trackback.aspx?guid=ff1dc504-f854-40b4-bfe7-250ce91efad7</trackback:ping>
      <pingback:server>http://www.manuelabadia.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.manuelabadia.com/blog/PermaLink,guid,ff1dc504-f854-40b4-bfe7-250ce91efad7.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://www.manuelabadia.com/blog/CommentView,guid,ff1dc504-f854-40b4-bfe7-250ce91efad7.aspx</wfw:comment>
      <wfw:commentRss>http://www.manuelabadia.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=ff1dc504-f854-40b4-bfe7-250ce91efad7</wfw:commentRss>
      <slash:comments>3</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a href="http://www.manuelabadia.com/blog/PermaLink,guid,5085c0cc-5256-429c-a18c-4639afa0dcc1.aspx">
            <font color="#003399">Click
here for Part 2 of this overview</font>
          </a>
          <br />
          <a href="http://www.manuelabadia.com/blog/PermaLink,guid,6e509f70-3db8-46f4-b451-1ef9dd80740b.aspx">
            <font color="#003399">Click
here for Part 3 of this overview</font>
          </a>
        </p>
        <p>
There are some articles out there about ANTLR v3 that cover how to define grammars
and tree parses but I haven’t seen any that gives a global vision about all the classes
and interfaces involved, so I’ll try to fill that gap. I’m using the C# version of
ANTLR 3.0b5 as it is what I use and it has better name conventions for interfaces
and classes.
</p>
        <p>
There’s an upcoming book about ANTLR by its autor that will be a very valuable material
if you work with ANTLR:
</p>
        <iframe style="WIDTH: 120px; HEIGHT: 240px" marginwidth="0" marginheight="0" src="http://rcm.amazon.com/e/cm?t=manuelabadias-20&amp;o=1&amp;p=8&amp;l=as1&amp;asins=0978739256&amp;fc1=000000&amp;IS2=1&amp;lt1=_blank&amp;lc1=0000FF&amp;bc1=000000&amp;bg1=FFFFFF&amp;f=ifr" frameborder="0" scrolling="no">
        </iframe>
        <p>
ANTLR lets us create a lexer, a parser and a tree parser. Depending on what you are
creating, the classes generated by ANTLR will inherit Lexer, Parser or the TreeParser
class. Those 3 classes inherit from a common abstract class called BaseRecognizer
where all the code for parsing is present.
</p>
        <p>
The Lexer class is also an abstract class that extends BaseRecognizer and implements
the ITokenSource interface.
</p>
        <p>
The ITokenSource interface has only one method, NextToken, that is used to get all
tokens from the input. For ANTLR a token is a class that implements the IToken interface:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">public</span>
            <span style="COLOR: blue">interface</span>
            <span style="COLOR: teal">IToken</span>
          </p>
          <p style="MARGIN: 0px">
{
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">int</span> Channel { <span style="COLOR: blue">get</span>; <span style="COLOR: blue">set</span>;
}
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">int</span> CharPositionInLine { <span style="COLOR: blue">get</span>; <span style="COLOR: blue">set</span>;
}
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">int</span> Line { <span style="COLOR: blue">get</span>; <span style="COLOR: blue">set</span>;
}
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">string</span> Text { <span style="COLOR: blue">get</span>; <span style="COLOR: blue">set</span>;
}
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">int</span> TokenIndex { <span style="COLOR: blue">get</span>; <span style="COLOR: blue">set</span>;
}
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">int</span> Type { <span style="COLOR: blue">get</span>; <span style="COLOR: blue">set</span>;
}
</p>
          <p style="MARGIN: 0px">
}
</p>
        </div>
        <!--EndFragment-->
        <p>
 
</p>
        <p>
The basic properties of a token are its type and its text. The Line and CharPositionInLine
are used to know where the token was read from the input.
</p>
        <p>
A parser will read tokens from a channel, so the Channel property is usually used
to disntinguish from a “normal” token from a white space or other token used as separator
that does not alter the input to be parsed.
</p>
        <p>
All tokens read from the input are assigned an unique TokenIndex (starting from 0
and incremented each time a token is read).
</p>
        <p>
The CommonToken class implements IToken and it is the class that is usually used to
represent a token in ANTLR. It has two properties not present in the IToken interface,
StartIndex and StopIndex, that are used to indicate where the token starts and ends
in the input stream. So the Text property returns the data directly from the input
stream unless the Text property has been explicitly set. The ToString method prints
a token like this:
</p>
        <p>
[@15,23:26=’else’,&lt;10&gt;,1:22]
</p>
        <p>
Where 15 is the TokenIndex, 23:26 are the StartIndex and StopIndex respectively, else
is the Text, 10 is the Type, and 1,22 are the Line and CharPositionInLine respectively.
</p>
        <p>
Returning to the Lexer class… it reads the characters from a ICharStream, that is
an interface that extends the IIntStream interface for reading characters and adding
line and column information to it:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">public</span>
            <span style="COLOR: blue">interface</span>
            <span style="COLOR: teal">IIntStream</span>
          </p>
          <p style="MARGIN: 0px">
{
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">void</span> Consume();
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">int</span> Index();
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">int</span> LA(<span style="COLOR: blue">int</span> i);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">int</span> Mark();
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">void</span> Release(<span style="COLOR: blue">int</span> marker);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">void</span> Rewind();
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">void</span> Rewind(<span style="COLOR: blue">int</span> marker);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">void</span> Seek(<span style="COLOR: blue">int</span> index);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">int</span> Size();
</p>
          <p style="MARGIN: 0px">
}
</p>
        </div>
        <p>
          <!--EndFragment-->
          <br />
The IIntStream interface is a contract for a stream of integers with variable lookahead
and marker points so the stream can save a return point with the Mark method and return
to it using the Rewind method.
</p>
        <p>
There are several classes implementing the ICharStream interface so the Lexer can
get data from several sources:
</p>
        <p>
• ANTLRStringStream: to provide data from a string.<br />
• ANTLRFileStream: to provide data from a file.<br />
• ANTLRReaderStream: to provide data from a TextReader.<br />
• ANTLRInputStream: to provide data from a Stream.<br />
 
</p>
        <p>
So finally we’re ready to understand the Lexer class:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">public</span>
            <span style="COLOR: blue">abstract</span>
            <span style="COLOR: blue">class</span>
            <span style="COLOR: teal">Lexer</span> : <span style="COLOR: teal">BaseRecognizer</span>, <span style="COLOR: teal">ITokenSource</span></p>
          <p style="MARGIN: 0px">
{
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span> Lexer();
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span> Lexer(<span style="COLOR: teal">ICharStream</span> input);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">virtual</span><span style="COLOR: blue">int</span> CharIndex
{ <span style="COLOR: blue">get</span>; }
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">virtual</span><span style="COLOR: blue">int</span> CharPositionInLine
{ <span style="COLOR: blue">get</span>; }
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">virtual</span><span style="COLOR: teal">ICharStream</span> CharStream
{ <span style="COLOR: blue">set</span>; }
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">override</span><span style="COLOR: teal">IIntStream</span> Input
{ <span style="COLOR: blue">get</span>; }
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">virtual</span><span style="COLOR: blue">int</span> Line
{ <span style="COLOR: blue">get</span>; }
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">virtual</span><span style="COLOR: blue">string</span> Text
{ <span style="COLOR: blue">get</span>; <span style="COLOR: blue">set</span>; }
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">static</span><span style="COLOR: blue">void</span> DisplayRecognitionError(<span style="COLOR: blue">string</span> name, <span style="COLOR: teal">RecognitionException</span> e);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">virtual</span><span style="COLOR: blue">void</span> Emit(<span style="COLOR: teal">IToken</span> token);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">virtual</span><span style="COLOR: teal">IToken</span> Emit(<span style="COLOR: blue">int</span> tokenType, <span style="COLOR: blue">int</span> line, <span style="COLOR: blue">int</span> charPosition, <span style="COLOR: blue">int</span> channel, <span style="COLOR: blue">int</span> start, <span style="COLOR: blue">int</span> stop);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">virtual</span><span style="COLOR: blue">void</span> Match(<span style="COLOR: blue">int</span> c);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">virtual</span><span style="COLOR: blue">void</span> Match(<span style="COLOR: blue">string</span> s);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">virtual</span><span style="COLOR: blue">void</span> MatchAny();
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">virtual</span><span style="COLOR: blue">void</span> MatchRange(<span style="COLOR: blue">int</span> a, <span style="COLOR: blue">int</span> b);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">abstract</span><span style="COLOR: blue">void</span> mTokens();
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">virtual</span><span style="COLOR: teal">IToken</span> NextToken();
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">virtual</span><span style="COLOR: blue">void</span> Recover(<span style="COLOR: teal">RecognitionException</span> re);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">override</span><span style="COLOR: blue">void</span> ReportError(<span style="COLOR: teal">RecognitionException</span> e);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">void</span> Skip();
</p>
          <p style="MARGIN: 0px">
}
</p>
        </div>
        <!--EndFragment-->
        <p>
 
</p>
        <p>
The Lexer works using a ICharStream as its input and offers a bunch of properties
to get information about the current character position of the underlying ICharStream. 
</p>
        <p>
The main operation accomplished by the Lexer class is to obtain tokens from the input
stream when the NextToken method (of the implemented interface ITokenSource) is called.
</p>
        <p>
When a Lexer is generated using ANTLR, a class that inherits Lexer is generated. That
class will have a method called mXXX for each lexer rule where XXX is the rule name.
Also a method called mTYYY (where YYY is an integer) will be generated for each token
implicitly defined in a lexer rule like ‘&gt;=’.
</p>
        <p>
By default, each generated method will check if the expected characters are read from
the input stream (using the Math, MathAny and MathRange methods) and then call the
Emit method to generate the associated token, that is stored in a field called token.
</p>
        <p>
When the NextToken method is called, the Lexer class the abstract method mTokens that
is implemented in the class generated by ANTLR and  what it does is to select
one of the m* methods explained before to call based on the input (using a DFA for
this). That method will set the token field, and if the token should not be skipped
(to skip a token you have to call to the Skip method in the Lexer class) it returns
it. If not it repeats the process until a token is returned or the end of the input
is found (EOF).
</p>
        <p>
The Parser class inherits from BaseRecognizer and reads tokens from an object that
implements ITokenStream. ITokenStream is just a specialization of the IIntStream to
work with ITokens instead of ints:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">public</span>
            <span style="COLOR: blue">interface</span>
            <span style="COLOR: teal">ITokenStream</span> : <span style="COLOR: teal">IIntStream</span></p>
          <p style="MARGIN: 0px">
{
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: teal">IToken</span> Get(<span style="COLOR: blue">int</span> i);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: teal">ITokenSource</span> GetTokenSource();
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: teal">IToken</span> LT(<span style="COLOR: blue">int</span> k);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">string</span> ToString(<span style="COLOR: blue">int</span> start, <span style="COLOR: blue">int</span> stop);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">string</span> ToString(<span style="COLOR: teal">IToken</span> start, <span style="COLOR: teal">IToken</span> stop);
</p>
          <p style="MARGIN: 0px">
}
</p>
        </div>
        <!--EndFragment-->
        <p>
 
</p>
        <p>
ITokenStream uses an object that implements ITokenSource (remember that the Lexer
class implements ITokenSource) to obtain tokens. There are two classes implementing
ITokenStream, CommonTokenStream and TokenRewriteString. The CommonTokenStream class
buffers all the tokens and will return tokens in a specific channel. The TokenRewriteString
class has additional functionality to insert, update and delete tokens.
</p>
        <p>
The Parser class is very simple:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">public</span>
            <span style="COLOR: blue">class</span>
            <span style="COLOR: teal">Parser</span> : <span style="COLOR: teal">BaseRecognizer</span></p>
          <p style="MARGIN: 0px">
{
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span> Parser(<span style="COLOR: teal">ITokenStream</span> input);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">override</span><span style="COLOR: teal">IIntStream</span> Input
{ <span style="COLOR: blue">get</span>; }
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">virtual</span><span style="COLOR: teal">ITokenStream</span> TokenStream
{ <span style="COLOR: blue">get</span>; <span style="COLOR: blue">set</span>; }
</p>
          <p style="MARGIN: 0px">
}
</p>
        </div>
        <!--EndFragment-->
        <p>
 
</p>
        <p>
As only adds an additional property to return the ITokenStream that feeds the parser.
</p>
        <p>
When a Parser is generated using ANTLR, a class that inherits from Parser is generated.
For each parser rule, that class will have a method with the same name as the rule.
The method signature will depend on the attributes used (if any) in the rule and if
abstract syntax tree (AST) construction is enabled or not.
</p>
        <p>
Tree parsers will be explained in another post as there is a lot of tree related theory
to introduce.
</p>
        <p>
        </p>
        <img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=ff1dc504-f854-40b4-bfe7-250ce91efad7" />
      </body>
      <title>ANTLR C# Overview - Part 1</title>
      <guid isPermaLink="false">http://www.manuelabadia.com/blog/PermaLink,guid,ff1dc504-f854-40b4-bfe7-250ce91efad7.aspx</guid>
      <link>http://www.manuelabadia.com/blog/PermaLink,guid,ff1dc504-f854-40b4-bfe7-250ce91efad7.aspx</link>
      <pubDate>Tue, 26 Dec 2006 15:10:19 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a href="http://www.manuelabadia.com/blog/PermaLink,guid,5085c0cc-5256-429c-a18c-4639afa0dcc1.aspx"&gt;&lt;font color=#003399&gt;Click
here for Part&amp;nbsp;2 of this overview&lt;/font&gt;&lt;/a&gt;
&lt;br&gt;
&lt;a href="http://www.manuelabadia.com/blog/PermaLink,guid,6e509f70-3db8-46f4-b451-1ef9dd80740b.aspx"&gt;&lt;font color=#003399&gt;Click
here for Part&amp;nbsp;3 of this overview&lt;/font&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
There are some articles out there about ANTLR v3 that cover how to define grammars
and tree parses but I haven’t seen any that gives a global vision about all the classes
and interfaces involved, so I’ll try to fill that gap. I’m using the C# version of
ANTLR 3.0b5 as it is what I use and it has better name conventions for interfaces
and classes.
&lt;/p&gt;
&lt;p&gt;
There’s an upcoming book about ANTLR by its autor that will be a very valuable material
if you work with ANTLR:
&lt;/p&gt;
&lt;iframe style="WIDTH: 120px; HEIGHT: 240px" marginwidth=0 marginheight=0 src="http://rcm.amazon.com/e/cm?t=manuelabadias-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=as1&amp;amp;asins=0978739256&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" frameborder=0 scrolling=no&gt;
&lt;/iframe&gt;
&lt;p&gt;
ANTLR lets us create a lexer, a parser and a tree parser. Depending on what you are
creating, the classes generated by ANTLR will inherit Lexer, Parser or the TreeParser
class. Those 3 classes inherit from a common abstract class called BaseRecognizer
where all the code for parsing is present.
&lt;/p&gt;
&lt;p&gt;
The Lexer class is also an abstract class that extends BaseRecognizer and implements
the ITokenSource interface.
&lt;/p&gt;
&lt;p&gt;
The ITokenSource interface has only one method, NextToken, that is used to get all
tokens from the input. For ANTLR a token is a class that implements the IToken interface:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;interface&lt;/span&gt; &lt;span style="COLOR: teal"&gt;IToken&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; Channel { &lt;span style="COLOR: blue"&gt;get&lt;/span&gt;; &lt;span style="COLOR: blue"&gt;set&lt;/span&gt;;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; CharPositionInLine { &lt;span style="COLOR: blue"&gt;get&lt;/span&gt;; &lt;span style="COLOR: blue"&gt;set&lt;/span&gt;;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; Line { &lt;span style="COLOR: blue"&gt;get&lt;/span&gt;; &lt;span style="COLOR: blue"&gt;set&lt;/span&gt;;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; Text { &lt;span style="COLOR: blue"&gt;get&lt;/span&gt;; &lt;span style="COLOR: blue"&gt;set&lt;/span&gt;;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; TokenIndex { &lt;span style="COLOR: blue"&gt;get&lt;/span&gt;; &lt;span style="COLOR: blue"&gt;set&lt;/span&gt;;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; Type { &lt;span style="COLOR: blue"&gt;get&lt;/span&gt;; &lt;span style="COLOR: blue"&gt;set&lt;/span&gt;;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
The basic properties of a token are its type and its text. The Line and CharPositionInLine
are used to know where the token was read from the input.
&lt;/p&gt;
&lt;p&gt;
A parser will read tokens from a channel, so the Channel property is usually used
to disntinguish from a “normal” token from a white space or other token used as separator
that does not alter the input to be parsed.
&lt;/p&gt;
&lt;p&gt;
All tokens read from the input are assigned an unique TokenIndex (starting from 0
and incremented each time a token is read).
&lt;/p&gt;
&lt;p&gt;
The CommonToken class implements IToken and it is the class that is usually used to
represent a token in ANTLR. It has two properties not present in the IToken interface,
StartIndex and StopIndex, that are used to indicate where the token starts and ends
in the input stream. So the Text property returns the data directly from the input
stream unless the Text property has been explicitly set. The ToString method prints
a token like this:
&lt;/p&gt;
&lt;p&gt;
[@15,23:26=’else’,&amp;lt;10&amp;gt;,1:22]
&lt;/p&gt;
&lt;p&gt;
Where 15 is the TokenIndex, 23:26 are the StartIndex and StopIndex respectively, else
is the Text, 10 is the Type, and 1,22 are the Line and CharPositionInLine respectively.
&lt;/p&gt;
&lt;p&gt;
Returning to the Lexer class… it reads the characters from a ICharStream, that is
an interface that extends the IIntStream interface for reading characters and adding
line and column information to it:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;interface&lt;/span&gt; &lt;span style="COLOR: teal"&gt;IIntStream&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; Consume();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; Index();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; LA(&lt;span style="COLOR: blue"&gt;int&lt;/span&gt; i);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; Mark();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; Release(&lt;span style="COLOR: blue"&gt;int&lt;/span&gt; marker);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; Rewind();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; Rewind(&lt;span style="COLOR: blue"&gt;int&lt;/span&gt; marker);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; Seek(&lt;span style="COLOR: blue"&gt;int&lt;/span&gt; index);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; Size();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;!--EndFragment--&gt;
&lt;br&gt;
The IIntStream interface is a contract for a stream of integers with variable lookahead
and marker points so the stream can save a return point with the Mark method and return
to it using the Rewind method.
&lt;/p&gt;
&lt;p&gt;
There are several classes implementing the ICharStream interface so the Lexer can
get data from several sources:
&lt;/p&gt;
&lt;p&gt;
•&amp;nbsp;ANTLRStringStream: to provide data from a string.&lt;br&gt;
•&amp;nbsp;ANTLRFileStream: to provide data from a file.&lt;br&gt;
•&amp;nbsp;ANTLRReaderStream: to provide data from a TextReader.&lt;br&gt;
•&amp;nbsp;ANTLRInputStream: to provide data from a Stream.&lt;br&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
So finally we’re ready to understand the Lexer class:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;abstract&lt;/span&gt; &lt;span style="COLOR: blue"&gt;class&lt;/span&gt; &lt;span style="COLOR: teal"&gt;Lexer&lt;/span&gt; : &lt;span style="COLOR: teal"&gt;BaseRecognizer&lt;/span&gt;, &lt;span style="COLOR: teal"&gt;ITokenSource&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; Lexer();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; Lexer(&lt;span style="COLOR: teal"&gt;ICharStream&lt;/span&gt; input);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;virtual&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; CharIndex
{ &lt;span style="COLOR: blue"&gt;get&lt;/span&gt;; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;virtual&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; CharPositionInLine
{ &lt;span style="COLOR: blue"&gt;get&lt;/span&gt;; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;virtual&lt;/span&gt; &lt;span style="COLOR: teal"&gt;ICharStream&lt;/span&gt; CharStream
{ &lt;span style="COLOR: blue"&gt;set&lt;/span&gt;; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;override&lt;/span&gt; &lt;span style="COLOR: teal"&gt;IIntStream&lt;/span&gt; Input
{ &lt;span style="COLOR: blue"&gt;get&lt;/span&gt;; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;virtual&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; Line
{ &lt;span style="COLOR: blue"&gt;get&lt;/span&gt;; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;virtual&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; Text
{ &lt;span style="COLOR: blue"&gt;get&lt;/span&gt;; &lt;span style="COLOR: blue"&gt;set&lt;/span&gt;; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;static&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; DisplayRecognitionError(&lt;span style="COLOR: blue"&gt;string&lt;/span&gt; name, &lt;span style="COLOR: teal"&gt;RecognitionException&lt;/span&gt; e);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;virtual&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; Emit(&lt;span style="COLOR: teal"&gt;IToken&lt;/span&gt; token);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;virtual&lt;/span&gt; &lt;span style="COLOR: teal"&gt;IToken&lt;/span&gt; Emit(&lt;span style="COLOR: blue"&gt;int&lt;/span&gt; tokenType, &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; line, &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; charPosition, &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; channel, &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; start, &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; stop);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;virtual&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; Match(&lt;span style="COLOR: blue"&gt;int&lt;/span&gt; c);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;virtual&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; Match(&lt;span style="COLOR: blue"&gt;string&lt;/span&gt; s);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;virtual&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; MatchAny();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;virtual&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; MatchRange(&lt;span style="COLOR: blue"&gt;int&lt;/span&gt; a, &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; b);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;abstract&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; mTokens();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;virtual&lt;/span&gt; &lt;span style="COLOR: teal"&gt;IToken&lt;/span&gt; NextToken();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;virtual&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; Recover(&lt;span style="COLOR: teal"&gt;RecognitionException&lt;/span&gt; re);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;override&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; ReportError(&lt;span style="COLOR: teal"&gt;RecognitionException&lt;/span&gt; e);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; Skip();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
The Lexer works using a ICharStream as its input and offers a bunch of properties
to get information about the current character position of the underlying ICharStream. 
&lt;/p&gt;
&lt;p&gt;
The main operation accomplished by the Lexer class is to obtain tokens from the input
stream when the NextToken method (of the implemented interface ITokenSource) is called.
&lt;/p&gt;
&lt;p&gt;
When a Lexer is generated using ANTLR, a class that inherits Lexer is generated. That
class will have a method called mXXX for each lexer rule where XXX is the rule name.
Also a method called mTYYY (where YYY is an integer) will be generated for each token
implicitly defined in a lexer rule like ‘&amp;gt;=’.
&lt;/p&gt;
&lt;p&gt;
By default, each generated method will check if the expected characters are read from
the input stream (using the Math, MathAny and MathRange methods) and then call the
Emit method to generate the associated token, that is stored in a field called token.
&lt;/p&gt;
&lt;p&gt;
When the NextToken method is called, the Lexer class the abstract method mTokens that
is implemented in the class generated by ANTLR and &amp;nbsp;what it does is to select
one of the m* methods explained before to call based on the input (using a DFA for
this). That method will set the token field, and if the token should not be skipped
(to skip a token you have to call to the Skip method in the Lexer class) it returns
it. If not it repeats the process until a token is returned or the end of the input
is found (EOF).
&lt;/p&gt;
&lt;p&gt;
The Parser class inherits from BaseRecognizer and reads tokens from an object that
implements ITokenStream. ITokenStream is just a specialization of the IIntStream to
work with ITokens instead of ints:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;interface&lt;/span&gt; &lt;span style="COLOR: teal"&gt;ITokenStream&lt;/span&gt; : &lt;span style="COLOR: teal"&gt;IIntStream&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: teal"&gt;IToken&lt;/span&gt; Get(&lt;span style="COLOR: blue"&gt;int&lt;/span&gt; i);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: teal"&gt;ITokenSource&lt;/span&gt; GetTokenSource();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: teal"&gt;IToken&lt;/span&gt; LT(&lt;span style="COLOR: blue"&gt;int&lt;/span&gt; k);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; ToString(&lt;span style="COLOR: blue"&gt;int&lt;/span&gt; start, &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; stop);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; ToString(&lt;span style="COLOR: teal"&gt;IToken&lt;/span&gt; start, &lt;span style="COLOR: teal"&gt;IToken&lt;/span&gt; stop);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
ITokenStream uses an object that implements ITokenSource (remember that the Lexer
class implements ITokenSource) to obtain tokens. There are two classes implementing
ITokenStream, CommonTokenStream and TokenRewriteString. The CommonTokenStream class
buffers all the tokens and will return tokens in a specific channel. The TokenRewriteString
class has additional functionality to insert, update and delete tokens.
&lt;/p&gt;
&lt;p&gt;
The Parser class is very simple:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;class&lt;/span&gt; &lt;span style="COLOR: teal"&gt;Parser&lt;/span&gt; : &lt;span style="COLOR: teal"&gt;BaseRecognizer&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; Parser(&lt;span style="COLOR: teal"&gt;ITokenStream&lt;/span&gt; input);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;override&lt;/span&gt; &lt;span style="COLOR: teal"&gt;IIntStream&lt;/span&gt; Input
{ &lt;span style="COLOR: blue"&gt;get&lt;/span&gt;; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;virtual&lt;/span&gt; &lt;span style="COLOR: teal"&gt;ITokenStream&lt;/span&gt; TokenStream
{ &lt;span style="COLOR: blue"&gt;get&lt;/span&gt;; &lt;span style="COLOR: blue"&gt;set&lt;/span&gt;; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
As only adds an additional property to return the ITokenStream that feeds the parser.
&lt;/p&gt;
&lt;p&gt;
When a Parser is generated using ANTLR, a class that inherits from Parser is generated.
For each parser rule, that class will have a method with the same name as the rule.
The method signature will depend on the attributes used (if any) in the rule and if
abstract syntax tree (AST) construction is enabled or not.
&lt;/p&gt;
&lt;p&gt;
Tree parsers will be explained in another post as there is a lot of tree related theory
to introduce.
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=ff1dc504-f854-40b4-bfe7-250ce91efad7" /&gt;</description>
      <comments>http://www.manuelabadia.com/blog/CommentView,guid,ff1dc504-f854-40b4-bfe7-250ce91efad7.aspx</comments>
      <category>ANTLR;Microsoft .NET Framework</category>
    </item>
    <item>
      <trackback:ping>http://www.manuelabadia.com/blog/Trackback.aspx?guid=6839c49c-d9c9-4fc7-80e0-1fc4dd384cdc</trackback:ping>
      <pingback:server>http://www.manuelabadia.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.manuelabadia.com/blog/PermaLink,guid,6839c49c-d9c9-4fc7-80e0-1fc4dd384cdc.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://www.manuelabadia.com/blog/CommentView,guid,6839c49c-d9c9-4fc7-80e0-1fc4dd384cdc.aspx</wfw:comment>
      <wfw:commentRss>http://www.manuelabadia.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=6839c49c-d9c9-4fc7-80e0-1fc4dd384cdc</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I couldn’t resist to improve StructsViz in order to add support for trees. Even if
everybody has his own tree implementation, we can come up with a common agreement: 
</p>
        <blockquote dir="ltr" style="MARGIN-RIGHT: 0px">
          <p>
            <strong>
              <em>A tree is a collection of nodes, where each node has zero or more child
nodes. Each node has zero or one parent. The only node that doesn’t have a parent
is the root node.</em>
            </strong>
          </p>
        </blockquote>
        <p>
So based on the previous definition, I have defined this interface that is mandatory
to implement in order to visualize a tree node in StructsViz:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">public</span>
            <span style="COLOR: blue">interface</span>
            <span style="COLOR: teal">ITreeNode</span>&lt;T&gt;
</p>
          <p style="MARGIN: 0px">
{
</p>
          <p style="MARGIN: 0px">
    T Value { <span style="COLOR: blue">get</span>; <span style="COLOR: blue">set</span>;
}
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: teal">ITreeNode</span>&lt;T&gt; Parent { <span style="COLOR: blue">get</span>; <span style="COLOR: blue">set</span>;
}
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">bool</span> HasChildren { <span style="COLOR: blue">get</span>;
}
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: teal">ICollection</span>&lt;<span style="COLOR: teal">ITreeNode</span>&lt;T&gt;&gt;
Children { <span style="COLOR: blue">get</span>; }
</p>
          <p style="MARGIN: 0px">
}
</p>
        </div>
        <!--EndFragment-->
        <p>
 
</p>
        <p>
I think that any tree node implementation can easily implement this interface. 
</p>
        <p>
With that interface implemented, StructsViz will be able to draw your tree node.
</p>
        <p>
I have been playing a bit with automatic layout positioning for trees, and with different
kind of connections:
</p>
        <img src="http://www.manuelabadia.com/blog/content/binary/tree1.PNG" border="0" />
        <br />
        <img src="http://www.manuelabadia.com/blog/content/binary/tree2.PNG" border="0" />
        <br />
        <img src="http://www.manuelabadia.com/blog/content/binary/tree3.PNG" border="0" />
        <br />
        <br />
        <p>
 
</p>
        <p>
The pictures show debug information of the subtree areas needed to position the elements
properly using a recursive algorithm. For example, the rectangle labeled as ST 2,
is the subtree area for node 2, and it is calculated based on the ST 6 and ST 7 (subtree
areas for node 6 and 7 respectively). With ST 1, ST 2 and ST 3, we can properly position
node 0.
</p>
        <p>
I’m giving the final touches to this and it will be included in the next StructsViz
version.<br /></p>
        <img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=6839c49c-d9c9-4fc7-80e0-1fc4dd384cdc" />
      </body>
      <title>Debugging trees</title>
      <guid isPermaLink="false">http://www.manuelabadia.com/blog/PermaLink,guid,6839c49c-d9c9-4fc7-80e0-1fc4dd384cdc.aspx</guid>
      <link>http://www.manuelabadia.com/blog/PermaLink,guid,6839c49c-d9c9-4fc7-80e0-1fc4dd384cdc.aspx</link>
      <pubDate>Sat, 02 Dec 2006 16:17:59 GMT</pubDate>
      <description>&lt;p&gt;
I couldn’t resist to improve StructsViz in order to add support for trees. Even if
everybody has his own tree implementation, we can come up with a common agreement: 
&lt;/p&gt;
&lt;blockquote dir=ltr style="MARGIN-RIGHT: 0px"&gt; 
&lt;p&gt;
&lt;strong&gt;&lt;em&gt;A tree is a collection of nodes, where each node has zero or more child
nodes. Each node has zero or one parent. The only node that doesn’t have a parent
is the root node.&lt;/em&gt;&lt;/strong&gt;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
So based on the previous definition, I have defined this interface that is mandatory
to implement in order to visualize a tree node in StructsViz:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;interface&lt;/span&gt; &lt;span style="COLOR: teal"&gt;ITreeNode&lt;/span&gt;&amp;lt;T&amp;gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; T Value { &lt;span style="COLOR: blue"&gt;get&lt;/span&gt;; &lt;span style="COLOR: blue"&gt;set&lt;/span&gt;;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: teal"&gt;ITreeNode&lt;/span&gt;&amp;lt;T&amp;gt; Parent { &lt;span style="COLOR: blue"&gt;get&lt;/span&gt;; &lt;span style="COLOR: blue"&gt;set&lt;/span&gt;;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;bool&lt;/span&gt; HasChildren { &lt;span style="COLOR: blue"&gt;get&lt;/span&gt;;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: teal"&gt;ICollection&lt;/span&gt;&amp;lt;&lt;span style="COLOR: teal"&gt;ITreeNode&lt;/span&gt;&amp;lt;T&amp;gt;&amp;gt;
Children { &lt;span style="COLOR: blue"&gt;get&lt;/span&gt;; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
I think that any tree node implementation can easily implement this interface. 
&lt;/p&gt;
&lt;p&gt;
With that interface implemented, StructsViz will be able to draw your tree node.
&lt;/p&gt;
&lt;p&gt;
I have been playing a bit with automatic layout positioning for trees, and with different
kind of connections:
&lt;/p&gt;
&lt;img src="http://www.manuelabadia.com/blog/content/binary/tree1.PNG" border=0&gt;
&lt;br&gt;
&lt;img src="http://www.manuelabadia.com/blog/content/binary/tree2.PNG" border=0&gt;
&lt;br&gt;
&lt;img src="http://www.manuelabadia.com/blog/content/binary/tree3.PNG" border=0&gt;
&lt;br&gt;
&lt;br&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
The pictures show debug information of the subtree areas needed to position the elements
properly using a recursive algorithm. For example, the rectangle labeled as ST 2,
is the subtree area for node 2, and it is calculated based on the ST 6 and ST 7 (subtree
areas for node 6 and 7 respectively). With ST 1, ST 2 and ST 3, we can properly position
node 0.
&lt;/p&gt;
&lt;p&gt;
I’m giving the final touches to this and it will be included in the next StructsViz
version.&lt;br&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=6839c49c-d9c9-4fc7-80e0-1fc4dd384cdc" /&gt;</description>
      <comments>http://www.manuelabadia.com/blog/CommentView,guid,6839c49c-d9c9-4fc7-80e0-1fc4dd384cdc.aspx</comments>
      <category>ASP.NET;Microsoft .NET Framework</category>
    </item>
    <item>
      <trackback:ping>http://www.manuelabadia.com/blog/Trackback.aspx?guid=3eb29015-3e3b-484f-8d81-392b893667e6</trackback:ping>
      <pingback:server>http://www.manuelabadia.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.manuelabadia.com/blog/PermaLink,guid,3eb29015-3e3b-484f-8d81-392b893667e6.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://www.manuelabadia.com/blog/CommentView,guid,3eb29015-3e3b-484f-8d81-392b893667e6.aspx</wfw:comment>
      <wfw:commentRss>http://www.manuelabadia.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=3eb29015-3e3b-484f-8d81-392b893667e6</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Visual Studio.NET 2005 has a really cool feature called debugger visualizers. When
you are inspecting an object while debugging, there are times that the standard inspection
of fields and properties of the debugger is not the best way to check if the internal
state of the object is correct. For example, a DataSet is very difficult to debug,
because the data is stored in a long hierarchy of objects. A debugger visualizer is
a viewer of objects of a predetermined type that presents the object to the developer
using a custom UI that helps debugging it.
</p>
        <p>
The debugger visualizer executes on a different application domain than the application
we’re debugging so to access the object being inspected the data needs to be sent
from one application domain to the other application domain. This implies that the
object we’re inspecting needs to be serializable or we need to create a serializable
proxy in order to visualize it.
</p>
        <p>
There are quite a few articles on the web about debugger visualizers so I will not
enter in detail in the process of writing a visualizer, but I’ll explain the basics.
As I explained before, the visualizer runs in a different application domain than
the process we’re debugging. To communicate those application domains, an object that
inherits from VisualizerObjectSource is created. The visualizer inherits from the
DialogDebuggerVisualizer class and has to implement the Show method, showing a custom
dialog. Before showing the dialog, the visualizer usually retrieves data requesting
it to the VisualizerObjectSource using an intermediate object that implements the
IVisualizerObjectProvider.
</p>
        <p>
The main method of the VisualizerObjectSource is GetData, where the object being debugged
should be sent through a stream. If the object being debugged is big, this could be
a long operation so a thing that can be done is to send a simplified object in the
GetData method, and when the user wants to see more detail of the simplified object,
transfer a more data using the TransferData method.
</p>
        <p>
A data structure is something that is better represented graphically so I spent some
days writing a bunch of visualizers for all the .NET System.Collections.* classes.
Here you have some pics of it:
</p>
        <img alt="Stack visualizer" src="http://www.manuelabadia.com/products/content-images/stackvisualizer.png" />
        <img alt="StringDictionary visualizer" src="http://www.manuelabadia.com/products/content-images/stringdictionaryvisualizer.png" />
        <img alt="Custom collection visualizer" src="http://www.manuelabadia.com/products/content-images/customcollectionvisualizer.png" />
        <p>
I had to write a basic diagramming engine in order to get some nice results. Writing
the diagramming engine was the funniest part. I wanted a lot of flexibility so I end
up implementing absolute and relative element positioning, cascading styles, shape
composition, expandable elements, automatic layout adjustment, zooming, etc. I think
that the resulting object model was pretty good even if it isn’t a complete diagramming
engine.
</p>
        <p>
After some work with the debugger visualizers, a big limitation surfaces. You can
only attach a visualizer to classes and not to interfaces. I think Microsoft should
change this is the next version as this is severely limiting the power of the visualizers.
</p>
        <p>
Also, it is a shame that the .NET framework doesn’t include more complex data structures
like a Tree or a Graph. A visualizer for a Dictionary, a List or a Queue can be useful,
but a visualizer for a Tree and a Graph is very very useful. Every developer has to
code his own Tree and Graph, so creating a viewer for them will make the developers
to use my implementation if they want to visualize it because of the limitation of
the debugger visualizers, and that can’t be done in a lot of cases.
</p>
        <p>
You can read more about the visualizer pack here:
</p>
        <p>
          <a href="http://www.manuelabadia.com/products/StructsViz_features.aspx">http://www.manuelabadia.com/products/StructsViz_features.aspx</a>
        </p>
        <p>
You can take a look to the evaluation version here:
</p>
        <p>
          <a href="http://www.manuelabadia.com/products/Purchase.aspx">http://www.manuelabadia.com/products/Purchase.aspx</a>
          <br />
        </p>
        <p>
        </p>
        <img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=3eb29015-3e3b-484f-8d81-392b893667e6" />
      </body>
      <title>Debugger Visualizers and Data Structures</title>
      <guid isPermaLink="false">http://www.manuelabadia.com/blog/PermaLink,guid,3eb29015-3e3b-484f-8d81-392b893667e6.aspx</guid>
      <link>http://www.manuelabadia.com/blog/PermaLink,guid,3eb29015-3e3b-484f-8d81-392b893667e6.aspx</link>
      <pubDate>Sun, 26 Nov 2006 23:37:06 GMT</pubDate>
      <description>&lt;p&gt;
Visual Studio.NET 2005 has a really cool feature called debugger visualizers. When
you are inspecting an object while debugging, there are times that the standard inspection
of fields and properties of the debugger is not the best way to check if the internal
state of the object is correct. For example, a DataSet is very difficult to debug,
because the data is stored in a long hierarchy of objects. A debugger visualizer is
a viewer of objects of a predetermined type that presents the object to the developer
using a custom UI that helps debugging it.
&lt;/p&gt;
&lt;p&gt;
The debugger visualizer executes on a different application domain than the application
we’re debugging so to access the object being inspected the data needs to be sent
from one application domain to the other application domain. This implies that the
object we’re inspecting needs to be serializable or we need to create a serializable
proxy in order to visualize it.
&lt;/p&gt;
&lt;p&gt;
There are quite a few articles on the web about debugger visualizers so I will not
enter in detail in the process of writing a visualizer, but I’ll explain the basics.
As I explained before, the visualizer runs in a different application domain than
the process we’re debugging. To communicate those application domains, an object that
inherits from VisualizerObjectSource is created. The visualizer inherits from the
DialogDebuggerVisualizer class and has to implement the Show method, showing a custom
dialog. Before showing the dialog, the visualizer usually retrieves data requesting
it to the VisualizerObjectSource using an intermediate object that implements the
IVisualizerObjectProvider.
&lt;/p&gt;
&lt;p&gt;
The main method of the VisualizerObjectSource is GetData, where the object being debugged
should be sent through a stream. If the object being debugged is big, this could be
a long operation so a thing that can be done is to send a simplified object in the
GetData method, and when the user wants to see more detail of the simplified object,
transfer a more data using the TransferData method.
&lt;/p&gt;
&lt;p&gt;
A data structure is something that is better represented graphically so I spent some
days writing a bunch of visualizers for all the .NET System.Collections.* classes.
Here you have some pics of it:
&lt;/p&gt;
&lt;img alt="Stack visualizer" src="http://www.manuelabadia.com/products/content-images/stackvisualizer.png"&gt; &lt;img alt="StringDictionary visualizer" src="http://www.manuelabadia.com/products/content-images/stringdictionaryvisualizer.png"&gt; &lt;img alt="Custom collection visualizer" src="http://www.manuelabadia.com/products/content-images/customcollectionvisualizer.png"&gt; 
&lt;p&gt;
I had to write a basic diagramming engine in order to get some nice results. Writing
the diagramming engine was the funniest part. I wanted a lot of flexibility so I end
up implementing absolute and relative element positioning, cascading styles, shape
composition, expandable elements, automatic layout adjustment, zooming, etc. I think
that the resulting object model was pretty good even if it isn’t a complete diagramming
engine.
&lt;/p&gt;
&lt;p&gt;
After some work with the debugger visualizers, a big limitation surfaces. You can
only attach a visualizer to classes and not to interfaces. I think Microsoft should
change this is the next version as this is severely limiting the power of the visualizers.
&lt;/p&gt;
&lt;p&gt;
Also, it is a shame that the .NET framework doesn’t include more complex data structures
like a Tree or a Graph. A visualizer for a Dictionary, a List or a Queue can be useful,
but a visualizer for a Tree and a Graph is very very useful. Every developer has to
code his own Tree and Graph, so creating a viewer for them will make the developers
to use my implementation if they want to visualize it because of the limitation of
the debugger visualizers, and that can’t be done in a lot of cases.
&lt;/p&gt;
&lt;p&gt;
You can read more about the visualizer pack here:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.manuelabadia.com/products/StructsViz_features.aspx"&gt;http://www.manuelabadia.com/products/StructsViz_features.aspx&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
You can take a look to the evaluation version here:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.manuelabadia.com/products/Purchase.aspx"&gt;http://www.manuelabadia.com/products/Purchase.aspx&lt;/a&gt;
&lt;br&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=3eb29015-3e3b-484f-8d81-392b893667e6" /&gt;</description>
      <comments>http://www.manuelabadia.com/blog/CommentView,guid,3eb29015-3e3b-484f-8d81-392b893667e6.aspx</comments>
      <category>ASP.NET;Microsoft .NET Framework</category>
    </item>
    <item>
      <trackback:ping>http://www.manuelabadia.com/blog/Trackback.aspx?guid=41bb5688-8d60-4f0d-a6f5-b4c690faabac</trackback:ping>
      <pingback:server>http://www.manuelabadia.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.manuelabadia.com/blog/PermaLink,guid,41bb5688-8d60-4f0d-a6f5-b4c690faabac.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://www.manuelabadia.com/blog/CommentView,guid,41bb5688-8d60-4f0d-a6f5-b4c690faabac.aspx</wfw:comment>
      <wfw:commentRss>http://www.manuelabadia.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=41bb5688-8d60-4f0d-a6f5-b4c690faabac</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I have been playing lately with compiler generators and related stuff for something
I’m working on. I had to re-read some parts of the dragon book (my memory is pretty
bad) and I also found out that a new edition of the dragon book was released this
year:
</p>
        <p>
          <iframe style="WIDTH: 120px; HEIGHT: 240px" marginwidth="0" marginheight="0" src="http://rcm.amazon.com/e/cm?t=manuelabadias-20&amp;o=1&amp;p=8&amp;l=as1&amp;asins=0321486811&amp;fc1=000000&amp;IS2=1&amp;lt1=_blank&amp;lc1=0000FF&amp;bc1=000000&amp;bg1=FFFFFF&amp;f=ifr" frameborder="0" scrolling="no">
          </iframe>
        </p>
        <p>
The best tool I have found is <a href="http://www.antlr.org">ANTLR</a>. It is completely
free, it can generate a lexer, a parser and a tree parser, so it can be used to generate
all the needed stuff without having to use different tools. It supports C#, Java,
C++ and Python. Also, it generates descendant recursive parsers so the code generated
can be understood by a human (no more transition tables like yacc/bison). Even if predictive
top down parsers can not handle all the context free grammars, this one supports pred-LL(k)
grammars (LL(k) means Left to right Left most derivation with k tokens of lookahead,
and the pred prefix means that it supports predicates to see if a rule has to be applied
or not) with backtracking so it is really powerful.
</p>
        <p>
The latest version (v3) is still in beta but it has some nice improvements over v2
so that’s the one I’m using. For v3 there isn’t much documentation so the learning
curve is a bit high but it seems worth the effort. IMHO one of the bests things of
ANTLR is that it has a great development IDE called <a href="http://www.antlr.org/works/index.html">ANTLRWorks</a> that
is amazing. Just look at this screenshots I took of some C# 2.0 grammar tests I did:
</p>
        <br />
        <img src="http://www.manuelabadia.com/blog/content/binary/ANTRLWorks.png" border="0" />
        <br />
        <br />
        <img src="http://www.manuelabadia.com/blog/content/binary/dependencies.png" border="0" />
        <br />
        <br />
        <img src="http://www.manuelabadia.com/blog/content/binary/parse_tree.png" border="0" />
        <br />
        <br />
        <img src="http://www.manuelabadia.com/blog/content/binary/tokensDFA.png" border="0" />
        <br />
        <br />
        <p>
You have real time error checking, you can see a syntax diagram of the current rule,
you can view the generated parse tree, debug the grammar, see rules dependencies,
the DFA for the tokens, automatically remove left recursion from rules… awesome!
</p>
        <p>
If you are wondering if ANTLR is good enough for you, think that JetBrains (the company
that created ReSharper) uses it.
</p>
        <p>
Enough talking, back to ANTLR…<br /></p>
        <img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=41bb5688-8d60-4f0d-a6f5-b4c690faabac" />
      </body>
      <title>Compiler tools for .NET</title>
      <guid isPermaLink="false">http://www.manuelabadia.com/blog/PermaLink,guid,41bb5688-8d60-4f0d-a6f5-b4c690faabac.aspx</guid>
      <link>http://www.manuelabadia.com/blog/PermaLink,guid,41bb5688-8d60-4f0d-a6f5-b4c690faabac.aspx</link>
      <pubDate>Thu, 09 Nov 2006 23:06:09 GMT</pubDate>
      <description>&lt;p&gt;
I have been playing lately with compiler generators and related stuff for something
I’m working on. I had to re-read some parts of the dragon book (my memory is pretty
bad) and I also found out that a new edition of the dragon book was released this
year:
&lt;/p&gt;
&lt;p&gt;
&lt;iframe style="WIDTH: 120px; HEIGHT: 240px" marginwidth=0 marginheight=0 src="http://rcm.amazon.com/e/cm?t=manuelabadias-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=as1&amp;amp;asins=0321486811&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;lc1=0000FF&amp;amp;bc1=000000&amp;amp;bg1=FFFFFF&amp;amp;f=ifr" frameborder=0 scrolling=no&gt;
&lt;/iframe&gt;
&lt;/p&gt;
&lt;p&gt;
The best tool I have found is &lt;a href="http://www.antlr.org"&gt;ANTLR&lt;/a&gt;. It is completely
free, it can generate a lexer, a parser and a tree parser, so it can be used to generate
all the needed stuff without having to use different tools. It supports C#, Java,
C++ and Python. Also, it generates descendant recursive parsers so the code generated
can be understood by a human (no more transition tables like yacc/bison). Even if&amp;nbsp;predictive
top down parsers can not handle all the context free grammars, this one supports pred-LL(k)
grammars (LL(k) means Left to right Left most derivation with k tokens of lookahead,
and the pred prefix means that it supports predicates to see if a rule has to be applied
or not) with backtracking so it is really powerful.
&lt;/p&gt;
&lt;p&gt;
The latest version (v3) is still in beta but it has some nice improvements over v2
so that’s the one I’m using. For v3 there isn’t much documentation so the learning
curve is a bit high but it seems worth the effort. IMHO one of the bests things of
ANTLR is that it has a great development IDE called &lt;a href="http://www.antlr.org/works/index.html"&gt;ANTLRWorks&lt;/a&gt; that
is amazing. Just look at this screenshots I took of some C# 2.0 grammar tests I did:
&lt;/p&gt;
&lt;br&gt;
&lt;img src="http://www.manuelabadia.com/blog/content/binary/ANTRLWorks.png" border=0&gt;
&lt;br&gt;
&lt;br&gt;
&lt;img src="http://www.manuelabadia.com/blog/content/binary/dependencies.png" border=0&gt;
&lt;br&gt;
&lt;br&gt;
&lt;img src="http://www.manuelabadia.com/blog/content/binary/parse_tree.png" border=0&gt;
&lt;br&gt;
&lt;br&gt;
&lt;img src="http://www.manuelabadia.com/blog/content/binary/tokensDFA.png" border=0&gt;
&lt;br&gt;
&lt;br&gt;
&lt;p&gt;
You have real time error checking, you can see a syntax diagram of the current rule,
you can view the generated parse tree, debug the grammar, see rules dependencies,
the DFA for the tokens, automatically remove left recursion from rules… awesome!
&lt;/p&gt;
&lt;p&gt;
If you are wondering if ANTLR is good enough for you, think that JetBrains (the company
that created ReSharper) uses it.
&lt;/p&gt;
&lt;p&gt;
Enough talking, back to ANTLR…&lt;br&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=41bb5688-8d60-4f0d-a6f5-b4c690faabac" /&gt;</description>
      <comments>http://www.manuelabadia.com/blog/CommentView,guid,41bb5688-8d60-4f0d-a6f5-b4c690faabac.aspx</comments>
      <category>ANTLR;Microsoft .NET Framework</category>
    </item>
    <item>
      <trackback:ping>http://www.manuelabadia.com/blog/Trackback.aspx?guid=3579b743-cecb-46a6-9d15-424f3eb971c0</trackback:ping>
      <pingback:server>http://www.manuelabadia.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.manuelabadia.com/blog/PermaLink,guid,3579b743-cecb-46a6-9d15-424f3eb971c0.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://www.manuelabadia.com/blog/CommentView,guid,3579b743-cecb-46a6-9d15-424f3eb971c0.aspx</wfw:comment>
      <wfw:commentRss>http://www.manuelabadia.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=3579b743-cecb-46a6-9d15-424f3eb971c0</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
The NDoc creators where spending a lot of time with the project with very little (if
any) economic reward as it is happening in most open source projects (my personal
experience with <a href="http://www.mame.net/">M.A.M.E.</a> was even worse, because
us (the developers) didn’t get a buck but a lot of people outside the team were getting
tons of money, illegally selling it in cabinets or creating commercial console (or
computer) arcade packs using the MAME source code without permission…) So, they have
discontinued NDoc. 
</p>
        <p>
As Visual Studio 2005 didn’t come with a documentation generator (as Visual Studio
2003 had) this was a big problem for the dot net community, but Microsoft reacted
quickly and created SandCastle, a cool documentation project. The problem is that
SandCastle is in beta stage and it doesn’t have any GUI yet so you have to run several
executables one after another to get the documentation. You can download the current
version here: 
</p>
        <p>
          <a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=E82EA71D-DA89-42EE-A715-696E3A4873B2&amp;displaylang=en">http://www.microsoft.com/downloads/details.aspx?FamilyId=E82EA71D-DA89-42EE-A715-696E3A4873B2&amp;displaylang=en</a>
        </p>
        <p>
And there is a nice blog about information in how to use the executables to get the
documentation done here: 
</p>
        <p>
          <a href="http://blogs.msdn.com/sandcastle">http://blogs.msdn.com/sandcastle</a>
        </p>
        <p>
As most people (myself included) don’t want to spent a lot of time and neurons in
order to build a CHM documentation file, Eric Woodruff has provided a nice GUI that
makes using SandCastle straightforward (and it’s very similar to the one provided
by NDoc): 
</p>
        <p>
          <a href="http://www.codeproject.com/useritems/SandcastleBuilder.asp">http://www.codeproject.com/useritems/SandcastleBuilder.asp</a>
        </p>
        <p>
If you are curious, here you have a screenshot of the generated CHM file using the
most common settings: 
</p>
        <p>
 <img height="549" alt="SandCastle documentation" src="http://www.manuelabadia.com/blog/content/binary/sandcastlesample.jpg" width="792" border="0" /></p>
        <p>
And talking about sandcastles… here are two from my visit to <a href="http://maps.google.com/maps?f=q&amp;hl=en&amp;ie=UTF8&amp;z=16&amp;ll=37.975631,-0.674018&amp;spn=0.011789,0.019784&amp;t=k&amp;om=1">Torrevieja
(Spain) </a>this summer: 
</p>
        <table>
          <tbody>
            <tr>
              <td>
                <img alt="sandcastle" src="http://www.manuelabadia.com/blog/content/binary/sandcastle2.jpg" border="0" />
              </td>
            </tr>
            <tr>
            </tr>
            <img alt="Sandcastle" src="http://www.manuelabadia.com/blog/content/binary/sandcastle1.jpg" border="0" />
            <td>
            </td>
          </tbody>
        </table>
        <img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=3579b743-cecb-46a6-9d15-424f3eb971c0" />
      </body>
      <title>NDoc has died… long live to SandCastle! </title>
      <guid isPermaLink="false">http://www.manuelabadia.com/blog/PermaLink,guid,3579b743-cecb-46a6-9d15-424f3eb971c0.aspx</guid>
      <link>http://www.manuelabadia.com/blog/PermaLink,guid,3579b743-cecb-46a6-9d15-424f3eb971c0.aspx</link>
      <pubDate>Mon, 04 Sep 2006 22:58:49 GMT</pubDate>
      <description>&lt;p&gt;
The NDoc creators where spending a lot of time with the project with very little (if
any) economic reward as it is happening in most open source projects (my personal
experience with &lt;a href="http://www.mame.net/"&gt;M.A.M.E.&lt;/a&gt; was even worse, because
us (the developers) didn’t get a buck but a lot of people outside the team were getting
tons of money, illegally selling it in cabinets or creating commercial console (or
computer) arcade packs using the MAME source code without permission…) So, they have
discontinued NDoc. 
&lt;/p&gt;
&lt;p&gt;
As Visual Studio 2005 didn’t come with a documentation generator (as Visual Studio
2003 had) this was a big problem for the dot net community, but Microsoft reacted
quickly and created SandCastle, a cool documentation project. The problem is that
SandCastle is in beta stage and it doesn’t have any GUI yet so you have to run several
executables one after another to get the documentation. You can download the current
version here: 
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=E82EA71D-DA89-42EE-A715-696E3A4873B2&amp;amp;displaylang=en"&gt;http://www.microsoft.com/downloads/details.aspx?FamilyId=E82EA71D-DA89-42EE-A715-696E3A4873B2&amp;amp;displaylang=en&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
And there is a nice blog about information in how to use the executables to get the
documentation done here: 
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blogs.msdn.com/sandcastle"&gt;http://blogs.msdn.com/sandcastle&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
As most people (myself included) don’t want to spent a lot of time and neurons in
order to build a CHM documentation file, Eric Woodruff has provided a nice GUI that
makes using SandCastle straightforward (and it’s very similar to the one provided
by NDoc): 
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.codeproject.com/useritems/SandcastleBuilder.asp"&gt;http://www.codeproject.com/useritems/SandcastleBuilder.asp&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
If you are curious, here you have a screenshot of the generated CHM file using the
most common settings: 
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;&lt;img height=549 alt="SandCastle documentation" src="http://www.manuelabadia.com/blog/content/binary/sandcastlesample.jpg" width=792 border=0&gt;
&lt;/p&gt;
&lt;p&gt;
And talking about sandcastles… here are two from my visit to &lt;a href="http://maps.google.com/maps?f=q&amp;amp;hl=en&amp;amp;ie=UTF8&amp;amp;z=16&amp;amp;ll=37.975631,-0.674018&amp;amp;spn=0.011789,0.019784&amp;amp;t=k&amp;amp;om=1"&gt;Torrevieja
(Spain) &lt;/a&gt;this summer: 
&lt;/p&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;img alt=sandcastle src="http://www.manuelabadia.com/blog/content/binary/sandcastle2.jpg" border=0&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&gt;
&lt;img alt=Sandcastle src="http://www.manuelabadia.com/blog/content/binary/sandcastle1.jpg" border=0&gt; 
&lt;td&gt;
&lt;/td&gt;
&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=3579b743-cecb-46a6-9d15-424f3eb971c0" /&gt;</description>
      <comments>http://www.manuelabadia.com/blog/CommentView,guid,3579b743-cecb-46a6-9d15-424f3eb971c0.aspx</comments>
      <category>ASP.NET;General;Microsoft .NET Framework</category>
    </item>
    <item>
      <trackback:ping>http://www.manuelabadia.com/blog/Trackback.aspx?guid=dc72b235-1381-4c91-8706-e36216f49b94</trackback:ping>
      <pingback:server>http://www.manuelabadia.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.manuelabadia.com/blog/PermaLink,guid,dc72b235-1381-4c91-8706-e36216f49b94.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://www.manuelabadia.com/blog/CommentView,guid,dc72b235-1381-4c91-8706-e36216f49b94.aspx</wfw:comment>
      <wfw:commentRss>http://www.manuelabadia.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=dc72b235-1381-4c91-8706-e36216f49b94</wfw:commentRss>
      <slash:comments>3</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
        </p>
        <p>
Being able to dynamically call an arbitrary method on an object or the ability to
get/set any arbitrary property by name at run time is very important when it comes
to do some generic stuff. In .NET Framework 1.x the only way to do that was using
reflection and that means to do it slow. For simple things or if we don’t have a lot
of concurrent users we can live with it, but sometimes the performance is important
and reflection isn’t an acceptable solution.
</p>
        <p>
Fortunately, the .NET Framework 2.0 introduces a new class that let us to quickly
call an arbitrary method without the overhead of a reflection call. How? Well, the
idea is to generate the same MSIL as the compiler generates when calling a function
but on the fly, and then we obtain a delegate that when called will execute the MSIL
we have just created. This is really useful in a lot of scenarios!
</p>
        <p>
I read something about this in Marc’s blog (<a href="http://musingmarc.blogspot.com/">http://musingmarc.blogspot.com/</a>)
but I didn’t have time to look at it in more detail in that moment. Today I read an
article at codeproject that talked about this (<a href="http://www.codeproject.com/useritems/FastMethodInvoker.asp">http://www.codeproject.com/useritems/FastMethodInvoker.asp</a>)
so I finally forced myself to spend some time playing with dynamic MSIL code generation
and I’m quite impressed with the possibilities.
</p>
        <p>
If you want to play with this you should download an excellent debugger visualizer
that will let you show the MSIL generated by a DynamicMethod:
</p>
        <p>
          <a href="http://blogs.msdn.com/haibo_luo/archive/2005/10/25/484861.aspx">http://blogs.msdn.com/haibo_luo/archive/2005/10/25/484861.aspx</a>
        </p>
        <p>
I have made a little helper class (based on the codeproject article) that can be used
to replace MethodInfo.Invoke, PropertyInfo.GetValue, PropertyInfo.SetValue and Activator.CreateInstance
that are the reflection methods that I use most often. In order to use it in your
own projects, remember to cache the delegates obtained because every time you call
the CreateDelegate the MSIL generation takes place and that takes some time.
</p>
        <p>
I have also created a simple test to show a comparison between direct calls, reflection
calls and dynamic method calls. The results are here:
</p>
        <p>
------ Object Creation ------<br />
direct - object creation: 63ms<br />
dynamic method - object creation: 86ms<br />
reflection - object creation: 391ms<br />
------ Property Get ------<br />
direct - property get: 21ms<br />
dynamic method - property get: 81ms<br />
reflection - property get: 1849ms<br />
------ Property Set ------<br />
direct - property set: 21ms<br />
dynamic method - property set: 67ms<br />
reflection - property set: 2476ms<br />
------ Instance Method Call ------<br />
direct - instance method call: 24ms<br />
dynamic method - instance method call: 154ms<br />
reflection - instance method call: 3266ms<br />
------ Static Method Call ------<br />
direct - static method call: 36ms<br />
dynamic method - static method call: 157ms<br />
reflection - static method call: 3139ms
</p>
        <p>
To summarize: 
<br />
• For object creation, using reflection is 6.2 times slower than direct object
creation. With DynamicMethods is only 1.3 times slower than direct object creation.
Using DynamicMethods is about 4.5 times faster than using reflection.<br />
• To get a property using reflection is 90.1 times slower than direct property
access. With DynamicMethods is only 3.8 times slower than direct property access.
Using DynamicMethods is nearly 23 times faster than using reflection.<br />
• To set a property using reflection is 117.9 times slower than direct property
set. With DynamicMethods is only 3.2 times slower than direct property set. Using
DynamicMethods is about 37 times faster than using reflection.<br />
• For instance method invocation, using reflection is 136.1 times slower than
direct method call. With DynamicMethods is only 6.4 times slower than direct method
call. Using DynamicMethods is about 21 times faster than using reflection.<br />
• For static method invocation, using reflection is 87.2 times slower than direct
method call. With DynamicMethods is only 4.3 times slower than direct method call.
Using DynamicMethods is about 20 times faster than using reflection.
</p>
        <p>
I’m going to modify my <a href="http://www.manuelabadia.com/products/EODS_features.aspx">ExtendedObjectDataSource</a> to
use DynamicMethods in order to gain a 20x speed increase compared to reflection calls.
</p>
        <p>
The code used for the tests and the helper class for the DynamicMethods are shown
here and can be downloaded at the end of this post:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">using</span> System;
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">using</span> System.Reflection;
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">using</span> System.Reflection.Emit;
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">namespace</span> Manu.Utils
</p>
          <p style="MARGIN: 0px">
{
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;summary&gt;</span><span style="COLOR: green">Delegate
for calling a method that is not known at runtime.</span><span style="COLOR: gray">&lt;/summary&gt;</span></p>
          <p style="MARGIN: 0px">
    <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;param
name="target"&gt;</span><span style="COLOR: green">the object to be called or null
if the call is to a static method.</span><span style="COLOR: gray">&lt;/param&gt;</span></p>
          <p style="MARGIN: 0px">
    <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;param
name="paramters"&gt;</span><span style="COLOR: green">the parameters to the method.</span><span style="COLOR: gray">&lt;/param&gt;</span></p>
          <p style="MARGIN: 0px">
    <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;returns&gt;</span><span style="COLOR: green">the
return value for the method or null if it doesn't return anything.</span><span style="COLOR: gray">&lt;/returns&gt;</span></p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">delegate</span><span style="COLOR: blue">object</span><span style="COLOR: teal">FastInvokeHandler</span>(<span style="COLOR: blue">object</span> target, <span style="COLOR: blue">object</span>[]
parameters);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;summary&gt;</span><span style="COLOR: green">Delegate
for creating and object at runtime using the default constructor.</span><span style="COLOR: gray">&lt;/summary&gt;</span></p>
          <p style="MARGIN: 0px">
    <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;returns&gt;</span><span style="COLOR: green">the
newly created object.</span><span style="COLOR: gray">&lt;/returns&gt;</span></p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">delegate</span><span style="COLOR: blue">object</span><span style="COLOR: teal">FastCreateInstanceHandler</span>();
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;summary&gt;</span><span style="COLOR: green">Delegate
to get an arbitraty property at runtime.</span><span style="COLOR: gray">&lt;/summary&gt;</span></p>
          <p style="MARGIN: 0px">
    <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;param
name="target"&gt;</span><span style="COLOR: green">the object instance whose property
will be obtained.</span><span style="COLOR: gray">&lt;/param&gt;</span></p>
          <p style="MARGIN: 0px">
    <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;returns&gt;</span><span style="COLOR: green">the
property value.</span><span style="COLOR: gray">&lt;/returns&gt;</span></p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">delegate</span><span style="COLOR: blue">object</span><span style="COLOR: teal">FastPropertyGetHandler</span>(<span style="COLOR: blue">object</span> target);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;summary&gt;</span><span style="COLOR: green">Delegate
to set an arbitrary property at runtime.</span><span style="COLOR: gray">&lt;/summary&gt;</span></p>
          <p style="MARGIN: 0px">
    <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;param
name="target"&gt;</span><span style="COLOR: green">the object instance whose property
will be modified.</span><span style="COLOR: gray">&lt;/param&gt;</span></p>
          <p style="MARGIN: 0px">
    <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;param
name="parameter"&gt;&lt;/param&gt;</span></p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">delegate</span><span style="COLOR: blue">void</span><span style="COLOR: teal">FastPropertySetHandler</span>(<span style="COLOR: blue">object</span> target, <span style="COLOR: blue">object</span> parameter);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;summary&gt;</span><span style="COLOR: green">Class
with helper methods for dynamic invocation generating IL on the fly.</span><span style="COLOR: gray">&lt;/summary&gt;</span></p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">static</span><span style="COLOR: blue">class</span><span style="COLOR: teal">DynamicCalls</span></p>
          <p style="MARGIN: 0px">
    {
</p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">public</span><span style="COLOR: blue">static</span><span style="COLOR: teal">FastInvokeHandler</span> GetMethodInvoker(<span style="COLOR: teal">MethodInfo</span> methodInfo)
</p>
          <p style="MARGIN: 0px">
        {
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: green">//
generates a dynamic method to generate a FastInvokeHandler delegate</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: teal">DynamicMethod</span> dynamicMethod
= <span style="COLOR: blue">new</span><span style="COLOR: teal">DynamicMethod</span>(<span style="COLOR: blue">string</span>.Empty, <span style="COLOR: blue">typeof</span>(<span style="COLOR: blue">object</span>), <span style="COLOR: blue">new</span><span style="COLOR: teal">Type</span>[]
{ <span style="COLOR: blue">typeof</span>(<span style="COLOR: blue">object</span>), <span style="COLOR: blue">typeof</span>(<span style="COLOR: blue">object</span>[])
}, methodInfo.DeclaringType.Module);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: teal">ILGenerator</span> ilGenerator
= dynamicMethod.GetILGenerator();
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: teal">ParameterInfo</span>[]
parameters = methodInfo.GetParameters();
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: teal">Type</span>[]
paramTypes = <span style="COLOR: blue">new</span><span style="COLOR: teal">Type</span>[parameters.Length];
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: green">//
copies the parameter types to an array</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">for</span> (<span style="COLOR: blue">int</span> i
= 0; i &lt; paramTypes.Length; i++) {
</p>
          <p style="MARGIN: 0px">
                <span style="COLOR: blue">if</span> (parameters[i].ParameterType.IsByRef)
</p>
          <p style="MARGIN: 0px">
                   
paramTypes[i] = parameters[i].ParameterType.GetElementType();
</p>
          <p style="MARGIN: 0px">
                <span style="COLOR: blue">else</span></p>
          <p style="MARGIN: 0px">
                   
paramTypes[i] = parameters[i].ParameterType;
</p>
          <p style="MARGIN: 0px">
            }
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: teal">LocalBuilder</span>[]
locals = <span style="COLOR: blue">new</span><span style="COLOR: teal">LocalBuilder</span>[paramTypes.Length];
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: green">//
generates a local variable for each parameter</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">for</span> (<span style="COLOR: blue">int</span> i
= 0; i &lt; paramTypes.Length; i++) {
</p>
          <p style="MARGIN: 0px">
                locals[i]
= ilGenerator.DeclareLocal(paramTypes[i], <span style="COLOR: blue">true</span>);
</p>
          <p style="MARGIN: 0px">
            }
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: green">//
creates code to copy the parameters to the local variables</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">for</span> (<span style="COLOR: blue">int</span> i
= 0; i &lt; paramTypes.Length; i++) {
</p>
          <p style="MARGIN: 0px">
                ilGenerator.Emit(<span style="COLOR: teal">OpCodes</span>.Ldarg_1);
</p>
          <p style="MARGIN: 0px">
                EmitFastInt(ilGenerator,
i);
</p>
          <p style="MARGIN: 0px">
                ilGenerator.Emit(<span style="COLOR: teal">OpCodes</span>.Ldelem_Ref);
</p>
          <p style="MARGIN: 0px">
                EmitCastToReference(ilGenerator,
paramTypes[i]);
</p>
          <p style="MARGIN: 0px">
                ilGenerator.Emit(<span style="COLOR: teal">OpCodes</span>.Stloc,
locals[i]);
</p>
          <p style="MARGIN: 0px">
            }
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">if</span> (!methodInfo.IsStatic)
{
</p>
          <p style="MARGIN: 0px">
                <span style="COLOR: green">//
loads the object into the stack</span></p>
          <p style="MARGIN: 0px">
                ilGenerator.Emit(<span style="COLOR: teal">OpCodes</span>.Ldarg_0);
</p>
          <p style="MARGIN: 0px">
            }
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: green">//
loads the parameters copied to the local variables into the stack</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">for</span> (<span style="COLOR: blue">int</span> i
= 0; i &lt; paramTypes.Length; i++) {
</p>
          <p style="MARGIN: 0px">
                <span style="COLOR: blue">if</span> (parameters[i].ParameterType.IsByRef)
</p>
          <p style="MARGIN: 0px">
                   
ilGenerator.Emit(<span style="COLOR: teal">OpCodes</span>.Ldloca_S, locals[i]);
</p>
          <p style="MARGIN: 0px">
                <span style="COLOR: blue">else</span></p>
          <p style="MARGIN: 0px">
                   
ilGenerator.Emit(<span style="COLOR: teal">OpCodes</span>.Ldloc, locals[i]);
</p>
          <p style="MARGIN: 0px">
            }
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: green">//
calls the method</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">if</span> (!methodInfo.IsStatic)
{
</p>
          <p style="MARGIN: 0px">
                ilGenerator.EmitCall(<span style="COLOR: teal">OpCodes</span>.Callvirt,
methodInfo, <span style="COLOR: blue">null</span>);
</p>
          <p style="MARGIN: 0px">
            } <span style="COLOR: blue">else</span> {
</p>
          <p style="MARGIN: 0px">
                ilGenerator.EmitCall(<span style="COLOR: teal">OpCodes</span>.Call,
methodInfo, <span style="COLOR: blue">null</span>);
</p>
          <p style="MARGIN: 0px">
            }
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: green">//
creates code for handling the return value</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">if</span> (methodInfo.ReturnType
== <span style="COLOR: blue">typeof</span>(<span style="COLOR: blue">void</span>))
{
</p>
          <p style="MARGIN: 0px">
                ilGenerator.Emit(<span style="COLOR: teal">OpCodes</span>.Ldnull);
</p>
          <p style="MARGIN: 0px">
            } <span style="COLOR: blue">else</span> {
</p>
          <p style="MARGIN: 0px">
                EmitBoxIfNeeded(ilGenerator,
methodInfo.ReturnType);
</p>
          <p style="MARGIN: 0px">
            }
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: green">//
iterates through the parameters updating the parameters passed by ref</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">for</span> (<span style="COLOR: blue">int</span> i
= 0; i &lt; paramTypes.Length; i++) {
</p>
          <p style="MARGIN: 0px">
                <span style="COLOR: blue">if</span> (parameters[i].ParameterType.IsByRef)
{
</p>
          <p style="MARGIN: 0px">
                   
ilGenerator.Emit(<span style="COLOR: teal">OpCodes</span>.Ldarg_1);
</p>
          <p style="MARGIN: 0px">
                   
EmitFastInt(ilGenerator, i);
</p>
          <p style="MARGIN: 0px">
                   
ilGenerator.Emit(<span style="COLOR: teal">OpCodes</span>.Ldloc, locals[i]);
</p>
          <p style="MARGIN: 0px">
                    <span style="COLOR: blue">if</span> (locals[i].LocalType.IsValueType)
</p>
          <p style="MARGIN: 0px">
                   
    ilGenerator.Emit(<span style="COLOR: teal">OpCodes</span>.Box,
locals[i].LocalType);
</p>
          <p style="MARGIN: 0px">
                   
ilGenerator.Emit(<span style="COLOR: teal">OpCodes</span>.Stelem_Ref);
</p>
          <p style="MARGIN: 0px">
                }
</p>
          <p style="MARGIN: 0px">
            }
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: green">//
returns the value to the caller</span></p>
          <p style="MARGIN: 0px">
            ilGenerator.Emit(<span style="COLOR: teal">OpCodes</span>.Ret);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: green">//
converts the DynamicMethod to a FastInvokeHandler delegate to call to the method</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: teal">FastInvokeHandler</span> invoker
= (<span style="COLOR: teal">FastInvokeHandler</span>)dynamicMethod.CreateDelegate(<span style="COLOR: blue">typeof</span>(<span style="COLOR: teal">FastInvokeHandler</span>));
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">return</span> invoker;
</p>
          <p style="MARGIN: 0px">
        }
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
        <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;summary&gt;</span><span style="COLOR: green">Gets
the instance creator delegate that can be use to create instances of the specified
type.</span><span style="COLOR: gray">&lt;/summary&gt;</span></p>
          <p style="MARGIN: 0px">
        <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;param
name="type"&gt;</span><span style="COLOR: green">The type of the objects we want to
create.</span><span style="COLOR: gray">&lt;/param&gt;</span></p>
          <p style="MARGIN: 0px">
        <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;returns&gt;</span><span style="COLOR: green">A
delegate that can be used to create the objects.</span><span style="COLOR: gray">&lt;/returns&gt;</span></p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">public</span><span style="COLOR: blue">static</span><span style="COLOR: teal">FastCreateInstanceHandler</span> GetInstanceCreator(<span style="COLOR: teal">Type</span> type)
</p>
          <p style="MARGIN: 0px">
        {
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: green">//
generates a dynamic method to generate a FastCreateInstanceHandler delegate</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: teal">DynamicMethod</span> dynamicMethod
= <span style="COLOR: blue">new</span><span style="COLOR: teal">DynamicMethod</span>(<span style="COLOR: blue">string</span>.Empty,
type, <span style="COLOR: blue">new</span><span style="COLOR: teal">Type</span>[0], <span style="COLOR: blue">typeof</span>(<span style="COLOR: teal">DynamicCalls</span>).Module);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: teal">ILGenerator</span> ilGenerator
= dynamicMethod.GetILGenerator();
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: green">//
generates code to create a new object of the specified type using the default constructor</span></p>
          <p style="MARGIN: 0px">
            ilGenerator.Emit(<span style="COLOR: teal">OpCodes</span>.Newobj,
type.GetConstructor(<span style="COLOR: teal">Type</span>.EmptyTypes));
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: green">//
returns the value to the caller</span></p>
          <p style="MARGIN: 0px">
            ilGenerator.Emit(<span style="COLOR: teal">OpCodes</span>.Ret);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: green">//
converts the DynamicMethod to a FastCreateInstanceHandler delegate to create the object</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: teal">FastCreateInstanceHandler</span> creator
= (<span style="COLOR: teal">FastCreateInstanceHandler</span>)dynamicMethod.CreateDelegate(<span style="COLOR: blue">typeof</span>(<span style="COLOR: teal">FastCreateInstanceHandler</span>));
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">return</span> creator;
</p>
          <p style="MARGIN: 0px">
        }
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">public</span><span style="COLOR: blue">static</span><span style="COLOR: teal">FastPropertyGetHandler</span> GetPropertyGetter(<span style="COLOR: teal">PropertyInfo</span> propInfo)
</p>
          <p style="MARGIN: 0px">
        {
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: green">//
generates a dynamic method to generate a FastPropertyGetHandler delegate</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: teal">DynamicMethod</span> dynamicMethod
= <span style="COLOR: blue">new</span><span style="COLOR: teal">DynamicMethod</span>(<span style="COLOR: blue">string</span>.Empty, <span style="COLOR: blue">typeof</span>(<span style="COLOR: blue">object</span>), <span style="COLOR: blue">new</span><span style="COLOR: teal">Type</span>[]
{ <span style="COLOR: blue">typeof</span>(<span style="COLOR: blue">object</span>)
}, propInfo.DeclaringType.Module);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: teal">ILGenerator</span> ilGenerator
= dynamicMethod.GetILGenerator();
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: green">//
loads the object into the stack</span></p>
          <p style="MARGIN: 0px">
            ilGenerator.Emit(<span style="COLOR: teal">OpCodes</span>.Ldarg_0);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: green">//
calls the getter</span></p>
          <p style="MARGIN: 0px">
            ilGenerator.EmitCall(<span style="COLOR: teal">OpCodes</span>.Callvirt,
propInfo.GetGetMethod(), <span style="COLOR: blue">null</span>);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: green">//
creates code for handling the return value</span></p>
          <p style="MARGIN: 0px">
            EmitBoxIfNeeded(ilGenerator,
propInfo.PropertyType);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: green">//
returns the value to the caller</span></p>
          <p style="MARGIN: 0px">
            ilGenerator.Emit(<span style="COLOR: teal">OpCodes</span>.Ret);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: green">//
converts the DynamicMethod to a FastPropertyGetHandler delegate to get the property</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: teal">FastPropertyGetHandler</span> getter
= (<span style="COLOR: teal">FastPropertyGetHandler</span>)dynamicMethod.CreateDelegate(<span style="COLOR: blue">typeof</span>(<span style="COLOR: teal">FastPropertyGetHandler</span>));
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">return</span> getter;
</p>
          <p style="MARGIN: 0px">
        }
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">public</span><span style="COLOR: blue">static</span><span style="COLOR: teal">FastPropertySetHandler</span> GetPropertySetter(<span style="COLOR: teal">PropertyInfo</span> propInfo)
</p>
          <p style="MARGIN: 0px">
        {
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: green">//
generates a dynamic method to generate a FastPropertySetHandler delegate</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: teal">DynamicMethod</span> dynamicMethod
= <span style="COLOR: blue">new</span><span style="COLOR: teal">DynamicMethod</span>(<span style="COLOR: blue">string</span>.Empty, <span style="COLOR: blue">null</span>, <span style="COLOR: blue">new</span><span style="COLOR: teal">Type</span>[]
{ <span style="COLOR: blue">typeof</span>(<span style="COLOR: blue">object</span>), <span style="COLOR: blue">typeof</span>(<span style="COLOR: blue">object</span>)
}, propInfo.DeclaringType.Module);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: teal">ILGenerator</span> ilGenerator
= dynamicMethod.GetILGenerator();
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: green">//
loads the object into the stack</span></p>
          <p style="MARGIN: 0px">
            ilGenerator.Emit(<span style="COLOR: teal">OpCodes</span>.Ldarg_0);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: green">//
loads the parameter from the stack</span></p>
          <p style="MARGIN: 0px">
            ilGenerator.Emit(<span style="COLOR: teal">OpCodes</span>.Ldarg_1);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: green">//
cast to the proper type (unboxing if needed)</span></p>
          <p style="MARGIN: 0px">
            EmitCastToReference(ilGenerator,
propInfo.PropertyType);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: green">//
calls the setter</span></p>
          <p style="MARGIN: 0px">
            ilGenerator.EmitCall(<span style="COLOR: teal">OpCodes</span>.Callvirt,
propInfo.GetSetMethod(), <span style="COLOR: blue">null</span>);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: green">//
terminates the call</span></p>
          <p style="MARGIN: 0px">
            ilGenerator.Emit(<span style="COLOR: teal">OpCodes</span>.Ret);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: green">//
converts the DynamicMethod to a FastPropertyGetHandler delegate to get the property</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: teal">FastPropertySetHandler</span> setter
= (<span style="COLOR: teal">FastPropertySetHandler</span>)dynamicMethod.CreateDelegate(<span style="COLOR: blue">typeof</span>(<span style="COLOR: teal">FastPropertySetHandler</span>));
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">return</span> setter;
</p>
          <p style="MARGIN: 0px">
        }
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
        <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;summary&gt;</span><span style="COLOR: green">Emits
the cast to a reference, unboxing if needed.</span><span style="COLOR: gray">&lt;/summary&gt;</span></p>
          <p style="MARGIN: 0px">
        <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;param
name="il"&gt;</span><span style="COLOR: green">The MSIL generator.</span><span style="COLOR: gray">&lt;/param&gt;</span></p>
          <p style="MARGIN: 0px">
        <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;param
name="type"&gt;</span><span style="COLOR: green">The type to cast.</span><span style="COLOR: gray">&lt;/param&gt;</span></p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">private</span><span style="COLOR: blue">static</span><span style="COLOR: blue">void</span> EmitCastToReference(<span style="COLOR: teal">ILGenerator</span> ilGenerator,
System.<span style="COLOR: teal">Type</span> type)
</p>
          <p style="MARGIN: 0px">
        {
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">if</span> (type.IsValueType)
{
</p>
          <p style="MARGIN: 0px">
                ilGenerator.Emit(<span style="COLOR: teal">OpCodes</span>.Unbox_Any,
type);
</p>
          <p style="MARGIN: 0px">
            } <span style="COLOR: blue">else</span> {
</p>
          <p style="MARGIN: 0px">
                ilGenerator.Emit(<span style="COLOR: teal">OpCodes</span>.Castclass,
type);
</p>
          <p style="MARGIN: 0px">
            }
</p>
          <p style="MARGIN: 0px">
        }
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
        <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;summary&gt;</span><span style="COLOR: green">Boxes
a type if needed.</span><span style="COLOR: gray">&lt;/summary&gt;</span></p>
          <p style="MARGIN: 0px">
        <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;param
name="ilGenerator"&gt;</span><span style="COLOR: green">The MSIL generator.</span><span style="COLOR: gray">&lt;/param&gt;</span></p>
          <p style="MARGIN: 0px">
        <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;param
name="type"&gt;</span><span style="COLOR: green">The type.</span><span style="COLOR: gray">&lt;/param&gt;</span></p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">private</span><span style="COLOR: blue">static</span><span style="COLOR: blue">void</span> EmitBoxIfNeeded(<span style="COLOR: teal">ILGenerator</span> ilGenerator,
System.<span style="COLOR: teal">Type</span> type)
</p>
          <p style="MARGIN: 0px">
        {
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">if</span> (type.IsValueType)
{
</p>
          <p style="MARGIN: 0px">
                ilGenerator.Emit(<span style="COLOR: teal">OpCodes</span>.Box,
type);
</p>
          <p style="MARGIN: 0px">
            }
</p>
          <p style="MARGIN: 0px">
        }
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
        <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;summary&gt;</span><span style="COLOR: green">Emits
code to save an integer to the evaluation stack.</span><span style="COLOR: gray">&lt;/summary&gt;</span></p>
          <p style="MARGIN: 0px">
        <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;param
name="ilGeneartor"&gt;</span><span style="COLOR: green">The MSIL generator.</span><span style="COLOR: gray">&lt;/param&gt;</span></p>
          <p style="MARGIN: 0px">
        <span style="COLOR: gray">///</span><span style="COLOR: green"></span><span style="COLOR: gray">&lt;param
name="value"&gt;</span><span style="COLOR: green">The value to push.</span><span style="COLOR: gray">&lt;/param&gt;</span></p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">private</span><span style="COLOR: blue">static</span><span style="COLOR: blue">void</span> EmitFastInt(<span style="COLOR: teal">ILGenerator</span> ilGenerator, <span style="COLOR: blue">int</span> value)
</p>
          <p style="MARGIN: 0px">
        {
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: green">//
for small integers, emit the proper opcode</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">switch</span> (value)
{
</p>
          <p style="MARGIN: 0px">
                <span style="COLOR: blue">case</span> -1:
</p>
          <p style="MARGIN: 0px">
                   
ilGenerator.Emit(<span style="COLOR: teal">OpCodes</span>.Ldc_I4_M1);
</p>
          <p style="MARGIN: 0px">
                    <span style="COLOR: blue">return</span>;
</p>
          <p style="MARGIN: 0px">
                <span style="COLOR: blue">case</span> 0:
</p>
          <p style="MARGIN: 0px">
                   
ilGenerator.Emit(<span style="COLOR: teal">OpCodes</span>.Ldc_I4_0);
</p>
          <p style="MARGIN: 0px">
                    <span style="COLOR: blue">return</span>;
</p>
          <p style="MARGIN: 0px">
                <span style="COLOR: blue">case</span> 1:
</p>
          <p style="MARGIN: 0px">
                   
ilGenerator.Emit(<span style="COLOR: teal">OpCodes</span>.Ldc_I4_1);
</p>
          <p style="MARGIN: 0px">
                    <span style="COLOR: blue">return</span>;
</p>
          <p style="MARGIN: 0px">
                <span style="COLOR: blue">case</span> 2:
</p>
          <p style="MARGIN: 0px">
                   
ilGenerator.Emit(<span style="COLOR: teal">OpCodes</span>.Ldc_I4_2);
</p>
          <p style="MARGIN: 0px">
                    <span style="COLOR: blue">return</span>;
</p>
          <p style="MARGIN: 0px">
                <span style="COLOR: blue">case</span> 3:
</p>
          <p style="MARGIN: 0px">
                   
ilGenerator.Emit(<span style="COLOR: teal">OpCodes</span>.Ldc_I4_3);
</p>
          <p style="MARGIN: 0px">
                    <span style="COLOR: blue">return</span>;
</p>
          <p style="MARGIN: 0px">
                <span style="COLOR: blue">case</span> 4:
</p>
          <p style="MARGIN: 0px">
                   
ilGenerator.Emit(<span style="COLOR: teal">OpCodes</span>.Ldc_I4_4);
</p>
          <p style="MARGIN: 0px">
                    <span style="COLOR: blue">return</span>;
</p>
          <p style="MARGIN: 0px">
                <span style="COLOR: blue">case</span> 5:
</p>
          <p style="MARGIN: 0px">
                   
ilGenerator.Emit(<span style="COLOR: teal">OpCodes</span>.Ldc_I4_5);
</p>
          <p style="MARGIN: 0px">
                    <span style="COLOR: blue">return</span>;
</p>
          <p style="MARGIN: 0px">
                <span style="COLOR: blue">case</span> 6:
</p>
          <p style="MARGIN: 0px">
                   
ilGenerator.Emit(<span style="COLOR: teal">OpCodes</span>.Ldc_I4_6);
</p>
          <p style="MARGIN: 0px">
                    <span style="COLOR: blue">return</span>;
</p>
          <p style="MARGIN: 0px">
                <span style="COLOR: blue">case</span> 7:
</p>
          <p style="MARGIN: 0px">
                   
ilGenerator.Emit(<span style="COLOR: teal">OpCodes</span>.Ldc_I4_7);
</p>
          <p style="MARGIN: 0px">
                    <span style="COLOR: blue">return</span>;
</p>
          <p style="MARGIN: 0px">
                <span style="COLOR: blue">case</span> 8:
</p>
          <p style="MARGIN: 0px">
                   
ilGenerator.Emit(<span style="COLOR: teal">OpCodes</span>.Ldc_I4_8);
</p>
          <p style="MARGIN: 0px">
                    <span style="COLOR: blue">return</span>;
</p>
          <p style="MARGIN: 0px">
            }
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: green">//
for bigger values emit the short or long opcode</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">if</span> (value
&gt; -129 &amp;&amp; value &lt; 128) {
</p>
          <p style="MARGIN: 0px">
                ilGenerator.Emit(<span style="COLOR: teal">OpCodes</span>.Ldc_I4_S,
(<span style="COLOR: teal">SByte</span>)value);
</p>
          <p style="MARGIN: 0px">
            } <span style="COLOR: blue">else</span> {
</p>
          <p style="MARGIN: 0px">
                ilGenerator.Emit(<span style="COLOR: teal">OpCodes</span>.Ldc_I4,
value);
</p>
          <p style="MARGIN: 0px">
            }
</p>
          <p style="MARGIN: 0px">
        }
</p>
          <p style="MARGIN: 0px">
    }
</p>
          <p style="MARGIN: 0px">
}
</p>
        </div>
        <p>
          <!--EndFragment-->
        </p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">using</span> System;
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">using</span> System.Reflection;
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">using</span> System.Reflection.Emit;
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">using</span> System.Collections.Generic;
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">using</span> System.Diagnostics;
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">using</span> Manu.Utils;
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">namespace</span> DynamicMethods
</p>
          <p style="MARGIN: 0px">
{
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">class</span><span style="COLOR: teal">Program</span></p>
          <p style="MARGIN: 0px">
    {
</p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">public</span><span style="COLOR: blue">static</span><span style="COLOR: blue">void</span> Main(<span style="COLOR: blue">string</span>[]
args)
</p>
          <p style="MARGIN: 0px">
        {
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: green">//
object creation</span></p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: teal">Console</span>.WriteLine(<span style="COLOR: maroon">"------
Object Creation ------"</span>);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            EvaluateMethod(<span style="COLOR: maroon">"direct
- object creation"</span>, <span style="COLOR: blue">delegate</span>() {
</p>
          <p style="MARGIN: 0px">
                <span style="COLOR: teal">TestClass</span> p
= <span style="COLOR: blue">new</span><span style="COLOR: teal">TestClass</span>();
</p>
          <p style="MARGIN: 0px">
            }, 1000000);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: teal">FastCreateInstanceHandler</span> creator
= <span style="COLOR: teal">DynamicCalls</span>.GetInstanceCreator(<span style="COLOR: blue">typeof</span>(<span style="COLOR: teal">TestClass</span>));
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            EvaluateMethod(<span style="COLOR: maroon">"dynamic
method - object creation"</span>, <span style="COLOR: blue">delegate</span>() {
</p>
          <p style="MARGIN: 0px">
                <span style="COLOR: teal">TestClass</span> p
= (<span style="COLOR: teal">TestClass</span>)creator.Invoke();
</p>
          <p style="MARGIN: 0px">
            }, 1000000);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            EvaluateMethod(<span style="COLOR: maroon">"reflection
- object creation"</span>, <span style="COLOR: blue">delegate</span>() {
</p>
          <p style="MARGIN: 0px">
                <span style="COLOR: teal">TestClass</span> p
= (<span style="COLOR: teal">TestClass</span>)<span style="COLOR: teal">Activator</span>.CreateInstance(<span style="COLOR: blue">typeof</span>(<span style="COLOR: teal">TestClass</span>));
</p>
          <p style="MARGIN: 0px">
            }, 1000000);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: green">//
property get</span></p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: teal">Console</span>.WriteLine(<span style="COLOR: maroon">"------
Property Get ------"</span>);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: teal">TestClass</span> prod
= <span style="COLOR: blue">new</span><span style="COLOR: teal">TestClass</span>();
</p>
          <p style="MARGIN: 0px">
            prod.Num = 123;
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            EvaluateMethod(<span style="COLOR: maroon">"direct
- property get"</span>, <span style="COLOR: blue">delegate</span>() {
</p>
          <p style="MARGIN: 0px">
                <span style="COLOR: blue">int</span> num
= prod.Num;
</p>
          <p style="MARGIN: 0px">
            }, 1000000);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: teal">PropertyInfo</span> propInfo
= <span style="COLOR: blue">typeof</span>(<span style="COLOR: teal">TestClass</span>).GetProperty(<span style="COLOR: maroon">"Num"</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: teal">FastPropertyGetHandler</span> getter
= <span style="COLOR: teal">DynamicCalls</span>.GetPropertyGetter(propInfo);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            EvaluateMethod(<span style="COLOR: maroon">"dynamic
method - property get"</span>, <span style="COLOR: blue">delegate</span>() {
</p>
          <p style="MARGIN: 0px">
                <span style="COLOR: blue">int</span> num
= (<span style="COLOR: blue">int</span>)getter(prod);
</p>
          <p style="MARGIN: 0px">
            }, 1000000);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            EvaluateMethod(<span style="COLOR: maroon">"reflection
- property get"</span>, <span style="COLOR: blue">delegate</span>() {
</p>
          <p style="MARGIN: 0px">
                <span style="COLOR: blue">int</span> num
= (<span style="COLOR: blue">int</span>)propInfo.GetValue(prod, <span style="COLOR: blue">null</span>);
</p>
          <p style="MARGIN: 0px">
            }, 1000000);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: green">//
property set</span></p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: teal">Console</span>.WriteLine(<span style="COLOR: maroon">"------
Property Set ------"</span>);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            EvaluateMethod(<span style="COLOR: maroon">"direct
- property set"</span>, <span style="COLOR: blue">delegate</span>() {
</p>
          <p style="MARGIN: 0px">
                prod.Num
= 33;
</p>
          <p style="MARGIN: 0px">
            }, 1000000);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: teal">FastPropertySetHandler</span> setter
= <span style="COLOR: teal">DynamicCalls</span>.GetPropertySetter(propInfo);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            EvaluateMethod(<span style="COLOR: maroon">"dynamic
method - property set"</span>, <span style="COLOR: blue">delegate</span>() {
</p>
          <p style="MARGIN: 0px">
                setter(prod,
32);
</p>
          <p style="MARGIN: 0px">
            }, 1000000);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            EvaluateMethod(<span style="COLOR: maroon">"reflection
- property set"</span>, <span style="COLOR: blue">delegate</span>() {
</p>
          <p style="MARGIN: 0px">
                propInfo.SetValue(prod,
31, <span style="COLOR: blue">null</span>);
</p>
          <p style="MARGIN: 0px">
            }, 1000000);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: green">//
instance method call</span></p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: teal">Console</span>.WriteLine(<span style="COLOR: maroon">"------
Instance Method Call ------"</span>);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            EvaluateMethod(<span style="COLOR: maroon">"direct
- instance method call"</span>, <span style="COLOR: blue">delegate</span>() {
</p>
          <p style="MARGIN: 0px">
                <span style="COLOR: blue">int</span> result
= prod.Multiply(3, 5);
</p>
          <p style="MARGIN: 0px">
            }, 1000000);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: teal">MethodInfo</span> methodInfo1
= <span style="COLOR: blue">typeof</span>(<span style="COLOR: teal">TestClass</span>).GetMethod(<span style="COLOR: maroon">"Multiply"</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: teal">FastInvokeHandler</span> fastInvoker1
= <span style="COLOR: teal">DynamicCalls</span>.GetMethodInvoker(methodInfo1);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            EvaluateMethod(<span style="COLOR: maroon">"dynamic
method - instance method call"</span>, <span style="COLOR: blue">delegate</span>()
{
</p>
          <p style="MARGIN: 0px">
                <span style="COLOR: blue">int</span> result
= (<span style="COLOR: blue">int</span>)fastInvoker1(prod, <span style="COLOR: blue">new</span><span style="COLOR: blue">object</span>[]
{ 3, 5 });
</p>
          <p style="MARGIN: 0px">
            }, 1000000);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            EvaluateMethod(<span style="COLOR: maroon">"reflection
- instance method call"</span>, <span style="COLOR: blue">delegate</span>() {
</p>
          <p style="MARGIN: 0px">
                <span style="COLOR: blue">int</span> result
= (<span style="COLOR: blue">int</span>)methodInfo1.Invoke(prod, <span style="COLOR: blue">new</span><span style="COLOR: blue">object</span>[]
{ 3, 5 });
</p>
          <p style="MARGIN: 0px">
            }, 1000000);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: green">//
static method call</span></p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: teal">Console</span>.WriteLine(<span style="COLOR: maroon">"------
Static Method Call ------"</span>);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            EvaluateMethod(<span style="COLOR: maroon">"direct
- static method call"</span>, <span style="COLOR: blue">delegate</span>() {
</p>
          <p style="MARGIN: 0px">
                <span style="COLOR: blue">int</span> result
= <span style="COLOR: teal">TestClass</span>.StaticMultiply(3, 5);
</p>
          <p style="MARGIN: 0px">
            }, 1000000);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: teal">MethodInfo</span> methodInfo2
= <span style="COLOR: blue">typeof</span>(<span style="COLOR: teal">TestClass</span>).GetMethod(<span style="COLOR: maroon">"StaticMultiply"</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: teal">FastInvokeHandler</span> fastInvoker2
= <span style="COLOR: teal">DynamicCalls</span>.GetMethodInvoker(methodInfo2);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            EvaluateMethod(<span style="COLOR: maroon">"dynamic
method - static method call"</span>, <span style="COLOR: blue">delegate</span>() {
</p>
          <p style="MARGIN: 0px">
                <span style="COLOR: blue">int</span> result
= (<span style="COLOR: blue">int</span>)fastInvoker2(<span style="COLOR: blue">null</span>, <span style="COLOR: blue">new</span><span style="COLOR: blue">object</span>[]
{ 3, 5 });
</p>
          <p style="MARGIN: 0px">
            }, 1000000);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            EvaluateMethod(<span style="COLOR: maroon">"reflection
- static method call"</span>, <span style="COLOR: blue">delegate</span>() {
</p>
          <p style="MARGIN: 0px">
                <span style="COLOR: blue">int</span> result
= (<span style="COLOR: blue">int</span>)methodInfo2.Invoke(<span style="COLOR: blue">null</span>, <span style="COLOR: blue">new</span><span style="COLOR: blue">object</span>[]
{ 3, 5 });
</p>
          <p style="MARGIN: 0px">
            }, 1000000);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: teal">Console</span>.ReadLine();
</p>
          <p style="MARGIN: 0px">
        }
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">delegate</span><span style="COLOR: blue">void</span><span style="COLOR: teal">MethodToEvaluate</span>();
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
        <span style="COLOR: green">// evaluates a method
the specified number of times and print performance information</span></p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">static</span><span style="COLOR: blue">void</span> EvaluateMethod(<span style="COLOR: blue">string</span> testName, <span style="COLOR: teal">MethodToEvaluate</span> method, <span style="COLOR: blue">long</span> times)
</p>
          <p style="MARGIN: 0px">
        {
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: teal">Stopwatch</span> watch
= <span style="COLOR: blue">new</span><span style="COLOR: teal">Stopwatch</span>();
</p>
          <p style="MARGIN: 0px">
            watch.Start();
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">for</span> (<span style="COLOR: blue">long</span> i
= 0; i &lt; times; i++) {
</p>
          <p style="MARGIN: 0px">
                method();
</p>
          <p style="MARGIN: 0px">
            }
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            watch.Stop();
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: teal">Console</span>.WriteLine(testName
+ <span style="COLOR: maroon">": "</span> + watch.ElapsedMilliseconds + <span style="COLOR: maroon">"ms"</span>);
</p>
          <p style="MARGIN: 0px">
        }
</p>
          <p style="MARGIN: 0px">
    }
</p>
          <p style="MARGIN: 0px">
}
</p>
        </div>
        <!--EndFragment-->
        <p>
 
</p>
        <p>
          <a href="http://www.manuelabadia.com/blog/content/binary/DynamicMethods.zip">DynamicMethods.zip
(5.01 KB)</a>
        </p>
        <img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=dc72b235-1381-4c91-8706-e36216f49b94" />
      </body>
      <title>Generic method invocation at runtime without using reflection – DynamicMethods</title>
      <guid isPermaLink="false">http://www.manuelabadia.com/blog/PermaLink,guid,dc72b235-1381-4c91-8706-e36216f49b94.aspx</guid>
      <link>http://www.manuelabadia.com/blog/PermaLink,guid,dc72b235-1381-4c91-8706-e36216f49b94.aspx</link>
      <pubDate>Tue, 04 Jul 2006 23:47:29 GMT</pubDate>
      <description>&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
Being able to dynamically call an arbitrary method on an object or the ability to
get/set any arbitrary property by name at run time is very important when it comes
to do some generic stuff. In .NET Framework 1.x the only way to do that was using
reflection and that means to do it slow. For simple things or if we don’t have a lot
of concurrent users we can live with it, but sometimes the performance is important
and reflection isn’t an acceptable solution.
&lt;/p&gt;
&lt;p&gt;
Fortunately, the .NET Framework 2.0 introduces a new class that let us to quickly
call an arbitrary method without the overhead of a reflection call. How? Well, the
idea is to generate the same MSIL as the compiler generates when calling a function
but on the fly, and then we obtain a delegate that when called will execute the MSIL
we have just created. This is really useful in a lot of scenarios!
&lt;/p&gt;
&lt;p&gt;
I read something about this in Marc’s blog (&lt;a href="http://musingmarc.blogspot.com/"&gt;http://musingmarc.blogspot.com/&lt;/a&gt;)
but I didn’t have time to look at it in more detail in that moment. Today I read an
article at codeproject that talked about this (&lt;a href="http://www.codeproject.com/useritems/FastMethodInvoker.asp"&gt;http://www.codeproject.com/useritems/FastMethodInvoker.asp&lt;/a&gt;)
so I finally forced myself to spend some time playing with dynamic MSIL code generation
and I’m quite impressed with the possibilities.
&lt;/p&gt;
&lt;p&gt;
If you want to play with this you should download an excellent debugger visualizer
that will let you show the MSIL generated by a DynamicMethod:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blogs.msdn.com/haibo_luo/archive/2005/10/25/484861.aspx"&gt;http://blogs.msdn.com/haibo_luo/archive/2005/10/25/484861.aspx&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
I have made a little helper class (based on the codeproject article) that can be used
to replace MethodInfo.Invoke, PropertyInfo.GetValue, PropertyInfo.SetValue and Activator.CreateInstance
that are the reflection methods that I use most often. In order to use it in your
own projects, remember to cache the delegates obtained because every time you call
the CreateDelegate the MSIL generation takes place and that takes some time.
&lt;/p&gt;
&lt;p&gt;
I have also created a simple test to show a comparison between direct calls, reflection
calls and dynamic method calls. The results are here:
&lt;/p&gt;
&lt;p&gt;
------ Object Creation ------&lt;br&gt;
direct - object creation: 63ms&lt;br&gt;
dynamic method - object creation: 86ms&lt;br&gt;
reflection - object creation: 391ms&lt;br&gt;
------ Property Get ------&lt;br&gt;
direct - property get: 21ms&lt;br&gt;
dynamic method - property get: 81ms&lt;br&gt;
reflection - property get: 1849ms&lt;br&gt;
------ Property Set ------&lt;br&gt;
direct - property set: 21ms&lt;br&gt;
dynamic method - property set: 67ms&lt;br&gt;
reflection - property set: 2476ms&lt;br&gt;
------ Instance Method Call ------&lt;br&gt;
direct - instance method call: 24ms&lt;br&gt;
dynamic method - instance method call: 154ms&lt;br&gt;
reflection - instance method call: 3266ms&lt;br&gt;
------ Static Method Call ------&lt;br&gt;
direct - static method call: 36ms&lt;br&gt;
dynamic method - static method call: 157ms&lt;br&gt;
reflection - static method call: 3139ms
&lt;/p&gt;
&lt;p&gt;
To summarize: 
&lt;br&gt;
•&amp;nbsp;For object creation, using reflection is 6.2 times slower than direct object
creation. With DynamicMethods is only 1.3 times slower than direct object creation.
Using DynamicMethods is about 4.5 times faster than using reflection.&lt;br&gt;
•&amp;nbsp;To get a property using reflection is 90.1 times slower than direct property
access. With DynamicMethods is only 3.8 times slower than direct property access.
Using DynamicMethods is nearly 23 times faster than using reflection.&lt;br&gt;
•&amp;nbsp;To set a property using reflection is 117.9 times slower than direct property
set. With DynamicMethods is only 3.2 times slower than direct property set. Using
DynamicMethods is about 37 times faster than using reflection.&lt;br&gt;
•&amp;nbsp;For instance method invocation, using reflection is 136.1 times slower than
direct method call. With DynamicMethods is only 6.4 times slower than direct method
call. Using DynamicMethods is about 21 times faster than using reflection.&lt;br&gt;
•&amp;nbsp;For static method invocation, using reflection is 87.2 times slower than direct
method call. With DynamicMethods is only 4.3 times slower than direct method call.
Using DynamicMethods is about 20 times faster than using reflection.
&lt;/p&gt;
&lt;p&gt;
I’m going to modify my &lt;a href="http://www.manuelabadia.com/products/EODS_features.aspx"&gt;ExtendedObjectDataSource&lt;/a&gt; to
use DynamicMethods in order to gain a 20x speed increase compared to reflection calls.
&lt;/p&gt;
&lt;p&gt;
The code used for the tests and the helper class for the DynamicMethods are shown
here and can be downloaded at the end of this post:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;using&lt;/span&gt; System;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;using&lt;/span&gt; System.Reflection;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;using&lt;/span&gt; System.Reflection.Emit;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;namespace&lt;/span&gt; Manu.Utils
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;Delegate
for calling a method that is not known at runtime.&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;param
name="target"&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;the object to be called or null
if the call is to a static method.&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;param
name="paramters"&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;the parameters to the method.&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;returns&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;the
return value for the method or null if it doesn't return anything.&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/returns&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;delegate&lt;/span&gt; &lt;span style="COLOR: blue"&gt;object&lt;/span&gt; &lt;span style="COLOR: teal"&gt;FastInvokeHandler&lt;/span&gt;(&lt;span style="COLOR: blue"&gt;object&lt;/span&gt; target, &lt;span style="COLOR: blue"&gt;object&lt;/span&gt;[]
parameters);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;Delegate
for creating and object at runtime using the default constructor.&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;returns&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;the
newly created object.&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/returns&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;delegate&lt;/span&gt; &lt;span style="COLOR: blue"&gt;object&lt;/span&gt; &lt;span style="COLOR: teal"&gt;FastCreateInstanceHandler&lt;/span&gt;();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;Delegate
to get an arbitraty property at runtime.&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;param
name="target"&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;the object instance whose property
will be obtained.&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;returns&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;the
property value.&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/returns&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;delegate&lt;/span&gt; &lt;span style="COLOR: blue"&gt;object&lt;/span&gt; &lt;span style="COLOR: teal"&gt;FastPropertyGetHandler&lt;/span&gt;(&lt;span style="COLOR: blue"&gt;object&lt;/span&gt; target);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;Delegate
to set an arbitrary property at runtime.&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;param
name="target"&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;the object instance whose property
will be modified.&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;param
name="parameter"&amp;gt;&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;delegate&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; &lt;span style="COLOR: teal"&gt;FastPropertySetHandler&lt;/span&gt;(&lt;span style="COLOR: blue"&gt;object&lt;/span&gt; target, &lt;span style="COLOR: blue"&gt;object&lt;/span&gt; parameter);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;Class
with helper methods for dynamic invocation generating IL on the fly.&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;static&lt;/span&gt; &lt;span style="COLOR: blue"&gt;class&lt;/span&gt; &lt;span style="COLOR: teal"&gt;DynamicCalls&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;static&lt;/span&gt; &lt;span style="COLOR: teal"&gt;FastInvokeHandler&lt;/span&gt; GetMethodInvoker(&lt;span style="COLOR: teal"&gt;MethodInfo&lt;/span&gt; methodInfo)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
generates a dynamic method to generate a FastInvokeHandler delegate&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: teal"&gt;DynamicMethod&lt;/span&gt; dynamicMethod
= &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: teal"&gt;DynamicMethod&lt;/span&gt;(&lt;span style="COLOR: blue"&gt;string&lt;/span&gt;.Empty, &lt;span style="COLOR: blue"&gt;typeof&lt;/span&gt;(&lt;span style="COLOR: blue"&gt;object&lt;/span&gt;), &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: teal"&gt;Type&lt;/span&gt;[]
{ &lt;span style="COLOR: blue"&gt;typeof&lt;/span&gt;(&lt;span style="COLOR: blue"&gt;object&lt;/span&gt;), &lt;span style="COLOR: blue"&gt;typeof&lt;/span&gt;(&lt;span style="COLOR: blue"&gt;object&lt;/span&gt;[])
}, methodInfo.DeclaringType.Module);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: teal"&gt;ILGenerator&lt;/span&gt; ilGenerator
= dynamicMethod.GetILGenerator();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: teal"&gt;ParameterInfo&lt;/span&gt;[]
parameters = methodInfo.GetParameters();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: teal"&gt;Type&lt;/span&gt;[]
paramTypes = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: teal"&gt;Type&lt;/span&gt;[parameters.Length];
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
copies the parameter types to an array&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;for&lt;/span&gt; (&lt;span style="COLOR: blue"&gt;int&lt;/span&gt; i
= 0; i &amp;lt; paramTypes.Length; i++) {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (parameters[i].ParameterType.IsByRef)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
paramTypes[i] = parameters[i].ParameterType.GetElementType();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;else&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
paramTypes[i] = parameters[i].ParameterType;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: teal"&gt;LocalBuilder&lt;/span&gt;[]
locals = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: teal"&gt;LocalBuilder&lt;/span&gt;[paramTypes.Length];
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
generates a local variable for each parameter&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;for&lt;/span&gt; (&lt;span style="COLOR: blue"&gt;int&lt;/span&gt; i
= 0; i &amp;lt; paramTypes.Length; i++) {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; locals[i]
= ilGenerator.DeclareLocal(paramTypes[i], &lt;span style="COLOR: blue"&gt;true&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
creates code to copy the parameters to the local variables&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;for&lt;/span&gt; (&lt;span style="COLOR: blue"&gt;int&lt;/span&gt; i
= 0; i &amp;lt; paramTypes.Length; i++) {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ilGenerator.Emit(&lt;span style="COLOR: teal"&gt;OpCodes&lt;/span&gt;.Ldarg_1);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; EmitFastInt(ilGenerator,
i);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ilGenerator.Emit(&lt;span style="COLOR: teal"&gt;OpCodes&lt;/span&gt;.Ldelem_Ref);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; EmitCastToReference(ilGenerator,
paramTypes[i]);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ilGenerator.Emit(&lt;span style="COLOR: teal"&gt;OpCodes&lt;/span&gt;.Stloc,
locals[i]);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (!methodInfo.IsStatic)
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
loads the object into the stack&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ilGenerator.Emit(&lt;span style="COLOR: teal"&gt;OpCodes&lt;/span&gt;.Ldarg_0);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
loads the parameters copied to the local variables into the stack&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;for&lt;/span&gt; (&lt;span style="COLOR: blue"&gt;int&lt;/span&gt; i
= 0; i &amp;lt; paramTypes.Length; i++) {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (parameters[i].ParameterType.IsByRef)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
ilGenerator.Emit(&lt;span style="COLOR: teal"&gt;OpCodes&lt;/span&gt;.Ldloca_S, locals[i]);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;else&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
ilGenerator.Emit(&lt;span style="COLOR: teal"&gt;OpCodes&lt;/span&gt;.Ldloc, locals[i]);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
calls the method&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (!methodInfo.IsStatic)
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ilGenerator.EmitCall(&lt;span style="COLOR: teal"&gt;OpCodes&lt;/span&gt;.Callvirt,
methodInfo, &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;span style="COLOR: blue"&gt;else&lt;/span&gt; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ilGenerator.EmitCall(&lt;span style="COLOR: teal"&gt;OpCodes&lt;/span&gt;.Call,
methodInfo, &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
creates code for handling the return value&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (methodInfo.ReturnType
== &lt;span style="COLOR: blue"&gt;typeof&lt;/span&gt;(&lt;span style="COLOR: blue"&gt;void&lt;/span&gt;))
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ilGenerator.Emit(&lt;span style="COLOR: teal"&gt;OpCodes&lt;/span&gt;.Ldnull);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;span style="COLOR: blue"&gt;else&lt;/span&gt; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; EmitBoxIfNeeded(ilGenerator,
methodInfo.ReturnType);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
iterates through the parameters updating the parameters passed by ref&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;for&lt;/span&gt; (&lt;span style="COLOR: blue"&gt;int&lt;/span&gt; i
= 0; i &amp;lt; paramTypes.Length; i++) {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (parameters[i].ParameterType.IsByRef)
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
ilGenerator.Emit(&lt;span style="COLOR: teal"&gt;OpCodes&lt;/span&gt;.Ldarg_1);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
EmitFastInt(ilGenerator, i);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
ilGenerator.Emit(&lt;span style="COLOR: teal"&gt;OpCodes&lt;/span&gt;.Ldloc, locals[i]);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (locals[i].LocalType.IsValueType)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; ilGenerator.Emit(&lt;span style="COLOR: teal"&gt;OpCodes&lt;/span&gt;.Box,
locals[i].LocalType);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
ilGenerator.Emit(&lt;span style="COLOR: teal"&gt;OpCodes&lt;/span&gt;.Stelem_Ref);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
returns the value to the caller&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ilGenerator.Emit(&lt;span style="COLOR: teal"&gt;OpCodes&lt;/span&gt;.Ret);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
converts the DynamicMethod to a FastInvokeHandler delegate to call to the method&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: teal"&gt;FastInvokeHandler&lt;/span&gt; invoker
= (&lt;span style="COLOR: teal"&gt;FastInvokeHandler&lt;/span&gt;)dynamicMethod.CreateDelegate(&lt;span style="COLOR: blue"&gt;typeof&lt;/span&gt;(&lt;span style="COLOR: teal"&gt;FastInvokeHandler&lt;/span&gt;));
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; invoker;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;Gets
the instance creator delegate that can be use to create instances of the specified
type.&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;param
name="type"&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;The type of the objects we want to
create.&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;returns&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;A
delegate that can be used to create the objects.&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/returns&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;static&lt;/span&gt; &lt;span style="COLOR: teal"&gt;FastCreateInstanceHandler&lt;/span&gt; GetInstanceCreator(&lt;span style="COLOR: teal"&gt;Type&lt;/span&gt; type)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
generates a dynamic method to generate a FastCreateInstanceHandler delegate&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: teal"&gt;DynamicMethod&lt;/span&gt; dynamicMethod
= &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: teal"&gt;DynamicMethod&lt;/span&gt;(&lt;span style="COLOR: blue"&gt;string&lt;/span&gt;.Empty,
type, &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: teal"&gt;Type&lt;/span&gt;[0], &lt;span style="COLOR: blue"&gt;typeof&lt;/span&gt;(&lt;span style="COLOR: teal"&gt;DynamicCalls&lt;/span&gt;).Module);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: teal"&gt;ILGenerator&lt;/span&gt; ilGenerator
= dynamicMethod.GetILGenerator();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
generates code to create a new object of the specified type using the default constructor&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ilGenerator.Emit(&lt;span style="COLOR: teal"&gt;OpCodes&lt;/span&gt;.Newobj,
type.GetConstructor(&lt;span style="COLOR: teal"&gt;Type&lt;/span&gt;.EmptyTypes));
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
returns the value to the caller&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ilGenerator.Emit(&lt;span style="COLOR: teal"&gt;OpCodes&lt;/span&gt;.Ret);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
converts the DynamicMethod to a FastCreateInstanceHandler delegate to create the object&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: teal"&gt;FastCreateInstanceHandler&lt;/span&gt; creator
= (&lt;span style="COLOR: teal"&gt;FastCreateInstanceHandler&lt;/span&gt;)dynamicMethod.CreateDelegate(&lt;span style="COLOR: blue"&gt;typeof&lt;/span&gt;(&lt;span style="COLOR: teal"&gt;FastCreateInstanceHandler&lt;/span&gt;));
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; creator;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;static&lt;/span&gt; &lt;span style="COLOR: teal"&gt;FastPropertyGetHandler&lt;/span&gt; GetPropertyGetter(&lt;span style="COLOR: teal"&gt;PropertyInfo&lt;/span&gt; propInfo)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
generates a dynamic method to generate a FastPropertyGetHandler delegate&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: teal"&gt;DynamicMethod&lt;/span&gt; dynamicMethod
= &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: teal"&gt;DynamicMethod&lt;/span&gt;(&lt;span style="COLOR: blue"&gt;string&lt;/span&gt;.Empty, &lt;span style="COLOR: blue"&gt;typeof&lt;/span&gt;(&lt;span style="COLOR: blue"&gt;object&lt;/span&gt;), &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: teal"&gt;Type&lt;/span&gt;[]
{ &lt;span style="COLOR: blue"&gt;typeof&lt;/span&gt;(&lt;span style="COLOR: blue"&gt;object&lt;/span&gt;)
}, propInfo.DeclaringType.Module);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: teal"&gt;ILGenerator&lt;/span&gt; ilGenerator
= dynamicMethod.GetILGenerator();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
loads the object into the stack&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ilGenerator.Emit(&lt;span style="COLOR: teal"&gt;OpCodes&lt;/span&gt;.Ldarg_0);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
calls the getter&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ilGenerator.EmitCall(&lt;span style="COLOR: teal"&gt;OpCodes&lt;/span&gt;.Callvirt,
propInfo.GetGetMethod(), &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
creates code for handling the return value&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; EmitBoxIfNeeded(ilGenerator,
propInfo.PropertyType);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
returns the value to the caller&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ilGenerator.Emit(&lt;span style="COLOR: teal"&gt;OpCodes&lt;/span&gt;.Ret);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
converts the DynamicMethod to a FastPropertyGetHandler delegate to get the property&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: teal"&gt;FastPropertyGetHandler&lt;/span&gt; getter
= (&lt;span style="COLOR: teal"&gt;FastPropertyGetHandler&lt;/span&gt;)dynamicMethod.CreateDelegate(&lt;span style="COLOR: blue"&gt;typeof&lt;/span&gt;(&lt;span style="COLOR: teal"&gt;FastPropertyGetHandler&lt;/span&gt;));
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; getter;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;static&lt;/span&gt; &lt;span style="COLOR: teal"&gt;FastPropertySetHandler&lt;/span&gt; GetPropertySetter(&lt;span style="COLOR: teal"&gt;PropertyInfo&lt;/span&gt; propInfo)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
generates a dynamic method to generate a FastPropertySetHandler delegate&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: teal"&gt;DynamicMethod&lt;/span&gt; dynamicMethod
= &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: teal"&gt;DynamicMethod&lt;/span&gt;(&lt;span style="COLOR: blue"&gt;string&lt;/span&gt;.Empty, &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;, &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: teal"&gt;Type&lt;/span&gt;[]
{ &lt;span style="COLOR: blue"&gt;typeof&lt;/span&gt;(&lt;span style="COLOR: blue"&gt;object&lt;/span&gt;), &lt;span style="COLOR: blue"&gt;typeof&lt;/span&gt;(&lt;span style="COLOR: blue"&gt;object&lt;/span&gt;)
}, propInfo.DeclaringType.Module);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: teal"&gt;ILGenerator&lt;/span&gt; ilGenerator
= dynamicMethod.GetILGenerator();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
loads the object into the stack&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ilGenerator.Emit(&lt;span style="COLOR: teal"&gt;OpCodes&lt;/span&gt;.Ldarg_0);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
loads the parameter from the stack&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ilGenerator.Emit(&lt;span style="COLOR: teal"&gt;OpCodes&lt;/span&gt;.Ldarg_1);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
cast to the proper type (unboxing if needed)&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; EmitCastToReference(ilGenerator,
propInfo.PropertyType);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
calls the setter&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ilGenerator.EmitCall(&lt;span style="COLOR: teal"&gt;OpCodes&lt;/span&gt;.Callvirt,
propInfo.GetSetMethod(), &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
terminates the call&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ilGenerator.Emit(&lt;span style="COLOR: teal"&gt;OpCodes&lt;/span&gt;.Ret);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
converts the DynamicMethod to a FastPropertyGetHandler delegate to get the property&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: teal"&gt;FastPropertySetHandler&lt;/span&gt; setter
= (&lt;span style="COLOR: teal"&gt;FastPropertySetHandler&lt;/span&gt;)dynamicMethod.CreateDelegate(&lt;span style="COLOR: blue"&gt;typeof&lt;/span&gt;(&lt;span style="COLOR: teal"&gt;FastPropertySetHandler&lt;/span&gt;));
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; setter;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;Emits
the cast to a reference, unboxing if needed.&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;param
name="il"&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;The MSIL generator.&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;param
name="type"&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;The type to cast.&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: blue"&gt;static&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; EmitCastToReference(&lt;span style="COLOR: teal"&gt;ILGenerator&lt;/span&gt; ilGenerator,
System.&lt;span style="COLOR: teal"&gt;Type&lt;/span&gt; type)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (type.IsValueType)
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ilGenerator.Emit(&lt;span style="COLOR: teal"&gt;OpCodes&lt;/span&gt;.Unbox_Any,
type);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;span style="COLOR: blue"&gt;else&lt;/span&gt; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ilGenerator.Emit(&lt;span style="COLOR: teal"&gt;OpCodes&lt;/span&gt;.Castclass,
type);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;Boxes
a type if needed.&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;param
name="ilGenerator"&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;The MSIL generator.&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;param
name="type"&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;The type.&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: blue"&gt;static&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; EmitBoxIfNeeded(&lt;span style="COLOR: teal"&gt;ILGenerator&lt;/span&gt; ilGenerator,
System.&lt;span style="COLOR: teal"&gt;Type&lt;/span&gt; type)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (type.IsValueType)
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ilGenerator.Emit(&lt;span style="COLOR: teal"&gt;OpCodes&lt;/span&gt;.Box,
type);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;Emits
code to save an integer to the evaluation stack.&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;param
name="ilGeneartor"&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;The MSIL generator.&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;param
name="value"&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;The value to push.&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: blue"&gt;static&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; EmitFastInt(&lt;span style="COLOR: teal"&gt;ILGenerator&lt;/span&gt; ilGenerator, &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; value)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
for small integers, emit the proper opcode&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;switch&lt;/span&gt; (value)
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; -1:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
ilGenerator.Emit(&lt;span style="COLOR: teal"&gt;OpCodes&lt;/span&gt;.Ldc_I4_M1);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; 0:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
ilGenerator.Emit(&lt;span style="COLOR: teal"&gt;OpCodes&lt;/span&gt;.Ldc_I4_0);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; 1:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
ilGenerator.Emit(&lt;span style="COLOR: teal"&gt;OpCodes&lt;/span&gt;.Ldc_I4_1);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; 2:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
ilGenerator.Emit(&lt;span style="COLOR: teal"&gt;OpCodes&lt;/span&gt;.Ldc_I4_2);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; 3:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
ilGenerator.Emit(&lt;span style="COLOR: teal"&gt;OpCodes&lt;/span&gt;.Ldc_I4_3);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; 4:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
ilGenerator.Emit(&lt;span style="COLOR: teal"&gt;OpCodes&lt;/span&gt;.Ldc_I4_4);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; 5:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
ilGenerator.Emit(&lt;span style="COLOR: teal"&gt;OpCodes&lt;/span&gt;.Ldc_I4_5);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; 6:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
ilGenerator.Emit(&lt;span style="COLOR: teal"&gt;OpCodes&lt;/span&gt;.Ldc_I4_6);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; 7:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
ilGenerator.Emit(&lt;span style="COLOR: teal"&gt;OpCodes&lt;/span&gt;.Ldc_I4_7);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;case&lt;/span&gt; 8:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
ilGenerator.Emit(&lt;span style="COLOR: teal"&gt;OpCodes&lt;/span&gt;.Ldc_I4_8);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
for bigger values emit the short or long opcode&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (value
&amp;gt; -129 &amp;amp;&amp;amp; value &amp;lt; 128) {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ilGenerator.Emit(&lt;span style="COLOR: teal"&gt;OpCodes&lt;/span&gt;.Ldc_I4_S,
(&lt;span style="COLOR: teal"&gt;SByte&lt;/span&gt;)value);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;span style="COLOR: blue"&gt;else&lt;/span&gt; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ilGenerator.Emit(&lt;span style="COLOR: teal"&gt;OpCodes&lt;/span&gt;.Ldc_I4,
value);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;!--EndFragment--&gt;
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;using&lt;/span&gt; System;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;using&lt;/span&gt; System.Reflection;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;using&lt;/span&gt; System.Reflection.Emit;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;using&lt;/span&gt; System.Collections.Generic;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;using&lt;/span&gt; System.Diagnostics;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;using&lt;/span&gt; Manu.Utils;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;namespace&lt;/span&gt; DynamicMethods
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;class&lt;/span&gt; &lt;span style="COLOR: teal"&gt;Program&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;static&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; Main(&lt;span style="COLOR: blue"&gt;string&lt;/span&gt;[]
args)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
object creation&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: teal"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="COLOR: maroon"&gt;"------
Object Creation ------"&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; EvaluateMethod(&lt;span style="COLOR: maroon"&gt;"direct
- object creation"&lt;/span&gt;, &lt;span style="COLOR: blue"&gt;delegate&lt;/span&gt;() {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: teal"&gt;TestClass&lt;/span&gt; p
= &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: teal"&gt;TestClass&lt;/span&gt;();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }, 1000000);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: teal"&gt;FastCreateInstanceHandler&lt;/span&gt; creator
= &lt;span style="COLOR: teal"&gt;DynamicCalls&lt;/span&gt;.GetInstanceCreator(&lt;span style="COLOR: blue"&gt;typeof&lt;/span&gt;(&lt;span style="COLOR: teal"&gt;TestClass&lt;/span&gt;));
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; EvaluateMethod(&lt;span style="COLOR: maroon"&gt;"dynamic
method - object creation"&lt;/span&gt;, &lt;span style="COLOR: blue"&gt;delegate&lt;/span&gt;() {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: teal"&gt;TestClass&lt;/span&gt; p
= (&lt;span style="COLOR: teal"&gt;TestClass&lt;/span&gt;)creator.Invoke();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }, 1000000);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; EvaluateMethod(&lt;span style="COLOR: maroon"&gt;"reflection
- object creation"&lt;/span&gt;, &lt;span style="COLOR: blue"&gt;delegate&lt;/span&gt;() {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: teal"&gt;TestClass&lt;/span&gt; p
= (&lt;span style="COLOR: teal"&gt;TestClass&lt;/span&gt;)&lt;span style="COLOR: teal"&gt;Activator&lt;/span&gt;.CreateInstance(&lt;span style="COLOR: blue"&gt;typeof&lt;/span&gt;(&lt;span style="COLOR: teal"&gt;TestClass&lt;/span&gt;));
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }, 1000000);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
property get&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: teal"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="COLOR: maroon"&gt;"------
Property Get ------"&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: teal"&gt;TestClass&lt;/span&gt; prod
= &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: teal"&gt;TestClass&lt;/span&gt;();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; prod.Num = 123;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; EvaluateMethod(&lt;span style="COLOR: maroon"&gt;"direct
- property get"&lt;/span&gt;, &lt;span style="COLOR: blue"&gt;delegate&lt;/span&gt;() {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; num
= prod.Num;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }, 1000000);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: teal"&gt;PropertyInfo&lt;/span&gt; propInfo
= &lt;span style="COLOR: blue"&gt;typeof&lt;/span&gt;(&lt;span style="COLOR: teal"&gt;TestClass&lt;/span&gt;).GetProperty(&lt;span style="COLOR: maroon"&gt;"Num"&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: teal"&gt;FastPropertyGetHandler&lt;/span&gt; getter
= &lt;span style="COLOR: teal"&gt;DynamicCalls&lt;/span&gt;.GetPropertyGetter(propInfo);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; EvaluateMethod(&lt;span style="COLOR: maroon"&gt;"dynamic
method - property get"&lt;/span&gt;, &lt;span style="COLOR: blue"&gt;delegate&lt;/span&gt;() {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; num
= (&lt;span style="COLOR: blue"&gt;int&lt;/span&gt;)getter(prod);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }, 1000000);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; EvaluateMethod(&lt;span style="COLOR: maroon"&gt;"reflection
- property get"&lt;/span&gt;, &lt;span style="COLOR: blue"&gt;delegate&lt;/span&gt;() {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; num
= (&lt;span style="COLOR: blue"&gt;int&lt;/span&gt;)propInfo.GetValue(prod, &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }, 1000000);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
property set&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: teal"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="COLOR: maroon"&gt;"------
Property Set ------"&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; EvaluateMethod(&lt;span style="COLOR: maroon"&gt;"direct
- property set"&lt;/span&gt;, &lt;span style="COLOR: blue"&gt;delegate&lt;/span&gt;() {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; prod.Num
= 33;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }, 1000000);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: teal"&gt;FastPropertySetHandler&lt;/span&gt; setter
= &lt;span style="COLOR: teal"&gt;DynamicCalls&lt;/span&gt;.GetPropertySetter(propInfo);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; EvaluateMethod(&lt;span style="COLOR: maroon"&gt;"dynamic
method - property set"&lt;/span&gt;, &lt;span style="COLOR: blue"&gt;delegate&lt;/span&gt;() {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; setter(prod,
32);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }, 1000000);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; EvaluateMethod(&lt;span style="COLOR: maroon"&gt;"reflection
- property set"&lt;/span&gt;, &lt;span style="COLOR: blue"&gt;delegate&lt;/span&gt;() {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; propInfo.SetValue(prod,
31, &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }, 1000000);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
instance method call&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: teal"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="COLOR: maroon"&gt;"------
Instance Method Call ------"&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; EvaluateMethod(&lt;span style="COLOR: maroon"&gt;"direct
- instance method call"&lt;/span&gt;, &lt;span style="COLOR: blue"&gt;delegate&lt;/span&gt;() {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; result
= prod.Multiply(3, 5);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }, 1000000);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: teal"&gt;MethodInfo&lt;/span&gt; methodInfo1
= &lt;span style="COLOR: blue"&gt;typeof&lt;/span&gt;(&lt;span style="COLOR: teal"&gt;TestClass&lt;/span&gt;).GetMethod(&lt;span style="COLOR: maroon"&gt;"Multiply"&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: teal"&gt;FastInvokeHandler&lt;/span&gt; fastInvoker1
= &lt;span style="COLOR: teal"&gt;DynamicCalls&lt;/span&gt;.GetMethodInvoker(methodInfo1);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; EvaluateMethod(&lt;span style="COLOR: maroon"&gt;"dynamic
method - instance method call"&lt;/span&gt;, &lt;span style="COLOR: blue"&gt;delegate&lt;/span&gt;()
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; result
= (&lt;span style="COLOR: blue"&gt;int&lt;/span&gt;)fastInvoker1(prod, &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: blue"&gt;object&lt;/span&gt;[]
{ 3, 5 });
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }, 1000000);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; EvaluateMethod(&lt;span style="COLOR: maroon"&gt;"reflection
- instance method call"&lt;/span&gt;, &lt;span style="COLOR: blue"&gt;delegate&lt;/span&gt;() {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; result
= (&lt;span style="COLOR: blue"&gt;int&lt;/span&gt;)methodInfo1.Invoke(prod, &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: blue"&gt;object&lt;/span&gt;[]
{ 3, 5 });
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }, 1000000);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
static method call&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: teal"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="COLOR: maroon"&gt;"------
Static Method Call ------"&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; EvaluateMethod(&lt;span style="COLOR: maroon"&gt;"direct
- static method call"&lt;/span&gt;, &lt;span style="COLOR: blue"&gt;delegate&lt;/span&gt;() {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; result
= &lt;span style="COLOR: teal"&gt;TestClass&lt;/span&gt;.StaticMultiply(3, 5);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }, 1000000);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: teal"&gt;MethodInfo&lt;/span&gt; methodInfo2
= &lt;span style="COLOR: blue"&gt;typeof&lt;/span&gt;(&lt;span style="COLOR: teal"&gt;TestClass&lt;/span&gt;).GetMethod(&lt;span style="COLOR: maroon"&gt;"StaticMultiply"&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: teal"&gt;FastInvokeHandler&lt;/span&gt; fastInvoker2
= &lt;span style="COLOR: teal"&gt;DynamicCalls&lt;/span&gt;.GetMethodInvoker(methodInfo2);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; EvaluateMethod(&lt;span style="COLOR: maroon"&gt;"dynamic
method - static method call"&lt;/span&gt;, &lt;span style="COLOR: blue"&gt;delegate&lt;/span&gt;() {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; result
= (&lt;span style="COLOR: blue"&gt;int&lt;/span&gt;)fastInvoker2(&lt;span style="COLOR: blue"&gt;null&lt;/span&gt;, &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: blue"&gt;object&lt;/span&gt;[]
{ 3, 5 });
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }, 1000000);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; EvaluateMethod(&lt;span style="COLOR: maroon"&gt;"reflection
- static method call"&lt;/span&gt;, &lt;span style="COLOR: blue"&gt;delegate&lt;/span&gt;() {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; result
= (&lt;span style="COLOR: blue"&gt;int&lt;/span&gt;)methodInfo2.Invoke(&lt;span style="COLOR: blue"&gt;null&lt;/span&gt;, &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: blue"&gt;object&lt;/span&gt;[]
{ 3, 5 });
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }, 1000000);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: teal"&gt;Console&lt;/span&gt;.ReadLine();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;delegate&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; &lt;span style="COLOR: teal"&gt;MethodToEvaluate&lt;/span&gt;();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;// evaluates a method
the specified number of times and print performance information&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;static&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; EvaluateMethod(&lt;span style="COLOR: blue"&gt;string&lt;/span&gt; testName, &lt;span style="COLOR: teal"&gt;MethodToEvaluate&lt;/span&gt; method, &lt;span style="COLOR: blue"&gt;long&lt;/span&gt; times)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: teal"&gt;Stopwatch&lt;/span&gt; watch
= &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: teal"&gt;Stopwatch&lt;/span&gt;();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; watch.Start();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;for&lt;/span&gt; (&lt;span style="COLOR: blue"&gt;long&lt;/span&gt; i
= 0; i &amp;lt; times; i++) {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; method();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; watch.Stop();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: teal"&gt;Console&lt;/span&gt;.WriteLine(testName
+ &lt;span style="COLOR: maroon"&gt;": "&lt;/span&gt; + watch.ElapsedMilliseconds + &lt;span style="COLOR: maroon"&gt;"ms"&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.manuelabadia.com/blog/content/binary/DynamicMethods.zip"&gt;DynamicMethods.zip
(5.01 KB)&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=dc72b235-1381-4c91-8706-e36216f49b94" /&gt;</description>
      <comments>http://www.manuelabadia.com/blog/CommentView,guid,dc72b235-1381-4c91-8706-e36216f49b94.aspx</comments>
      <category>ASP.NET;Microsoft .NET Framework</category>
    </item>
    <item>
      <trackback:ping>http://www.manuelabadia.com/blog/Trackback.aspx?guid=9f82b3ce-616a-4bda-a4b5-4bd59a2448a7</trackback:ping>
      <pingback:server>http://www.manuelabadia.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.manuelabadia.com/blog/PermaLink,guid,9f82b3ce-616a-4bda-a4b5-4bd59a2448a7.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://www.manuelabadia.com/blog/CommentView,guid,9f82b3ce-616a-4bda-a4b5-4bd59a2448a7.aspx</wfw:comment>
      <wfw:commentRss>http://www.manuelabadia.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=9f82b3ce-616a-4bda-a4b5-4bd59a2448a7</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
A friend recommended me to read the book “POJOs in action: Developing Enterprise Applications
with Lightweight Frameworks”. In case you haven’t heard what a POJO is, it’s an acronym
that stands for Plain Old Java Objects. Of course, my first reaction was that it was
a Java book not a .net book but he told me that the book is about generic concepts
that could be used in .net without much trouble so I purchased the book:
</p>
        <br />
        <iframe style="WIDTH: 120px; HEIGHT: 240px" marginwidth="0" marginheight="0" src="http://rcm.amazon.com/e/cm?t=manuelabadias-20&amp;o=1&amp;p=8&amp;l=as1&amp;asins=1932394583&amp;fc1=000000&amp;IS2=1&amp;lt1=_blank&amp;lc1=0000ff&amp;bc1=000000&amp;bg1=ffffff&amp;f=ifr" frameborder="0" scrolling="no">
        </iframe>
        <br />
        <p>
This book complements Fowler’s Enterprise Architectural Patterns[1] as it is more
practical and it has a lot of samples. The author (Chris Richardson) explains his
methodology to build enterprise applications using test driven development.
</p>
        <p>
I haven’t used Java since 2001 and I didn’t have any problem following the book. If
you are not a Java expert you can still read the book ignoring the comments about
EJB. A little of background of JSP and Servlets is usefull when talking about the
presentation layer but you can understand most of the content without it. The author
uses a lot of Java tools/frameworks that have an equivalent counterpart in the .net
world (NUnit, NMock, NHibernate, Spring Framework .net, etc) so even if there are
some differences between the Java and the .net versions the information provided is
useful.
</p>
        <p>
The first pages of the book are about the decisions to make when building an
application (organizing the business logic, encapsulating the business logic, accessing
the database, handling concurrency in database transactions and handling concurrency
in long transactions), and the rest of the book elaborates more on the usual strategies
chosen in the design (OO domain model with O/R mapping) and some variations (transaction
scripts, exposed domain model). When the author explains a topic it provides useful
samples and the pros and cons of using one approach versus other approaches.
</p>
        <p>
The O/R mapping material is very good and details the inner workings of JDO (AFAIK
a Java only O/R mapper so I skipped most sections about it) and Hibernate. Also there
is a chapter about complex search forms and how to make dynamic paged queries in order
to retrieve data as fast as possible and integrate those queries with Hibernate.
</p>
        <p>
The last part of the book is about concurrency in short and long transactions and
I found it quite useful as in most applications I’ve seen don’t do anything about
concurrency conflicts in long running transactions and the book has code explaining
how to implement it where other books only give guidelines.
</p>
        <p>
After reading the book I have added to my long TODO list to take a look to the spring
framework so if somebody that reads this wants to share his experiences with it feel
free to send me an email or post a comment.
</p>
        <p>
        </p>
        <br />
[1] Fowler's book<br /><iframe style="WIDTH: 120px; HEIGHT: 240px" marginwidth="0" marginheight="0" src="http://rcm.amazon.com/e/cm?t=manuelabadias-20&amp;o=1&amp;p=8&amp;l=as1&amp;asins=0321127420&amp;fc1=000000&amp;IS2=1&amp;lt1=_blank&amp;lc1=0000ff&amp;bc1=000000&amp;bg1=ffffff&amp;f=ifr" frameborder="0" scrolling="no"></iframe><img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=9f82b3ce-616a-4bda-a4b5-4bd59a2448a7" /></body>
      <title>Review of POJOs in action: Developing Enterprise Applications with Lightweight Frameworks</title>
      <guid isPermaLink="false">http://www.manuelabadia.com/blog/PermaLink,guid,9f82b3ce-616a-4bda-a4b5-4bd59a2448a7.aspx</guid>
      <link>http://www.manuelabadia.com/blog/PermaLink,guid,9f82b3ce-616a-4bda-a4b5-4bd59a2448a7.aspx</link>
      <pubDate>Wed, 28 Jun 2006 12:16:47 GMT</pubDate>
      <description>&lt;p&gt;
A friend recommended me to read the book “POJOs in action: Developing Enterprise Applications
with Lightweight Frameworks”. In case you haven’t heard what a POJO is, it’s an acronym
that stands for Plain Old Java Objects. Of course, my first reaction was that it was
a Java book not a .net book but he told me that the book is about generic concepts
that could be used in .net without much trouble so I purchased the book:
&lt;/p&gt;
&lt;br&gt;
&lt;iframe style="WIDTH: 120px; HEIGHT: 240px" marginwidth=0 marginheight=0 src="http://rcm.amazon.com/e/cm?t=manuelabadias-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=as1&amp;amp;asins=1932394583&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;lc1=0000ff&amp;amp;bc1=000000&amp;amp;bg1=ffffff&amp;amp;f=ifr" frameborder=0 scrolling=no&gt;
&lt;/iframe&gt;
&lt;br&gt;
&lt;p&gt;
This book complements Fowler’s Enterprise Architectural Patterns[1] as it is more
practical and it has a lot of samples. The author (Chris Richardson) explains his
methodology to build enterprise applications using test driven development.
&lt;/p&gt;
&lt;p&gt;
I haven’t used Java since 2001 and I didn’t have any problem following the book. If
you are not a Java expert you can still read the book ignoring the comments about
EJB. A little of background of JSP and Servlets is usefull when talking about the
presentation layer but you can understand most of the content without it. The author
uses a lot of Java tools/frameworks that have an equivalent counterpart in the .net
world (NUnit, NMock, NHibernate, Spring Framework .net, etc) so even if there are
some differences between the Java and the .net versions the information provided is
useful.
&lt;/p&gt;
&lt;p&gt;
The first pages of the book&amp;nbsp;are about the decisions to make when building an
application (organizing the business logic, encapsulating the business logic, accessing
the database, handling concurrency in database transactions and handling concurrency
in long transactions), and the rest of the book elaborates more on the usual strategies
chosen in the design (OO domain model with O/R mapping) and some variations (transaction
scripts, exposed domain model). When the author explains a topic it provides useful
samples and the pros and cons of using one approach versus other approaches.
&lt;/p&gt;
&lt;p&gt;
The O/R mapping material is very good and details the inner workings of JDO (AFAIK
a Java only O/R mapper so I skipped most sections about it) and Hibernate. Also there
is a chapter about complex search forms and how to make dynamic paged queries in order
to retrieve data as fast as possible and integrate those queries with Hibernate.
&lt;/p&gt;
&lt;p&gt;
The last part of the book is about concurrency in short and long transactions and
I found it quite useful as in most applications I’ve seen don’t do anything about
concurrency conflicts in long running transactions and the book has code explaining
how to implement it where other books only give guidelines.
&lt;/p&gt;
&lt;p&gt;
After reading the book I have added to my long TODO list to take a look to the spring
framework so if somebody that reads this wants to share his experiences with it feel
free to send me an email or post a comment.
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;br&gt;
[1] Fowler's book&lt;br&gt;
&lt;iframe style="WIDTH: 120px; HEIGHT: 240px" marginwidth=0 marginheight=0 src="http://rcm.amazon.com/e/cm?t=manuelabadias-20&amp;amp;o=1&amp;amp;p=8&amp;amp;l=as1&amp;amp;asins=0321127420&amp;amp;fc1=000000&amp;amp;IS2=1&amp;amp;lt1=_blank&amp;amp;lc1=0000ff&amp;amp;bc1=000000&amp;amp;bg1=ffffff&amp;amp;f=ifr" frameborder=0 scrolling=no&gt;
&lt;/iframe&gt;
&lt;img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=9f82b3ce-616a-4bda-a4b5-4bd59a2448a7" /&gt;</description>
      <comments>http://www.manuelabadia.com/blog/CommentView,guid,9f82b3ce-616a-4bda-a4b5-4bd59a2448a7.aspx</comments>
      <category>ASP.NET;Microsoft .NET Framework</category>
    </item>
    <item>
      <trackback:ping>http://www.manuelabadia.com/blog/Trackback.aspx?guid=e8e0c020-f9d3-4174-a0e0-2f55ff29f565</trackback:ping>
      <pingback:server>http://www.manuelabadia.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.manuelabadia.com/blog/PermaLink,guid,e8e0c020-f9d3-4174-a0e0-2f55ff29f565.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://www.manuelabadia.com/blog/CommentView,guid,e8e0c020-f9d3-4174-a0e0-2f55ff29f565.aspx</wfw:comment>
      <wfw:commentRss>http://www.manuelabadia.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=e8e0c020-f9d3-4174-a0e0-2f55ff29f565</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
First I have to apologize for not posting anything in nearly two weeks, but a lot
of things have happened lately: I did a quick work (a week) for Namco Mobile; I have
been two days in bed with temperature; I did a Reiki first degree course; too much
work in the last days and a lot more to come until august…
</p>
        <p>
I read somewhere that Microsoft .NET Framework 3.0 will be released at the end of
the year. Even if it is not a complete change of the .NET Framework 2.0 and can be
seen as .NET Framework 2.0 + Windows Presentation Foundation (WPF) + Windows Communication
Foundation (WCF) + Windows Workflow Foundation (WF) + Windows CardSpace (WCS) it is
kind of a pain to be learning version 2.0 and have a new release before mastering
.NET Framework 2.0. If you add Atlas to the mix the conclusion is: “Too many things
to learn and no time to do it!”. I hope we can live with .NET Framework 3.0 for a
few years. 
</p>
        <p>
I don’t know what happens in other cities/countries but most of the companies here
are still using .NET 1.x and probably a lot of them will still be using it when .NET
3.0 is released…
</p>
        <p>
Talking about other things, I have started to add full design time support to the
ExtendedObjectDataSource package and this is what I have at the moment:
</p>
        <p>
          <img height="451" alt="Design time wizard" src="http://www.manuelabadia.com/blog/content/binary/CODS_designtime1.gif" width="581" border="0" />
        </p>
        <p>
          <img height="451" alt="Design time wizard" src="http://www.manuelabadia.com/blog/content/binary/CODS_designtime2.gif" width="581" border="0" />
        </p>
        <p>
          <br />
As you can see I have added more options that are not present in the standard ObjectDataSource
like being able to configure paging in the wizard and also being able to choose also
the SelectCountMethod (for the CompatObjectDataSource. The ExtendedObjectDataSource
can extract the total row count in the SelectMethod).
</p>
        <p>
If somebody misses something in the wizard let me know ASAP so I can think of including
it.
</p>
        <p>
Every time I have to use Winforms I really hate the poor control set that is available
(at least in version 2.0 you have a menu that does not look like it was made for windows
95 :-P). I can’t believe that the framework didn’t ship with a wizard control so I
had to waste my time coding one.
</p>
        <p>
To finish this post, I’ll tell you a cool tip to debug design time stuff. Forget everything
that you did to set up the project to debug design time classes. You’ll have a debugger
attached to the current Visual Studio instance and awaiting your orders if you add
this line of code where you want the debugger to show up:
</p>
        <p>
System.Diagnostics.Debugger.Launch();
</p>
        <img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=e8e0c020-f9d3-4174-a0e0-2f55ff29f565" />
      </body>
      <title>Microsoft .NET Framework 3.0, Design time stuff and more</title>
      <guid isPermaLink="false">http://www.manuelabadia.com/blog/PermaLink,guid,e8e0c020-f9d3-4174-a0e0-2f55ff29f565.aspx</guid>
      <link>http://www.manuelabadia.com/blog/PermaLink,guid,e8e0c020-f9d3-4174-a0e0-2f55ff29f565.aspx</link>
      <pubDate>Sun, 18 Jun 2006 22:49:35 GMT</pubDate>
      <description>&lt;p&gt;
First I have to apologize for not posting anything in nearly two weeks, but a lot
of things have happened lately: I did a quick work (a week) for Namco Mobile; I have
been two days in bed with temperature; I did a Reiki first degree course; too much
work in the last days and a lot more to come until august…
&lt;/p&gt;
&lt;p&gt;
I read somewhere that Microsoft .NET Framework 3.0 will be released at the end of
the year. Even if it is not a complete change of the .NET Framework 2.0 and can be
seen as .NET Framework 2.0 + Windows Presentation Foundation (WPF) + Windows Communication
Foundation (WCF) + Windows Workflow Foundation (WF) + Windows CardSpace (WCS) it is
kind of a pain to be learning version 2.0 and have a new release before mastering
.NET Framework 2.0. If you add Atlas to the mix the conclusion is: “Too many things
to learn and no time to do it!”. I hope we can live with .NET Framework 3.0 for a
few years. 
&lt;/p&gt;
&lt;p&gt;
I don’t know what happens in other cities/countries but most of the companies here
are still using .NET 1.x and probably a lot of them will still be using it when .NET
3.0 is released…
&lt;/p&gt;
&lt;p&gt;
Talking about other things, I have started to add full design time support to the
ExtendedObjectDataSource package and this is what I have at the moment:
&lt;/p&gt;
&lt;p&gt;
&lt;img height=451 alt="Design time wizard" src="http://www.manuelabadia.com/blog/content/binary/CODS_designtime1.gif" width=581 border=0&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;img height=451 alt="Design time wizard" src="http://www.manuelabadia.com/blog/content/binary/CODS_designtime2.gif" width=581 border=0&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;br&gt;
As you can see I have added more options that are not present in the standard ObjectDataSource
like being able to configure paging in the wizard and also being able to choose also
the SelectCountMethod (for the CompatObjectDataSource. The ExtendedObjectDataSource
can extract the total row count in the SelectMethod).
&lt;/p&gt;
&lt;p&gt;
If somebody misses something in the wizard let me know ASAP so I can think of including
it.
&lt;/p&gt;
&lt;p&gt;
Every time I have to use Winforms I really hate the poor control set that is available
(at least in version 2.0 you have a menu that does not look like it was made for windows
95 :-P). I can’t believe that the framework didn’t ship with a wizard control so I
had to waste my time coding one.
&lt;/p&gt;
&lt;p&gt;
To finish this post, I’ll tell you a cool tip to debug design time stuff. Forget everything
that you did to set up the project to debug design time classes. You’ll have a debugger
attached to the current Visual Studio instance and awaiting your orders if you add
this line of code where you want the debugger to show up:
&lt;/p&gt;
&lt;p&gt;
System.Diagnostics.Debugger.Launch();
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=e8e0c020-f9d3-4174-a0e0-2f55ff29f565" /&gt;</description>
      <comments>http://www.manuelabadia.com/blog/CommentView,guid,e8e0c020-f9d3-4174-a0e0-2f55ff29f565.aspx</comments>
      <category>ASP.NET;General;Microsoft .NET Framework</category>
    </item>
    <item>
      <trackback:ping>http://www.manuelabadia.com/blog/Trackback.aspx?guid=d57337b5-b4da-4cb0-ad22-595379ca24ad</trackback:ping>
      <pingback:server>http://www.manuelabadia.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.manuelabadia.com/blog/PermaLink,guid,d57337b5-b4da-4cb0-ad22-595379ca24ad.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://www.manuelabadia.com/blog/CommentView,guid,d57337b5-b4da-4cb0-ad22-595379ca24ad.aspx</wfw:comment>
      <wfw:commentRss>http://www.manuelabadia.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=d57337b5-b4da-4cb0-ad22-595379ca24ad</wfw:commentRss>
      <slash:comments>5</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
When I was making the layout for the book last month I had to do a lot of repetitive
tasks. I was on a hurry to finish the book so I didn’t have a chance to look at InDesign
scripting capabilities. However, a few days after helping my friend I told him that
a process like making the layout of a book could be automated a lot with scripting
in order to avoid repetitive tasks. 
</p>
        <p>
When I started reading about InDesign scripting I thought that I had to do it using
JavaScript. I didn’t have to learn another language so that was good. However, working
with JavaScript is always slower than working with other languages (maybe because
the lack of good tools?).
</p>
        <p>
However I was surprised when I read that all InDesign features were exposed as a COM
object. I could leverage the power of Visual Studio 2005 to do everything without
having to do it in JavaScript!
</p>
        <p>
To use InDesign from C# I had to import the InDesign Type Library and Visual Studio
generated a COM wrapper for it. That was it! Of course, not all was perfect or straightforward.
There were some things to consider:
</p>
        <blockquote dir="ltr" style="MARGIN-RIGHT: 0px">
          <p>
• All InDesign collections start at index 1 instead of 0<br />
• A lot of methods return object instead of a strongly typed object so a lot
of casting is needed.<br />
• There are times when you don’t know exactly what kind of object you get when
calling a method and inspecting it in the debugger doesn’t help. Fortunately <a href="http://www.khmerang.com/index.php?p=53">this
guy</a> used the compiler services to load all InDesign types and try to convert the
object to all types until a match was found. This is very helpful when working with
InDesign.<br />
• There were times that setting the content of a paragraph or some text didn’t
work as expected but setting it indirectly (calling a find/replace method for example)
worked fine.<br />
• The documentation is minimal. Sometimes I wonder why the MSDN documentation
is obscure and reduced in some classes but you have to see InDesign scripting reference:
</p>
          <blockquote dir="ltr" style="MARGIN-RIGHT: 0px">
            <p>
              <img src="http://www.manuelabadia.com/blog/content/binary/InDesign_ref.jpg" border="0" />
            </p>
            <p>
If you find a description with more than four words it’s your lucky day. It seems
that the documentation is completely generated by a tool similar to GhostDoc and then
a few properties and methods have been comented.
</p>
            <p>
And the description of the classes is amazing:<br />
Story: A story.<br />
TrapPreset: A trapping preset.
</p>
          </blockquote>
        </blockquote>
        <p>
 
</p>
        <p>
If someone wants to start using InDesign with C# an example could be useful:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">private</span>
            <span style="COLOR: blue">int</span> RemoveCRFromFootnotes()
</p>
          <p style="MARGIN: 0px">
        {
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: green">//
gets the InDesign App</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: teal">Type</span> inDesignAppType
= <span style="COLOR: teal">Type</span>.GetTypeFromProgID(<span style="COLOR: maroon">"InDesign.Application.CS2"</span>);
</p>
          <p style="MARGIN: 0px">
            InDesign.<span style="COLOR: teal">Application</span> myInDesign
= (InDesign.<span style="COLOR: teal">Application</span>)<span style="COLOR: teal">Activator</span>.CreateInstance(inDesignAppType);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">string</span> footNotesFixed
= <span style="COLOR: maroon">""</span>;
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            InDesign.<span style="COLOR: teal">Document</span> myDocument
= <span style="COLOR: blue">null</span>;
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: green">//
gets the current active document    </span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">try</span> {
</p>
          <p style="MARGIN: 0px">
                myDocument
= myInDesign.ActiveDocument;
</p>
          <p style="MARGIN: 0px">
            } <span style="COLOR: blue">catch</span> {
</p>
          <p style="MARGIN: 0px">
                <span style="COLOR: blue">throw</span><span style="COLOR: blue">new</span><span style="COLOR: teal">Exception</span>(<span style="COLOR: maroon">"You
need to have an active document to run this script"</span>);
</p>
          <p style="MARGIN: 0px">
            }
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: green">//
iterates through all the stories in the current document</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">for</span> (<span style="COLOR: blue">int</span> i
= 1; i &lt;= myDocument.Stories.Count; i++) {
</p>
          <p style="MARGIN: 0px">
                InDesign.<span style="COLOR: teal">Story</span> currentStory
= (InDesign.<span style="COLOR: teal">Story</span>)myDocument.Stories[i];
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
                <span style="COLOR: green">//
iterates trough all the FootNotes in the current story</span></p>
          <p style="MARGIN: 0px">
                <span style="COLOR: blue">for</span> (<span style="COLOR: blue">int</span> fn
= 1; fn &lt; currentStory.Footnotes.Count; fn++) {
</p>
          <p style="MARGIN: 0px">
                   
InDesign.<span style="COLOR: teal">Footnote</span> currentFootNote = (InDesign.<span style="COLOR: teal">Footnote</span>)currentStory.Footnotes[fn];
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
                    <span style="COLOR: green">//
goes to the last parragraph in the FootNote</span></p>
          <p style="MARGIN: 0px">
                    <span style="COLOR: blue">if</span> (currentFootNote.Paragraphs.Count
&gt; 0) {
</p>
          <p style="MARGIN: 0px">
                   
    <span style="COLOR: blue">try</span> {
</p>
          <p style="MARGIN: 0px">
                   
        InDesign.<span style="COLOR: teal">Paragraph</span> currentParagraph
= (InDesign.<span style="COLOR: teal">Paragraph</span>)currentFootNote.Paragraphs[currentFootNote.Paragraphs.Count];
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
                   
        <span style="COLOR: green">// if ends with a
carriage return, remove it</span></p>
          <p style="MARGIN: 0px">
                   
        <span style="COLOR: blue">string</span> contents
= currentParagraph.Contents <span style="COLOR: blue">as</span><span style="COLOR: blue">string</span>;
</p>
          <p style="MARGIN: 0px">
                   
        <span style="COLOR: blue">if</span> (contents
!= <span style="COLOR: blue">null</span>) {
</p>
          <p style="MARGIN: 0px">
                   
            <span style="COLOR: blue">if</span> (contents.EndsWith(<span style="COLOR: maroon">"\r"</span>))
{
</p>
          <p style="MARGIN: 0px">
                   
                <span style="COLOR: green">//
assigning content deletes the footnote number but search and replace works</span></p>
          <p style="MARGIN: 0px">
                   
                currentParagraph.Search(currentParagraph.Contents, <span style="COLOR: blue">false</span>, <span style="COLOR: blue">true</span>,
contents.Substring(0, contents.Length - 1));
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
                   
                footNotesFixed
+= <span style="COLOR: maroon">" "</span> + currentFootNote.Index.ToString();
</p>
          <p style="MARGIN: 0px">
                   
            }
</p>
          <p style="MARGIN: 0px">
                   
        }
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
                   
    } <span style="COLOR: blue">catch</span> {
</p>
          <p style="MARGIN: 0px">
                   
    }
</p>
          <p style="MARGIN: 0px">
                   
}
</p>
          <p style="MARGIN: 0px">
                }
</p>
          <p style="MARGIN: 0px">
            }
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">return</span> footNotesFixed;
</p>
          <p style="MARGIN: 0px">
        }
</p>
        </div>
        <!--EndFragment-->
        <p>
 
</p>
        <p>
This sample removes the carriage return at the end of the footnotes that word usually
lefts.
</p>
        <img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=d57337b5-b4da-4cb0-ad22-595379ca24ad" />
      </body>
      <title>Using Adobe InDesign with C#</title>
      <guid isPermaLink="false">http://www.manuelabadia.com/blog/PermaLink,guid,d57337b5-b4da-4cb0-ad22-595379ca24ad.aspx</guid>
      <link>http://www.manuelabadia.com/blog/PermaLink,guid,d57337b5-b4da-4cb0-ad22-595379ca24ad.aspx</link>
      <pubDate>Tue, 18 Apr 2006 06:57:19 GMT</pubDate>
      <description>&lt;p&gt;
When I was making the layout for the book last month I had to do a lot of repetitive
tasks. I was on a hurry to finish the book so I didn’t have a chance to look at InDesign
scripting capabilities. However, a few days after helping my friend I told him that
a process like making the layout of a book could be automated a lot with scripting
in order to avoid repetitive tasks. 
&lt;/p&gt;
&lt;p&gt;
When I started reading about InDesign scripting I thought that I had to do it using
JavaScript. I didn’t have to learn another language so that was good. However, working
with JavaScript is always slower than working with other languages (maybe because
the lack of good tools?).
&lt;/p&gt;
&lt;p&gt;
However I was surprised when I read that all InDesign features were exposed as a COM
object. I could leverage the power of Visual Studio 2005 to do everything without
having to do it in JavaScript!
&lt;/p&gt;
&lt;p&gt;
To use InDesign from C# I had to import the InDesign Type Library and Visual Studio
generated a COM wrapper for it. That was it! Of course, not all was perfect or straightforward.
There were some things to consider:
&lt;/p&gt;
&lt;blockquote dir=ltr style="MARGIN-RIGHT: 0px"&gt; 
&lt;p&gt;
•&amp;nbsp;All InDesign collections start at index 1 instead of 0&lt;br&gt;
•&amp;nbsp;A lot of methods return object instead of a strongly typed object so a lot
of casting is needed.&lt;br&gt;
•&amp;nbsp;There are times when you don’t know exactly what kind of object you get when
calling a method and inspecting it in the debugger doesn’t help. Fortunately &lt;a href="http://www.khmerang.com/index.php?p=53"&gt;this
guy&lt;/a&gt; used the compiler services to load all InDesign types and try to convert the
object to all types until a match was found. This is very helpful when working with
InDesign.&lt;br&gt;
•&amp;nbsp;There were times that setting the content of a paragraph or some text didn’t
work as expected but setting it indirectly (calling a find/replace method for example)
worked fine.&lt;br&gt;
•&amp;nbsp;The documentation is minimal. Sometimes I wonder why the MSDN documentation
is obscure and reduced in some classes but you have to see InDesign scripting reference:
&lt;/p&gt;
&lt;blockquote dir=ltr style="MARGIN-RIGHT: 0px"&gt; 
&lt;p&gt;
&lt;img src="http://www.manuelabadia.com/blog/content/binary/InDesign_ref.jpg" border=0&gt;
&lt;/p&gt;
&lt;p&gt;
If you find a description with more than four words it’s your lucky day. It seems
that the documentation is completely generated by a tool similar to GhostDoc and then
a few properties and methods have been comented.
&lt;/p&gt;
&lt;p&gt;
And the description of the classes is amazing:&lt;br&gt;
Story: A story.&lt;br&gt;
TrapPreset: A trapping preset.
&lt;/p&gt;
&lt;/blockquote&gt;&lt;/blockquote&gt; 
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
If someone wants to start using InDesign with C# an example could be useful:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; RemoveCRFromFootnotes()
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
gets the InDesign App&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: teal"&gt;Type&lt;/span&gt; inDesignAppType
= &lt;span style="COLOR: teal"&gt;Type&lt;/span&gt;.GetTypeFromProgID(&lt;span style="COLOR: maroon"&gt;"InDesign.Application.CS2"&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; InDesign.&lt;span style="COLOR: teal"&gt;Application&lt;/span&gt; myInDesign
= (InDesign.&lt;span style="COLOR: teal"&gt;Application&lt;/span&gt;)&lt;span style="COLOR: teal"&gt;Activator&lt;/span&gt;.CreateInstance(inDesignAppType);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; footNotesFixed
= &lt;span style="COLOR: maroon"&gt;""&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; InDesign.&lt;span style="COLOR: teal"&gt;Document&lt;/span&gt; myDocument
= &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
gets the current active document&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;try&lt;/span&gt; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; myDocument
= myInDesign.ActiveDocument;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;span style="COLOR: blue"&gt;catch&lt;/span&gt; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;throw&lt;/span&gt; &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: teal"&gt;Exception&lt;/span&gt;(&lt;span style="COLOR: maroon"&gt;"You
need to have an active document to run this script"&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
iterates through all the stories in the current document&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;for&lt;/span&gt; (&lt;span style="COLOR: blue"&gt;int&lt;/span&gt; i
= 1; i &amp;lt;= myDocument.Stories.Count; i++) {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; InDesign.&lt;span style="COLOR: teal"&gt;Story&lt;/span&gt; currentStory
= (InDesign.&lt;span style="COLOR: teal"&gt;Story&lt;/span&gt;)myDocument.Stories[i];
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
iterates trough all the FootNotes in the current story&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;for&lt;/span&gt; (&lt;span style="COLOR: blue"&gt;int&lt;/span&gt; fn
= 1; fn &amp;lt; currentStory.Footnotes.Count; fn++) {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
InDesign.&lt;span style="COLOR: teal"&gt;Footnote&lt;/span&gt; currentFootNote = (InDesign.&lt;span style="COLOR: teal"&gt;Footnote&lt;/span&gt;)currentStory.Footnotes[fn];
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
goes to the last parragraph in the FootNote&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (currentFootNote.Paragraphs.Count
&amp;gt; 0) {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;try&lt;/span&gt; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; InDesign.&lt;span style="COLOR: teal"&gt;Paragraph&lt;/span&gt; currentParagraph
= (InDesign.&lt;span style="COLOR: teal"&gt;Paragraph&lt;/span&gt;)currentFootNote.Paragraphs[currentFootNote.Paragraphs.Count];
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;// if ends with a
carriage return, remove it&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; contents
= currentParagraph.Contents &lt;span style="COLOR: blue"&gt;as&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (contents
!= &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;) {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (contents.EndsWith(&lt;span style="COLOR: maroon"&gt;"\r"&lt;/span&gt;))
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//
assigning content deletes the footnote number but search and replace works&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; currentParagraph.Search(currentParagraph.Contents, &lt;span style="COLOR: blue"&gt;false&lt;/span&gt;, &lt;span style="COLOR: blue"&gt;true&lt;/span&gt;,
contents.Substring(0, contents.Length - 1));
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; footNotesFixed
+= &lt;span style="COLOR: maroon"&gt;" "&lt;/span&gt; + currentFootNote.Index.ToString();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;span style="COLOR: blue"&gt;catch&lt;/span&gt; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; footNotesFixed;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
This sample removes the carriage return at the end of the footnotes that word usually
lefts.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=d57337b5-b4da-4cb0-ad22-595379ca24ad" /&gt;</description>
      <comments>http://www.manuelabadia.com/blog/CommentView,guid,d57337b5-b4da-4cb0-ad22-595379ca24ad.aspx</comments>
      <category>Microsoft .NET Framework</category>
    </item>
  </channel>
</rss>