<?xml version="1.0"?><?xml-stylesheet type="text/xsl" href="http://www.codeplex.com/rss.xsl"?><rss version="2.0"><channel><title>Toad, a .net compiler playground</title><link>http://www.codeplex.com/toad/Project/ProjectRss.aspx</link><description>Toad, .net compiler playground</description><item><title>New Post: System.Linq.Expressions?</title><link>http://www.codeplex.com/toad/Thread/View.aspx?ThreadId=30412</link><description>&lt;div style="line-height: normal;"&gt;Hi - I stumbled on Toad looking for a way to generate IL from System.Linq.Expressions trees.&amp;nbsp; Unusually I actually *want* the IL and not the compiled delegate.&amp;nbsp; Any ideas if Toad could handle this? (or maybe&amp;nbsp;a &amp;quot;Toad Lite&amp;quot; is in the works?).&lt;br&gt;
&lt;br&gt;
Thanks.
&lt;/div&gt;</description><author>BobStrogg</author><pubDate>Fri, 27 Jun 2008 18:23:16 GMT</pubDate><guid isPermaLink="false">New Post: System.Linq.Expressions? 20080627062316P</guid></item><item><title>Source code checked in</title><link>http://www.codeplex.com/toad/SourceControl/ListDownloadableCommits.aspx</link><description></description><author>pelikhan</author><pubDate>Sun, 10 Feb 2008 21:52:01 GMT</pubDate><guid isPermaLink="false">Source code checked in 20080210095201P</guid></item><item><title>Source code checked in</title><link>http://www.codeplex.com/toad/SourceControl/ListDownloadableCommits.aspx</link><description>added CSharp language</description><author>pelikhan</author><pubDate>Sun, 08 Jul 2007 19:07:02 GMT</pubDate><guid isPermaLink="false">Source code checked in 20070708070702P</guid></item><item><title>UPDATED WIKI: Home</title><link>http://www.codeplex.com/toad/Wiki/View.aspx?title=Home&amp;version=18</link><description>&lt;div class="wikidoc"&gt;
&lt;h4&gt;
Toad, a framework for building toy compilers and languages in .net.
&lt;/h4&gt;&lt;i&gt;made while commuting&lt;/i&gt;&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Toad&lt;/b&gt; is a framework to play around building languages and compiler for .net. Toad provides an AST (expression and statement tree) which gets compiled to &lt;a href="http://www.codeplex.com/toad/Wiki/View.aspx?title=MSIL&amp;amp;referringTitle=Home"&gt;MSIL&lt;/a&gt; using &lt;a href="http://www.codeplex.com/toad/Wiki/View.aspx?title=Reflection.Emit&amp;amp;referringTitle=Home"&gt;Reflection.Emit&lt;/a&gt;. Toad also comes with a set of visitors to solve common task such as inferring variable types, computing closures, optimization string concats or refactoring to some extent.&lt;br /&gt; &lt;br /&gt;&lt;ul&gt;
&lt;li&gt;Curious? Check out &lt;a href="http://www.codeplex.com/toad/Wiki/View.aspx?title=Hello%20World&amp;amp;referringTitle=Home"&gt;Hello World&lt;/a&gt; or &lt;a href="http://www.codeplex.com/toad/Wiki/View.aspx?title=Simple%20Xml%20Serializer%20Compiler&amp;amp;referringTitle=Home"&gt;a simple Xml serializer compiler&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeplex.com/toad/Wiki/View.aspx?title=User%20Manual&amp;amp;referringTitle=Home"&gt;User Manual&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://blog.dotnetwiki.org" class="externalLink"&gt;Peli's blog&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;&lt;h6&gt;
Disclaimer
&lt;/h6&gt;&lt;i&gt;Toad was written to get a better understanding of what it takes to build languages.... during my daily work commute&lt;/i&gt;&lt;br /&gt;&lt;ul&gt;
&lt;li&gt;&lt;i&gt;It is not meant to be complete and certaintly not used in production.&lt;/i&gt;&lt;/li&gt;&lt;li&gt;&lt;i&gt;Toad does not understand the DLR (currently)&lt;/i&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;</description><author>pelikhan</author><pubDate>Sun, 20 May 2007 17:06:30 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Home 20070520050630P</guid></item><item><title>UPDATED WIKI: Home</title><link>http://www.codeplex.com/toad/Wiki/View.aspx?title=Home&amp;version=17</link><description>&lt;div class="wikidoc"&gt;
&lt;h4&gt;
Toad, a framework for building toy compilers and languages in .net.
&lt;/h4&gt;&lt;i&gt;made while commuting&lt;/i&gt;&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Toad&lt;/b&gt; is a framework to play around building languages and compiler for .net. Toad provides an AST (expression and statement tree) which gets compiled to &lt;a href="http://www.codeplex.com/toad/Wiki/View.aspx?title=MSIL&amp;amp;referringTitle=Home"&gt;MSIL&lt;/a&gt; using &lt;a href="http://www.codeplex.com/toad/Wiki/View.aspx?title=Reflection.Emit&amp;amp;referringTitle=Home"&gt;Reflection.Emit&lt;/a&gt;. Toad also comes with a set of visitors to solve common task such as inferring variable types, computing closures, optimization string concats or refactoring to some extent.&lt;br /&gt; &lt;br /&gt;&lt;ul&gt;
&lt;li&gt;Curious? Check out &lt;a href="http://www.codeplex.com/toad/Wiki/View.aspx?title=Hello%20World&amp;amp;referringTitle=Home"&gt;Hello World&lt;/a&gt; or &lt;a href="http://www.codeplex.com/toad/Wiki/View.aspx?title=Simple%20Xml%20Serializer%20Compiler&amp;amp;referringTitle=Home"&gt;a simple Xml serializer compiler&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeplex.com/toad/Wiki/View.aspx?title=User%20Manual&amp;amp;referringTitle=Home"&gt;User Manual&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://blog.dotnetwiki.org" class="externalLink"&gt;Peli's blog&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;&lt;h6&gt;
Disclaimer
&lt;/h6&gt;&lt;i&gt;Toad was written to get a better understanding of what it takes to build languages.... during my commute sessions&lt;/i&gt;&lt;br /&gt;&lt;ul&gt;
&lt;li&gt;&lt;i&gt;It is not meant to be complete and certaintly not used in production.&lt;/i&gt;&lt;/li&gt;&lt;li&gt;&lt;i&gt;Toad does not understand the DLR (currently)&lt;/i&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;</description><author>pelikhan</author><pubDate>Sun, 20 May 2007 17:06:08 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Home 20070520050608P</guid></item><item><title>UPDATED WIKI: Home</title><link>http://www.codeplex.com/toad/Wiki/View.aspx?title=Home&amp;version=16</link><description>&lt;div class="wikidoc"&gt;
&lt;h4&gt;
Toad, a framework for building toy compilers and languages in .net.
&lt;/h4&gt;&lt;i&gt;made while commuting&lt;/i&gt;&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Toad&lt;/b&gt; is a framework to play around building languages and compiler for .net. Toad provides an AST (expression and statement tree) which gets compiled to &lt;a href="http://www.codeplex.com/toad/Wiki/View.aspx?title=MSIL&amp;amp;referringTitle=Home"&gt;MSIL&lt;/a&gt; using &lt;a href="http://www.codeplex.com/toad/Wiki/View.aspx?title=Reflection.Emit&amp;amp;referringTitle=Home"&gt;Reflection.Emit&lt;/a&gt;. Toad also comes with a set of visitors to solve common task such as inferring variable types, computing closures, optimization string concats or refactoring to some extent.&lt;br /&gt; &lt;br /&gt;&lt;ul&gt;
&lt;li&gt;Curious? Check out &lt;a href="http://www.codeplex.com/toad/Wiki/View.aspx?title=Hello%20World&amp;amp;referringTitle=Home"&gt;Hello World&lt;/a&gt; or &lt;a href="http://www.codeplex.com/toad/Wiki/View.aspx?title=Simple%20Xml%20Serializer%20Compiler&amp;amp;referringTitle=Home"&gt;a simple Xml serializer compiler&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeplex.com/toad/Wiki/View.aspx?title=User%20Manual&amp;amp;referringTitle=Home"&gt;User Manual&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://blog.dotnetwiki.org" class="externalLink"&gt;Peli's blog&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;_Toad was written to get a better understanding of what it takes to build languages.... during my commute sessions.&lt;br /&gt;&lt;ul&gt;
&lt;li&gt;&lt;i&gt;It is not meant to be complete and certaintly not used in production.&lt;/i&gt;&lt;/li&gt;&lt;li&gt;&lt;i&gt;Toad does not understand the DLR (currently)&lt;/i&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;</description><author>pelikhan</author><pubDate>Sun, 20 May 2007 17:05:51 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Home 20070520050551P</guid></item><item><title>UPDATED WIKI: Home</title><link>http://www.codeplex.com/toad/Wiki/View.aspx?title=Home&amp;version=15</link><description>&lt;div class="wikidoc"&gt;
&lt;h4&gt;
Toad, a framework for building toy compilers and languages in .net.
&lt;/h4&gt;&lt;i&gt;made while commuting&lt;/i&gt;&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Toad&lt;/b&gt; is a framework to play around building languages and compiler for .net. Toad provides an AST (expression and statement tree) which gets compiled to &lt;a href="http://www.codeplex.com/toad/Wiki/View.aspx?title=MSIL&amp;amp;referringTitle=Home"&gt;MSIL&lt;/a&gt; using &lt;a href="http://www.codeplex.com/toad/Wiki/View.aspx?title=Reflection.Emit&amp;amp;referringTitle=Home"&gt;Reflection.Emit&lt;/a&gt;. Toad also comes with a set of visitors to solve common task such as inferring variable types, computing closures, optimization string concats or refactoring to some extent.&lt;br /&gt; &lt;br /&gt;&lt;ul&gt;
&lt;li&gt;Curious? Check out &lt;a href="http://www.codeplex.com/toad/Wiki/View.aspx?title=Hello%20World&amp;amp;referringTitle=Home"&gt;Hello World&lt;/a&gt; or &lt;a href="http://www.codeplex.com/toad/Wiki/View.aspx?title=Simple%20Xml%20Serializer%20Compiler&amp;amp;referringTitle=Home"&gt;a simple Xml serializer compiler&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeplex.com/toad/Wiki/View.aspx?title=User%20Manual&amp;amp;referringTitle=Home"&gt;User Manual&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://blog.dotnetwiki.org" class="externalLink"&gt;Peli's blog&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;_Toad was written to get a better understanding of what it takes to build languages.... during my commute sessions.&lt;br /&gt;&lt;ul&gt;
&lt;li&gt;It is not meant to be complete and certaintly not used in production.&lt;/li&gt;&lt;li&gt;Toad does not understand the DLR currently_&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;</description><author>pelikhan</author><pubDate>Sun, 20 May 2007 17:02:52 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Home 20070520050252P</guid></item><item><title>UPDATED WIKI: Simple Xml Serializer Compiler</title><link>http://www.codeplex.com/toad/Wiki/View.aspx?title=Simple Xml Serializer Compiler&amp;version=9</link><description>&lt;div class="wikidoc"&gt;
&lt;h4&gt;
Simplex Xml Serializer Compiler
&lt;/h4&gt; &lt;br /&gt;In this exercise, we will build a mini compiler that takes a &lt;span class="codeInline"&gt;Type&lt;/span&gt; annotated with some &lt;span class="codeInline"&gt;System.Xml.Serialization&lt;/span&gt; attributes and generates a lightweight serializer on the fly.&lt;br /&gt; &lt;br /&gt;&lt;h5&gt;
What we want to do...
&lt;/h5&gt; &lt;br /&gt;For the sake of simplicity we will support properties tagged with &lt;span class="codeInline"&gt;XmlAttributeAttribute&lt;/span&gt; and &lt;span class="codeInline"&gt;XmlElementAttribute&lt;/span&gt;, in which cases the property can be an array as well. Let's this with an example:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
public class Foo
{
    [XmlAttribute]
    public string Name {get;set;}
 
    [XmlElement]
    public Bar MyBar {get;set;}
}
 
    public class Bar
    {
        [XmlElement]
        public Foo[] Foes {get;set;}
    }
&lt;/pre&gt; &lt;br /&gt;Given a little object tree, we'll expect the serializer to produce a nice xml output:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
Foo foo = new Foo();
foo.Name = &amp;quot;Hello&amp;quot;;
foo.MyBar = new Bar();
foo.MyBar.Foes = new Foo[]{ new Foo(), new Foo(), null };
foo.MyBar.Foes[0].Name = &amp;quot;foo1&amp;quot;;
foo.MyBar.Foes[1].Name = &amp;quot;foo2&amp;quot;;
&lt;/pre&gt;gives&lt;br /&gt;&lt;pre&gt;
&amp;lt;Foo Name=&amp;quot;Hello&amp;quot;&amp;gt;
  &amp;lt;Bar&amp;gt;
    &amp;lt;Foes&amp;gt;
      &amp;lt;Foo Name=&amp;quot;foo1&amp;quot; /&amp;gt;
      &amp;lt;Foo Name=&amp;quot;foo2&amp;quot; /&amp;gt;
    &amp;lt;/Foes&amp;gt;
  &amp;lt;/Bar&amp;gt;
&amp;lt;/Foo&amp;gt;
&lt;/pre&gt; &lt;br /&gt;&lt;h4&gt;
Designing the serializer
&lt;/h4&gt; &lt;br /&gt;Given the type &lt;span class="codeInline"&gt;Foo&lt;/span&gt;, we expect the compiler to generate a method for each type &lt;span class="codeInline"&gt;Foo&lt;/span&gt; and &lt;span class="codeInline"&gt;Bar&lt;/span&gt; that works directly on a &lt;span class="codeInline"&gt;XmlWriter&lt;/span&gt;:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
void WriteFoo(XmlWriter writer, Foo target)
{
    writer.WriteStartElement(&amp;quot;Foo&amp;quot;);
    writer.WriteAttributeString(&amp;quot;Name&amp;quot;, target.Name);
    if (target.Bar != null)
        WriteBar(writer, target.Bar);
    writer.WriteEndElement();
}
 
void WriteBar(XmlWriter writer, Bar bar)
{
    writer.WriteStartElement(&amp;quot;Bar&amp;quot;);
    if (bar.Foes!=null)
    {
        writer.WriteStartElements(&amp;quot;Foes&amp;quot;);
        foreach(Foo foo in bar.Foes)
        {  
            if (foo!=null)
                WriteFoo(writer, foo); 
        }
        writer.WriteEndElement();
    }
    writer.WriteEndElement();
}
&lt;/pre&gt; &lt;br /&gt;&lt;h4&gt;
Building the compiler
&lt;/h4&gt; &lt;br /&gt;The compilation process is a 2-pass algorithm: &lt;br /&gt;&lt;ul&gt;
&lt;li&gt;collect the list of types that might be serialized by walking the property types. For each type, define new {{WriteXXX} method,&lt;/li&gt;
&lt;/ul&gt;* bake the body for each {{WriteXXX}} method&lt;br /&gt; &lt;br /&gt;The full source of this sample is in the source distribution. Let's focus on interresting parts, i.e. generating the method bodies.&lt;br /&gt; &lt;br /&gt;&lt;ul&gt;
&lt;li&gt;Write a property as argument: &lt;/li&gt;&lt;ul&gt;
&lt;li&gt;fetch the property value, &lt;/li&gt;&lt;li&gt;if the property is not a string, convert the value to &lt;span class="codeInline"&gt;string&lt;/span&gt; using &lt;span class="codeInline"&gt;XmlConvert&lt;/span&gt;,&lt;/li&gt;&lt;li&gt;invoke &lt;span class="codeInline"&gt;XmlWriter.WriteAttributeString&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;&lt;pre&gt;
PropertyInfo property = ...;
XmlAttributeAttribute xmlAttribute = Attribute.GetCustomAttribute(property, typeof(XmlAttributeAttribute)) 
    as XmlAttributeAttribute; // is this an attribute?
if (xmlAttribute!=null)
{
    // var value = target.Foo;
    Expression pvalue= Expr.Param(value).GetProperty(property);
    if (property.PropertyType != typeof(string))
    {
        // WriteAttributeString works with string
        // string value = XmlConvert.ToString(target.Foo);
        pvalue = Expr.InvokeMethod(
            typeof(XmlConvert), &amp;quot;ToString&amp;quot;, BindingFlags.Public | BindingFlags.Static, pvalue);
     }
 
     // writer.WriteAttributeString(&amp;quot;Foo&amp;quot;, XmlConvert.ToString(target.Foo);
     body.Statements.Add(
         Expr.Param(writer).InvokeMethod(
             &amp;quot;WriteAttributeString&amp;quot;, Expr.Prim(property.Name), pvalue)
         );
}
&lt;/pre&gt;&lt;ul&gt;
&lt;li&gt;Write an element:&lt;/li&gt;&lt;ul&gt;
&lt;li&gt;if the element is not null, call the corresponding &lt;span class="codeInline"&gt;WriteXXX&lt;/span&gt; method:&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;&lt;pre&gt;
// types is a dictionary containing the WriteXXX methods
MethodFactoryBase method = this.types[property.PropertyType];
 
// WriteFoo(writer, value.Foo); 
MethodInvokeExpression invoke = new MethodInvokeExpression(
    null, // static method
    (MethodInfo)method.Method,
    method.Parameters.GetParameterTypes());
invoke.Arguments.Add(Expr.Param(writer));
invoke.Arguments.Add(Expr.Param(value).GetProperty(property));
 
// if (value.Foo != null) WriteFoo(writer, value.Foo);
body.Statements.Add(
    Stm.If(
        Expr.Inequality(Expr.Param(value).GetProperty(property), Expr.Null),
        Stm.Expr(invoke)
        ) // If
    ); // Add
&lt;/pre&gt; &lt;br /&gt;&lt;ul&gt;
&lt;li&gt;Write an array of elements:&lt;/li&gt;&lt;ul&gt;
&lt;li&gt;check that the array is not null,&lt;/li&gt;&lt;li&gt;create a &lt;span class="codeInline"&gt;foreach&lt;/span&gt; loop that invokes the corresponding &lt;span class="codeInline"&gt;WriteXXX&lt;/span&gt; method. Even better, &lt;b&gt;Toad&lt;/b&gt; supports adding a condition on the foreach (i.e. &lt;span class="codeInline"&gt;foreach ... where&lt;/span&gt;) so we can filter out null elements in the array:&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;&lt;pre&gt;
//  foreach(Foo foo in target.Foes where foo != null)
ForEachStatement fe = Stm.ForEach(
    property.PropertyType.GetElementType(),
    &amp;quot;item&amp;quot;,
    Expr.Param(value).GetProperty(property));
// where x != null                               
fe.WhereExpression = Expr.Inequality(Expr.Var(fe.Variable), Expr.Null);
 
// WriteFoo(writer, foo);    
MethodFactoryBase method = this.types[property.PropertyType.GetElementType()];
MethodInvokeExpression invoke = new MethodInvokeExpression(...);
invoke.Arguments.Add(Expr.Param(writer));
invoke.Arguments.Add(Expr.Var(fe.Variable));
 
// foreach(...) { WriteFoo(writer, foo); }
fe.Body = Stm.Expr(invoke);
 
// if (value.Foes != null) { foreach... }
body.Statements.Add(
    Stm.If(
        Expr.Inequality(Expr.Param(value).GetProperty(property), Expr.Null),
        fe
        )
    );
&lt;/pre&gt; &lt;br /&gt;That's it. Glue the pieces together and let Toad bake the IL for you :)&lt;br /&gt;
&lt;/div&gt;</description><author>pelikhan</author><pubDate>Sun, 20 May 2007 17:00:38 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Simple Xml Serializer Compiler 20070520050038P</guid></item><item><title>UPDATED WIKI: Simple Xml Serializer Compiler</title><link>http://www.codeplex.com/toad/Wiki/View.aspx?title=Simple Xml Serializer Compiler&amp;version=8</link><description>&lt;div class="wikidoc"&gt;
&lt;h4&gt;
Simplex Xml Serializer Compiler
&lt;/h4&gt; &lt;br /&gt;In this exercise, we will build a mini compiler that takes a &lt;span class="codeInline"&gt;Type&lt;/span&gt; annotated with some &lt;span class="codeInline"&gt;System.Xml.Serialization&lt;/span&gt; attributes and generates a lightweight serializer on the fly.&lt;br /&gt; &lt;br /&gt;&lt;h5&gt;
What we want to do...
&lt;/h5&gt; &lt;br /&gt;For the sake of simplicity we will support properties tagged with &lt;span class="codeInline"&gt;XmlAttributeAttribute&lt;/span&gt; and &lt;span class="codeInline"&gt;XmlElementAttribute&lt;/span&gt;, in which cases the property can be an array as well. Let's this with an example:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
public class Foo
{
    [XmlAttribute]
    public string Name {get;set;}
 
    [XmlElement]
    public Bar MyBar {get;set;}
}
 
    public class Bar
    {
        [XmlElement]
        public Foo[] Foes {get;set;}
    }
&lt;/pre&gt; &lt;br /&gt;Given a little object tree, we'll expect the serializer to produce a nice xml output:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
Foo foo = new Foo();
foo.Name = &amp;quot;Hello&amp;quot;;
foo.MyBar = new Bar();
foo.MyBar.Foes = new Foo[]{ new Foo(), new Foo(), null };
foo.MyBar.Foes[0].Name = &amp;quot;foo1&amp;quot;;
foo.MyBar.Foes[1].Name = &amp;quot;foo2&amp;quot;;
&lt;/pre&gt;gives&lt;br /&gt;&lt;pre&gt;
&amp;lt;Foo Name=&amp;quot;Hello&amp;quot;&amp;gt;
  &amp;lt;Bar&amp;gt;
    &amp;lt;Foes&amp;gt;
      &amp;lt;Foo Name=&amp;quot;foo1&amp;quot; /&amp;gt;
      &amp;lt;Foo Name=&amp;quot;foo2&amp;quot; /&amp;gt;
    &amp;lt;/Foes&amp;gt;
  &amp;lt;/Bar&amp;gt;
&amp;lt;/Foo&amp;gt;
&lt;/pre&gt; &lt;br /&gt;&lt;h4&gt;
Designing the serializer
&lt;/h4&gt; &lt;br /&gt;Given the type &lt;span class="codeInline"&gt;Foo&lt;/span&gt;, we expect the compiler to generate a method for each type &lt;span class="codeInline"&gt;Foo&lt;/span&gt; and &lt;span class="codeInline"&gt;Bar&lt;/span&gt; that works directly on a &lt;span class="codeInline"&gt;XmlWriter&lt;/span&gt;:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
void WriteFoo(XmlWriter writer, Foo target)
{
    writer.WriteStartElement(&amp;quot;Foo&amp;quot;);
    writer.WriteAttributeString(&amp;quot;Name&amp;quot;, target.Name);
    if (target.Bar != null)
        WriteBar(writer, target.Bar);
    writer.WriteEndElement();
}
 
void WriteBar(XmlWriter writer, Bar bar)
{
    writer.WriteStartElement(&amp;quot;Bar&amp;quot;);
    if (bar.Foes!=null)
    {
        writer.WriteStartElements(&amp;quot;Foes&amp;quot;);
        foreach(Foo foo in bar.Foes)
        {  
            if (foo!=null)
                WriteFoo(writer, foo); 
        }
        writer.WriteEndElement();
    }
    writer.WriteEndElement();
}
&lt;/pre&gt; &lt;br /&gt;&lt;h4&gt;
Building the compiler
&lt;/h4&gt; &lt;br /&gt;The compilation process is a 2-pass algorithm: &lt;br /&gt;&lt;ul&gt;
&lt;li&gt;collect the list of types that might be serialized by walking the property types. For each type, define new {{WriteXXX} method,&lt;/li&gt;
&lt;/ul&gt;* bake the body for each {{WriteXXX}} method&lt;br /&gt; &lt;br /&gt;The full source of this sample is in the source distribution. Let's focus on interresting parts, i.e. generating the method bodies.&lt;br /&gt; &lt;br /&gt;&lt;ul&gt;
&lt;li&gt;Write a property as argument: &lt;/li&gt;&lt;ul&gt;
&lt;li&gt;fetch the property value, &lt;/li&gt;&lt;li&gt;if the property is not a string, convert the value to &lt;span class="codeInline"&gt;string&lt;/span&gt; using &lt;span class="codeInline"&gt;XmlConvert&lt;/span&gt;,&lt;/li&gt;&lt;li&gt;invoke &lt;span class="codeInline"&gt;XmlWriter.WriteAttributeString&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;&lt;pre&gt;
PropertyInfo property = ...;
XmlAttributeAttribute xmlAttribute = Attribute.GetCustomAttribute(property, typeof(XmlAttributeAttribute)) 
    as XmlAttributeAttribute; // is this an attribute?
if (xmlAttribute!=null)
{
    // var value = target.Foo;
    Expression pvalue= Expr.Param(value).GetProperty(property);
    if (property.PropertyType != typeof(string))
    {
        // WriteAttributeString works with string
        // string value = XmlConvert.ToString(target.Foo);
        pvalue = Expr.InvokeMethod(
            typeof(XmlConvert), &amp;quot;ToString&amp;quot;, BindingFlags.Public | BindingFlags.Static, pvalue);
     }
 
     // writer.WriteAttributeString(&amp;quot;Foo&amp;quot;, XmlConvert.ToString(target.Foo);
     body.Statements.Add(
         Expr.Param(writer).InvokeMethod(
             &amp;quot;WriteAttributeString&amp;quot;, Expr.Prim(property.Name), pvalue)
         );
}
&lt;/pre&gt;&lt;ul&gt;
&lt;li&gt;Write an element:&lt;/li&gt;&lt;ul&gt;
&lt;li&gt;if the element is not null, call the corresponding &lt;span class="codeInline"&gt;WriteXXX&lt;/span&gt; method:&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;&lt;pre&gt;
// types is a dictionary containing the WriteXXX methods
MethodFactoryBase method = this.types[property.PropertyType];
 
// WriteFoo(writer, value.Foo); 
MethodInvokeExpression invoke = new MethodInvokeExpression(
    null, // static method
    (MethodInfo)method.Method,
    method.Parameters.GetParameterTypes());
invoke.Arguments.Add(Expr.Param(writer));
invoke.Arguments.Add(Expr.Param(value).GetProperty(property));
 
// if (value.Foo != null) WriteFoo(writer, value.Foo);
body.Statements.Add(
    Stm.If(
        Expr.Inequality(Expr.Param(value).GetProperty(property), Expr.Null),
        Stm.Expr(invoke)
        ) // If
    ); // Add
&lt;/pre&gt; &lt;br /&gt;&lt;ul&gt;
&lt;li&gt;Write an array of elements:&lt;/li&gt;&lt;ul&gt;
&lt;li&gt;check that the array is not null,&lt;/li&gt;&lt;li&gt;create a &lt;span class="codeInline"&gt;foreach&lt;/span&gt; loop that invokes the corresponding &lt;span class="codeInline"&gt;WriteXXX&lt;/span&gt; method. Even better, &lt;b&gt;Toad&lt;/b&gt; supports adding a condition on the foreach (i.e. &lt;span class="codeInline"&gt;foreach ... where&lt;/span&gt;) so we can filter out null elements in the array:&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;&lt;pre&gt;
//  foreach(Foo foo in target.Foes where foo != null)
ForEachStatement fe = Stm.ForEach(
    property.PropertyType.GetElementType(),
    &amp;quot;item&amp;quot;,
    Expr.Param(value).GetProperty(property));
// where x != null                               
fe.WhereExpression = Expr.Inequality(Expr.Var(fe.Variable), Expr.Null);
 
// WriteFoo(writer, foo);    
MethodFactoryBase method = this.types[property.PropertyType.GetElementType()];
MethodInvokeExpression invoke = new MethodInvokeExpression(...);
invoke.Arguments.Add(Expr.Param(writer));
invoke.Arguments.Add(Expr.Var(fe.Variable));
 
// foreach(...) { WriteFoo(writer, foo); }
fe.Body = Stm.Expr(invoke);
 
// if (value.Foes != null) { foreach... }
body.Statements.Add(
    Stm.If(
        Expr.Inequality(Expr.Param(value).GetProperty(property), Expr.Null),
        fe
        )
    );
&lt;/pre&gt;
&lt;/div&gt;</description><author>pelikhan</author><pubDate>Sun, 20 May 2007 16:59:55 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Simple Xml Serializer Compiler 20070520045955P</guid></item><item><title>UPDATED WIKI: Simple Xml Serializer Compiler</title><link>http://www.codeplex.com/toad/Wiki/View.aspx?title=Simple Xml Serializer Compiler&amp;version=7</link><description>&lt;div class="wikidoc"&gt;
&lt;h4&gt;
Simplex Xml Serializer Compiler
&lt;/h4&gt; &lt;br /&gt;In this exercise, we will build a mini compiler that takes a &lt;span class="codeInline"&gt;Type&lt;/span&gt; annotated with some &lt;span class="codeInline"&gt;System.Xml.Serialization&lt;/span&gt; attributes and generates a lightweight serializer on the fly.&lt;br /&gt; &lt;br /&gt;&lt;h5&gt;
What we want to do...
&lt;/h5&gt; &lt;br /&gt;For the sake of simplicity we will support properties tagged with &lt;span class="codeInline"&gt;XmlAttributeAttribute&lt;/span&gt; and &lt;span class="codeInline"&gt;XmlElementAttribute&lt;/span&gt;, in which cases the property can be an array as well. Let's this with an example:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
public class Foo
{
    [XmlAttribute]
    public string Name {get;set;}
 
    [XmlElement]
    public Bar MyBar {get;set;}
}
 
    public class Bar
    {
        [XmlElement]
        public Foo[] Foes {get;set;}
    }
&lt;/pre&gt; &lt;br /&gt;Given a little object tree, we'll expect the serializer to produce a nice xml output:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
Foo foo = new Foo();
foo.Name = &amp;quot;Hello&amp;quot;;
foo.MyBar = new Bar();
foo.MyBar.Foes = new Foo[]{ new Foo(), new Foo(), null };
foo.MyBar.Foes[0].Name = &amp;quot;foo1&amp;quot;;
foo.MyBar.Foes[1].Name = &amp;quot;foo2&amp;quot;;
&lt;/pre&gt;gives&lt;br /&gt;&lt;pre&gt;
&amp;lt;Foo Name=&amp;quot;Hello&amp;quot;&amp;gt;
  &amp;lt;Bar&amp;gt;
    &amp;lt;Foes&amp;gt;
      &amp;lt;Foo Name=&amp;quot;foo1&amp;quot; /&amp;gt;
      &amp;lt;Foo Name=&amp;quot;foo2&amp;quot; /&amp;gt;
    &amp;lt;/Foes&amp;gt;
  &amp;lt;/Bar&amp;gt;
&amp;lt;/Foo&amp;gt;
&lt;/pre&gt; &lt;br /&gt;&lt;h4&gt;
Designing the serializer
&lt;/h4&gt; &lt;br /&gt;Given the type &lt;span class="codeInline"&gt;Foo&lt;/span&gt;, we expect the compiler to generate a method for each type &lt;span class="codeInline"&gt;Foo&lt;/span&gt; and &lt;span class="codeInline"&gt;Bar&lt;/span&gt; that works directly on a &lt;span class="codeInline"&gt;XmlWriter&lt;/span&gt;:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
void WriteFoo(XmlWriter writer, Foo target)
{
    writer.WriteStartElement(&amp;quot;Foo&amp;quot;);
    writer.WriteAttributeString(&amp;quot;Name&amp;quot;, target.Name);
    if (target.Bar != null)
        WriteBar(writer, target.Bar);
    writer.WriteEndElement();
}
 
void WriteBar(XmlWriter writer, Bar bar)
{
    writer.WriteStartElement(&amp;quot;Bar&amp;quot;);
    if (bar.Foes!=null)
    {
        writer.WriteStartElements(&amp;quot;Foes&amp;quot;);
        foreach(Foo foo in bar.Foes)
        {  
            if (foo!=null)
                WriteFoo(writer, foo); 
        }
        writer.WriteEndElement();
    }
    writer.WriteEndElement();
}
&lt;/pre&gt; &lt;br /&gt;&lt;h4&gt;
Building the compiler
&lt;/h4&gt; &lt;br /&gt;The compilation process is a 2-pass algorithm: &lt;br /&gt;&lt;ul&gt;
&lt;li&gt;collect the list of types that might be serialized by walking the property types. For each type, define new {{WriteXXX} method,&lt;/li&gt;
&lt;/ul&gt;* bake the body for each {{WriteXXX}} method&lt;br /&gt; &lt;br /&gt;The full source of this sample is in the source distribution. Let's focus on interresting parts, i.e. generating the method bodies.&lt;br /&gt; &lt;br /&gt;&lt;ul&gt;
&lt;li&gt;Write a property as argument: &lt;/li&gt;&lt;ul&gt;
&lt;li&gt;fetch the property value, &lt;/li&gt;&lt;li&gt;if the property is not a string, convert the value to &lt;span class="codeInline"&gt;string&lt;/span&gt; using &lt;span class="codeInline"&gt;XmlConvert&lt;/span&gt;,&lt;/li&gt;&lt;li&gt;invoke &lt;span class="codeInline"&gt;XmlWriter.WriteAttributeString&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;&lt;pre&gt;
PropertyInfo property = ...;
XmlAttributeAttribute xmlAttribute = Attribute.GetCustomAttribute(property, typeof(XmlAttributeAttribute)) 
    as XmlAttributeAttribute; // is this an attribute?
if (xmlAttribute!=null)
{
    // var value = target.Foo;
    Expression pvalue= Expr.Param(value).GetProperty(property);
    if (property.PropertyType != typeof(string))
    {
        // WriteAttributeString works with string
        // string value = XmlConvert.ToString(target.Foo);
        pvalue = Expr.InvokeMethod(
            typeof(XmlConvert), &amp;quot;ToString&amp;quot;, BindingFlags.Public | BindingFlags.Static, pvalue);
     }
 
     // writer.WriteAttributeString(&amp;quot;Foo&amp;quot;, XmlConvert.ToString(target.Foo);
     body.Statements.Add(
         Expr.Param(writer).InvokeMethod(
             &amp;quot;WriteAttributeString&amp;quot;, Expr.Prim(property.Name), pvalue)
         );
}
&lt;/pre&gt;&lt;ul&gt;
&lt;li&gt;Write an element:&lt;/li&gt;&lt;ul&gt;
&lt;li&gt;if the element is not null, call the corresponding &lt;span class="codeInline"&gt;WriteXXX&lt;/span&gt; method:&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;&lt;pre&gt;
// types is a dictionary containing the WriteXXX methods
MethodFactoryBase method = this.types[property.PropertyType];
 
// WriteFoo(writer, value.Foo); 
MethodInvokeExpression invoke = new MethodInvokeExpression(
    null, // static method
    (MethodInfo)method.Method,
    method.Parameters.GetParameterTypes());
invoke.Arguments.Add(Expr.Param(writer));
invoke.Arguments.Add(Expr.Param(value).GetProperty(property));
 
// if (value.Foo != null) WriteFoo(writer, value.Foo);
body.Statements.Add(
    Stm.If(
        Expr.Inequality(Expr.Param(value).GetProperty(property), Expr.Null),
        Stm.Expr(invoke)
        ) // If
    ); // Add
&lt;/pre&gt;
&lt;/div&gt;</description><author>pelikhan</author><pubDate>Sun, 20 May 2007 16:52:58 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Simple Xml Serializer Compiler 20070520045258P</guid></item><item><title>UPDATED WIKI: Simple Xml Serializer Compiler</title><link>http://www.codeplex.com/toad/Wiki/View.aspx?title=Simple Xml Serializer Compiler&amp;version=6</link><description>&lt;div class="wikidoc"&gt;
&lt;h4&gt;
Simplex Xml Serializer Compiler
&lt;/h4&gt; &lt;br /&gt;In this exercise, we will build a mini compiler that takes a &lt;span class="codeInline"&gt;Type&lt;/span&gt; annotated with some &lt;span class="codeInline"&gt;System.Xml.Serialization&lt;/span&gt; attributes and generates a lightweight serializer on the fly.&lt;br /&gt; &lt;br /&gt;&lt;h5&gt;
What we want to do...
&lt;/h5&gt; &lt;br /&gt;For the sake of simplicity we will support properties tagged with &lt;span class="codeInline"&gt;XmlAttributeAttribute&lt;/span&gt; and &lt;span class="codeInline"&gt;XmlElementAttribute&lt;/span&gt;, in which cases the property can be an array as well. Let's this with an example:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
public class Foo
{
    [XmlAttribute]
    public string Name {get;set;}
 
    [XmlElement]
    public Bar MyBar {get;set;}
}
 
    public class Bar
    {
        [XmlElement]
        public Foo[] Foes {get;set;}
    }
&lt;/pre&gt; &lt;br /&gt;Given a little object tree, we'll expect the serializer to produce a nice xml output:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
Foo foo = new Foo();
foo.Name = &amp;quot;Hello&amp;quot;;
foo.MyBar = new Bar();
foo.MyBar.Foes = new Foo[]{ new Foo(), new Foo(), null };
foo.MyBar.Foes[0].Name = &amp;quot;foo1&amp;quot;;
foo.MyBar.Foes[1].Name = &amp;quot;foo2&amp;quot;;
&lt;/pre&gt;gives&lt;br /&gt;&lt;pre&gt;
&amp;lt;Foo Name=&amp;quot;Hello&amp;quot;&amp;gt;
  &amp;lt;Bar&amp;gt;
    &amp;lt;Foes&amp;gt;
      &amp;lt;Foo Name=&amp;quot;foo1&amp;quot; /&amp;gt;
      &amp;lt;Foo Name=&amp;quot;foo2&amp;quot; /&amp;gt;
    &amp;lt;/Foes&amp;gt;
  &amp;lt;/Bar&amp;gt;
&amp;lt;/Foo&amp;gt;
&lt;/pre&gt; &lt;br /&gt;&lt;h4&gt;
Designing the serializer
&lt;/h4&gt; &lt;br /&gt;Given the type &lt;span class="codeInline"&gt;Foo&lt;/span&gt;, we expect the compiler to generate a method for each type &lt;span class="codeInline"&gt;Foo&lt;/span&gt; and &lt;span class="codeInline"&gt;Bar&lt;/span&gt; that works directly on a &lt;span class="codeInline"&gt;XmlWriter&lt;/span&gt;:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
void WriteFoo(XmlWriter writer, Foo target)
{
    writer.WriteStartElement(&amp;quot;Foo&amp;quot;);
    writer.WriteAttributeString(&amp;quot;Name&amp;quot;, target.Name);
    if (target.Bar != null)
        WriteBar(writer, target.Bar);
    writer.WriteEndElement();
}
 
void WriteBar(XmlWriter writer, Bar bar)
{
    writer.WriteStartElement(&amp;quot;Bar&amp;quot;);
    if (bar.Foes!=null)
    {
        writer.WriteStartElements(&amp;quot;Foes&amp;quot;);
        foreach(Foo foo in bar.Foes)
        {  
            if (foo!=null)
                WriteFoo(writer, foo); 
        }
        writer.WriteEndElement();
    }
    writer.WriteEndElement();
}
&lt;/pre&gt; &lt;br /&gt;&lt;h4&gt;
Building the compiler
&lt;/h4&gt; &lt;br /&gt;The compilation process is a 2-pass algorithm: &lt;br /&gt;&lt;ul&gt;
&lt;li&gt;collect the list of types that might be serialized by walking the property types. For each type, define new {{WriteXXX} method,&lt;/li&gt;
&lt;/ul&gt;* bake the body for each {{WriteXXX}} method&lt;br /&gt; &lt;br /&gt;The full source of this sample is in the source distribution. Let's focus on interresting parts, i.e. generating the method bodies.&lt;br /&gt; &lt;br /&gt;&lt;ul&gt;
&lt;li&gt;Write a property as argument:&lt;/li&gt;
&lt;/ul&gt;&lt;pre&gt;
PropertyInfo property = ...;
XmlAttributeAttribute xmlAttribute = Attribute.GetCustomAttribute(property, typeof(XmlAttributeAttribute)) 
    as XmlAttributeAttribute; // is this an attribute?
 
if (xmlAttribute!=null)
{
    // var value = target.Foo;
    Expression pvalue= Expr.Param(value).GetProperty(property);
    if (property.PropertyType != typeof(string))
    {
        // WriteAttributeString works with string
        // string value = XmlConvert.ToString(target.Foo);
        pvalue = Expr.InvokeMethod(
            typeof(XmlConvert), &amp;quot;ToString&amp;quot;, BindingFlags.Public | BindingFlags.Static, pvalue);
     }
 
     // writer.WriteAttributeString(&amp;quot;Foo&amp;quot;, XmlConvert.ToString(target.Foo);
     body.Statements.Add(
         Expr.Param(writer).InvokeMethod(
             &amp;quot;WriteAttributeString&amp;quot;, Expr.Prim(property.Name), pvalue)
         );
}
&lt;/pre&gt;
&lt;/div&gt;</description><author>pelikhan</author><pubDate>Sun, 20 May 2007 16:48:16 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Simple Xml Serializer Compiler 20070520044816P</guid></item><item><title>UPDATED WIKI: Simple Xml Serializer Compiler</title><link>http://www.codeplex.com/toad/Wiki/View.aspx?title=Simple Xml Serializer Compiler&amp;version=5</link><description>&lt;div class="wikidoc"&gt;
&lt;h4&gt;
Simplex Xml Serializer Compiler
&lt;/h4&gt; &lt;br /&gt;In this exercise, we will build a mini compiler that takes a &lt;span class="codeInline"&gt;Type&lt;/span&gt; annotated with some &lt;span class="codeInline"&gt;System.Xml.Serialization&lt;/span&gt; attributes and generates a lightweight serializer on the fly.&lt;br /&gt; &lt;br /&gt;&lt;h5&gt;
What we want to do...
&lt;/h5&gt; &lt;br /&gt;For the sake of simplicity we will support properties tagged with &lt;span class="codeInline"&gt;XmlAttributeAttribute&lt;/span&gt; and &lt;span class="codeInline"&gt;XmlElementAttribute&lt;/span&gt;, in which cases the property can be an array as well. Let's this with an example:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
public class Foo
{
    [XmlAttribute]
    public string Name {get;set;}
 
    [XmlElement]
    public Bar MyBar {get;set;}
}
 
    public class Bar
    {
        [XmlElement]
        public Foo[] Foes {get;set;}
    }
&lt;/pre&gt; &lt;br /&gt;Given a little object tree, we'll expect the serializer to produce a nice xml output:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
Foo foo = new Foo();
foo.Name = &amp;quot;Hello&amp;quot;;
foo.MyBar = new Bar();
foo.MyBar.Foes = new Foo[]{ new Foo(), new Foo(), null };
foo.MyBar.Foes[0].Name = &amp;quot;foo1&amp;quot;;
foo.MyBar.Foes[1].Name = &amp;quot;foo2&amp;quot;;
&lt;/pre&gt;gives&lt;br /&gt;&lt;pre&gt;
&amp;lt;Foo Name=&amp;quot;Hello&amp;quot;&amp;gt;
  &amp;lt;Bar&amp;gt;
    &amp;lt;Foes&amp;gt;
      &amp;lt;Foo Name=&amp;quot;foo1&amp;quot; /&amp;gt;
      &amp;lt;Foo Name=&amp;quot;foo2&amp;quot; /&amp;gt;
    &amp;lt;/Foes&amp;gt;
  &amp;lt;/Bar&amp;gt;
&amp;lt;/Foo&amp;gt;
&lt;/pre&gt; &lt;br /&gt;&lt;h4&gt;
Designing the serializer
&lt;/h4&gt; &lt;br /&gt;Given the type &lt;span class="codeInline"&gt;Foo&lt;/span&gt;, we expect the compiler to generate a method for each type &lt;span class="codeInline"&gt;Foo&lt;/span&gt; and &lt;span class="codeInline"&gt;Bar&lt;/span&gt; that works directly on a &lt;span class="codeInline"&gt;XmlWriter&lt;/span&gt;:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
void WriteFoo(XmlWriter writer, Foo target)
{
    writer.WriteStartElement(&amp;quot;Foo&amp;quot;);
    writer.WriteAttributeString(&amp;quot;Name&amp;quot;, target.Name);
    if (target.Bar != null)
        WriteBar(writer, target.Bar);
    writer.WriteEndElement();
}
 
void WriteBar(XmlWriter writer, Bar bar)
{
    writer.WriteStartElement(&amp;quot;Bar&amp;quot;);
    if (bar.Foes!=null)
    {
        writer.WriteStartElements(&amp;quot;Foes&amp;quot;);
        foreach(Foo foo in bar.Foes)
        {  
            if (foo!=null)
                WriteFoo(writer, foo); 
        }
        writer.WriteEndElement();
    }
    writer.WriteEndElement();
}
&lt;/pre&gt; &lt;br /&gt;&lt;h4&gt;
Compiler frontend
&lt;/h4&gt; &lt;br /&gt;&lt;pre&gt;
    public delegate void XmlWriterDelegate&amp;lt;T&amp;gt;(XmlWriter writer, T value);
&lt;/pre&gt;
&lt;/div&gt;</description><author>pelikhan</author><pubDate>Sun, 20 May 2007 16:33:38 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Simple Xml Serializer Compiler 20070520043338P</guid></item><item><title>UPDATED WIKI: Simple Xml Serializer Compiler</title><link>http://www.codeplex.com/toad/Wiki/View.aspx?title=Simple Xml Serializer Compiler&amp;version=4</link><description>&lt;div class="wikidoc"&gt;
&lt;h4&gt;
Simplex Xml Serializer Compiler
&lt;/h4&gt; &lt;br /&gt;In this exercise, we will build a mini compiler that takes a &lt;span class="codeInline"&gt;Type&lt;/span&gt; annotated with some &lt;span class="codeInline"&gt;System.Xml.Serialization&lt;/span&gt; attributes and generates a lightweight serializer on the fly.&lt;br /&gt; &lt;br /&gt;&lt;h5&gt;
'Language design'
&lt;/h5&gt; &lt;br /&gt;For the sake of simplicity we will support properties tagged with &lt;span class="codeInline"&gt;XmlAttributeAttribute&lt;/span&gt; and &lt;span class="codeInline"&gt;XmlElementAttribute&lt;/span&gt;, in which cases the property can be an array as well. Let's this with an example:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
public class Foo
{
    [XmlAttribute]
    public string Name {get;set;}
 
    [XmlElement]
    public Bar MyBar {get;set;}
}
 
    public class Bar
    {
        [XmlElement]
        public Foo[] Foes {get;set;}
    }
&lt;/pre&gt; &lt;br /&gt;Given a little object tree, we'll expect the serializer to produce a nice xml output:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
Foo foo = new Foo();
foo.Name = &amp;quot;Hello&amp;quot;;
foo.MyBar = new Bar();
foo.MyBar.Foes = new Foo[]{ new Foo(), new Foo(), null };
foo.MyBar.Foes[0].Name = &amp;quot;foo1&amp;quot;;
foo.MyBar.Foes[1].Name = &amp;quot;foo2&amp;quot;;
&lt;/pre&gt;gives&lt;br /&gt;&lt;pre&gt;
&amp;lt;Foo Name=&amp;quot;Hello&amp;quot;&amp;gt;
  &amp;lt;Bar&amp;gt;
    &amp;lt;Foes&amp;gt;
      &amp;lt;Foo Name=&amp;quot;foo1&amp;quot; /&amp;gt;
      &amp;lt;Foo Name=&amp;quot;foo2&amp;quot; /&amp;gt;
    &amp;lt;/Foes&amp;gt;
  &amp;lt;/Bar&amp;gt;
&amp;lt;/Foo&amp;gt;
&lt;/pre&gt; &lt;br /&gt;Given the type &lt;span class="codeInline"&gt;Foo&lt;/span&gt;, we expect the compiler to generate a method for each type &lt;span class="codeInline"&gt;Foo&lt;/span&gt; and &lt;span class="codeInline"&gt;Bar&lt;/span&gt; that works directly on a &lt;span class="codeInline"&gt;XmlWriter&lt;/span&gt;:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
void WriteFoo(XmlWriter writer, Foo target)
{
    writer.WriteStartElement(&amp;quot;Foo&amp;quot;);
    writer.WriteAttributeString(&amp;quot;Name&amp;quot;, target.Name);
    if (target.Bar != null)
        WriteBar(writer, target.Bar);
    writer.WriteEndElement();
}
 
void WriteBar(XmlWriter writer, Bar bar)
{
    writer.WriteStartElement(&amp;quot;Bar&amp;quot;);
    if (bar.Foes!=null)
    {
        writer.WriteStartElements(&amp;quot;Foes&amp;quot;);
        foreach(Foo foo in bar.Foes)
        {  
            if (foo!=null)
                WriteFoo(writer, foo); 
        }
        writer.WriteEndElement();
    }
    writer.WriteEndElement();
}
&lt;/pre&gt; &lt;br /&gt;&lt;h4&gt;
Compiler frontend
&lt;/h4&gt; &lt;br /&gt;&lt;pre&gt;
    public delegate void XmlWriterDelegate&amp;lt;T&amp;gt;(XmlWriter writer, T value);
&lt;/pre&gt;
&lt;/div&gt;</description><author>pelikhan</author><pubDate>Sun, 20 May 2007 16:32:42 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Simple Xml Serializer Compiler 20070520043242P</guid></item><item><title>Source code checked in</title><link>http://www.codeplex.com/toad/SourceControl/ListDownloadableCommits.aspx</link><description>comestic changes</description><author>pelikhan</author><pubDate>Sun, 20 May 2007 14:52:37 GMT</pubDate><guid isPermaLink="false">Source code checked in 20070520025237P</guid></item><item><title>UPDATED WIKI: Simple Xml Serializer Compiler</title><link>http://www.codeplex.com/toad/Wiki/View.aspx?title=Simple Xml Serializer Compiler&amp;version=3</link><description>&lt;div class="wikidoc"&gt;
&lt;h4&gt;
Simplex Xml Serializer Compiler
&lt;/h4&gt; &lt;br /&gt;In this exercise, we will build a mini compiler that takes a &lt;span class="codeInline"&gt;Type&lt;/span&gt; annotated with some &lt;span class="codeInline"&gt;System.Xml.Serialization&lt;/span&gt; attributes and generates a lightweight serializer on the fly.&lt;br /&gt; &lt;br /&gt;&lt;h5&gt;
'Language design'
&lt;/h5&gt; &lt;br /&gt;For the sake of simplicity we will support properties tagged with &lt;span class="codeInline"&gt;XmlAttributeAttribute&lt;/span&gt; and &lt;span class="codeInline"&gt;XmlElementAttribute&lt;/span&gt;, in which cases the property can be an array as well. Let's this with an example:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
public class Foo
{
    [XmlAttribute]
    public string Name {get;set;}
 
    [XmlElement]
    public Bar MyBar {get;set;}
}
 
    public class Bar
    {
        [XmlElement]
        public Foo[] Foes {get;set;}
    }
&lt;/pre&gt; &lt;br /&gt;Given the type &lt;span class="codeInline"&gt;Foo&lt;/span&gt;, we expect the compiler to generate a method for each type &lt;span class="codeInline"&gt;Foo&lt;/span&gt; and &lt;span class="codeInline"&gt;Bar&lt;/span&gt; that works directly on a &lt;span class="codeInline"&gt;XmlWriter&lt;/span&gt;:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
void WriteFoo(XmlWriter writer, Foo target)
{
    writer.WriteStartElement(&amp;quot;Foo&amp;quot;);
    writer.WriteAttributeString(&amp;quot;Name&amp;quot;, target.Name);
    if (target.Bar != null)
        WriteBar(writer, target.Bar);
    writer.WriteEndElement();
}
 
void WriteBar(XmlWriter writer, Bar bar)
{
    writer.WriteStartElement(&amp;quot;Bar&amp;quot;);
    if (bar.Foes!=null)
    {
        writer.WriteStartElements(&amp;quot;Foes&amp;quot;);
        foreach(Foo foo in bar.Foes)
        {  
            if (foo!=null)
                WriteFoo(writer, foo); 
        }
        writer.WriteEndElement();
    }
    writer.WriteEndElement();
}
&lt;/pre&gt; &lt;br /&gt;&lt;h4&gt;
Compiler frontend
&lt;/h4&gt; &lt;br /&gt;&lt;pre&gt;
    public delegate void XmlWriterDelegate&amp;lt;T&amp;gt;(XmlWriter writer, T value);
&lt;/pre&gt;
&lt;/div&gt;</description><author>pelikhan</author><pubDate>Sun, 20 May 2007 14:50:53 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Simple Xml Serializer Compiler 20070520025053P</guid></item><item><title>UPDATED WIKI: Simple Xml Serializer Compiler</title><link>http://www.codeplex.com/toad/Wiki/View.aspx?title=Simple Xml Serializer Compiler&amp;version=2</link><description>&lt;div class="wikidoc"&gt;
&lt;h4&gt;
Simplex Xml Serializer Compiler
&lt;/h4&gt; &lt;br /&gt;In this exercise, we will build a mini compiler that takes a &lt;span class="codeInline"&gt;Type&lt;/span&gt; annotated with some &lt;span class="codeInline"&gt;System.Xml.Serialization&lt;/span&gt; attributes and generates a lightweight serializer on the fly.&lt;br /&gt; &lt;br /&gt;&lt;h5&gt;
'Language design'
&lt;/h5&gt; &lt;br /&gt;For the sake of simplicity we will support properties tagged with &lt;span class="codeInline"&gt;XmlAttributeAttribute&lt;/span&gt; and &lt;span class="codeInline"&gt;XmlElementAttribute&lt;/span&gt;, in which cases the property can be an array as well. Let's this with an example:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
    public class Foo
    {
        [XmlAttribute]
        public string Name {get;set;}
 
        [XmlElement]
        public Bar MyBar {get;set;}
    }
 
    public class Bar
    {
        [XmlElement]
        public Foo[] Foes {get;set;}
    }
&lt;/pre&gt; &lt;br /&gt;Given the type &lt;span class="codeInline"&gt;Foo&lt;/span&gt;, we expect the compiler to generate a method for each type &lt;span class="codeInline"&gt;Foo&lt;/span&gt; and &lt;span class="codeInline"&gt;Bar&lt;/span&gt; that works directly on a &lt;span class="codeInline"&gt;XmlWriter&lt;/span&gt;:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
void WriteFoo(XmlWriter writer, Foo target)
{
    writer.WriteStartElement(&amp;quot;Foo&amp;quot;);
    writer.WriteAttributeString(&amp;quot;Name&amp;quot;, target.Name);
    if (target.Bar != null)
        WriteBar(writer, target.Bar);
    writer.WriteEndElement();
}
 
void WriteBar(XmlWriter writer, Bar bar)
{
    writer.WriteStartElement(&amp;quot;Bar&amp;quot;);
    if (bar.Foes!=null)
    {
        writer.WriteStartElements(&amp;quot;Foes&amp;quot;);
        foreach(Foo foo in bar.Foes)
        {  
            if (foo!=null)
                WriteFoo(writer, foo); 
        }
        writer.WriteEndElement();
    }
    writer.WriteEndElement();
}
&lt;/pre&gt; &lt;br /&gt;&lt;h4&gt;
Compiler frontend
&lt;/h4&gt; &lt;br /&gt;&lt;pre&gt;
    public delegate void XmlWriterDelegate&amp;lt;T&amp;gt;(XmlWriter writer, T value);
&lt;/pre&gt;
&lt;/div&gt;</description><author>pelikhan</author><pubDate>Sun, 20 May 2007 14:50:29 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Simple Xml Serializer Compiler 20070520025029P</guid></item><item><title>UPDATED WIKI: Simple Xml Serializer Compiler</title><link>http://www.codeplex.com/toad/Wiki/View.aspx?title=Simple Xml Serializer Compiler&amp;version=1</link><description>&lt;div class="wikidoc"&gt;
&lt;h4&gt;
Simplex Xml Serializer Compiler
&lt;/h4&gt; &lt;br /&gt;In this exercise, we will build a mini compiler that takes a &lt;span class="codeInline"&gt;Type&lt;/span&gt; annotated with some &lt;span class="codeInline"&gt;System.Xml.Serialization&lt;/span&gt; attributes and generates a lightweight serializer on the fly.&lt;br /&gt; &lt;br /&gt;&lt;h5&gt;
'Language design'
&lt;/h5&gt; &lt;br /&gt;For the sake of simplicity we will support properties tagged with &lt;span class="codeInline"&gt;XmlAttributeAttribute&lt;/span&gt; and &lt;span class="codeInline"&gt;XmlElementAttribute&lt;/span&gt;, in which cases the property can be an array as well. Let's this with an example:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
    public class Foo
    {
        [XmlAttribute]
        public string Name {get;set;}
 
        [XmlElement]
        public Bar MyBar {get;set;}
    }
 
    public class Bar
    {
        [XmlElement]
        public Foo[] Foes {get;set;}
    }
&lt;/pre&gt; &lt;br /&gt;Given the type &lt;span class="codeInline"&gt;Foo&lt;/span&gt;, we expect the compiler to generate a method for each type &lt;span class="codeInline"&gt;Foo&lt;/span&gt; and &lt;span class="codeInline"&gt;Bar&lt;/span&gt; that works directly on a &lt;span class="codeInline"&gt;XmlWriter&lt;/span&gt;:&lt;br /&gt; &lt;br /&gt;&lt;pre&gt;
void WriteFoo(XmlWriter writer, Foo target)
{
    writer.WriteStartElement(&amp;quot;Foo&amp;quot;);
    writer.WriteAttributeString(&amp;quot;Name&amp;quot;, target.Name);
    if (target.Bar != null)
        WriteBar(writer, target.Bar);
    writer.WriteEndElement();
}
 
void WriteBar(XmlWriter writer, Bar bar)
{
    writer.WriteStartElement(&amp;quot;Bar&amp;quot;);
    if (bar.Foes!=null)
    {
        writer.WriteStartElements(&amp;quot;Foes&amp;quot;);
        foreach(Foo foo in bar.Foes)
        {  WriteFoo(writer, foo); }
        writer.WriteEndElement();
    }
    writer.WriteEndElement();
}
&lt;/pre&gt; &lt;br /&gt;&lt;h4&gt;
Compiler frontend
&lt;/h4&gt; &lt;br /&gt;&lt;pre&gt;
    public delegate void XmlWriterDelegate&amp;lt;T&amp;gt;(XmlWriter writer, T value);
&lt;/pre&gt;
&lt;/div&gt;</description><author>pelikhan</author><pubDate>Sun, 20 May 2007 14:49:46 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Simple Xml Serializer Compiler 20070520024946P</guid></item><item><title>UPDATED WIKI: Home</title><link>http://www.codeplex.com/toad/Wiki/View.aspx?title=Home&amp;version=14</link><description>&lt;div class="wikidoc"&gt;
&lt;h4&gt;
Toad, a framework for building toy compilers and languages in .net.
&lt;/h4&gt;&lt;i&gt;made while commuting&lt;/i&gt;&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Toad&lt;/b&gt; is a framework to play around building languages and compiler for .net. Toad provides an AST (expression and statement tree) which gets compiled to &lt;a href="http://www.codeplex.com/toad/Wiki/View.aspx?title=MSIL&amp;amp;referringTitle=Home"&gt;MSIL&lt;/a&gt; using &lt;a href="http://www.codeplex.com/toad/Wiki/View.aspx?title=Reflection.Emit&amp;amp;referringTitle=Home"&gt;Reflection.Emit&lt;/a&gt;. Toad also comes with a set of visitors to solve common task such as inferring variable types, computing closures, optimization string concats or refactoring to some extent.&lt;br /&gt; &lt;br /&gt;&lt;ul&gt;
&lt;li&gt;Curious? Check out &lt;a href="http://www.codeplex.com/toad/Wiki/View.aspx?title=Hello%20World&amp;amp;referringTitle=Home"&gt;Hello World&lt;/a&gt; or &lt;a href="http://www.codeplex.com/toad/Wiki/View.aspx?title=Simple%20Xml%20Serializer%20Compiler&amp;amp;referringTitle=Home"&gt;a simple Xml serializer compiler&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeplex.com/toad/Wiki/View.aspx?title=User%20Manual&amp;amp;referringTitle=Home"&gt;User Manual&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://blog.dotnetwiki.org" class="externalLink"&gt;Peli's blog&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;&lt;i&gt;Toad was written to get a better understanding of what it takes to build languages.... during my commute sessions. It is not meant to be complete and certaintly not used in production&lt;/i&gt;&lt;br /&gt;
&lt;/div&gt;</description><author>pelikhan</author><pubDate>Sun, 20 May 2007 14:31:43 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Home 20070520023143P</guid></item><item><title>UPDATED WIKI: Home</title><link>http://www.codeplex.com/toad/Wiki/View.aspx?title=Home&amp;version=13</link><description>&lt;div class="wikidoc"&gt;
&lt;h4&gt;
Toad, a .net compiler playground
&lt;/h4&gt;&lt;i&gt;made while commuting&lt;/i&gt;&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Toad&lt;/b&gt; is a framework to play around building languages and compiler for .net. Toad provides an AST (expression and statement tree) which gets compiled to &lt;a href="http://www.codeplex.com/toad/Wiki/View.aspx?title=MSIL&amp;amp;referringTitle=Home"&gt;MSIL&lt;/a&gt; using &lt;a href="http://www.codeplex.com/toad/Wiki/View.aspx?title=Reflection.Emit&amp;amp;referringTitle=Home"&gt;Reflection.Emit&lt;/a&gt;. Toad also comes with a set of visitors to solve common task such as inferring variable types, computing closures, optimization string concats or refactoring to some extent.&lt;br /&gt; &lt;br /&gt;&lt;ul&gt;
&lt;li&gt;Curious? Check out &lt;a href="http://www.codeplex.com/toad/Wiki/View.aspx?title=Hello%20World&amp;amp;referringTitle=Home"&gt;Hello World&lt;/a&gt; or &lt;a href="http://www.codeplex.com/toad/Wiki/View.aspx?title=Simple%20Xml%20Serializer%20Compiler&amp;amp;referringTitle=Home"&gt;a simple Xml serializer compiler&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeplex.com/toad/Wiki/View.aspx?title=User%20Manual&amp;amp;referringTitle=Home"&gt;User Manual&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://blog.dotnetwiki.org" class="externalLink"&gt;Peli's blog&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;&lt;i&gt;Toad was written to get a better understanding of what it takes to build languages.... during my commute sessions. It is not meant to be complete and certaintly not used in production&lt;/i&gt;&lt;br /&gt;
&lt;/div&gt;</description><author>pelikhan</author><pubDate>Sun, 20 May 2007 14:29:49 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Home 20070520022949P</guid></item><item><title>UPDATED WIKI: Home</title><link>http://www.codeplex.com/toad/Wiki/View.aspx?title=Home&amp;version=12</link><description>&lt;div class="wikidoc"&gt;
&lt;h4&gt;
Toad, a .net compiler playground
&lt;/h4&gt;&lt;i&gt;made while commuting&lt;/i&gt;&lt;br /&gt; &lt;br /&gt;&lt;b&gt;Toad&lt;/b&gt; is a framework to play around building languages and compiler for .net. Toad provides an AST (expression and statement tree) which gets compiled to &lt;a href="http://www.codeplex.com/toad/Wiki/View.aspx?title=MSIL&amp;amp;referringTitle=Home"&gt;MSIL&lt;/a&gt; using &lt;a href="http://www.codeplex.com/toad/Wiki/View.aspx?title=Reflection.Emit&amp;amp;referringTitle=Home"&gt;Reflection.Emit&lt;/a&gt;. Toad also comes with a set of AST visitors to solve common task such as inferring variable types, computing closures, optimization string concats or refactoring to some extent.&lt;br /&gt; &lt;br /&gt;&lt;ul&gt;
&lt;li&gt;Curious? Check out &lt;a href="http://www.codeplex.com/toad/Wiki/View.aspx?title=Hello%20World&amp;amp;referringTitle=Home"&gt;Hello World&lt;/a&gt; or &lt;a href="http://www.codeplex.com/toad/Wiki/View.aspx?title=Simple%20Xml%20Serializer%20Compiler&amp;amp;referringTitle=Home"&gt;a simple Xml serializer compiler&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.codeplex.com/toad/Wiki/View.aspx?title=User%20Manual&amp;amp;referringTitle=Home"&gt;User Manual&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://blog.dotnetwiki.org" class="externalLink"&gt;Peli's blog&lt;span class="externalLinkIcon"&gt;&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt; &lt;br /&gt;&lt;i&gt;Toad was written to get a better understanding of what it takes to build languages.... during my commute sessions. It is not meant to be complete and certaintly not used in production&lt;/i&gt;&lt;br /&gt;
&lt;/div&gt;</description><author>pelikhan</author><pubDate>Sun, 20 May 2007 14:28:45 GMT</pubDate><guid isPermaLink="false">UPDATED WIKI: Home 20070520022845P</guid></item></channel></rss>