Example #1
0
        public void GenerateCode(CodeDomGenerator.Language language)
        {
            if (_method == null)
            {
                return;
            }

            if (_method.ReturnType != null && _method.ReturnType.BaseType != "System.Void")
            {
                throw new NotSupportedException("Partial methods must have a void return type");
            }

            switch (language)
            {
            case CodeDomGenerator.Language.CSharp:
                GenerateCS();
                break;

            case CodeDomGenerator.Language.VB:
                GenerateVB();
                break;

            default:
                throw new NotImplementedException(language.ToString());
            }
        }
        public void GenerateCode(CodeDomGenerator.Language language)
        {
            switch (language)
            {
            case CodeDomGenerator.Language.CSharp:
                using (Microsoft.CSharp.CSharpCodeProvider provider = new Microsoft.CSharp.CSharpCodeProvider())
                {
                    System.CodeDom.Compiler.CodeGeneratorOptions opts = new System.CodeDom.Compiler.CodeGeneratorOptions();
                    using (System.CodeDom.Compiler.IndentedTextWriter tw = new System.CodeDom.Compiler.IndentedTextWriter(new StringWriter(), opts.IndentString))
                    {
                        tw.Write("break;");
                        Value = tw.InnerWriter.ToString();
                    }
                }
                break;

            case CodeDomGenerator.Language.VB:
                using (Microsoft.VisualBasic.VBCodeProvider provider = new Microsoft.VisualBasic.VBCodeProvider())
                {
                    System.CodeDom.Compiler.CodeGeneratorOptions opts = new System.CodeDom.Compiler.CodeGeneratorOptions();
                    using (System.CodeDom.Compiler.IndentedTextWriter tw = new System.CodeDom.Compiler.IndentedTextWriter(new StringWriter(), opts.IndentString))
                    {
                        tw.Write("Exit Do");
                        Value = tw.InnerWriter.ToString();
                    }
                }
                break;

            default:
                throw new NotImplementedException(language.ToString());
            }
        }
Example #3
0
        public void GenerateCode(CodeDomGenerator.Language language)
        {
            switch (language)
            {
            case CodeDomGenerator.Language.CSharp:
                using (Microsoft.CSharp.CSharpCodeProvider provider = new Microsoft.CSharp.CSharpCodeProvider())
                {
                    System.CodeDom.Compiler.CodeGeneratorOptions opts = new System.CodeDom.Compiler.CodeGeneratorOptions();
                    using (System.CodeDom.Compiler.IndentedTextWriter tw = new System.CodeDom.Compiler.IndentedTextWriter(new StringWriter(), opts.IndentString))
                    {
                        tw.Write("var {0} = ", provider.CreateEscapedIdentifier(VariableName));
                        provider.GenerateCodeFromExpression(InitExpression, tw, opts);
                        tw.Write(";");
                        Value = tw.InnerWriter.ToString();
                    }
                }
                break;

            case CodeDomGenerator.Language.VB:
                using (Microsoft.VisualBasic.VBCodeProvider provider = new Microsoft.VisualBasic.VBCodeProvider())
                {
                    System.CodeDom.Compiler.CodeGeneratorOptions opts = new System.CodeDom.Compiler.CodeGeneratorOptions();
                    using (System.CodeDom.Compiler.IndentedTextWriter tw = new System.CodeDom.Compiler.IndentedTextWriter(new StringWriter(), opts.IndentString))
                    {
                        tw.Write("Dim {0} = ", provider.CreateEscapedIdentifier(VariableName));
                        provider.GenerateCodeFromExpression(InitExpression, tw, opts);
                        Value = tw.InnerWriter.ToString();
                    }
                }
                break;

            default:
                throw new NotImplementedException(language.ToString());
            }
        }
Example #4
0
        public void GenerateCode(CodeDomGenerator.Language language)
        {
            switch (language)
            {
            case CodeDomGenerator.Language.CSharp:
                using (Microsoft.CSharp.CSharpCodeProvider provider = new Microsoft.CSharp.CSharpCodeProvider())
                {
                    System.CodeDom.Compiler.CodeGeneratorOptions opts = new System.CodeDom.Compiler.CodeGeneratorOptions();
                    using (System.CodeDom.Compiler.IndentedTextWriter tw = new System.CodeDom.Compiler.IndentedTextWriter(new StringWriter(), opts.IndentString))
                    {
                        tw.Write("new ");
                        provider.GenerateCodeFromExpression(new CodeTypeReferenceExpression(TypeReference.ArrayElementType), tw, opts);
                        tw.Write("[");
                        for (int i = 0; i < Dimensions.Count; i++)
                        {
                            if (i > 0)
                            {
                                tw.Write(",");
                            }
                            provider.GenerateCodeFromExpression(Dimensions[i], tw, opts);
                        }
                        tw.Write("]");
                        Value = tw.InnerWriter.ToString();
                    }
                }
                break;

            case CodeDomGenerator.Language.VB:
                using (Microsoft.VisualBasic.VBCodeProvider provider = new Microsoft.VisualBasic.VBCodeProvider())
                {
                    System.CodeDom.Compiler.CodeGeneratorOptions opts = new System.CodeDom.Compiler.CodeGeneratorOptions();
                    using (System.CodeDom.Compiler.IndentedTextWriter tw = new System.CodeDom.Compiler.IndentedTextWriter(new StringWriter(), opts.IndentString))
                    {
                        tw.Write("(");
                        for (int i = 0; i < Dimensions.Count; i++)
                        {
                            if (i > 0)
                            {
                                tw.Write(",");
                            }
                            tw.Write("(");
                            provider.GenerateCodeFromExpression(Dimensions[i], tw, opts);
                            tw.Write(")-1");
                        }
                        tw.Write(") as ");
                        provider.GenerateCodeFromExpression(new CodeTypeReferenceExpression(TypeReference), tw, opts);
                        Value = tw.InnerWriter.ToString();
                    }
                }
                break;

            default:
                throw new NotImplementedException(language.ToString());
            }
        }
Example #5
0
        public void GenerateCode(CodeDomGenerator.Language language)
        {
            switch (language)
            {
            case CodeDomGenerator.Language.CSharp:
                using (Microsoft.CSharp.CSharpCodeProvider provider = new Microsoft.CSharp.CSharpCodeProvider())
                {
                    System.CodeDom.Compiler.CodeGeneratorOptions opts = new System.CodeDom.Compiler.CodeGeneratorOptions();
                    using (System.CodeDom.Compiler.IndentedTextWriter tw = new System.CodeDom.Compiler.IndentedTextWriter(new StringWriter(), opts.IndentString))
                    {
                        if (!_eq)
                        {
                            tw.Write("!");
                        }
                        tw.Write("ReferenceEquals(");
                        provider.GenerateCodeFromExpression(_left, tw, opts);
                        tw.Write(", ");
                        provider.GenerateCodeFromExpression(_right, tw, opts);
                        tw.Write(")");
                        Value = tw.InnerWriter.ToString();
                    }
                }
                break;

            case CodeDomGenerator.Language.VB:
                using (Microsoft.VisualBasic.VBCodeProvider provider = new Microsoft.VisualBasic.VBCodeProvider())
                {
                    System.CodeDom.Compiler.CodeGeneratorOptions opts = new System.CodeDom.Compiler.CodeGeneratorOptions();
                    using (System.CodeDom.Compiler.IndentedTextWriter tw = new System.CodeDom.Compiler.IndentedTextWriter(new StringWriter(), opts.IndentString))
                    {
                        provider.GenerateCodeFromExpression(_left, tw, opts);
                        if (_eq)
                        {
                            tw.Write(" Is ");
                        }
                        else
                        {
                            tw.Write(" IsNot ");
                        }
                        provider.GenerateCodeFromExpression(_right, tw, opts);
                        Value = tw.InnerWriter.ToString();
                    }
                }
                break;

            default:
                throw new NotImplementedException(language.ToString());
            }
        }
Example #6
0
        public void GenerateCode(CodeDomGenerator.Language language)
        {
            switch (language)
            {
            case CodeDomGenerator.Language.CSharp:
                GenerateCS();
                break;

            case CodeDomGenerator.Language.VB:
                GenerateVB();
                break;

            default:
                throw new NotImplementedException(language.ToString());
            }
        }
        public void GenerateCode(CodeDomGenerator.Language language)
        {
            if (_left == null)
            {
                return;
            }

            switch (language)
            {
            case CodeDomGenerator.Language.CSharp:
                using (Microsoft.CSharp.CSharpCodeProvider provider = new Microsoft.CSharp.CSharpCodeProvider())
                {
                    System.CodeDom.Compiler.CodeGeneratorOptions opts = new System.CodeDom.Compiler.CodeGeneratorOptions();
                    using (System.CodeDom.Compiler.IndentedTextWriter tw = new System.CodeDom.Compiler.IndentedTextWriter(new StringWriter(), opts.IndentString))
                    {
                        provider.GenerateCodeFromExpression(_left, tw, opts);
                        if (_right != null)
                        {
                            tw.Write(_separator);
                            provider.GenerateCodeFromExpression(_right, tw, opts);
                        }
                        Value = tw.InnerWriter.ToString();
                    }
                }
                break;

            case CodeDomGenerator.Language.VB:
                using (Microsoft.VisualBasic.VBCodeProvider provider = new Microsoft.VisualBasic.VBCodeProvider())
                {
                    System.CodeDom.Compiler.CodeGeneratorOptions opts = new System.CodeDom.Compiler.CodeGeneratorOptions();
                    using (System.CodeDom.Compiler.IndentedTextWriter tw = new System.CodeDom.Compiler.IndentedTextWriter(new StringWriter(), opts.IndentString))
                    {
                        provider.GenerateCodeFromExpression(_left, tw, opts);
                        if (_right != null)
                        {
                            tw.Write(_separator);
                            provider.GenerateCodeFromExpression(_right, tw, opts);
                        }
                        Value = tw.InnerWriter.ToString();
                    }
                }
                break;

            default:
                throw new NotImplementedException(language.ToString());
            }
        }
        public void GenerateCode(CodeDomGenerator.Language language)
        {
            switch (language)
            {
            case CodeDomGenerator.Language.CSharp:
                using (Microsoft.CSharp.CSharpCodeProvider provider = new Microsoft.CSharp.CSharpCodeProvider())
                {
                    System.CodeDom.Compiler.CodeGeneratorOptions opts = new System.CodeDom.Compiler.CodeGeneratorOptions();
                    using (System.CodeDom.Compiler.IndentedTextWriter tw = new System.CodeDom.Compiler.IndentedTextWriter(new StringWriter(), opts.IndentString))
                    {
                        provider.GenerateCodeFromExpression(Parameter, tw, opts);
                        Value = tw.InnerWriter.ToString();
                    }
                }
                break;

            case CodeDomGenerator.Language.VB:
                using (Microsoft.VisualBasic.VBCodeProvider provider = new Microsoft.VisualBasic.VBCodeProvider())
                {
                    System.CodeDom.Compiler.CodeGeneratorOptions opts = new System.CodeDom.Compiler.CodeGeneratorOptions();
                    StringBuilder sb = new StringBuilder();
                    using (System.CodeDom.Compiler.IndentedTextWriter tw = new System.CodeDom.Compiler.IndentedTextWriter(new StringWriter(sb), opts.IndentString))
                    {
                        provider.GenerateCodeFromExpression(Parameter, tw, opts);
                        switch (Option)
                        {
                        case ParamOption.Optional:
                            sb.Replace("ByVal " + Parameter.Name, "Optional ByVal " + Parameter.Name);
                            break;

                        case ParamOption.ParamArray:
                            sb.Replace("ByVal " + Parameter.Name, "ByVal ParamArray " + Parameter.Name);
                            break;

                        default:
                            throw new NotSupportedException(Option.ToString());
                        }
                        Value = tw.InnerWriter.ToString();
                    }
                }
                break;

            default:
                throw new NotImplementedException(language.ToString());
            }
        }
        public void GenerateCode(CodeDomGenerator.Language language)
        {
            switch (language)
            {
            case CodeDomGenerator.Language.CSharp:
                using (Microsoft.CSharp.CSharpCodeProvider provider = new Microsoft.CSharp.CSharpCodeProvider())
                {
                    System.CodeDom.Compiler.CodeGeneratorOptions opts = new System.CodeDom.Compiler.CodeGeneratorOptions();
                    using (System.CodeDom.Compiler.IndentedTextWriter tw = new System.CodeDom.Compiler.IndentedTextWriter(new StringWriter(), opts.IndentString))
                    {
                        provider.GenerateCodeFromExpression(_condition, tw, opts);
                        tw.Write("?");
                        provider.GenerateCodeFromExpression(_truePart, tw, opts);
                        tw.Write(":");
                        provider.GenerateCodeFromExpression(_falsePart, tw, opts);
                        Value = tw.InnerWriter.ToString();
                    }
                }
                break;

            case CodeDomGenerator.Language.VB:
                using (Microsoft.VisualBasic.VBCodeProvider provider = new Microsoft.VisualBasic.VBCodeProvider())
                {
                    System.CodeDom.Compiler.CodeGeneratorOptions opts = new System.CodeDom.Compiler.CodeGeneratorOptions();
                    using (System.CodeDom.Compiler.IndentedTextWriter tw = new System.CodeDom.Compiler.IndentedTextWriter(new StringWriter(), opts.IndentString))
                    {
                        tw.Write("If(");
                        provider.GenerateCodeFromExpression(_condition, tw, opts);
                        tw.Write(",");
                        provider.GenerateCodeFromExpression(_truePart, tw, opts);
                        tw.Write(",");
                        provider.GenerateCodeFromExpression(_falsePart, tw, opts);
                        tw.Write(")");
                        Value = tw.InnerWriter.ToString();
                    }
                }
                break;

            default:
                throw new NotImplementedException(language.ToString());
            }
        }
Example #10
0
        public void GenerateCode(CodeDomGenerator.Language language)
        {
            if (m_parameters == null || m_statements == null || m_returnType == null)
            {
                return;
            }

            switch (language)
            {
            case CodeDomGenerator.Language.CSharp:
                GenerateCS();
                break;

            case CodeDomGenerator.Language.VB:
                GenerateVB();
                break;

            default:
                throw new NotImplementedException(language.ToString());
            }
        }
Example #11
0
        public void GenerateCode(CodeDomGenerator.Language language)
        {
            switch (language)
            {
            case CodeDomGenerator.Language.CSharp:
                using (CSharpCodeProvider provider = new CSharpCodeProvider())
                {
                    CodeGeneratorOptions opts = new CodeGeneratorOptions();
                    StringBuilder        sb   = new StringBuilder();
                    using (IndentedTextWriter tw = new IndentedTextWriter(new StringWriter(sb), opts.IndentString))
                    {
                        provider.GenerateCodeFromMember(Event, tw, opts);
                        sb.Replace(";", string.Empty);
                        tw.WriteLine("{");
                        tw.Indent++;
                        GenrateMeth(opts, provider, tw, AddMethod.GetStatements, "add");
                        GenrateMeth(opts, provider, tw, RemoveMethod.GetStatements, "remove");
                        tw.Indent--;
                        tw.WriteLine("}");
                    }
                    Text = sb.ToString();
                }
                break;

            case CodeDomGenerator.Language.VB:
                using (Microsoft.VisualBasic.VBCodeProvider provider = new Microsoft.VisualBasic.VBCodeProvider())
                {
                    CodeGeneratorOptions opts = new CodeGeneratorOptions();
                    var args = new StringWriter();
                    provider.GenerateCodeFromExpression(new CodeParameterDeclarationExpression(Event.Type, "value"), args, opts);

                    StringBuilder sb = new StringBuilder();
                    using (IndentedTextWriter tw = new IndentedTextWriter(new StringWriter(sb), opts.IndentString))
                    {
                        provider.GenerateCodeFromMember(Event, tw, opts);
                        sb.Replace(" Event ", " Custom Event ");
                        tw.Indent++;

                        tw.WriteLine("AddHandler({0})", args.GetStringBuilder());
                        tw.Indent++;
                        foreach (CodeStatement statement in AddMethod.GetStatements)
                        {
                            provider.GenerateCodeFromStatement(statement, tw, opts);
                        }
                        tw.Indent--;
                        tw.WriteLine("End AddHandler");

                        tw.WriteLine("RemoveHandler({0})", args.GetStringBuilder());
                        tw.Indent++;
                        foreach (CodeStatement statement in RemoveMethod.GetStatements)
                        {
                            provider.GenerateCodeFromStatement(statement, tw, opts);
                        }
                        tw.Indent--;
                        tw.WriteLine("End RemoveHandler");

                        //args = new StringWriter();
                        //provider.GenerateCodeFromMember(RaiseMethod, args, opts);

                        //StringReader sr = new StringReader(args.GetStringBuilder().ToString());
                        //string line = sr.ReadLine();
                        //while (string.IsNullOrEmpty(line))
                        //    line = sr.ReadLine();
                        //int idx = line.IndexOf(" " + RaiseMethod.Name);
                        //args.GetStringBuilder().Replace(line, "RaiseEvent" + line.Substring(idx + RaiseMethod.Name.Length + 1));
                        //tw.Write(args.GetStringBuilder().ToString());

                        tw.Write("RaiseEvent(");
                        for (int i = 0; i < RaiseMethod.Parameters.Count; i++)
                        {
                            if (i > 0)
                            {
                                tw.Write(", ");
                            }
                            provider.GenerateCodeFromExpression(RaiseMethod.Parameters[i], tw, opts);
                        }
                        tw.WriteLine(")");
                        tw.Indent++;
                        foreach (CodeStatement statement in RaiseMethod.Statements)
                        {
                            provider.GenerateCodeFromStatement(statement, tw, opts);
                        }
                        tw.Indent--;
                        tw.WriteLine("End RaiseEvent");

                        tw.Indent--;
                        tw.WriteLine("End Event");
                    }
                    Text = sb.ToString();
                }
                break;

            default:
                throw new NotImplementedException(language.ToString());
            }
        }
        public void GenerateCode(CodeDomGenerator.Language language)
        {
            switch (language)
            {
            case CodeDomGenerator.Language.CSharp:
                using (Microsoft.CSharp.CSharpCodeProvider provider = new Microsoft.CSharp.CSharpCodeProvider())
                {
                    System.CodeDom.Compiler.CodeGeneratorOptions opts = new System.CodeDom.Compiler.CodeGeneratorOptions();
                    using (System.CodeDom.Compiler.IndentedTextWriter tw = new System.CodeDom.Compiler.IndentedTextWriter(new StringWriter(), opts.IndentString))
                    {
                        tw.Write("foreach (");
                        provider.GenerateCodeFromExpression(new CodeTypeReferenceExpression(IterationItemType), tw, opts);
                        tw.Write(" {0} in ", provider.CreateValidIdentifier(IterationItemName));
                        provider.GenerateCodeFromExpression(IterExpression, tw, opts);
                        tw.WriteLine(")");
                        tw.WriteLine("{");
                        tw.Indent++;
                        if (Statements != null)
                        {
                            foreach (CodeStatement statement in Statements)
                            {
                                provider.GenerateCodeFromStatement(statement, tw, opts);
                            }
                        }
                        tw.Indent--;
                        tw.WriteLine("}");
                        Value = tw.InnerWriter.ToString();
                    }
                }
                break;

            case CodeDomGenerator.Language.VB:
                using (Microsoft.VisualBasic.VBCodeProvider provider = new Microsoft.VisualBasic.VBCodeProvider())
                {
                    System.CodeDom.Compiler.CodeGeneratorOptions opts = new System.CodeDom.Compiler.CodeGeneratorOptions();
                    using (System.CodeDom.Compiler.IndentedTextWriter tw = new System.CodeDom.Compiler.IndentedTextWriter(new StringWriter(), opts.IndentString))
                    {
                        tw.Write("For Each {0} As ", provider.CreateValidIdentifier(IterationItemName));
                        provider.GenerateCodeFromExpression(new CodeTypeReferenceExpression(IterationItemType), tw, opts);
                        tw.Write(" in ");
                        provider.GenerateCodeFromExpression(IterExpression, tw, opts);
                        tw.WriteLine();
                        tw.Indent++;
                        if (Statements != null)
                        {
                            foreach (CodeStatement statement in Statements)
                            {
                                provider.GenerateCodeFromStatement(statement, tw, opts);
                            }
                        }
                        tw.Indent--;
                        tw.WriteLine("Next");
                        Value = tw.InnerWriter.ToString();
                    }
                }
                break;

            default:
                throw new NotImplementedException(language.ToString());
            }
        }
Example #13
0
        //public CodeSwitchStatement Break()
        //{
        //    m_cases.Add(new CaseBlock());
        //    return this;
        //}

        #region ICustomCodeDomObject Members

        public void GenerateCode(CodeDomGenerator.Language language)
        {
            switch (language)
            {
            case CodeDomGenerator.Language.CSharp:
                using (Microsoft.CSharp.CSharpCodeProvider provider = new Microsoft.CSharp.CSharpCodeProvider())
                {
                    System.CodeDom.Compiler.CodeGeneratorOptions opts = new System.CodeDom.Compiler.CodeGeneratorOptions();
                    using (System.CodeDom.Compiler.IndentedTextWriter tw = new System.CodeDom.Compiler.IndentedTextWriter(new StringWriter(), opts.IndentString))
                    {
                        tw.Write("switch (");
                        if (SwitchExpression != null)
                        {
                            provider.GenerateCodeFromExpression(SwitchExpression, tw, opts);
                        }
                        tw.WriteLine(")");
                        tw.WriteLine("{");
                        tw.Indent++;
                        foreach (CaseBlock c in m_cases)
                        {
                            if (c.Statements != null)
                            {
                                if (c.CaseExpression != null)
                                {
                                    tw.Write("case ");
                                    provider.GenerateCodeFromExpression(c.CaseExpression, tw, opts);
                                    tw.WriteLine(":");
                                }
                                else
                                {
                                    tw.WriteLine("default:");
                                }

                                tw.Indent++;
                                foreach (CodeStatement stmt in c.Statements)
                                {
                                    provider.GenerateCodeFromStatement(stmt, tw, opts);
                                }
                                tw.Indent--;
                            }
                            //else
                            //{
                            //    tw.Indent++;
                            //    tw.WriteLine("break;");
                            //    tw.Indent--;
                            //}
                        }
                        tw.Indent--;
                        tw.WriteLine("}");
                        Value = tw.InnerWriter.ToString();
                    }
                }
                break;

            case CodeDomGenerator.Language.VB:
                using (Microsoft.VisualBasic.VBCodeProvider provider = new Microsoft.VisualBasic.VBCodeProvider())
                {
                    System.CodeDom.Compiler.CodeGeneratorOptions opts = new System.CodeDom.Compiler.CodeGeneratorOptions();
                    using (System.CodeDom.Compiler.IndentedTextWriter tw = new System.CodeDom.Compiler.IndentedTextWriter(new StringWriter(), opts.IndentString))
                    {
                        tw.Write("Select Case ");
                        if (SwitchExpression != null)
                        {
                            provider.GenerateCodeFromExpression(SwitchExpression, tw, opts);
                        }
                        tw.WriteLine();
                        tw.Indent++;
                        foreach (CaseBlock c in m_cases)
                        {
                            if (c.Statements != null)
                            {
                                if (c.CaseExpression != null)
                                {
                                    tw.Write("Case ");
                                    provider.GenerateCodeFromExpression(c.CaseExpression, tw, opts);
                                    tw.WriteLine();
                                }
                                else
                                {
                                    tw.WriteLine("Case Else");
                                }

                                tw.Indent++;
                                for (int i = 0; i < c.Statements.Length; i++)
                                {
                                    CodeStatement stmt = c.Statements[i];
                                    if (!(stmt is CodeExitSelectStatement) || i < c.Statements.Length - 1)
                                    {
                                        provider.GenerateCodeFromStatement(stmt, tw, opts);
                                    }
                                }
                                tw.Indent--;
                            }
                            //else if (i < m_cases.Count - 1)
                            //{
                            //    tw.Indent++;
                            //    tw.WriteLine("Exit Select");
                            //    tw.Indent--;
                            //}
                        }
                        tw.Indent--;
                        tw.WriteLine("End Select");
                        Value = tw.InnerWriter.ToString();
                    }
                }
                break;

            default:
                throw new NotImplementedException(language.ToString());
            }
        }
Example #14
0
        public void GenerateCode(CodeDomGenerator.Language language)
        {
            switch (language)
            {
            case CodeDomGenerator.Language.CSharp:
                using (Microsoft.CSharp.CSharpCodeProvider provider = new Microsoft.CSharp.CSharpCodeProvider())
                {
                    System.CodeDom.Compiler.CodeGeneratorOptions opts = new System.CodeDom.Compiler.CodeGeneratorOptions();
                    using (System.CodeDom.Compiler.IndentedTextWriter tw = new System.CodeDom.Compiler.IndentedTextWriter(new StringWriter(), opts.IndentString))
                    {
                        tw.Write("lock (");
                        if (LockExpression != null)
                        {
                            provider.GenerateCodeFromExpression(LockExpression, tw, opts);
                        }
                        tw.WriteLine(")");
                        tw.WriteLine("{");
                        tw.Indent++;
                        if (Statements != null)
                        {
                            foreach (CodeStatement statement in Statements)
                            {
                                provider.GenerateCodeFromStatement(statement, tw, opts);
                            }
                        }
                        tw.Indent--;
                        tw.WriteLine("}");
                        Value = tw.InnerWriter.ToString();
                    }
                }
                break;

            case CodeDomGenerator.Language.VB:
                using (Microsoft.VisualBasic.VBCodeProvider provider = new Microsoft.VisualBasic.VBCodeProvider())
                {
                    System.CodeDom.Compiler.CodeGeneratorOptions opts = new System.CodeDom.Compiler.CodeGeneratorOptions();
                    using (System.CodeDom.Compiler.IndentedTextWriter tw = new System.CodeDom.Compiler.IndentedTextWriter(new StringWriter(), opts.IndentString))
                    {
                        tw.Write("SyncLock ");
                        if (LockExpression != null)
                        {
                            provider.GenerateCodeFromExpression(LockExpression, tw, opts);
                        }
                        tw.WriteLine();
                        tw.Indent++;
                        if (Statements != null)
                        {
                            foreach (CodeStatement statement in Statements)
                            {
                                provider.GenerateCodeFromStatement(statement, tw, opts);
                            }
                        }
                        tw.Indent--;
                        tw.WriteLine("End SyncLock");
                        Value = tw.InnerWriter.ToString();
                    }
                }
                break;

            default:
                throw new NotImplementedException(language.ToString());
            }
        }
        public void GenerateCode(CodeDomGenerator.Language language)
        {
            switch (language)
            {
            case CodeDomGenerator.Language.CSharp:
                using (Microsoft.CSharp.CSharpCodeProvider provider = new Microsoft.CSharp.CSharpCodeProvider())
                {
                    System.CodeDom.Compiler.CodeGeneratorOptions opts = new System.CodeDom.Compiler.CodeGeneratorOptions();
                    using (System.CodeDom.Compiler.IndentedTextWriter tw = new System.CodeDom.Compiler.IndentedTextWriter(new StringWriter(), opts.IndentString))
                    {
                        if (_params.Count != 1 || _params[0].Type != null)
                        {
                            tw.Write("(");
                        }

                        for (int i = 0; i < _params.Count; i++)
                        {
                            if (i > 0)
                            {
                                tw.Write(", ");
                            }

                            if (_params[i].Type != null)
                            {
                                provider.GenerateCodeFromExpression(new CodeTypeReferenceExpression(_params[i].Type), tw, opts);
                                tw.Write(" ");
                            }

                            tw.Write(_params[i].Name);
                        }

                        if (_params.Count != 1 || _params[0].Type != null)
                        {
                            tw.Write(")");
                        }

                        tw.Write(" => ");
                        provider.GenerateCodeFromExpression(Expression, tw, opts);
                        Value = tw.InnerWriter.ToString();
                    }
                }
                break;

            case CodeDomGenerator.Language.VB:
                using (Microsoft.VisualBasic.VBCodeProvider provider = new Microsoft.VisualBasic.VBCodeProvider())
                {
                    System.CodeDom.Compiler.CodeGeneratorOptions opts = new System.CodeDom.Compiler.CodeGeneratorOptions();
                    using (System.CodeDom.Compiler.IndentedTextWriter tw = new System.CodeDom.Compiler.IndentedTextWriter(new StringWriter(), opts.IndentString))
                    {
                        tw.Write("Function(");

                        for (int i = 0; i < _params.Count; i++)
                        {
                            if (i > 0)
                            {
                                tw.Write(", ");
                            }

                            tw.Write(_params[i].Name);

                            if (_params[i].Type != null)
                            {
                                tw.Write(" As ");
                                provider.GenerateCodeFromExpression(new CodeTypeReferenceExpression(_params[i].Type), tw, opts);
                            }
                        }

                        tw.Write(") ");
                        provider.GenerateCodeFromExpression(Expression, tw, opts);
                        Value = tw.InnerWriter.ToString();
                    }
                }
                break;

            default:
                throw new NotImplementedException(language.ToString());
            }
        }