<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Coding Day &#187; Articles</title>
	<atom:link href="http://www.codingday.com/category/articles/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.codingday.com</link>
	<description>Adventures in Computing, Can Erten's blog</description>
	<lastBuildDate>Tue, 13 Jul 2010 12:52:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>LINQ Expression Trees-Lambdas to CodeDom Conversion</title>
		<link>http://www.codingday.com/meta-programming-with-expression-trees-lambdas-to-codedom-conversion/</link>
		<comments>http://www.codingday.com/meta-programming-with-expression-trees-lambdas-to-codedom-conversion/#comments</comments>
		<pubDate>Mon, 25 Feb 2008 00:23:34 +0000</pubDate>
		<dc:creator>Can</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Functional Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[linq]]></category>

		<guid isPermaLink="false">http://www.canerten.com/meta-programming-with-expression-trees-lambdas-to-codedom-conversion/</guid>
		<description><![CDATA[Introduction Some people are working to make the meta-programming possible. Some says as language oriented programming or domain specific language, but I prefer in general as meta-programming. For years programming languages supported to generate code with the powerful libraries or developers worked just with string concatenations and external linkers. Nowadays meta-programming is getting more and [...]]]></description>
			<content:encoded><![CDATA[<h1>Introduction</h1>
<p>Some people are working to make the meta-programming possible. Some says as language oriented programming or domain specific language, but I prefer in general as meta-programming. For years programming languages supported to generate code with the powerful libraries or developers worked just with string concatenations and external linkers.
<p>Nowadays meta-programming is getting more and more important as the domain expertise required. So the languages make meta programming possible at the compiler level with compiler directives.
<p>Indeed there a lot of ideas coming from functional programming world where everything treated as expressions.&nbsp; The code becomes data and data usage happens in the code. It should sound familiar with LINQ to SQL efforts to make this possible.<br />
<h1>Libraries</h1>
<p>.NET Framework had code generators since the beginning. CodeDom is probably the best known for tree based code generation. Codedom made possible to develop the ASP.NET engine, Windows Form designer, Web form designer, Web services wrapper LINQ entity objects and more. It is used extensively by the framework for the key technologies.
<p>Although there are other APIs in .NET framework such as System.Reflection, System.Reflection.Emit, in this post we will focus on CodeDom and the new comer Expression Trees.
<p>Expression Tree is the key API behind LINQ to SQL or IQueryable interface in general. Every query is expressed as typed trees that is parsed and converted to SQL later by the library.
<p>The syntax of expressing queries is very readable with query comprehension syntax. However sometimes I want to know about the generated tree, like actually which functions are getting involved in the query. I have used <a href="http://blogs.msdn.com/charlie/archive/2008/01/31/expression-tree-basics.aspx" target="_blank">Expression Tree Debugger Visualizer</a> to draw the tree. It is pretty handy tool but for big trees it is difficult to see what is going on. This was my main motivation actually, although we had the code, we don&#8217;t see what&#8217;s the magic going on with query comprehension.<br />
<h1>Implementation</h1>
<p>So the idea is to have the code regenerated from the tree. In the real world this will involve a parser, interpreter and some more compiler theory which requires a lot of research. And because this is just for fun and since we have a powerful CodeDom library to generate code, I tried to convert the expression tree to CodeDom tree. Than used the CodeDom to generate code in any language. Finally I wrote the extension methods so that the debuggers and my code can use it directly from the type.</p>
<p>The compiler generates automatically the expression trees if we use the proper syntax. So from the beginning we have the tree. In order to convert to CodeDom objects, we need to traverse the tree and generate the necessary CodeDom objects. So I wrote a&nbsp; tree walker that generates a CodeDom object to is parent while going to the last children. I didn&#8217;t realise how far it is going but that was it. When the tree walker finished with some more few lines of code the converter was just working. </p>
<p>I would like to put the code here as well but unfortunately it is too long for a blog post, so here are some snippets. Feel free to provide suggestions or bug reports.</p>
<p>LINQ Expression Visitor that generates CodeDom Trees
</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Collections.Generic</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Linq</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Text</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Collections.ObjectModel</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Linq.Expressions</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Reflection</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.CodeDom</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.CodeDom.Compiler</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.IO</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> ExpressionToCodedom
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span>  <span style="color: #FF0000;">class</span> CodeDomExpressionVisitor
    <span style="color: #000000;">&#123;</span>
&nbsp;
        Expression m_exp<span style="color: #008000;">;</span>
        Dictionary<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">string</span>, CodeTypeMember<span style="color: #008000;">&gt;</span> m_members<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> CodeDomExpressionVisitor<span style="color: #000000;">&#40;</span>Expression e<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            m_exp <span style="color: #008000;">=</span> e<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
        <span style="color: #0600FF;">internal</span> <span style="color: #FF0000;">string</span> GenerateSource<span style="color: #000000;">&#40;</span>CodeDomProvider codeProvider<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            StringBuilder sb <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> StringBuilder<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            TextWriter tWriter <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> IndentedTextWriter<span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> StringWriter<span style="color: #000000;">&#40;</span>sb<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            CodeCompileUnit ccu <span style="color: #008000;">=</span> GenerateCode<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            codeProvider.<span style="color: #0000FF;">GenerateCodeFromCompileUnit</span><span style="color: #000000;">&#40;</span>ccu, tWriter, <span style="color: #008000;">new</span> CodeGeneratorOptions<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            codeProvider.<span style="color: #0000FF;">Dispose</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            tWriter.<span style="color: #0000FF;">Close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF;">return</span> sb.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">internal</span> <span style="color: #FF0000;">string</span> GenerateSource<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> language<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
&nbsp;
&nbsp;
            CodeDomProvider codeProvider<span style="color: #008000;">=</span>null<span style="color: #008000;">;</span>
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>language <span style="color: #008000;">==</span> <span style="color: #666666;">&quot;cs&quot;</span><span style="color: #000000;">&#41;</span>
                codeProvider <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Microsoft.<span style="color: #0000FF;">CSharp</span>.<span style="color: #0000FF;">CSharpCodeProvider</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF;">else</span> <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>language <span style="color: #008000;">==</span> <span style="color: #666666;">&quot;vb&quot;</span><span style="color: #000000;">&#41;</span>
                codeProvider <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Microsoft.<span style="color: #0000FF;">VisualBasic</span>.<span style="color: #0000FF;">VBCodeProvider</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF;">else</span>
            <span style="color: #000000;">&#123;</span>                
&nbsp;
                    <span style="color: #0600FF;">throw</span> <span style="color: #008000;">new</span> Exception<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;make sure you are trying to load a CodeDomProvider assembly&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0600FF;">return</span> GenerateSource<span style="color: #000000;">&#40;</span>codeProvider<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span> 
&nbsp;
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> GenerateSource<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">return</span> GenerateSource<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;cs&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span> 
        <span style="color: #000000;">&#125;</span>
&nbsp;
&nbsp;
        <span style="color: #0600FF;">private</span> CodeCompileUnit GenerateCode<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            var code <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> CodeCompileUnit<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            m_members <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Dictionary<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">string</span>, CodeTypeMember<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            var LambdaTypeClass <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> CodeTypeDeclaration<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;LambdaExpression&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            var ns <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> CodeNamespace<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Runtime&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            ns.<span style="color: #0000FF;">Types</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>LambdaTypeClass<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>            
            ns.<span style="color: #0000FF;">Imports</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> CodeNamespaceImport<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;System&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008080; font-style: italic;">// add more types in case I want to compile</span>
&nbsp;
            code.<span style="color: #0000FF;">Namespaces</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>ns<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            CodeObject cEvaluationResult <span style="color: #008000;">=</span> Visit<span style="color: #000000;">&#40;</span>m_exp<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            var constructor <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> CodeConstructor<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>cEvaluationResult <span style="color: #008000;">is</span> CodeStatement<span style="color: #000000;">&#41;</span>
                constructor.<span style="color: #0000FF;">Statements</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>cEvaluationResult <span style="color: #0600FF;">as</span> CodeStatement<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF;">else</span> <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>cEvaluationResult <span style="color: #008000;">is</span> CodeExpression<span style="color: #000000;">&#41;</span>
                constructor.<span style="color: #0000FF;">Statements</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>cEvaluationResult <span style="color: #0600FF;">as</span> CodeExpression<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            LambdaTypeClass.<span style="color: #0000FF;">Members</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>constructor<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
&nbsp;
            <span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span>var item <span style="color: #0600FF;">in</span> m_members<span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                LambdaTypeClass.<span style="color: #0000FF;">Members</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>item.<span style="color: #0000FF;">Value</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
&nbsp;
            <span style="color: #0600FF;">return</span> code<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">virtual</span> CodeObject Visit<span style="color: #000000;">&#40;</span>Expression exp<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>exp <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
                <span style="color: #0600FF;">return</span> null<span style="color: #008000;">;</span>
            <span style="color: #0600FF;">switch</span> <span style="color: #000000;">&#40;</span>exp.<span style="color: #0000FF;">NodeType</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">Negate</span><span style="color: #008000;">:</span>
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">NegateChecked</span><span style="color: #008000;">:</span>
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">Not</span><span style="color: #008000;">:</span>
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">Convert</span><span style="color: #008000;">:</span>
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">ConvertChecked</span><span style="color: #008000;">:</span>
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">ArrayLength</span><span style="color: #008000;">:</span>
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">Quote</span><span style="color: #008000;">:</span>
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">TypeAs</span><span style="color: #008000;">:</span>
                    <span style="color: #0600FF;">return</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">VisitUnary</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>UnaryExpression<span style="color: #000000;">&#41;</span>exp<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">Add</span><span style="color: #008000;">:</span>
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">AddChecked</span><span style="color: #008000;">:</span>
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">Subtract</span><span style="color: #008000;">:</span>
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">SubtractChecked</span><span style="color: #008000;">:</span>
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">Multiply</span><span style="color: #008000;">:</span>
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">MultiplyChecked</span><span style="color: #008000;">:</span>
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">Divide</span><span style="color: #008000;">:</span>
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">Modulo</span><span style="color: #008000;">:</span>
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">And</span><span style="color: #008000;">:</span>
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">AndAlso</span><span style="color: #008000;">:</span>
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">Or</span><span style="color: #008000;">:</span>
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">OrElse</span><span style="color: #008000;">:</span>
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">LessThan</span><span style="color: #008000;">:</span>
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">LessThanOrEqual</span><span style="color: #008000;">:</span>
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">GreaterThan</span><span style="color: #008000;">:</span>
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">GreaterThanOrEqual</span><span style="color: #008000;">:</span>
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">Equal</span><span style="color: #008000;">:</span>
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">NotEqual</span><span style="color: #008000;">:</span>
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">Coalesce</span><span style="color: #008000;">:</span>
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">ArrayIndex</span><span style="color: #008000;">:</span>
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">RightShift</span><span style="color: #008000;">:</span>
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">LeftShift</span><span style="color: #008000;">:</span>
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">ExclusiveOr</span><span style="color: #008000;">:</span>
                    <span style="color: #0600FF;">return</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">VisitBinary</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>BinaryExpression<span style="color: #000000;">&#41;</span>exp<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">TypeIs</span><span style="color: #008000;">:</span>
                    <span style="color: #0600FF;">return</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">VisitTypeIs</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>TypeBinaryExpression<span style="color: #000000;">&#41;</span>exp<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">Conditional</span><span style="color: #008000;">:</span>
                    <span style="color: #0600FF;">return</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">VisitConditional</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>ConditionalExpression<span style="color: #000000;">&#41;</span>exp<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">Constant</span><span style="color: #008000;">:</span>
                    <span style="color: #0600FF;">return</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">VisitConstant</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>ConstantExpression<span style="color: #000000;">&#41;</span>exp<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">Parameter</span><span style="color: #008000;">:</span>
                    <span style="color: #0600FF;">return</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">VisitParameter</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>ParameterExpression<span style="color: #000000;">&#41;</span>exp<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">MemberAccess</span><span style="color: #008000;">:</span>
                    <span style="color: #0600FF;">return</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">VisitMemberAccess</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>MemberExpression<span style="color: #000000;">&#41;</span>exp<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">Call</span><span style="color: #008000;">:</span>
                    <span style="color: #0600FF;">return</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">VisitMethodCall</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>MethodCallExpression<span style="color: #000000;">&#41;</span>exp<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">Lambda</span><span style="color: #008000;">:</span>
                    <span style="color: #0600FF;">return</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">VisitLambda</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>LambdaExpression<span style="color: #000000;">&#41;</span>exp<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #008000;">New</span><span style="color: #008000;">:</span>
                    <span style="color: #0600FF;">return</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">VisitNew</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>NewExpression<span style="color: #000000;">&#41;</span>exp<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">NewArrayInit</span><span style="color: #008000;">:</span>
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">NewArrayBounds</span><span style="color: #008000;">:</span>
                    <span style="color: #0600FF;">return</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">VisitNewArray</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>NewArrayExpression<span style="color: #000000;">&#41;</span>exp<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">Invoke</span><span style="color: #008000;">:</span>
                    <span style="color: #0600FF;">return</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">VisitInvocation</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>InvocationExpression<span style="color: #000000;">&#41;</span>exp<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">MemberInit</span><span style="color: #008000;">:</span>
                    <span style="color: #0600FF;">return</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">VisitMemberInit</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>MemberInitExpression<span style="color: #000000;">&#41;</span>exp<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">ListInit</span><span style="color: #008000;">:</span>
                    <span style="color: #0600FF;">return</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">VisitListInit</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>ListInitExpression<span style="color: #000000;">&#41;</span>exp<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">default</span><span style="color: #008000;">:</span>
                    <span style="color: #0600FF;">throw</span> <span style="color: #008000;">new</span> Exception<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">Format</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Unhandled expression type: '{0}'&quot;</span>, exp.<span style="color: #0000FF;">NodeType</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">virtual</span> CodeObject VisitBinding<span style="color: #000000;">&#40;</span>MemberBinding binding<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>            
            <span style="color: #0600FF;">switch</span> <span style="color: #000000;">&#40;</span>binding.<span style="color: #0000FF;">BindingType</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">case</span> MemberBindingType.<span style="color: #0000FF;">Assignment</span><span style="color: #008000;">:</span>
                    <span style="color: #0600FF;">return</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">VisitMemberAssignment</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>MemberAssignment<span style="color: #000000;">&#41;</span>binding<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">case</span> MemberBindingType.<span style="color: #0000FF;">MemberBinding</span><span style="color: #008000;">:</span>
                    <span style="color: #0600FF;">return</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">VisitMemberMemberBinding</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>MemberMemberBinding<span style="color: #000000;">&#41;</span>binding<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">case</span> MemberBindingType.<span style="color: #0000FF;">ListBinding</span><span style="color: #008000;">:</span>
                    <span style="color: #0600FF;">return</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">VisitMemberListBinding</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>MemberListBinding<span style="color: #000000;">&#41;</span>binding<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">default</span><span style="color: #008000;">:</span>
                    <span style="color: #0600FF;">throw</span> <span style="color: #008000;">new</span> Exception<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">Format</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Unhandled binding type '{0}'&quot;</span>, binding.<span style="color: #0000FF;">BindingType</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">virtual</span> CodeExpression VisitElementInitializer<span style="color: #000000;">&#40;</span>ElementInit initializer<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>            
            ReadOnlyCollection<span style="color: #008000;">&lt;</span>CodeExpression<span style="color: #008000;">&gt;</span> arguments <span style="color: #008000;">=</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">VisitExpressionList</span><span style="color: #000000;">&#40;</span>initializer.<span style="color: #0000FF;">Arguments</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF;">return</span> <span style="color: #008000;">new</span> CodeMethodInvokeExpression<span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> CodeMethodReferenceExpression<span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> CodeThisReferenceExpression<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>,initializer.<span style="color: #0000FF;">AddMethod</span>.<span style="color: #0000FF;">Name</span><span style="color: #000000;">&#41;</span>, arguments.<span style="color: #0000FF;">ToArray</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>                               
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">virtual</span> CodeObject VisitUnary<span style="color: #000000;">&#40;</span>UnaryExpression u<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            CodeObject operand <span style="color: #008000;">=</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Visit</span><span style="color: #000000;">&#40;</span>u.<span style="color: #0000FF;">Operand</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF;">return</span> operand<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">private</span> CodeBinaryOperatorType BindOperant<span style="color: #000000;">&#40;</span>ExpressionType e<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">switch</span> <span style="color: #000000;">&#40;</span>e<span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">Add</span><span style="color: #008000;">:</span>
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">AddChecked</span><span style="color: #008000;">:</span>
                    <span style="color: #0600FF;">return</span> CodeBinaryOperatorType.<span style="color: #0000FF;">Add</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">And</span><span style="color: #008000;">:</span>
                    <span style="color: #0600FF;">return</span> CodeBinaryOperatorType.<span style="color: #0000FF;">BitwiseAnd</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">AndAlso</span><span style="color: #008000;">:</span>
                    <span style="color: #0600FF;">return</span> CodeBinaryOperatorType.<span style="color: #0000FF;">BooleanAnd</span><span style="color: #008000;">;</span>                  
&nbsp;
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">Or</span><span style="color: #008000;">:</span>
                    <span style="color: #0600FF;">return</span> CodeBinaryOperatorType.<span style="color: #0000FF;">BitwiseOr</span><span style="color: #008000;">;</span>                    
&nbsp;
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">OrElse</span><span style="color: #008000;">:</span>
                    <span style="color: #0600FF;">return</span> CodeBinaryOperatorType.<span style="color: #0000FF;">BooleanOr</span><span style="color: #008000;">;</span>                    
&nbsp;
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">ExclusiveOr</span><span style="color: #008000;">:</span>
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">ArrayIndex</span><span style="color: #008000;">:</span>
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">Coalesce</span><span style="color: #008000;">:</span>
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">RightShift</span><span style="color: #008000;">:</span>
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">LeftShift</span><span style="color: #008000;">:</span>
                    <span style="color: #0600FF;">throw</span> <span style="color: #008000;">new</span> NotSupportedException<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;no direct equivalent in codedom,so workarounds not implemented&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">Equal</span><span style="color: #008000;">:</span>
                    <span style="color: #0600FF;">return</span> CodeBinaryOperatorType.<span style="color: #0000FF;">IdentityEquality</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">NotEqual</span><span style="color: #008000;">:</span>
                    <span style="color: #0600FF;">return</span> CodeBinaryOperatorType.<span style="color: #0000FF;">IdentityInequality</span><span style="color: #008000;">;</span>                    
&nbsp;
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">GreaterThan</span><span style="color: #008000;">:</span>
                    <span style="color: #0600FF;">return</span> CodeBinaryOperatorType.<span style="color: #0000FF;">GreaterThan</span><span style="color: #008000;">;</span>                    
&nbsp;
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">GreaterThanOrEqual</span><span style="color: #008000;">:</span>
                    <span style="color: #0600FF;">return</span> CodeBinaryOperatorType.<span style="color: #0000FF;">GreaterThanOrEqual</span><span style="color: #008000;">;</span>                    
&nbsp;
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">LessThan</span><span style="color: #008000;">:</span>
                    <span style="color: #0600FF;">return</span> CodeBinaryOperatorType.<span style="color: #0000FF;">LessThan</span><span style="color: #008000;">;</span>                    
&nbsp;
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">LessThanOrEqual</span><span style="color: #008000;">:</span>
                    <span style="color: #0600FF;">return</span> CodeBinaryOperatorType.<span style="color: #0000FF;">LessThanOrEqual</span><span style="color: #008000;">;</span>                    
&nbsp;
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">Multiply</span><span style="color: #008000;">:</span>
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">MultiplyChecked</span><span style="color: #008000;">:</span>
                    <span style="color: #0600FF;">return</span> CodeBinaryOperatorType.<span style="color: #0000FF;">Multiply</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">Subtract</span><span style="color: #008000;">:</span>
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">SubtractChecked</span><span style="color: #008000;">:</span>
                    <span style="color: #0600FF;">return</span> CodeBinaryOperatorType.<span style="color: #0000FF;">Subtract</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">Power</span><span style="color: #008000;">:</span>
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">Divide</span><span style="color: #008000;">:</span>
                    <span style="color: #0600FF;">return</span> CodeBinaryOperatorType.<span style="color: #0000FF;">Divide</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #0600FF;">case</span> ExpressionType.<span style="color: #0000FF;">Modulo</span><span style="color: #008000;">:</span>
                    <span style="color: #0600FF;">return</span> CodeBinaryOperatorType.<span style="color: #0000FF;">Modulus</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #0600FF;">default</span><span style="color: #008000;">:</span>
                    <span style="color: #0600FF;">throw</span> <span style="color: #008000;">new</span> Exception<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;are you sure you are right?&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">virtual</span> CodeBinaryOperatorExpression VisitBinary<span style="color: #000000;">&#40;</span>BinaryExpression b<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            var left <span style="color: #008000;">=</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Visit</span><span style="color: #000000;">&#40;</span>b.<span style="color: #0000FF;">Left</span><span style="color: #000000;">&#41;</span> <span style="color: #0600FF;">as</span> CodeExpression<span style="color: #008000;">;</span>
            var right <span style="color: #008000;">=</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Visit</span><span style="color: #000000;">&#40;</span>b.<span style="color: #0000FF;">Right</span><span style="color: #000000;">&#41;</span> <span style="color: #0600FF;">as</span> CodeExpression<span style="color: #008000;">;</span>
            CodeObject conversion <span style="color: #008000;">=</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Visit</span><span style="color: #000000;">&#40;</span>b.<span style="color: #0000FF;">Conversion</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            CodeBinaryOperatorType operant <span style="color: #008000;">=</span> BindOperant<span style="color: #000000;">&#40;</span>b.<span style="color: #0000FF;">NodeType</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>           
            var condExpr <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> CodeBinaryOperatorExpression<span style="color: #000000;">&#40;</span>left, operant, right<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF;">return</span> condExpr<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">virtual</span> CodeObject VisitTypeIs<span style="color: #000000;">&#40;</span>TypeBinaryExpression b<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>            
            CodeObject expr <span style="color: #008000;">=</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Visit</span><span style="color: #000000;">&#40;</span>b.<span style="color: #0000FF;">Expression</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>          
            <span style="color: #0600FF;">return</span> expr<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">virtual</span> CodeExpression VisitConstant<span style="color: #000000;">&#40;</span>ConstantExpression c<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>c.<span style="color: #0000FF;">Value</span> <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">return</span> <span style="color: #008000;">new</span> CodePrimitiveExpression<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0600FF;">else</span> <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>c.<span style="color: #0000FF;">Value</span>.<span style="color: #0000FF;">GetType</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">IsValueType</span> <span style="color: #008000;">||</span> c.<span style="color: #0000FF;">Value</span>.<span style="color: #0000FF;">GetType</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">==</span> <span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                   <span style="color: #0600FF;">return</span> <span style="color: #008000;">new</span> CodePrimitiveExpression<span style="color: #000000;">&#40;</span>c.<span style="color: #0000FF;">Value</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0600FF;">else</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">return</span> <span style="color: #008000;">new</span> CodeVariableReferenceExpression<span style="color: #000000;">&#40;</span>c.<span style="color: #0000FF;">Value</span>.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>             
            <span style="color: #000000;">&#125;</span>                        
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">virtual</span> CodeObject VisitConditional<span style="color: #000000;">&#40;</span>ConditionalExpression c<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>            
            CodeObject test <span style="color: #008000;">=</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Visit</span><span style="color: #000000;">&#40;</span>c.<span style="color: #0000FF;">Test</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            CodeExpression ifTrue <span style="color: #008000;">=</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Visit</span><span style="color: #000000;">&#40;</span>c.<span style="color: #0000FF;">IfTrue</span><span style="color: #000000;">&#41;</span> <span style="color: #0600FF;">as</span> CodeExpression<span style="color: #008000;">;</span>
            CodeExpression ifFalse <span style="color: #008000;">=</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Visit</span><span style="color: #000000;">&#40;</span>c.<span style="color: #0000FF;">IfFalse</span><span style="color: #000000;">&#41;</span> <span style="color: #0600FF;">as</span> CodeExpression<span style="color: #008000;">;</span>
&nbsp;
            var ifStatement <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> CodeConditionStatement<span style="color: #000000;">&#40;</span>test <span style="color: #0600FF;">as</span> CodeExpression,
                                                         <span style="color: #008000;">new</span> CodeStatement<span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#123;</span><span style="color: #008000;">new</span> CodeExpressionStatement<span style="color: #000000;">&#40;</span>ifTrue<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#125;</span>, 
                                                         <span style="color: #008000;">new</span> CodeStatement<span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#123;</span><span style="color: #008000;">new</span> CodeExpressionStatement<span style="color: #000000;">&#40;</span>ifFalse<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>                    
            <span style="color: #0600FF;">return</span> ifStatement<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">virtual</span> CodeObject VisitParameter<span style="color: #000000;">&#40;</span>ParameterExpression p<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">return</span> <span style="color: #008000;">new</span> CodeArgumentReferenceExpression<span style="color: #000000;">&#40;</span>p.<span style="color: #0000FF;">Name</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>            
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">virtual</span> CodeObject VisitMemberAccess<span style="color: #000000;">&#40;</span>MemberExpression m<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
&nbsp;
            CodeObject exp <span style="color: #008000;">=</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Visit</span><span style="color: #000000;">&#40;</span>m.<span style="color: #0000FF;">Expression</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>exp <span style="color: #008000;">is</span> CodePrimitiveExpression<span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">return</span> exp<span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0600FF;">else</span>
            <span style="color: #000000;">&#123;</span>
                Type memType<span style="color: #008000;">;</span>
                <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>m.<span style="color: #0000FF;">Member</span>.<span style="color: #0000FF;">MemberType</span> <span style="color: #008000;">==</span> MemberTypes.<span style="color: #0000FF;">Field</span><span style="color: #000000;">&#41;</span>
                    memType <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>m.<span style="color: #0000FF;">Member</span> <span style="color: #0600FF;">as</span> FieldInfo<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">FieldType</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">else</span> memType <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>m.<span style="color: #0000FF;">Member</span> <span style="color: #0600FF;">as</span> PropertyInfo<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">PropertyType</span><span style="color: #008000;">;</span>
&nbsp;
&nbsp;
                m_members<span style="color: #000000;">&#91;</span>m.<span style="color: #0000FF;">Member</span>.<span style="color: #0000FF;">Name</span><span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> CodeMemberField<span style="color: #000000;">&#40;</span>memType, m.<span style="color: #0000FF;">Member</span>.<span style="color: #0000FF;">Name</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">return</span> <span style="color: #008000;">new</span> CodeVariableReferenceExpression<span style="color: #000000;">&#40;</span>m.<span style="color: #0000FF;">Member</span>.<span style="color: #0000FF;">Name</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>    
&nbsp;
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">virtual</span> CodeObject VisitMethodCall<span style="color: #000000;">&#40;</span>MethodCallExpression m<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>           
            CodeObject obj <span style="color: #008000;">=</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Visit</span><span style="color: #000000;">&#40;</span>m.<span style="color: #FF0000;">Object</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            IEnumerable<span style="color: #008000;">&lt;</span>CodeExpression<span style="color: #008000;">&gt;</span> args <span style="color: #008000;">=</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">VisitExpressionList</span><span style="color: #000000;">&#40;</span>m.<span style="color: #0000FF;">Arguments</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>obj <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>  <span style="color: #008080; font-style: italic;">//static method call</span>
                <span style="color: #0600FF;">return</span> <span style="color: #008000;">new</span> CodeMethodInvokeExpression<span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> CodeTypeReferenceExpression<span style="color: #000000;">&#40;</span>m.<span style="color: #0000FF;">Method</span>.<span style="color: #0000FF;">DeclaringType</span><span style="color: #000000;">&#41;</span>,m.<span style="color: #0000FF;">Method</span>.<span style="color: #0000FF;">Name</span>,args.<span style="color: #0000FF;">ToArray</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>                
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0600FF;">else</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">return</span> <span style="color: #008000;">new</span> CodeMethodInvokeExpression<span style="color: #000000;">&#40;</span>obj <span style="color: #0600FF;">as</span> CodeExpression, m.<span style="color: #0000FF;">Method</span>.<span style="color: #0000FF;">Name</span>, args.<span style="color: #0000FF;">ToArray</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>   
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">virtual</span> ReadOnlyCollection<span style="color: #008000;">&lt;</span>CodeExpression<span style="color: #008000;">&gt;</span> VisitExpressionList<span style="color: #000000;">&#40;</span>ReadOnlyCollection<span style="color: #008000;">&lt;</span>Expression<span style="color: #008000;">&gt;</span> original<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            List<span style="color: #008000;">&lt;</span>CodeExpression<span style="color: #008000;">&gt;</span> list <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span>CodeExpression<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span>, n <span style="color: #008000;">=</span> original.<span style="color: #0000FF;">Count</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> n<span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                CodeExpression p <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>CodeExpression<span style="color: #000000;">&#41;</span><span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Visit</span><span style="color: #000000;">&#40;</span>original<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>                
                    list.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>p<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>                
            <span style="color: #000000;">&#125;</span>            
            <span style="color: #0600FF;">return</span> list.<span style="color: #0000FF;">AsReadOnly</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">virtual</span> CodeExpression VisitMemberAssignment<span style="color: #000000;">&#40;</span>MemberAssignment assignment<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span><span style="color: #008080; font-style: italic;">// thhose are properties</span>
&nbsp;
            CodeObject e <span style="color: #008000;">=</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Visit</span><span style="color: #000000;">&#40;</span>assignment.<span style="color: #0000FF;">Expression</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF;">return</span> e <span style="color: #0600FF;">as</span> CodeExpression<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">virtual</span> CodeObject VisitMemberMemberBinding<span style="color: #000000;">&#40;</span>MemberMemberBinding binding<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
&nbsp;
            IEnumerable<span style="color: #008000;">&lt;</span>CodeExpression<span style="color: #008000;">&gt;</span> bindings <span style="color: #008000;">=</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">VisitBindingList</span><span style="color: #000000;">&#40;</span>binding.<span style="color: #0000FF;">Bindings</span><span style="color: #000000;">&#41;</span> <span style="color: #0600FF;">as</span> IEnumerable<span style="color: #008000;">&lt;</span>CodeExpression<span style="color: #008000;">&gt;;</span>
            <span style="color: #0600FF;">return</span> <span style="color: #008000;">new</span> CodeObjectCreateExpression<span style="color: #000000;">&#40;</span>binding.<span style="color: #0000FF;">Member</span>.<span style="color: #0000FF;">Name</span>, bindings.<span style="color: #0000FF;">ToArray</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>            
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">virtual</span> CodeObject VisitMemberListBinding<span style="color: #000000;">&#40;</span>MemberListBinding binding<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
&nbsp;
            IEnumerable<span style="color: #008000;">&lt;</span>CodeExpression<span style="color: #008000;">&gt;</span> initializers <span style="color: #008000;">=</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">VisitElementInitializerList</span><span style="color: #000000;">&#40;</span>binding.<span style="color: #0000FF;">Initializers</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF;">return</span> <span style="color: #008000;">new</span> CodeObjectCreateExpression<span style="color: #000000;">&#40;</span>binding.<span style="color: #0000FF;">Member</span>.<span style="color: #0000FF;">Name</span>, initializers.<span style="color: #0000FF;">ToArray</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">virtual</span> IEnumerable<span style="color: #008000;">&lt;</span>CodeExpression<span style="color: #008000;">&gt;</span> VisitBindingList<span style="color: #000000;">&#40;</span>ReadOnlyCollection<span style="color: #008000;">&lt;</span>MemberBinding<span style="color: #008000;">&gt;</span> original<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            List<span style="color: #008000;">&lt;</span>CodeExpression<span style="color: #008000;">&gt;</span> list <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span>CodeExpression<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span>, n <span style="color: #008000;">=</span> original.<span style="color: #0000FF;">Count</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> n<span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                CodeExpression b <span style="color: #008000;">=</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">VisitBinding</span><span style="color: #000000;">&#40;</span>original<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span> <span style="color: #0600FF;">as</span> CodeExpression<span style="color: #008000;">;</span>
&nbsp;
                    list.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>b<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0600FF;">return</span> list<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">virtual</span> IEnumerable<span style="color: #008000;">&lt;</span>CodeExpression<span style="color: #008000;">&gt;</span> VisitElementInitializerList<span style="color: #000000;">&#40;</span>ReadOnlyCollection<span style="color: #008000;">&lt;</span>ElementInit<span style="color: #008000;">&gt;</span> original<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            List<span style="color: #008000;">&lt;</span>CodeExpression<span style="color: #008000;">&gt;</span> list <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span>CodeExpression<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span>, n <span style="color: #008000;">=</span> original.<span style="color: #0000FF;">Count</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> n<span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                CodeExpression init <span style="color: #008000;">=</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">VisitElementInitializer</span><span style="color: #000000;">&#40;</span>original<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                list.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>init<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #000000;">&#125;</span>
&nbsp;
            <span style="color: #0600FF;">return</span> list<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">protected</span> CodeMethodReferenceExpression VisitLambda<span style="color: #000000;">&#40;</span>LambdaExpression lambda<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            var  body <span style="color: #008000;">=</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Visit</span><span style="color: #000000;">&#40;</span>lambda.<span style="color: #0000FF;">Body</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            var lambdaMethod <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> CodeMemberMethod<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            lambdaMethod.<span style="color: #0000FF;">Name</span> <span style="color: #008000;">=</span> lambda.<span style="color: #0000FF;">Type</span>.<span style="color: #0000FF;">Name</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>lambdaMethod.<span style="color: #0000FF;">Name</span>.<span style="color: #0000FF;">Contains</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Func&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
                lambdaMethod.<span style="color: #0000FF;">ReturnType</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> CodeTypeReference<span style="color: #000000;">&#40;</span>lambda.<span style="color: #0000FF;">Body</span>.<span style="color: #0000FF;">Type</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span>var item <span style="color: #0600FF;">in</span> lambda.<span style="color: #0000FF;">Parameters</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                lambdaMethod.<span style="color: #0000FF;">Parameters</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> CodeParameterDeclarationExpression<span style="color: #000000;">&#40;</span>item.<span style="color: #0000FF;">Type</span>, item.<span style="color: #0000FF;">Name</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
&nbsp;
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>body <span style="color: #008000;">is</span> CodeExpression<span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>lambdaMethod.<span style="color: #0000FF;">ReturnType</span>.<span style="color: #0000FF;">BaseType</span>.<span style="color: #0000FF;">Contains</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Void&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
                    lambdaMethod.<span style="color: #0000FF;">Statements</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>body <span style="color: #0600FF;">as</span> CodeExpression <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #0600FF;">else</span>
                    lambdaMethod.<span style="color: #0000FF;">Statements</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> CodeMethodReturnStatement<span style="color: #000000;">&#40;</span>body <span style="color: #0600FF;">as</span> CodeExpression<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0600FF;">else</span> <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>body <span style="color: #008000;">is</span> CodeStatement<span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                    lambdaMethod.<span style="color: #0000FF;">Statements</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>body <span style="color: #0600FF;">as</span> CodeStatement<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0600FF;">else</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">throw</span> <span style="color: #008000;">new</span> Exception<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;investigate...&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
&nbsp;
            m_members<span style="color: #000000;">&#91;</span>lambda.<span style="color: #0000FF;">Type</span>.<span style="color: #0000FF;">FullName</span><span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> lambdaMethod<span style="color: #008000;">;</span>
            <span style="color: #0600FF;">return</span> <span style="color: #008000;">new</span> CodeMethodReferenceExpression<span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> CodeThisReferenceExpression<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>, lambdaMethod.<span style="color: #0000FF;">Name</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">virtual</span> CodeObject VisitNew<span style="color: #000000;">&#40;</span>NewExpression nex<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>            
            IEnumerable<span style="color: #008000;">&lt;</span>CodeExpression<span style="color: #008000;">&gt;</span> args <span style="color: #008000;">=</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">VisitExpressionList</span><span style="color: #000000;">&#40;</span>nex.<span style="color: #0000FF;">Arguments</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
&nbsp;
            <span style="color: #0600FF;">return</span> <span style="color: #008000;">new</span> CodeObjectCreateExpression<span style="color: #000000;">&#40;</span>nex.<span style="color: #0000FF;">Type</span>.<span style="color: #0000FF;">Name</span>,args.<span style="color: #0000FF;">ToArray</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">virtual</span> CodeObject VisitMemberInit<span style="color: #000000;">&#40;</span>MemberInitExpression init<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            CodeObject n <span style="color: #008000;">=</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">VisitNew</span><span style="color: #000000;">&#40;</span>init.<span style="color: #0000FF;">NewExpression</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            CodeExpression<span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> bindings <span style="color: #008000;">=</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">VisitBindingList</span><span style="color: #000000;">&#40;</span>init.<span style="color: #0000FF;">Bindings</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">ToArray</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">//binding will return property initialisation</span>
&nbsp;
&nbsp;
            <span style="color: #0600FF;">for</span> <span style="color: #000000;">&#40;</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> init.<span style="color: #0000FF;">Bindings</span>.<span style="color: #0000FF;">Count</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #000000;">&#41;</span>            
            <span style="color: #000000;">&#123;</span>
                                                                    <span style="color: #008080; font-style: italic;">// need to do something with that////</span>
                var assignProperty <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> CodeAssignStatement<span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> CodePropertyReferenceExpression<span style="color: #000000;">&#40;</span>
                            n <span style="color: #0600FF;">as</span> CodeExpression, init.<span style="color: #0000FF;">Bindings</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">Member</span>.<span style="color: #0000FF;">Name</span><span style="color: #000000;">&#41;</span>, bindings<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>                                   
&nbsp;
            <span style="color: #0600FF;">return</span> n<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">virtual</span> CodeObject VisitListInit<span style="color: #000000;">&#40;</span>ListInitExpression init<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
&nbsp;
            CodeObject n <span style="color: #008000;">=</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">VisitNew</span><span style="color: #000000;">&#40;</span>init.<span style="color: #0000FF;">NewExpression</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            IEnumerable<span style="color: #008000;">&lt;</span>CodeExpression<span style="color: #008000;">&gt;</span> initializers <span style="color: #008000;">=</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">VisitElementInitializerList</span><span style="color: #000000;">&#40;</span>init.<span style="color: #0000FF;">Initializers</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF;">return</span> n<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">virtual</span> CodeObject VisitNewArray<span style="color: #000000;">&#40;</span>NewArrayExpression na<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
&nbsp;
            IEnumerable<span style="color: #008000;">&lt;</span>CodeExpression<span style="color: #008000;">&gt;</span> exprs <span style="color: #008000;">=</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">VisitExpressionList</span><span style="color: #000000;">&#40;</span>na.<span style="color: #0000FF;">Expressions</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
&nbsp;
            <span style="color: #0600FF;">return</span> <span style="color: #008000;">new</span> CodeArrayCreateExpression<span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> CodeTypeReference<span style="color: #000000;">&#40;</span>na.<span style="color: #0000FF;">Type</span><span style="color: #000000;">&#41;</span>, exprs.<span style="color: #0000FF;">ToArray</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">virtual</span> CodeObject VisitInvocation<span style="color: #000000;">&#40;</span>InvocationExpression iv<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>            
            IEnumerable<span style="color: #008000;">&lt;</span>CodeExpression<span style="color: #008000;">&gt;</span> args <span style="color: #008000;">=</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">VisitExpressionList</span><span style="color: #000000;">&#40;</span>iv.<span style="color: #0000FF;">Arguments</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            var expr <span style="color: #008000;">=</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Visit</span><span style="color: #000000;">&#40;</span>iv.<span style="color: #0000FF;">Expression</span><span style="color: #000000;">&#41;</span> <span style="color: #0600FF;">as</span> CodeExpression<span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF;">return</span> <span style="color: #008000;">new</span> CodeMethodInvokeExpression<span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> CodeMethodReferenceExpression<span style="color: #000000;">&#40;</span>expr, <span style="color: #666666;">&quot;Method&quot;</span><span style="color: #000000;">&#41;</span>, args.<span style="color: #0000FF;">ToArray</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>            
        <span style="color: #000000;">&#125;</span>      
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>
<div class='download-link'>
							<a href='http://www.codingday.com/download.php?file=http://www.codingday.com/downloads/Expression_Source.zip'><img alt='Download' class='leftalign' src='http://www.codingday.com/wp-content/plugins/dBeautifier/icons/tar.png' /></a>
							<h4>
								<a href='http://www.codingday.com/download.php?file=http://www.codingday.com/downloads/Expression_Source.zip'>Expression Tree to CodeDom Source Code</a>
							</h4><p>Downloads: 235  File Name: Expression_Source.zip</p>
						</div><br />
<div class='download-link'>
							<a href='http://www.codingday.com/download.php?file=http://www.codingday.com/downloads/ExpressionToCodedom.dll'><img alt='Download' class='leftalign' src='http://www.codingday.com/wp-content/plugins/dBeautifier/icons/downloads.png' /></a>
							<h4>
								<a href='http://www.codingday.com/download.php?file=http://www.codingday.com/downloads/ExpressionToCodedom.dll'>Expression Tree to CodeDom DLL</a>
							</h4><p>Downloads: 129  File Name: ExpressionToCodedom.dll</p>
						</div>
</p>
<h1>Example</h1>
<p>The extension methods enables to see the source code of any IQueryable and any Expression. Any of them have a GenerateSourceCodeMethod that gives back a string.</p>
<p><a href='http://www.codingday.com/wp-content/uploads/2008/02/visualizer.jpg' title='Expression Tree to CodeDom Visualizer'><img src='http://www.codingday.com/wp-content/uploads/2008/02/visualizer.thumbnail.jpg' alt='Expression Tree to CodeDom Visualizer' /></a></p>
<p>GenerateSourceCode(); // default C#</p>
<p>GenerateSourceCode(string language); // either cs or vb as input or&nbsp; Fully qualified name of the CodeDomProvider (like Microsoft.FSharp.Compiler.CodeDom.FSharpCodeProvider) It should be added as a reference to the project if you&#8217;re going to use it. </p>
<p>
Sample program that manipulates the expression trees and usage of CodeDom Converter with &#8220;item.GetCodeDomSource(&#8220;vb&#8221;)&#8221;</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #FF0000;">int</span> a <span style="color: #008000;">=</span> <span style="color: #FF0000;">3</span>, c <span style="color: #008000;">=</span> <span style="color: #FF0000;">2</span>, d <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
&nbsp;
var e1 <span style="color: #008000;">=</span> Expression.<span style="color: #0000FF;">Constant</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">5</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
var e2 <span style="color: #008000;">=</span> Expression.<span style="color: #0000FF;">And</span><span style="color: #000000;">&#40;</span>e1, e1<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
Expression<span style="color: #008000;">&lt;</span>Func<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">string</span>, Func<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">bool</span><span style="color: #008000;">&gt;&gt;&gt;</span> e3 <span style="color: #008000;">=</span> tbool <span style="color: #008000;">=&gt;</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=&gt;</span> a <span style="color: #008000;">&lt;</span> b <span style="color: #008000;">&amp;&amp;</span> <span style="color: #FF0000;">8</span> <span style="color: #008000;">&gt;</span> d <span style="color: #008000;">||</span> c <span style="color: #008000;">==</span> d<span style="color: #008000;">;</span>
Expression<span style="color: #008000;">&lt;</span>Func<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">bool</span><span style="color: #008000;">&gt;&gt;</span> e4 <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=&gt;</span> b <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">4</span><span style="color: #008000;">;</span>
Expression<span style="color: #008000;">&lt;</span>Func<span style="color: #008000;">&lt;</span>RecordName, <span style="color: #FF0000;">bool</span><span style="color: #008000;">&gt;&gt;</span> e5 <span style="color: #008000;">=</span> rn <span style="color: #008000;">=&gt;</span> rn.<span style="color: #0000FF;">LastName</span> <span style="color: #008000;">==</span> <span style="color: #666666;">&quot;ALFKI&quot;</span><span style="color: #008000;">;</span>
Expression<span style="color: #008000;">&lt;</span>Func<span style="color: #008000;">&lt;</span>StringBuilder<span style="color: #008000;">&gt;&gt;</span> e6 <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=&gt;</span> <span style="color: #008000;">new</span> StringBuilder <span style="color: #000000;">&#123;</span> Capacity <span style="color: #008000;">=</span> <span style="color: #FF0000;">20</span> <span style="color: #000000;">&#125;</span><span style="color: #008000;">;</span>
Expression<span style="color: #008000;">&lt;</span>Func<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">string</span>, <span style="color: #FF0000;">string</span><span style="color: #008000;">&gt;&gt;</span> e7 <span style="color: #008000;">=</span> word <span style="color: #008000;">=&gt;</span> word <span style="color: #008000;">==</span> <span style="color: #666666;">&quot;hello&quot;</span> <span style="color: #008000;">?</span> <span style="color: #666666;">&quot;yes&quot;</span> <span style="color: #008000;">:</span> <span style="color: #666666;">&quot;no&quot;</span><span style="color: #008000;">;</span>
&nbsp;
&nbsp;
<span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span>var item <span style="color: #0600FF;">in</span> <span style="color: #008000;">new</span> Expression<span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#123;</span> e1, e2, e3, e4, e5, e6,e7 <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span>item.<span style="color: #0000FF;">GetCodeDomSource</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;vb&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Visual Basic Output</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;">Namespace Runtime
&nbsp;
    <span style="color: #000080;">Public</span> Class LambdaExpression
&nbsp;
        <span style="color: #000080;">Private</span> LastName <span style="color: #000080;">As</span> <span style="color: #000080;">String</span>
&nbsp;
        <span style="color: #000080;">Private</span> <span style="color: #000080;">Sub</span> <span style="color: #000080;">New</span>()
            MyBase.<span style="color: #000080;">New</span>
            Me.Func`2
        <span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span>
&nbsp;
        <span style="color: #000080;">Private</span> <span style="color: #000080;">Function</span> Func`2(<span style="color: #000080;">ByVal</span> rn <span style="color: #000080;">As</span> Demo.Program.RecordName) <span style="color: #000080;">As</span> <span style="color: #000080;">Boolean</span>
            Return (LastName <span style="color: #000080;">Is</span> <span style="color: #800000;">&quot;ALFKI&quot;</span>)
        <span style="color: #000080;">End</span> <span style="color: #000080;">Function</span>
    <span style="color: #000080;">End</span> Class
<span style="color: #000080;">End</span> Namespace</pre></div></div>

<p>C# Output</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">namespace</span> Runtime <span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
&nbsp;
&nbsp;
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> LambdaExpression <span style="color: #000000;">&#123;</span>
&nbsp;
        <span style="color: #0600FF;">private</span> <span style="color: #FF0000;">string</span> LastName<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF;">private</span> LambdaExpression<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Func</span>`<span style="color: #FF0000;">2</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">private</span> <span style="color: #FF0000;">bool</span> Func`<span style="color: #FF0000;">2</span><span style="color: #000000;">&#40;</span>Demo.<span style="color: #0000FF;">Program</span>.<span style="color: #0000FF;">RecordName</span> rn<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">return</span> <span style="color: #000000;">&#40;</span>LastName <span style="color: #008000;">==</span> <span style="color: #666666;">&quot;ALFKI&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

</p>
<h1>Conclusion</h1>
<p>Codedom is too much C# centric, so it&#8217;s hard to make it available for every language. The difference between Code Statement  and Code Expressions  sometimes  makes it hard to convert from expression trees.  </p>
<p>
On the on the other hand Expression trees are too much LINQ oriented. They are less powerful than CodeDom but more easy to express. In expression trees everything is an expression unlike CodeDom. Some constructs are missing from expression trees like the assignment, but we will probably see the improvements in the expression trees in the future. So it might not be a true DSL or language generator, but sure it is enough to get the most of the databases. </p>
<p>There are some other more powerful meta-programming tools and libraries. F# quotation library supports all the available  full-set language features expressed as quotations. Dynamic Language Runtime is another expression tree like library focussed more on compiler developers. </p>
<p>
Finally this library is not build for runtime code conversion from expression tree to CodeDom, although it is possible. The CodeDom generated code is mainly for debugging to print the source code of the query. It might also be helpful for seeing what is going on under the hood.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codingday.com/meta-programming-with-expression-trees-lambdas-to-codedom-conversion/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Distributed Functional Programming with F# MPI Tools for .NET</title>
		<link>http://www.codingday.com/distributed-functional-programming-with-f-mpi-tools/</link>
		<comments>http://www.codingday.com/distributed-functional-programming-with-f-mpi-tools/#comments</comments>
		<pubDate>Sun, 20 Jan 2008 03:44:18 +0000</pubDate>
		<dc:creator>Can</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Concurrency]]></category>
		<category><![CDATA[Distributed]]></category>
		<category><![CDATA[F#]]></category>
		<category><![CDATA[Functional Programming]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[dll]]></category>
		<category><![CDATA[interop]]></category>
		<category><![CDATA[mpi]]></category>
		<category><![CDATA[mpich]]></category>

		<guid isPermaLink="false">http://www.canerten.com/distributed-functional-programming-with-f-mpi-tools/</guid>
		<description><![CDATA[Introduction For many years, parallel computing is an important area for research in high performance computing. Super computers dominated the industry all the time. However with the cost of obtaining a fast computer and a fast network, cluster computing considered as a good alternative. High Performance Computing market grew rapidly, mainly because of the clusters [...]]]></description>
			<content:encoded><![CDATA[<h2>Introduction</h2>
<p>For many years, parallel computing is an important area for research in high performance computing. Super computers dominated the industry all the time. However with the cost of obtaining a fast computer and a fast network, cluster computing considered as a good alternative. High Performance Computing market grew rapidly, mainly because of the clusters intensified. According to a research, clusters represent 50% of the High Performance Computing system revenue at the end of 2005.</p>
<p>The idea of cluster computing is to have many machines on a high-speed network, clusters of computers running the same program. Recently, with the invention and adoption of multi-core CPU systems for desktops, it has become even more important. MPI makes even easier for people to build supercomputers by the usage of powerful computers, high speed networks and powerful libraries.</p>
<p><a href="http://www.mpi-forum.org/" target="_blank">Message Passing Interface (MPI)</a> is the standard of message passing in a distributed computing environment. Its benefit for researchers is invaluable.</p>
<p><a href="http://www.mcs.anl.gov/research/projects/mpich2/" target="_blank">MPICH</a> is an open source, portable implementation of Message Passing Interface (MPI) for developing distributed memory application .</p>
<p>The goal of <a href="http://www.codeplex.com/fsmpitools" target="_blank">MPI Tools</a> is to make easy to write programs that runs on a cluster of machines. Also make the transition and the portability easy for existing programs in cluster. Using MPITools, it is possible to create distributed functional applications with F#. Although it is primarily developed for .NET framework, it can run on any CLI implementation.</p>
<h2>Implementation</h2>
<p>The first step involved to make MPICH available to use for F# platform. A wrapping library is implemented for MPICH. Mainly used MPICH functions made available to F#. Those MPI functions are implemented with the effective usage of types. MPI_Init,, MPI_Comm_size, MPI_Comm_rank, MPI_Finalize, MPI_Send, MPI_Recv, MPI_Abort,  MPI_Barrier, MPI_Bcast , MPI_Gather, MPI_Scatter, MPI_Reduce. In reality, you could write distributed programs with just the first six of those function as I will show on the samples.  When using the library you don&#8217;t have to worry about the types and data sizes as you usually do in C programming. The only thing important is the order of communication the same as socket programming.</p>
<p>Because MPICH is unmanaged library, it important to make the data types compatible using the interoperability libraries in .NET framework.  All of the exposed data types and functions are defined in &#8220;mpi.h&#8221; file in MPICH distribution. If you want to use a different MPI implementation then it is needed to change those functions definitions appropriately based on the documentation.</p>

<div class="wp_syntax"><div class="code"><pre class="fsharp" style="font-family:monospace;"><span style="color: #000080;">&#91;</span><span style="color: #000080;">&#93;</span>
<span style="color: #06c; font-weight: bold;">extern</span> int MPI_Send<span style="color: #000080;">&#40;</span> <span style="color: #06c; font-weight: bold;">void</span> <span style="color: #000080;">*</span>buf, int count, int MPI_Datatype,
int dest, int tag, int MPI_Comm<span style="color: #000080;">&#41;</span></pre></div></div>

<p>Once the value data types such as int, char, byte, double and float types implemented which are pretty same with C implementation. Next step was to make the reference types of the virtual machine available. Unfortunately not all reference types are possible to send out to wire because of the state or impureness of the type. The types have to be serializable in order to send or receive. To make that possible binary serialization is used and passed as a byte array to the MPI. Implementing the reference types made also possible to pass the functions and lambda functions in to the channel.</p>
<p>For the MPI development, the key factor is the data types. The parties have to agree with the file types. Also the size of the file types should be fixed in order to communicate. However the types are properly handled by the library using the sophisticated type system capabilities. In the programs the order becomes really important. In order to get to the internals of <a href="http://www.codeplex.com/fsmpitools" target="_blank">MPI Tools</a>, here is an implementation for standard MPICH type definitions and a type converter for it (shortened for simplicity).</p>

<div class="wp_syntax"><div class="code"><pre class="fsharp" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">type</span> MPI_Datatype <span style="color: #000080;">=</span>
<span style="color: #000080;">|</span> MPI_CHAR           <span style="color: #000080;">=</span>  0x4c000101
<span style="color: #000080;">|</span> MPI_SIGNED_CHAR    <span style="color: #000080;">=</span>  0x4c000118</pre></div></div>

<p>let private TypeConvert (t) =<br />
let res =<br />
match (box t) with<br />
| : ? byte    -&gt; MPI_Datatype.MPI_BYTE<br />
| : ? char    -&gt; MPI_Datatype.MPI_CHAR<br />
| _       -&gt;    failwith &#8220;not implemented data type<br />
Enum.to_int res</p>
</pre>
<p>The complicated, many parameter function calls in the unmanaged MPICH library becomes powerful function with a few arguments in the .NET library. For instance previously defined 6 argument MPI_Send function becomes a three argument polymorphic function. To make it easy, actually send function becomes in different flavours. Actually most of the communication functions come in different versions for different types. The version below is used for singular types. There are two more flavours one for arrays and other for matrix types.</p>

<div class="wp_syntax"><div class="code"><pre class="fsharp" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">let</span> send<span style="color: #000080;">&#40;</span>data,destination, tag<span style="color: #000080;">&#41;</span>
<span style="color: #000080;">'</span>a <span style="color: #000080;">*</span> int <span style="color: #000080;">*</span> int <span style="color: #000080;">-&amp;</span>gt<span style="color: #000080;">;</span> unit</pre></div></div>

<p>let sendArray(data : 'a array,destination,tag)<br />
a array * int * int -&gt; unit</p>
<p>let sendMatrix (data : matrix,destination,tag)<br />
matrix * int * int -&gt; unit
</pre>
<p>Similarly, the same pattern goes for the receive function. However, this time it is needed to specify the return type as a generic argument of the function.</p>

<div class="wp_syntax"><div class="code"><pre class="fsharp" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">let</span> receive<span style="color: #000080;">&amp;</span>lt<span style="color: #000080;">;'</span>a<span style="color: #000080;">&amp;</span>gt<span style="color: #000080;">;</span><span style="color: #000080;">&#40;</span>source,tag<span style="color: #000080;">&#41;</span>
int<span style="color: #000080;">*</span>int <span style="color: #000080;">-&amp;</span>gt<span style="color: #000080;">;</span> <span style="color: #000080;">'</span>a
&nbsp;
<span style="color: #06c; font-weight: bold;">let</span> receiveArray<span style="color: #000080;">&amp;</span>lt<span style="color: #000080;">;'</span>a<span style="color: #000080;">&amp;</span>gt<span style="color: #000080;">;</span> <span style="color: #000080;">&#40;</span>source, tag<span style="color: #000080;">&#41;</span>
int <span style="color: #000080;">*</span> int <span style="color: #000080;">-&amp;</span>gt<span style="color: #000080;">;</span> <span style="color: #000080;">'</span>a array
&nbsp;
<span style="color: #06c; font-weight: bold;">let</span> receiveMatrix<span style="color: #000080;">&#40;</span>source, tag<span style="color: #000080;">&#41;</span>
int <span style="color: #000080;">*</span> int <span style="color: #000080;">-&amp;</span>gt<span style="color: #000080;">;</span> matrix</pre></div></div>

<p>The other functions of MPI are implemented in a similar manner. You could also check the project as a tutorial as well. The library uses effectively active patterns, discriminated unions, interoperability and other functional structures</p>
<h2>Usage</h2>
<p>First of all MPICH needs to be installed prior to usage. The library is used just like another .NET library in your programs. However the execution is relatively different than usual. The programs have to be executed using the MPI daemon called "mpiexec". You could look at more on how to configure a cluster in the MPICH documentation. To run the process in n processor or processes “-n” switch needs to be given as a command line argument followed by the name of the compiled program.</p>
<p class="dos">mpiexec -n 2 test.exe</p>
<p>Here is a very simple ping pong application using <a href="http://www.codeplex.com/fsmpitools" target="_blank">MPI Tools</a>. You can find more samples on the MPI Tools Source code.</p>

<div class="wp_syntax"><div class="code"><pre class="fsharp" style="font-family:monospace;"><span style="color: #066; font-weight: bold;">#light</span>
<span style="color: #066; font-weight: bold;">#I @&quot;..\MPITools.Bindings\&quot;</span>
<span style="color: #066; font-weight: bold;">#r @&quot;MPITools.Bindings.dll&quot;</span>
<span style="color: #06c; font-weight: bold;">open</span> MPITools
MPI<span style="color: #000080;">.</span><span style="color: #505090;">initialize</span><span style="color: #000080;">&#40;</span><span style="color: #000080;">&#41;</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">let</span> procSize <span style="color: #000080;">=</span> MPI<span style="color: #000080;">.</span><span style="color: #505090;">size</span><span style="color: #000080;">&#40;</span><span style="color: #000080;">&#41;</span>
<span style="color: #06c; font-weight: bold;">let</span> curProcess <span style="color: #000080;">=</span>  MPI<span style="color: #000080;">.</span><span style="color: #505090;">rank</span><span style="color: #000080;">&#40;</span><span style="color: #000080;">&#41;</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">let</span> pingpong<span style="color: #000080;">&#40;</span><span style="color: #000080;">&#41;</span> <span style="color: #000080;">=</span>
<span style="color: #06c; font-weight: bold;">if</span> curProcess <span style="color: #000080;">=</span> <span style="color: #c6c;">0</span> <span style="color: #06c; font-weight: bold;">then</span>
<span style="color: #06c; font-weight: bold;">let</span> i <span style="color: #000080;">=</span>  <span style="color: #c6c;">0</span>
MPI<span style="color: #000080;">.</span><span style="color: #505090;">send</span><span style="color: #000080;">&#40;</span>i,<span style="color: #c6c;">1</span>,<span style="color: #c6c;">0</span><span style="color: #000080;">&#41;</span>
<span style="color: #06c; font-weight: bold;">let</span> b <span style="color: #000080;">=</span> MPI<span style="color: #000080;">.</span><span style="color: #505090;">receive</span><span style="color: #000080;">&#40;</span><span style="color: #c6c;">1</span>,<span style="color: #c6c;">0</span><span style="color: #000080;">&#41;</span>
<span style="color: #000080;">&#40;</span><span style="color: #000080;">&#41;</span>
<span style="color: #06c; font-weight: bold;">elif</span> curProcess <span style="color: #000080;">=</span> <span style="color: #c6c;">1</span> <span style="color: #06c; font-weight: bold;">then</span>
<span style="color: #06c; font-weight: bold;">let</span> b <span style="color: #000080;">=</span> MPI<span style="color: #000080;">.</span><span style="color: #505090;">receive</span><span style="color: #000080;">&#40;</span><span style="color: #c6c;">0</span>,<span style="color: #c6c;">0</span><span style="color: #000080;">&#41;</span>
MPI<span style="color: #000080;">.</span><span style="color: #505090;">send</span><span style="color: #000080;">&#40;</span>b<span style="color: #000080;">+</span><span style="color: #c6c;">1</span>,<span style="color: #c6c;">0</span>,<span style="color: #c6c;">0</span><span style="color: #000080;">&#41;</span>
pingpong<span style="color: #000080;">&#40;</span><span style="color: #000080;">&#41;</span>
MPI<span style="color: #000080;">.</span><span style="color: #505090;">finalize</span><span style="color: #000080;">&#40;</span><span style="color: #000080;">&#41;</span></pre></div></div>

<h2>Conclusion</h2>
<p>You can <a href="http://www.codeplex.com/fsmpitools">download MPI Tools</a> from codeplex. Using MPI Tools, the distributed programs will be short, expressive and well typed with the help of the glorified type system of F#.</p>
<p>MPI Tools is built with F# 1.9.3.7 Compiler for the .NET Framework 2.0. However it would possibly work with any CLI implementation. In the future, some more MPI functions will be implemented, including some helper functions that hides the imperative style programming. and the side effects.</p>
<p>I hope it will help to solve your high computation problems effectively. Please feel free to ask questions or to contribute to the project.</p>
<p>Have fun!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codingday.com/distributed-functional-programming-with-f-mpi-tools/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Power of Functional Programming, its Features and its Future</title>
		<link>http://www.codingday.com/power-of-functional-programming-its-features-and-its-future/</link>
		<comments>http://www.codingday.com/power-of-functional-programming-its-features-and-its-future/#comments</comments>
		<pubDate>Mon, 07 Jan 2008 16:08:16 +0000</pubDate>
		<dc:creator>Can</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[F#]]></category>
		<category><![CDATA[Functional Programming]]></category>
		<category><![CDATA[continuation]]></category>
		<category><![CDATA[domain specific language]]></category>
		<category><![CDATA[dsl]]></category>
		<category><![CDATA[erlang]]></category>
		<category><![CDATA[features]]></category>
		<category><![CDATA[Fun]]></category>
		<category><![CDATA[functional]]></category>
		<category><![CDATA[future]]></category>
		<category><![CDATA[lambda]]></category>
		<category><![CDATA[lisp]]></category>
		<category><![CDATA[ml]]></category>
		<category><![CDATA[monad]]></category>
		<category><![CDATA[object oriented]]></category>
		<category><![CDATA[ocaml]]></category>
		<category><![CDATA[paradigm]]></category>
		<category><![CDATA[polymorphic]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[recusion]]></category>

		<guid isPermaLink="false">http://www.canerten.com/power-of-functional-programming-its-features-and-its-future/</guid>
		<description><![CDATA[Power of Functional Programming Functional programming is one the oldest of major programming paradigms. Functional languages have been with us for a while. Languages like Lisp, Scheme, ML, OCaml, Haskell, Erlang and F# have well built compilers and tools and large user and development communities. However, the early success of the imperative programming languages made [...]]]></description>
			<content:encoded><![CDATA[<h2>Power of Functional Programming<br />
</h2>
<p>Functional programming is one the oldest of major programming paradigms. Functional languages have been with us for a while. Languages like Lisp, Scheme, ML, OCaml, Haskell, Erlang and F# have well built compilers and tools and large user and development communities. However, the early success of the imperative programming languages made the procedural languages extremely popular for more than three decades. This lead to the rise of the object-oriented paradigm and formed the basis of commercial software development. Object oriented programming is still the most popular paradigm today.
</p>
<p>Functional programming is a programming paradigm that uses the functions in their real mathematical sense. This means that functions are only computation objects where there is no mutable data and state information. This way it is more close to mathematical expressions. In contrast to imperative programming that is desperately dependent on the state of the objects, functional programming views all programs as collections of functions that accept arguments and return values.
</p>
<p>Modern functional programming languages have a number of different techniques to help program development. That includes but not limited to the
</p>
<ul>
<li><strong>Powerful typing systems</strong> : It is accomplished with the support of polymorphism, and type inference
</li>
<li><strong>Higher order functions</strong>: The higher-order functions are based on the concept of the first class values as functions mainly functions are actually like data.
</li>
<li><strong>Implicit recursion</strong>:  Implicit recursion is supported functional languages through the powerful functional data structures and also with higher-order functions such as fold, map and filter.
</li>
</ul>
<p>In programming languages, static typing means the type of expression is determined at compile by a technique called static program analysis. On the other hand dynamically typed languages, determines the types at the runtime by the aid of a runtime type checker. Personally, I like everything to be typed at the compile time with an extensive support of polymorphic types; because it allows seeing the errors at compile time and also it gives an optimised performance because there is no need for a runtime type checker. Luckily most of the functional languages benefit from the polymorphic statically typed systems.
</p>
<p>Pureness is another concept applied by some functional languages like Haskell. On the other hand, it might be a style of programming even if it is not forced by the compiler. In pure functional programming, side effects are not allowed in the program with immutable variable and no loops. Immutability means that when a value is assigned to an identifier (not a variable), it cannot change anymore. Loops can be achieved with recursive functions. This style is a bit more difficult to program and read as well, but the benefits could be massive. For instance, it might be possible to optimise the compiled code for multiple cores, because of the compositionality of the functions that form the program.
</p>
<h1>The Features of Functional Programming<br />
</h1>
<p>Functional Programming is not all about functions treated as first class values and immutable state. Functional programming also provides powerful features that every programmer should benefit.
</p>
<p><a href="http://en.wikipedia.org/wiki/Lambda_calculus">Lambda calculus</a> is a formal system designed to investigate function definition, function application and recursion. Lambda calculus could be used to define a computable function. Lambda calculus is used to develop a formal set theory. Function can be passed as an argument to other functions. There is another concept called curried functions when using lambda functions. The function reduces the term and returns another function with the normal form. This is called curried functions. In the lambda calculus, functions can only be created using another method, with higher-order functions and currying, another function creation is provided. A function in curried form is called partial application.
</p>
<p>The calculus has only functions of one argument. In the curried function systems, a function with multiple arguments is expressed using a function whose result is another function. Every argument is reduced by default and returns a function.
</p>
<p>Pattern matching is another powerful concept that functional and logic languages sport. It is used for assigning values to variables and for controlling the execution flow of a program. Pattern matching is used to match patterns with terms.  If a pattern and term have the same shape then the match will succeed and any variables occurring in the pattern will be bound to the data structures which occur in the corresponding positions in the term.
</p>
<p>Recursion is a mechanism for iterating an instruction or simply for a code reuse. By recursion it is possible to write a compact program that can help generalization. It is mainly used in functional programming.
</p>
<p>Nowadays collections are the most important data structures when writing programs in any programming languages because of the big datasets. In most of the functional languages there are special functions to make the programmers jobs easy. By the usage of first class functions and those methods ends up in a good way to handle the collections. Some of those higher-order functions are map, fold, filter etc.
</p>
<ul>
<li>Map : applies the function passed to each element of the collection. Resembles to for each loops for collections in procedural languages.
</li>
<li>Fold : applies the function to each element while sharing a resulting object. One common uses us to apply a sum operation to each member. It is similar to SQL aggregate functions but we pass the applying function.
</li>
<li>Filter : applies the filter function to each member of the collection and returns a list of object satisfying the conditional function.
</li>
</ul>
<p>Some pure languages implement those higher-order functions in a continuation style. But it could be implemented by simple loops in unpure languages as well.
</p>
<p>Functional languages help rapid prototyping with the aid of powerful type systems and usually with an interactive window that allows executing expressions one or more at a time. It enables to code complex algorithms without ignoring the mathematical representation. It is much easier to create domain-specific languages (DSLs). It improves the productivity of the developer.
</p>
<p>DSLs are specific programming languages made for use in a specific application domain. Programs written with a DSL are more clear and readable than those written with general-purpose languages.  DSLs are more declarative than the imperative languages and they focus on the problem rather than the rules of the language. Meta programming is building a program which manipulates the syntactic structures of other programs. DSLs and meta programming are closely related to each other. It is possible to build a domain specific language by the meta programming features of a language.
</p>
<h1>The Future of Functional Programming<br />
	</h1>
<p>Object oriented paradigm is crucial in programming current industrial applications. A functional language has usually been considered as an academic language but I believe that this is going to change in the real feature, because functional programming has a big potential in this demanding industry. The expressiveness, powerful unique concepts such as laziness, immutability, powerful pattern matching, continuations etc. and the elegant style of programming makes the implementation of some tools easier than other paradigms. Tools such as static analysis tools, high-level modelling, compilation, interpretation and verification tools are one of the target areas of functional programming. Moreover one of the todays hot topics domain specific languages, eventually meta programming and need for a &#8220;uniformed single language&#8221; for all solutions makes functional programming very important. Those tasks could be implemented with other languages as well, but functional languages fit better than the others. Also the distribution of tasks in multi-cores or multiple machines might be possible with functional programming if the program is written in an immutable style.
</p>
<p>Considering today&#8217;s facts, running systems, interoperability with the systems, non-functional world; using functional programming shouldn&#8217;t mean staying functional all the time. For the difficulty of some problems and previous experience of the developers it is inevitable to use procedural and object oriented paradigms. That&#8217;s how the mix functional object oriented programming emerged and affected the programming languages.
</p>
<p>Not surprisingly, some companies already work with functional programming in industry. For the moment their main areas of development is design, modelling, specification, or build compiler tools. But this is yet to change and augment.
</p>
<p><Have fun with Fun!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codingday.com/power-of-functional-programming-its-features-and-its-future/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>LINQ and XLINQ with Visual Basic Literals</title>
		<link>http://www.codingday.com/linq-and-xlinq-with-visual-basic-literals/</link>
		<comments>http://www.codingday.com/linq-and-xlinq-with-visual-basic-literals/#comments</comments>
		<pubDate>Tue, 11 Dec 2007 16:22:35 +0000</pubDate>
		<dc:creator>Can</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Search Engine]]></category>
		<category><![CDATA[Visual Basic]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[linq]]></category>
		<category><![CDATA[literal]]></category>
		<category><![CDATA[vb]]></category>
		<category><![CDATA[xlinq]]></category>

		<guid isPermaLink="false">http://www.canerten.com/linq-and-xlinq-with-visual-basic-literals/</guid>
		<description><![CDATA[I really liked the XML expressiveness of Visual Basic, let&#8217;s build a very simple MSN History Search Engine using LINQ and XML Literals in Visual Basic. The best thing is those literals could be used in LINQ expressions. Remember the simple XML file that MSN stores as a history. .@AttributeName : Accesses the attribute element [...]]]></description>
			<content:encoded><![CDATA[<p>I really liked the XML expressiveness of Visual Basic, let&#8217;s build a very simple MSN History Search Engine using LINQ and XML Literals in Visual Basic.</p>
<p>The best thing is those literals could be used in LINQ expressions. Remember the simple XML file that MSN stores as a history.</p>
<ul>
<li>.@AttributeName : Accesses the attribute element in XML</li>
<li>.&lt;ElementName&gt; : Accesses the element in XML</li>
<li>&#8230;&lt;Descendant name&gt;: Accesses the descendant name in XML</li>
</ul>
<p>Modifying the XML content is very neat as well either using the LINQ expressions or even in loops.</p>
<p>In .NET Framework 2.0 VB has one more feature called MY namespaces. It is very nice to access some dynamic data available like application or forms information. It also contains some helper functions to do some common tasks. Now I also found it very handy in a Windows Forms application.</p>
<p>Get the history files from the location and operate the XLINQ query:</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;"><span style="color: #000080;">Private</span> <span style="color: #000080;">Sub</span> btnSearch_Click(<span style="color: #000080;">ByVal</span> sender <span style="color: #000080;">As</span> System.<span style="color: #000080;">Object</span>, <span style="color: #000080;">ByVal</span> e <span style="color: #000080;">As</span> System.EventArgs)
&nbsp;
<span style="color: #000080;">For</span> <span style="color: #000080;">Each</span> file <span style="color: #000080;">In</span> My.Computer.FileSystem.GetFiles(dirLocation)
ProcessFile(file)
<span style="color: #000080;">Next</span>
txtOutput.Text = sBuild.ToString()
&nbsp;
<span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span></pre></div></div>

<p>The XLINQ query that does search magic for the messages is as follows :</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;"><span style="color: #000080;">Function</span> ProcessFile(<span style="color: #000080;">ByVal</span> s <span style="color: #000080;">As</span> <span style="color: #000080;">String</span>) <span style="color: #000080;">As</span> <span style="color: #000080;">Boolean</span>
<span style="color: #000080;">If</span> s.EndsWith(<span style="color: #800000;">&quot;xml&quot;</span>) <span style="color: #000080;">Then</span>
<span style="color: #000080;">Dim</span> msn = XElement.Load(s)
<span style="color: #000080;">Dim</span> q = From message <span style="color: #000080;">In</span> msn.&lt;message&gt; _
Where message.&lt;text&gt;.Value.Contains(txtSearch.Text) _
<span style="color: #000080;">Select</span> From = (message.&lt;from&gt;.@FriendlyName), Too = (message.&lt;to&gt;.@FriendlyNam), _
Message = message.&lt;text&gt;.Value
<span style="color: #000080;">For</span> <span style="color: #000080;">Each</span> msgFound <span style="color: #000080;">In</span> q
sBuild.AppendLine(msgFound.From + <span style="color: #800000;">&quot; says to &quot;</span> + msgFound.Too + _
<span style="color: #800000;">&quot; :  &quot;</span> + msgFound.Message)
<span style="color: #000080;">Next</span>
<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
<span style="color: #000080;">End</span> <span style="color: #000080;">Function</span></pre></div></div>

<p>What makes this different is the usage of literals. In C# that query would be longer than that.<br />
In the sample message.&lt;From&gt;.@FriendlyName<br />
means that it will get the From element and get the friendlyname attribute from it.</p>
<p>It is basically like having the XML data in your hands but there is no need to parse it or access the elements using the classes provided rather this work is done by the compiler at the compile time.</p>
<p>In a couple lines of code we have a fully featured MSN history searching. Let me know if you still want the source code (although that is all about it) or even the executable in case you are not into programming.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codingday.com/linq-and-xlinq-with-visual-basic-literals/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C# 3.0 vs. VB 9.0 and XML in the Language</title>
		<link>http://www.codingday.com/c-30-vs-vb-90-and-xml-in-the-language/</link>
		<comments>http://www.codingday.com/c-30-vs-vb-90-and-xml-in-the-language/#comments</comments>
		<pubDate>Tue, 11 Dec 2007 15:34:35 +0000</pubDate>
		<dc:creator>Can</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Articles]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Visual Basic]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[linq]]></category>
		<category><![CDATA[cs]]></category>
		<category><![CDATA[csharp]]></category>
		<category><![CDATA[macro]]></category>
		<category><![CDATA[vb]]></category>
		<category><![CDATA[xlinq]]></category>
		<category><![CDATA[xsl]]></category>
		<category><![CDATA[xslt]]></category>

		<guid isPermaLink="false">http://www.canerten.com/c-30-vs-vb-90-and-xml-in-the-language/</guid>
		<description><![CDATA[Here is the summary of new language features as mentioned on the &#8220;What&#8217;s new on ORCAS C# 3.0 Language Support: This CTP implements all of the C#3.0 language features from the May LINQ CTP including: Query Expressions Object and Collection Initializers Extension Methods Local Variable Type Inference and Anonymous Types Lambdas bound to Delegates and [...]]]></description>
			<content:encoded><![CDATA[<p>Here is the summary of new language features as mentioned on the &#8220;What&#8217;s new on ORCAS
</p>
<ul>
<li>
<div>C# 3.0 Language Support: This CTP implements all of the C#3.0 language features from the May LINQ CTP including:
				</div>
<ul>
<li>Query Expressions
					</li>
<li>Object and Collection Initializers
					</li>
<li>Extension Methods
					</li>
<li>Local Variable Type Inference and Anonymous Types
					</li>
<li>Lambdas bound to Delegates and Expression trees
					</li>
<li>
<div>Complete design-time support: Intellisense, Formatting, Colorization
</div>
</p>
</li>
</ul>
</li>
<li>
<div>VB 9.0 Language Support: This CTP contains the following language features:
				</div>
<ul>
<li>Query Expressions: Basic querying, filtering, and ordering support
					</li>
<li>Object Initializers
					</li>
<li>Extension Methods
					</li>
<li>Local Variable Type Inference
					</li>
<li>Anonymous Types
					</li>
<li>XML literals
</li>
<li>XML properties
</li>
<li>New Line and Expression IntelliSense</li>
</ul>
</li>
</ul>
<p>LINQ is all in both of the languages and indeed this is the main feature for .NET Framework 3.5. Writing any type of queries is the purpose of LINQ  at the end. Considering the abilities of LINQ, everything was possible before as well. LINQ makes us to get rid of the strings (the red coloured stuff) from the program in order to minimise the typo errors, easy to read programs by syntax highlighting. But all the best is that gives the ability to write declarative and functional style programs.
</p>
</p>
<p>Beside the new language features, as a compiler improvement, it is very surprising that C# still doesn&#8217;t have background compilation. There is background syntax checking but no compilation. I believe this is a definite need for C# because it is really helpful. For instance the F# projects do background compilation and syntax checks, that way it easy to investigate &#8220;silly errors&#8221; while coding.  Also this was one of the powerful features that I found on eclipse while working on a Java project.
</p>
<p>Visual basic has that feature moreover it has also automatic syntax fixing as well. Likewise if you call a method with lower case letters it is automatically converted to the actual method on the next line. Actually in a type inferenced language this is needed, because it is not easy to recognise the type information of all the members.
</p>
<p>Anyway I just wrote a quick macro to give the feeling of background compilation for C#. It is not really sophisticated but it works. Just put it into EnvironmentEvent macro in Visual Stuio.
</p>
</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;"><span style="color: #000080;">Dim</span> lastbuilt <span style="color: #000080;">As</span> DateTime
    <span style="color: #000080;">Private</span> <span style="color: #000080;">Sub</span> TextDocumentKeyPressEvents_AfterKeyPress(<span style="color: #000080;">ByVal</span> Keypress <span style="color: #000080;">As</span> <span style="color: #000080;">String</span>, <span style="color: #000080;">ByVal</span> Selection <span style="color: #000080;">As</span> EnvDTE.TextSelection, <span style="color: #000080;">ByVal</span> InStatementCompletion <span style="color: #000080;">As</span> <span style="color: #000080;">Boolean</span>) Handles TextDocumentKeyPressEvents.AfterKeyPress
        <span style="color: #000080;">Dim</span> doc = DTE.ActiveDocument
        <span style="color: #000080;">Dim</span> diff = DateTime.Now.Subtract(lastbuilt)
&nbsp;
        <span style="color: #000080;">If</span> <span style="color: #000080;">Not</span> Char.IsLetterOrDigit(Keypress(0)) <span style="color: #000080;">And</span> diff.Seconds &gt; 5 <span style="color: #000080;">Then</span>
            DTE.ExecuteCommand(<span style="color: #800000;">&quot;Build.BuildSelection&quot;</span>)
            lastbuilt = DateTime.Now
            doc.Activate()
        <span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
    <span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span></pre></div></div>

</p>
<h1>XML in Language<br />
</h1>
</p>
<p>All of the best is that now XML is a first class citizen in VB. I wouldn&#8217;t expect this as a serious feature but after trials it makes extremely relevant to use XML in Visual Basic. You get syntax highlighting and even intellisense for XML if the namespaces are specified and even more.
</p>
</p>
<p>Having XML literals in the language, it makes really sense to use XLinq with VB.
</p>
<p>Like consider the xml stored by messenger. You could just assign to a variable just like that.
</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">        Dim msn = <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
                  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml-stylesheet</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">'text/xsl'</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">'MessageLog.xsl'</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
                  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Log</span> <span style="color: #000066;">FirstSessionID</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000066;">LastSessionID</span>=<span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Message</span> <span style="color: #000066;">Date</span>=<span style="color: #ff0000;">&quot;25/03/2007&quot;</span> <span style="color: #000066;">Time</span>=<span style="color: #ff0000;">&quot;22:35:47&quot;</span> <span style="color: #000066;">DateTime</span>=<span style="color: #ff0000;">&quot;2007-03-25T21:35:47.173Z&quot;</span> <span style="color: #000066;">SessionID</span>=<span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;From<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;User</span> <span style="color: #000066;">FriendlyName</span>=<span style="color: #ff0000;">&quot;koko&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/From<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;To<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;User</span> <span style="color: #000066;">FriendlyName</span>=<span style="color: #ff0000;">&quot;opopop&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/To<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Text</span> <span style="color: #000066;">Style</span>=<span style="color: #ff0000;">&quot;font-family:Comic Sans MS; font-weight:bold; color:#0000a0; &quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>151515<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Text<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Message<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Message</span> <span style="color: #000066;">Date</span>=<span style="color: #ff0000;">&quot;25/03/2007&quot;</span> <span style="color: #000066;">Time</span>=<span style="color: #ff0000;">&quot;22:35:55&quot;</span> <span style="color: #000066;">DateTime</span>=<span style="color: #ff0000;">&quot;2007-03-25T21:35:55.344Z&quot;</span> <span style="color: #000066;">SessionID</span>=<span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;From<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;User</span> <span style="color: #000066;">FriendlyName</span>=<span style="color: #ff0000;">&quot;koko&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/From<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;To<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;User</span> <span style="color: #000066;">FriendlyName</span>=<span style="color: #ff0000;">&quot;opopop&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/To<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Text</span> <span style="color: #000066;">Style</span>=<span style="color: #ff0000;">&quot;font-family:Comic Sans MS; font-weight:bold; color:#0000a0; &quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>5959959<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Text<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/Message<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Log<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

</p>
<p> It will have the type of System.Xml.Linq.XDocument.
</p>
</p>
<p>Let&#8217;s define the XML Stylesheet :
</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">        Dim xslt = <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
                   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:stylesheet</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">xmlns:xsl</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/1999/XSL/Transform&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:template</span> <span style="color: #000066;">match</span>=<span style="color: #ff0000;">&quot;Log&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                           <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;html<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                               <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                                   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> Message Log for <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                               <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                               <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;body</span> <span style="color: #000066;">style</span>=<span style="color: #ff0000;">'margin:0'</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                                   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;table</span> <span style="color: #000066;">border</span>=<span style="color: #ff0000;">'1'</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                                       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tr<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                                           <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;td<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> From <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                                           <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;td<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> To <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                                           <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;td<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> Message <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                                       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tr<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                                       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:for-each</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;/Log/Message&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                                           <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tr<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                                               <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;td<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;xsl:value-of</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;From/User/@FriendlyName&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/td<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                                               <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;td<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;xsl:value-of</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;To/User/@FriendlyName&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/td<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                                               <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;td<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;xsl:value-of</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;Text&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/td<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                                           <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tr<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                                       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:for-each<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                                   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/table<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                               <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                           <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/html<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:template<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:stylesheet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

</p>
<p>If we want to do an XSLT transformation to that snippet, it is even easier than it used to be.
</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;"><span style="color: #000080;">Dim</span> xTransform = <span style="color: #000080;">New</span> System.Xml.Xsl.XslCompiledTransform()
xTransform.Load(xslt.CreateReader())
xTransform.Transform(msn.CreateReader(), <span style="color: #000080;">New</span> System.Xml.XmlTextWriter(<span style="color: #800000;">&quot;test.html&quot;</span>, <span style="color: #000080;">New</span> System.Text.UnicodeEncoding()))</pre></div></div>

</p>
<p>I think working with xml data using Visual Basic should be considered as a manipulation language. Since we are all becoming multilingual  this shouldn&#8217;t be a problem.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codingday.com/c-30-vs-vb-90-and-xml-in-the-language/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Software Agent Systems and their Applications &#8211; message based parallel programming (Erlang style)</title>
		<link>http://www.codingday.com/software-agent-systems-and-their-applications/</link>
		<comments>http://www.codingday.com/software-agent-systems-and-their-applications/#comments</comments>
		<pubDate>Fri, 15 Jun 2007 23:24:45 +0000</pubDate>
		<dc:creator>Can</dc:creator>
				<category><![CDATA[AI]]></category>
		<category><![CDATA[Articles]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[human_computer_interaction]]></category>
		<category><![CDATA[intelligent_agents]]></category>
		<category><![CDATA[research_papers]]></category>
		<category><![CDATA[software_agents]]></category>
		<category><![CDATA[software_agent_systems]]></category>

		<guid isPermaLink="false">http://www.canerten.com/software-agent-systems-and-their-applications/</guid>
		<description><![CDATA[Introduction Software agent is a program that handles the behaviour of a user or software with the aid of an agency. The software agents are not called by a user or by a process, they are acting themselves, they decide the next task to do. This drives the system to the concept of intelligent agents. [...]]]></description>
			<content:encoded><![CDATA[<h1>Introduction<br />
</h1>
<p>Software agent is a program that handles the behaviour of a user or software with the aid of an agency. The software agents are not called by a user or by a process, they are acting themselves, they decide the next task to do. This drives the system to the concept of intelligent agents.
</p>
<p>Agent system is a system composed of several software agents. It provides the collective environment for making the goals possible for individual agent. It helps the agents to communicate and delegate the task. Although software agents are considered as autonomous, all agents operate on a human supervision.
</p>
<p>For agent systems, there are no currently implemented commercial applications; however there are a lot of ongoing research projects in the software agents and agent systems area. I have read a couple of research papers in software agent systems and software agents. One of the research papers is focussing on the different architectures behind the software agent systems. The other research paper is about different implications of the software agents for different scenarios.
</p>
<p>Software agents and agent systems will be the key elements in information technology. They will solve many problems of information overload and this will change the human computer interaction. It will also change the way we develop software for large systems.
</p>
<p>It is possible to use modern agent platforms to implement large scale agent systems. They are some working applications of software agents in an e-commerce system and software agents as a resource broker in the grid.  I will try to investigate on different types of software agents and their implications.
</p>
<p>There are different types of agent systems. Intelligent agents are capable of modifying their behaviour based on their learning and reasoning. Distributed agents are executed physically in distinct machines. Multi-agent systems are basically distributed agents that are not capable of doing alone the objective. They need to talk and communicate. Mobile agents are the agents that can execute on different processors.
</p>
<h1>Software Agents and Agent Systems<br />
</h1>
<p>In real life, agents are expert people on some areas. For example a travel agent has the information needed for you to travel. They have the information and they have the connections to make the travel for us. Another example is the insurance agent, they have a deep knowledge in their fields and they provide this information for us.
</p>
<p>These are the characteristics of software agents as well. They are specialised and provide only the needed knowledge. It is possible to find, filter or customise the interaction with software agents.  Software agents will affect relatively the software evolution. We have some technologies used in software development like object orientation, and multi-threaded objects. The main concept is the execution in threads and communication between threads. Next thing will be the software agents. The agent based approach will be the revolution for building complex software systems.  They are some implications of software agents. For instance Bio-agents work on a cellular automaton. They have a simple behaviour and they don&#8217;t have any intelligence.
</p>
<p>Software agents are designed with dynamic transportations. In dynamic transportation the parts are changing, the environment does not build thousand parts. It works with real-time scheduling and it chooses the best scenario based on the real-life conditions.
</p>
<p>A tool called JADE can be used as a software agent system. In JADE, agents communicate with messages. They send and receive ACL messages. JADE also provides queue for the agents.
</p>
<p>Some real world examples exist for software agents. Agents can operate in an e-shop application. They can go to e-shop; buy some things and can kill themselves can be a simple usage of the software agents. There exist also agent systems for large distributed area like GRID systems. Agents can travel in the grid for resource broking.
</p>
<p>There are some assumptions of the agents in the grid. The agents work in teams, and each agent has a team leader. Incoming agents can join any team based on the criteria they have been created.  Teams can accept or reject the incoming agents based on their criteria of acceptance. There exists different type of architectures.  One of the approaches is the usage of thread pool. Task-per-thread paradigm is being used in that architecture.  Another approach is the use of databases. Database agents are located on remote machines contributing additional computational power.
</p>
<p>Developing high-quality industry ready is difficult to achieve.  It is one of the complex construction tasks to build software in telecommunication or other big industrial areas because of the size of the data and because of the rules to implement.
</p>
<p>I think complex software systems can be built and designed by the use of autonomous agents. It can give some advantages to the software engineers especially for some areas. GRID computing is the most complex system that can be handled with software agents.
</p>
<p>Computers are becoming more important for everyday activities of every business and every people. The speed of access to the information is less than seconds and the information is increasing exponentionally every single hour. Current software implementations are enough to handle that huge request for the moment; however without an autonomous system this task is getting harder to accomplish with the technological developments. The human driven mechanism for handling the information will collapse soon or later. This metaphor has to change from the software systems perspective. Software agents can help in organising the data without human interaction and make the data ready for people&#8217;s use.
</p>
<h1>Conclusion<br />
</h1>
<p>Agent-oriented techniques are used in many big areas. There are some experiments on the GRID computing which makes this work very important. GRID computing is very important especially in the research area. However it will be more relevant for the industry as well.
</p>
<p>JADE is one of the great multi-agent development tools that support different architectures. None of the architectures can be good for a particular solution. Each problem has different situations and each might have a different architecture.  As the research and development continues in that area, every problem will be investigated and will have a particular solution.
</p>
<p>Software agents can be applied to many different areas. Software engineers will accept the agent-based approach soon or later to make their system autonomous and intelligent.  We might see a combination of paradigms in the future. Agent-oriented concepts and techniques are well suited to developing complex and distributed systems as an extension to the current paradigms.<span style="color:black; font-family:Arial; font-size:12pt"><br />
		</span></p>
<p>Software engineering started to be like a car manufacturing company. Many things are getting automated and many software paradigms are becoming de facto standard for a particular problem. It is sometimes make the process easier; on the other hand it makes difficult to implement for some scenarios. <span style="color:black; font-family:Times New Roman; font-size:11pt"><br />
		</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.codingday.com/software-agent-systems-and-their-applications/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Collaborative System: Microsoft SharePoint Portal Server-Part 2</title>
		<link>http://www.codingday.com/collaborative-system-microsoft-sharepoint-portal-server-part-2/</link>
		<comments>http://www.codingday.com/collaborative-system-microsoft-sharepoint-portal-server-part-2/#comments</comments>
		<pubDate>Tue, 17 Apr 2007 00:57:44 +0000</pubDate>
		<dc:creator>Can</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Sharepoint]]></category>

		<guid isPermaLink="false">http://www.canerten.com/collaborative-system-microsoft-sharepoint-portal-server-part-2/</guid>
		<description><![CDATA[Technology Review The system of Microsoft SharePoint Portal Server is specified in Table 1. Table 1: SharePoint System Windows Internal Database / SQL Server 2000 ASP.NET 1.1 IIS 6 .NET Framework 1.1 Windows Server Â Â Data storage Microsoft SharePoint Portal Server stores its data in the Windows Internal Database, registry, and SQL Server 2000. [...]]]></description>
			<content:encoded><![CDATA[<h1>Technology Review<br />
</h1>
<p style="margin-left: 18pt">The system of Microsoft SharePoint Portal Server is specified in Table 1.
</p>
<p><span style="font-family:Times New Roman; font-size:10pt"><strong>Table 1: SharePoint System<br />
</strong></span></p>
<div>
<table style="border-collapse:collapse" border="0">
<colgroup>
<col style="width:189px"/>
<col style="width:189px"/>
<col style="width:189px"/></colgroup>
<tbody valign="top">
<tr>
<td rowspan="2" vAlign="middle" style="padding-left: 7px; padding-right: 7px; border-top:  solid 0.5pt; border-left:  solid 0.5pt; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt">
<p style="text-align: center"><span style="font-family:Times New Roman; font-size:10pt">Windows Internal Database /<br />
</span></p>
<p style="text-align: center"><span style="font-family:Times New Roman; font-size:10pt">SQL Server 2000</span></p>
</td>
<td colspan="2" vAlign="middle" style="padding-left: 7px; padding-right: 7px; border-top:  solid 0.5pt; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt">
<p style="text-align: center"><span style="font-family:Times New Roman; font-size:10pt">ASP.NET 1.1</span></p>
</td>
</tr>
<tr>
<td vAlign="middle" style="padding-left: 7px; padding-right: 7px; border-top:  none; border-left:  solid 0.5pt; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt">
<p style="text-align: center"><span style="font-family:Times New Roman; font-size:10pt">IIS 6</span></p>
</td>
<td vAlign="middle" style="padding-left: 7px; padding-right: 7px; border-top:  none; border-left:  none; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt">
<p style="text-align: center"><span style="font-family:Times New Roman; font-size:10pt">.NET Framework 1.1</span></p>
</td>
</tr>
<tr>
<td colspan="3" vAlign="middle" style="padding-left: 7px; padding-right: 7px; border-top:  none; border-left:  solid 0.5pt; border-bottom:  solid 0.5pt; border-right:  solid 0.5pt">
<p style="text-align: center"><span style="font-family:Times New Roman; font-size:10pt">Windows Server</span></p>
</td>
</tr>
</tbody>
</table>
</div>
<p>
Â </p>
<p>
Â </p>
<h2>Data storage<br />
</h2>
<p style="text-align: justify">Microsoft SharePoint Portal Server stores its data in the Windows Internal Database, registry, and SQL Server 2000. The organization does not have to buy SQL Server; SharePoint Portal Server comes with SQL Server Desktop Edition which allows the company to have a database up to 2 GB for 10 concurrent connections. The SQL Server Desktop Edition will be enough for many organizations. Although the users can be stored in the database, the default users&#8217; storage is the Active Directory of Windows Server Operating system. When the organisation adds users through the SharePoint interface it is automatically added to the Active Directory.
</p>
<h2>Programming languages<br />
</h2>
<p style="text-align: justify">Windows SharePoint Services are built from the ground up using .Net Framework technologies. It has been developed with C# using ASP.Net. Microsoft SharePoint Portal Server is built on top of the Windows SharePoint Services. As a result, SharePoint Portal Server provides all the facilities SharePoint Services providing.
</p>
<p style="text-align: justify">SharePoint Portal Server is built with the consideration of providing extensibility. For extensibility, they are some special types of web user controls, called Web Parts. Web Parts enable the developers to assemble a view of information from many sources. Developers can integrate the Customer Relationship Management (CRM) systems, file shares, Web sites, Web Services in the Web Parts.  Web Parts can be developed in any .Net language. With web parts, the end users will get drag and drop design features, connection features ready.
</p>
<h2>Operating Systems<br />
</h2>
<p style="text-align: justify">Windows SharePoint Services requires Windows Server 2003 with the latest service packs installed. As a web server, it requires IIS 6.0 with .Net Framework 1.1 components installed. Microsoft SharePoint Portal Server requires Windows SharePoint Services installed on the system. Active Directory Service of Windows 2003 should be installed for the user database and the computers within the organisation should be in the same domain.
</p>
<h2>Web Generation<br />
</h2>
<p style="text-align: justify">In SharePoint Portal Server 5<sup>th</sup> Generation Web is used. JavaScript is heavily used for giving the user a good user interface (like drag and drop features). It provides many web services for accessing the internal data of SharePoint. Although modifying data directly from SQL Server is also possible, it is not an easy task to do because they are many dependencies in the database. With SharePoint Web Services many tasks, that can be done using menus in the portal, can be done programmatically like adding users or modifying a list.
</p>
<h1>Improvements<br />
</h1>
<h2>Better Support for Teamwork<br />
</h2>
<p style="text-align: justify">Microsoft SharePoint Portal provides some basic mail alerts for the sites changes. The alert system should be optimized, make more configurable. There should be alarms for the inactive sites in the system, so that the administrator could delete the sites and increase the system performance. This would affect the users to open only the active sites. There might be some specific alarms for particular events in the lists or in the sites. The alert system should not be only through mail, it might have some in-site alerts recommending the user what to do.
</p>
<p style="text-align: justify">SharePoint Portal Server can track the changes to the documents, but it is only limited to Microsoft Office documents. Many organisations use different type of software and documents, it should be give support to different type of documents. Also, SharePoint Portal does not include a form tracking facility. There are some third party solutions for providing that facility, but it would be better to support the form tracking inside the SharePoint Portal.
</p>
<p style="text-align: justify">The folder system of the directories is sometimes not enough for classifying the documents. A tagging system should be implemented inside the SharePoint Portal Server. Then the users can set different keywords for a document.
</p>
<h2>Better Support for Individual Work<br />
</h2>
<p style="text-align: justify">Workflow is a need for collaborative systems and it is not supported on SharePoint Portal Server 2003. Workflow should be implemented in a document library, in the designer or in the web services that SharePoint provides. Workflow should be easily implemented using the web interface of the portal or should be programmatically accessed to workflow libraries, as a result it would be possible to develop Web Parts that follows the workflow.
</p>
<p style="text-align: justify">SharePoint does not have an internal backup solution. A backup can be done using SQL Server backup solutions; it should have a web based scheduled backup and restore system for different types of data specified by the users.
</p>
<h2>The System Link into any other university systems<br />
</h2>
<p style="text-align: justify">The system should link into other university systems if there is a need for collaboration with the university.  This can easily be done by developing web parts or web services talking to the university server.
</p>
<h2>Another functionality/tools<br />
</h2>
<p style="text-align: justify">In SharePoint Portal Server, it is impossible to track change within the portals because everything is stored in Microsoft SQL Server database. Sometimes it is needed to track for the activities going on the portal in terms of security. This information can be queried using the IIS logs or SQL Server transaction logs; however they will display all the going operations in the servers.  It is rather difficult to analyse those data. SharePoint Portal Server should have a separate activity tracking mechanism to analyse and report.
</p>
<h2>Other points<br />
</h2>
<p style="text-align: justify">SharePoint Portal Server is a good collaborative system; on the other hand it depends on many technologies. It should be separated from other components like SharePoint Services, SQL Server to enable the upgrade easy. It should be loosely coupled to the other systems.
</p>
<h1>Conclusion<br />
</h1>
<p style="text-align: justify">Microsoft SharePoint Portal Server is enterprise level collaboration software providing services for the organisation and customers.  Although, there are some problems with SharePoint Portal Server in terms of compatibility with other systems, SharePoint Portal Server is a unique solution in collaboration environments. It is Windows based, but is accessible from any other platform using a high-end web browser. The installation and administration of the system is very easy and works without any extra configuration. As a result, the users will get high security options, great collaborative environment for sharing documents, easy to manage system, and great team integration.
</p>
<p style="text-align: justify">SharePoint Portal Server is also great development environment for programmers. It can be personalised within the organisation based on needs. It can be integrated with any other application without affecting the system&#8217;s security. Many software vendors were also providing web parts for SharePoint Portal Server which makes the integration very easy with their product.
</p>
<p style="text-align: justify"> Workflow is a definite need for a collaborative environment. That issue will be solved internally with a new framework in the coming version of SharePoint which is Microsoft SharePoint Portal Server 2007.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codingday.com/collaborative-system-microsoft-sharepoint-portal-server-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Collaborative System: Microsoft SharePoint Portal Server-Part 1</title>
		<link>http://www.codingday.com/collaborative-system-microsoft-sharepoint-portal-server-part-1/</link>
		<comments>http://www.codingday.com/collaborative-system-microsoft-sharepoint-portal-server-part-1/#comments</comments>
		<pubDate>Tue, 17 Apr 2007 00:57:39 +0000</pubDate>
		<dc:creator>Can</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Sharepoint]]></category>

		<guid isPermaLink="false">http://www.canerten.com/collaborative-system-microsoft-sharepoint-portal-server-part-1/</guid>
		<description><![CDATA[Abstract Microsoft SharePoint Products are Web Based Collaborative System that facilitates the collaboration within the organisation and customers. There are two types of SharePoint products, SharePoint Portal Services and SharePoint Portal Server. SharePoint Portal Server is built on top of SharePoint Portal Services. Using SharePoint Portal Server 2003, users can create, manage and build collaborative [...]]]></description>
			<content:encoded><![CDATA[<h1>Abstract<br />
</h1>
<p style="text-align: justify">Microsoft SharePoint Products are Web Based Collaborative System that facilitates the collaboration within the organisation and customers. There are two types of SharePoint products, SharePoint Portal Services and SharePoint Portal Server. SharePoint Portal Server is built on top of SharePoint Portal Services.
</p>
<p style="text-align: justify">Using SharePoint Portal Server 2003, users can create, manage and build collaborative Web sites. SharePoint Portal Server 2003 is built on top of Microsoft SharePoint Services. Although SharePoint Portal Services are free, SharePoint Portal Server provides more facilities to work collaboratively. This paper will focus on Microsoft SharePoint Portal Server rather than Microsoft SharePoint Services
</p>
<h1>Web Evolution<br />
</h1>
<h2>Usability<br />
</h2>
<p style="text-align: justify">Â Â Â Â SharePoint Portal Server is scalable, secure, and enterprise level portal server. Using SharePoint Portal Server 2003, users can add, manage, and organize news and topics, sites with different views, and information. They are also able to search across files shares, Web servers. They can make notification alerts based on the changes of the information, documents or applications. There is no need for administrators to create a site. It can be used for the team workspace, contact list, meetings, tasks, document sharing and collaboration. Moreover, it can be used for customized shared and collaborated solutions within the organisation and customers.
</p>
<p style="text-align: justify">Many organizations use shared folders among the network and e-mail for collaboration. A user creates a file in the shared folder, and then e-mails the link to the reviewers of the document. Windows SharePoint provides a Document Workspace site for shared documents. It stores the document and tracks the changes if needed. Users are also able to see the different versions of the document.
</p>
<h2>Accessibility<br />
</h2>
<p style="text-align: justify">Â Â Â Â SharePoint Portal Server is accessible through the network or through the internet using the most recent web browsers. The workers or teams in an organisation can access it through the Intranet. Some companies provide some portals to their customers, in that case they might open some or all part of SharePoint Portal Server to the Internet.
</p>
<p style="text-align: justify">Â Â Â Â SharePoint Portal Server is also accessible through web services for third party programs or for developers. They are many web services that the users can query the system for different lists, documents.
</p>
<p style="text-align: justify">SharePoint Portal Server has a Meeting Workspace for managing meetings. It can be accessed from Outlook 2003 for scheduling a meeting. This way, the users can request a meeting from their mail program.
</p>
<h2>Security<br />
</h2>
<p style="text-align: justify">Â Â Â Â The authentication is provided by IIS (Internet Information Services) using the Kerberos authentication to NTLM authentication. The organisation can also add SSL (Secure Sockets Layer) certificate to the SharePoint virtual directory to make the portal encrypted.
</p>
<p style="text-align: justify">Â Â Â Â The authorization is done internally. SharePoint Portal Server 2003 provides user based and role based security to access the content. Users can be the users of the active directory or can be created using SharePoint Portal Server. There are five types of roles administrator, web designer, contributor, reader and guess. Administrator can assign rights to different lists, web parts, documents for the users or the roles. The user and role data is stored on the database encrypted. SharePoint Portal Server also provides single sign-on.
</p>
<h1>Pro&#8217;s of the system<br />
</h1>
<p style="text-align: justify">The architecture of SharePoint Portal Server is very extensible and secure. A developer can link web services to the SharePoint Portal Server as list of objects or can develop web parts easily Single sign-on provides great security for the system. Single Sign-On Service provides sign on to multiple enterprise applications (like SAP, Siebel) using a single set of credentials even if they use different types of authentication methods. Each Web Part in the site can use the credentials that the user provided once to access different resources in the system without prompting the user. Having a web part talking to external systems has been greatly done.
</p>
<p style="text-align: justify">Windows SharePoint Portal is integrated with Microsoft Office Products. Users can use the menu commands from the Office family to add or modify different parts of the system. Beside that, the user interface of adding web parts to the site and organizing them using drag and drop is a good thing in a web interface without needing the administrator.
</p>
<p style="text-align: justify">The search engine provided by Windows SharePoint Portal server can query most of the objects of the system like lists, documents, meetings, contacts, surveys. Sites are also indexed in the SQL Server in an indexed table which makes the text queries to perform fast. The track versions of the documents are also stored in the database, the users can easily rollback a document to previous version or update the current document. It helps managing the document creation and editing.
</p>
<h1>Con&#8217;s of the system<br />
</h1>
<p style="text-align: justify">The users can build their own sites without administrator help; however this might result to inactive sites after the project has finished or the users decide to change the site. The sites take space on the server and it can decrease the overall performance of the system or it might result in an unmanaged portal unless the administrator continuously checks the active sites.
</p>
<p style="text-align: justify">SharePoint Portal Server is platform and application dependent. If the organisation is not using Microsoft Office and Servers it will not be the best solution for them. Beside that, SharePoint Portal server is not a future proof product. Migration or upgrade will not be easy, because it depends on other products like Microsoft Windows Server and Microsoft SQL Server. When the company want to upgrade SharePoint, Microsoft might force them to upgrade the other servers as well.
</p>
<h1>The SharePoint Portal Server lacks the workflow support for the operations. Workflows can be done by using some other components, like BizTalk Server, again the company need to pay for that. Although BizTalk Server and SharePoint Portal Server offer a powerful and integrated platform, without workflow support it might not be considered as a true collaborative suite. </h1>
]]></content:encoded>
			<wfw:commentRss>http://www.codingday.com/collaborative-system-microsoft-sharepoint-portal-server-part-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>P2P: Potential Future Applications &#8211; Part 2</title>
		<link>http://www.codingday.com/p2p-potential-future-applications-part-2/</link>
		<comments>http://www.codingday.com/p2p-potential-future-applications-part-2/#comments</comments>
		<pubDate>Tue, 03 Apr 2007 23:28:23 +0000</pubDate>
		<dc:creator>Can</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Network]]></category>
		<category><![CDATA[collaborative-work]]></category>
		<category><![CDATA[file-sharing]]></category>
		<category><![CDATA[high-performance-computing]]></category>
		<category><![CDATA[p2p]]></category>
		<category><![CDATA[peer-to-peer]]></category>

		<guid isPermaLink="false">http://www.canerten.com/p2p-potential-future-applications-part-2/</guid>
		<description><![CDATA[The second part of p2p article is on ReadWriteWeb. Thanks to Richard MacManus again for his contributions. This is the second in a 2-part series exploring the world of P2P on the Web. Part 1 was a general introduction to P2P, along with some real-world applications of P2P. Part 2 (this post) discusses future applications.. [...]]]></description>
			<content:encoded><![CDATA[<p>The second part of p2p article is on <a href="http://www.readwriteweb.com/archives/p2p_potential_future_applications.php">ReadWriteWeb</a>. Thanks to Richard MacManus again for his contributions.</p>
<p>
This is the second in a 2-part series exploring the world of P2P on the Web. Part 1 was a general introduction to P2P, along with some real-world applications of P2P. Part 2 (this post) discusses future applications..<br />
For the rest : <a href="http://www.readwriteweb.com/archives/p2p_potential_future_applications.php">P2P: Potential Future Applications &#8211; Part 2</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.codingday.com/p2p-potential-future-applications-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>P2P: Introduction and Real World Applications &#8211; Part 1</title>
		<link>http://www.codingday.com/p2p-introduction-and-real-world-applications-part-1/</link>
		<comments>http://www.codingday.com/p2p-introduction-and-real-world-applications-part-1/#comments</comments>
		<pubDate>Fri, 30 Mar 2007 20:25:19 +0000</pubDate>
		<dc:creator>Can</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Network]]></category>
		<category><![CDATA[collaborative_work]]></category>
		<category><![CDATA[file_sharing]]></category>
		<category><![CDATA[high_performance_computing]]></category>
		<category><![CDATA[p2p]]></category>
		<category><![CDATA[peer_to_peer]]></category>
		<category><![CDATA[peer_to_peer_networks]]></category>

		<guid isPermaLink="false">http://www.canerten.com/p2p-introduction-and-real-world-applications-part-1/</guid>
		<description><![CDATA[My article is on readwriteweb. I am glad to see there, thanks to Richard MacManus for his editing and creating readwriteweb. Abstract As the connection speed of the internet has increased, the demand for web related services has also increased. After the Web revolution, peer-to-peer networks evolved and currently have a number of different usages [...]]]></description>
			<content:encoded><![CDATA[<p>My article is on readwriteweb. I am glad to see there, thanks to Richard MacManus for his editing and creating readwriteweb.</p>
<h2>Abstract</h2>
<p>
As the connection speed of the internet has increased, the demand for web related services has also increased. After the Web revolution, peer-to-peer networks evolved and currently have a number of different usages &#8211; instant messaging, file sharing, etc. Some other revolutionary ideas are still in research. People want to use peer-to-peer in many different applications including e-commerce, education, collaborative work, search, file storage, high performance computing. In this series of posts, we will look at different peer-to-peer ideas and applications.
</p>
<p>
For the rest you can visit<br />
<a href="http://www.readwriteweb.com/archives/p2p_introduction_real_world_applications.php">P2P: Introduction and Real World Applications</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.codingday.com/p2p-introduction-and-real-world-applications-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
