예제 #1
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());
     }
 }
 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());
     }
 }
예제 #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("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 For");
                     Value = tw.InnerWriter.ToString();
                 }
             }
             break;
         default:
             throw new NotImplementedException(language.ToString());
     }
 }
예제 #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.WriteLine("do");
                            tw.WriteLine("{");
                            tw.Indent++;
                            if (Statements != null)
                                foreach (CodeStatement statement in Statements)
                                {
                                    provider.GenerateCodeFromStatement(statement, tw, opts);
                                }
                            tw.Indent--;
                            tw.Write("} while (");
                            if (TestExpression != null)
                                provider.GenerateCodeFromExpression(TestExpression, tw, opts);
                            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.WriteLine("Do");
                            tw.Indent++;
                            if (Statements != null)
                                foreach (CodeStatement statement in Statements)
                                {
                                    provider.GenerateCodeFromStatement(statement, tw, opts);
                                }
                            tw.Indent--;
                            tw.Write("Loop Until ");
                            if (TestExpression != null)
                                provider.GenerateCodeFromExpression(TestExpression, tw, opts);
                            tw.WriteLine();

                            Value = tw.InnerWriter.ToString();
                        }
                    }
                    break;
                default:
                    throw new NotImplementedException(language.ToString());
            }
        }
예제 #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))
                 {
                     tw.Write("(");
                     provider.GenerateCodeFromExpression(Expression, tw, opts);
                     tw.Write(" is ");
                     provider.GenerateCodeFromExpression(new CodeTypeReferenceExpression(TypeReference), 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("( TypeOf ");
                     provider.GenerateCodeFromExpression(Expression, tw, opts);
                     tw.Write(" Is ");
                     provider.GenerateCodeFromExpression(new CodeTypeReferenceExpression(TypeReference), tw, opts);
                     tw.Write(")");
                     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 (!_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());
     }
 }
예제 #7
0
 protected virtual void BaseTrace(System.CodeDom.Compiler.IndentedTextWriter writer)
 {
     writer.Write("[");
     writer.Write("Id=");
     writer.Write(this.Id);
     writer.Write(",");
     writer.Write("Name=");
     writer.Write(this.Name);
     writer.Write(",");
     writer.Write("Address=");
     writer.Write(this.Address);
     writer.Write(",");
     writer.Write("City=");
     writer.Write(this.City);
     writer.Write(",");
     writer.Write("ZipCode=");
     writer.Write(this.ZipCode);
     writer.Write(",");
     writer.Write("Country=");
     writer.Write(this.Country);
     writer.Write(",");
     writer.Write("Phone=");
     writer.Write(this.Phone);
     writer.Write(",");
     writer.Write("Fax=");
     writer.Write(this.Fax);
     writer.Write(",");
     writer.Write("WebSite=");
     writer.Write(this.WebSite);
     writer.Write(",");
     writer.Write("Language=");
     writer.Write(this.Language);
     writer.Write(",");
     writer.Write("CustomerType=");
     writer.Write(this.CustomerType);
     writer.Write(", EntityState=");
     writer.Write(this.EntityState);
     writer.Write("]");
 }
예제 #8
0
 internal override void Write(System.CodeDom.Compiler.IndentedTextWriter writer, JsFormatter formatter)
 {
     writer.Write("return ");
     Expression.Write(writer, formatter);
     writer.WriteLine(";");
 }
예제 #9
0
 protected virtual void BaseTrace(System.CodeDom.Compiler.IndentedTextWriter writer)
 {
     writer.Write("[");
     writer.Write("Id=");
     writer.Write(this.Id);
     writer.Write(",");
     writer.Write("Type=");
     writer.Write(this.Type);
     writer.Write(",");
     writer.Write("Value=");
     writer.Write(this.Value);
     writer.Write(",");
     writer.Write("ValueType=");
     writer.Write(this.ValueType);
     writer.Write(",");
     writer.Write("Role=");
     if ((this._role != null))
     {
         ((CodeFluent.Runtime.ICodeFluentObject)(this._role)).Trace(writer);
     }
     else
     {
         writer.Write("<null>");
     }
     writer.Write(",");
     writer.Write("_roleId=");
     writer.Write(this._roleId);
     writer.Write(", EntityState=");
     writer.Write(this.EntityState);
     writer.Write("]");
 }
예제 #10
0
파일: Tests.cs 프로젝트: zanyants/mvp.xml
		public void XmlDocumentLoading()
		{
			string xml = "<customer id='1' pp:id='aba' xmlns='urn-kzu' xmlns:pp='urn-pepenamespace'><pp:order /><order id='1'>Chocolates</order></customer>";

			XPathNavigator nav = new XPathDocument(new StringReader(xml)).CreateNavigator();

			XmlReader reader = new XPathNavigatorReader(nav);
			//XmlReader reader = new XmlTextReader(new StringReader(xml));

			//reader.MoveToContent();
			//Console.WriteLine(reader.ReadOuterXml());

			System.CodeDom.Compiler.IndentedTextWriter tw = new System.CodeDom.Compiler.IndentedTextWriter(Console.Out);

			while (reader.Read())
			{
				tw.Indent = reader.Depth;
				tw.WriteLine("Name={0}, Type={1}", reader.Name, reader.NodeType);
				int count = reader.AttributeCount;
				//reader.MoveToFirstAttribute();
				//for (int i = 0; i < count; i++) 
				while (reader.MoveToNextAttribute())
				{
					tw.Indent = reader.Depth;
					tw.Write("{0}=", reader.Name);
					reader.ReadAttributeValue();
					tw.WriteLine(reader.Value);
					//reader.MoveToNextAttribute();
				}
			}

			//reader = new DebuggingXmlTextReader(new XPathNavigatorReader(nav));
			reader = new XPathNavigatorReader(nav);
			XmlDocument doc = new XmlDocument(nav.NameTable);
			doc.Load( reader );
           
			Assert.AreEqual("customer", doc.DocumentElement.LocalName);
			Assert.AreEqual("urn-kzu", doc.DocumentElement.NamespaceURI);
			Assert.AreEqual(4, doc.DocumentElement.Attributes.Count);
			Assert.AreEqual(2, doc.DocumentElement.ChildNodes.Count);
		}
예제 #11
0
 protected virtual void BaseTrace(System.CodeDom.Compiler.IndentedTextWriter writer)
 {
     writer.Write("[");
     writer.Write("Id=");
     writer.Write(this.Id);
     writer.Write(",");
     writer.Write("Email=");
     writer.Write(this.Email);
     writer.Write(",");
     writer.Write("FirstName=");
     writer.Write(this.FirstName);
     writer.Write(",");
     writer.Write("LastName=");
     writer.Write(this.LastName);
     writer.Write(",");
     writer.Write("ContactSource=");
     if ((this._contactSource != null))
     {
         ((CodeFluent.Runtime.Diagnostics.ITraceable)(this._contactSource)).Trace(writer);
     }
     else
     {
         writer.Write("<null>");
     }
     writer.Write(",");
     writer.Write("_contactSourceId=");
     writer.Write(this._contactSourceId);
     writer.Write(",");
     writer.Write("Status=");
     writer.Write(this.Status);
     writer.Write(",");
     writer.Write("Address=");
     if ((this._address != null))
     {
         ((CodeFluent.Runtime.Diagnostics.ITraceable)(this._address)).Trace(writer);
     }
     else
     {
         writer.Write("<null>");
     }
     writer.Write(",");
     writer.Write("_addressId=");
     writer.Write(this._addressId);
     writer.Write(",");
     writer.Write("User="******"<null>");
     }
     writer.Write(",");
     writer.Write("_userId=");
     writer.Write(this._userId);
     writer.Write(",");
     writer.Write("Description=");
     writer.Write(this.Description);
     writer.Write(", EntityState=");
     writer.Write(this.EntityState);
     writer.Write("]");
 }
예제 #12
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 (_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());
            }
        }
예제 #13
0
 protected virtual void BaseTrace(System.CodeDom.Compiler.IndentedTextWriter writer)
 {
     writer.Write("[");
     writer.Write("Id=");
     writer.Write(this.Id);
     writer.Write(",");
     writer.Write("Document=");
     if ((this._document != null))
     {
         ((CodeFluent.Runtime.ICodeFluentObject)(this._document)).Trace(writer);
     }
     else
     {
         writer.Write("<null>");
     }
     writer.Write(",");
     writer.Write("_documentId=");
     writer.Write(this._documentId);
     writer.Write(",");
     writer.Write("Text=");
     writer.Write(this.Text);
     writer.Write(",");
     writer.Write("IsProcessed=");
     writer.Write(this.IsProcessed);
     writer.Write(",");
     writer.Write("IsReady=");
     writer.Write(this.IsReady);
     writer.Write(",");
     writer.Write("Token=");
     writer.Write(this.Token);
     writer.Write(",");
     writer.Write("Order=");
     writer.Write(this.Order);
     writer.Write(", EntityState=");
     writer.Write(this.EntityState);
     writer.Write("]");
 }
예제 #14
0
 protected virtual void BaseTrace(System.CodeDom.Compiler.IndentedTextWriter writer)
 {
     writer.Write("[");
     writer.Write("Id=");
     writer.Write(this.Id);
     writer.Write(",");
     writer.Write("Password="******",");
     writer.Write("UserName="******",");
     writer.Write("SecurityStamp=");
     writer.Write(this.SecurityStamp);
     writer.Write(",");
     writer.Write("Roles=");
     if ((this._roles != null))
     {
         ((CodeFluent.Runtime.ICodeFluentObject)(this._roles)).Trace(writer);
     }
     else
     {
         writer.Write("<null>");
     }
     writer.Write(",");
     writer.Write("ExternalLogins=");
     if ((this._externalLogins != null))
     {
         ((CodeFluent.Runtime.ICodeFluentObject)(this._externalLogins)).Trace(writer);
     }
     else
     {
         writer.Write("<null>");
     }
     writer.Write(",");
     writer.Write("Claims=");
     if ((this._claims != null))
     {
         ((CodeFluent.Runtime.ICodeFluentObject)(this._claims)).Trace(writer);
     }
     else
     {
         writer.Write("<null>");
     }
     writer.Write(", EntityState=");
     writer.Write(this.EntityState);
     writer.Write("]");
 }
예제 #15
0
 protected virtual void BaseTrace(System.CodeDom.Compiler.IndentedTextWriter writer)
 {
     writer.Write("[");
     writer.Write("Id=");
     writer.Write(this.Id);
     writer.Write(",");
     writer.Write("Name=");
     writer.Write(this.Name);
     writer.Write(",");
     writer.Write("Description=");
     writer.Write(this.Description);
     writer.Write(",");
     writer.Write("Width=");
     writer.Write(this.Width);
     writer.Write(",");
     writer.Write("Height=");
     writer.Write(this.Height);
     writer.Write(",");
     writer.Write("TVA=");
     writer.Write(this.TVA);
     writer.Write(",");
     writer.Write("Price=");
     writer.Write(this.Price);
     writer.Write(",");
     writer.Write("Support=");
     if ((this._support != null))
     {
         ((CodeFluent.Runtime.ICodeFluentObject)(this._support)).Trace(writer);
     }
     else
     {
         writer.Write("<null>");
     }
     writer.Write(", EntityState=");
     writer.Write(this.EntityState);
     writer.Write("]");
 }
예제 #16
0
 public override void ToSource(System.CodeDom.Compiler.IndentedTextWriter sb)    
 {
     sb.Write("<T>{0}", ToString());
 }
예제 #17
0
 protected virtual void BaseTrace(System.CodeDom.Compiler.IndentedTextWriter writer)
 {
     writer.Write("[");
     writer.Write("Id=");
     writer.Write(this.Id);
     writer.Write(",");
     writer.Write("Gender=");
     writer.Write(this.Gender);
     writer.Write(",");
     writer.Write("Day=");
     writer.Write(this.Day);
     writer.Write(", EntityState=");
     writer.Write(this.EntityState);
     writer.Write("]");
 }
예제 #18
0
 protected virtual void BaseTrace(System.CodeDom.Compiler.IndentedTextWriter writer)
 {
     writer.Write("[");
     writer.Write("Id=");
     writer.Write(this.Id);
     writer.Write(",");
     writer.Write("Label=");
     writer.Write(this.Label);
     writer.Write(",");
     writer.Write("Quantity=");
     writer.Write(this.Quantity);
     writer.Write(",");
     writer.Write("Name=");
     writer.Write(this.Name);
     writer.Write(",");
     writer.Write("List=");
     if ((this._list != null))
     {
         ((CodeFluent.Runtime.ICodeFluentObject)(this._list)).Trace(writer);
     }
     else
     {
         writer.Write("<null>");
     }
     writer.Write(",");
     writer.Write("_listId=");
     writer.Write(this._listId);
     writer.Write(", EntityState=");
     writer.Write(this.EntityState);
     writer.Write("]");
 }
예제 #19
0
        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());
            }
        }
예제 #20
0
 internal override void Write(System.CodeDom.Compiler.IndentedTextWriter writer, GmlFormatter formatter)
 {
     writer.Write("-");
     Operand.Write(writer, formatter);
 }
예제 #21
0
 internal override void Write(System.CodeDom.Compiler.IndentedTextWriter writer, GmlFormatter formatter)
 {
     Left.Write(writer, formatter);
     writer.Write(string.Concat(formatter.Padding, Operator, formatter.Padding));
     Right.Write(writer, formatter);
 }
예제 #22
0
 protected virtual void BaseTrace(System.CodeDom.Compiler.IndentedTextWriter writer)
 {
     writer.Write("[");
     writer.Write("Id=");
     writer.Write(this.Id);
     writer.Write(",");
     writer.Write("Publication=");
     if ((this._publication != null))
     {
         ((CodeFluent.Runtime.ICodeFluentObject)(this._publication)).Trace(writer);
     }
     else
     {
         writer.Write("<null>");
     }
     writer.Write(",");
     writer.Write("_publicationId=");
     writer.Write(this._publicationId);
     writer.Write(",");
     writer.Write("Space=");
     if ((this._space != null))
     {
         ((CodeFluent.Runtime.ICodeFluentObject)(this._space)).Trace(writer);
     }
     else
     {
         writer.Write("<null>");
     }
     writer.Write(",");
     writer.Write("_spaceId=");
     writer.Write(this._spaceId);
     writer.Write(",");
     writer.Write("Quantity=");
     writer.Write(this.Quantity);
     writer.Write(",");
     writer.Write("AvailableQuantity=");
     writer.Write(this.AvailableQuantity);
     writer.Write(", EntityState=");
     writer.Write(this.EntityState);
     writer.Write("]");
 }
예제 #23
0
 protected virtual void BaseTrace(System.CodeDom.Compiler.IndentedTextWriter writer)
 {
     writer.Write("[");
     writer.Write("Id=");
     writer.Write(this.Id);
     writer.Write(",");
     writer.Write("Name=");
     writer.Write(this.Name);
     writer.Write(",");
     writer.Write("Description=");
     writer.Write(this.Description);
     writer.Write(",");
     writer.Write("Category=");
     if ((this._category != null))
     {
         ((CodeFluent.Runtime.ICodeFluentObject)(this._category)).Trace(writer);
     }
     else
     {
         writer.Write("<null>");
     }
     writer.Write(",");
     writer.Write("_categoryId=");
     writer.Write(this._categoryId);
     writer.Write(", EntityState=");
     writer.Write(this.EntityState);
     writer.Write("]");
 }
예제 #24
0
 protected virtual void BaseTrace(System.CodeDom.Compiler.IndentedTextWriter writer)
 {
     writer.Write("[");
     writer.Write("Id=");
     writer.Write(this.Id);
     writer.Write(",");
     writer.Write("Text=");
     writer.Write(this.Text);
     writer.Write(",");
     writer.Write("User="******"<null>");
     }
     writer.Write(",");
     writer.Write("_userId=");
     writer.Write(this._userId);
     writer.Write(",");
     writer.Write("Title=");
     writer.Write(this.Title);
     writer.Write(",");
     writer.Write("Directory=");
     if ((this._directory != null))
     {
         ((CodeFluent.Runtime.ICodeFluentObject)(this._directory)).Trace(writer);
     }
     else
     {
         writer.Write("<null>");
     }
     writer.Write(",");
     writer.Write("_directoryId=");
     writer.Write(this._directoryId);
     writer.Write(",");
     writer.Write("Pages=");
     if ((this._pages != null))
     {
         ((CodeFluent.Runtime.ICodeFluentObject)(this._pages)).Trace(writer);
     }
     else
     {
         writer.Write("<null>");
     }
     writer.Write(",");
     writer.Write("Reference=");
     writer.Write(this.Reference);
     writer.Write(",");
     writer.Write("Token=");
     writer.Write(this.Token);
     writer.Write(",");
     writer.Write("IsProcessed=");
     writer.Write(this.IsProcessed);
     writer.Write(",");
     writer.Write("IsReady=");
     writer.Write(this.IsReady);
     writer.Write(", EntityState=");
     writer.Write(this.EntityState);
     writer.Write("]");
 }
예제 #25
0
 public void Log(string message, Exception ex)
 {
     indentWriter.Write(message);
     logException(ex);
 }
예제 #26
0
 internal override void Write(System.CodeDom.Compiler.IndentedTextWriter writer, GmlFormatter formatter)
 {
     writer.Write("(");
     InnerExpression.Write(writer, formatter);
     writer.Write(")");
 }
예제 #27
0
 protected virtual void BaseTrace(System.CodeDom.Compiler.IndentedTextWriter writer)
 {
     writer.Write("[");
     writer.Write("Id=");
     writer.Write(this.Id);
     writer.Write(",");
     writer.Write("Line1=");
     writer.Write(this.Line1);
     writer.Write(",");
     writer.Write("Line2=");
     writer.Write(this.Line2);
     writer.Write(",");
     writer.Write("City=");
     writer.Write(this.City);
     writer.Write(",");
     writer.Write("Zip=");
     writer.Write(this.Zip);
     writer.Write(",");
     writer.Write("Country=");
     writer.Write(this.Country);
     writer.Write(",");
     writer.Write("Contact=");
     if ((this._contact != null))
     {
         ((CodeFluent.Runtime.Diagnostics.ITraceable)(this._contact)).Trace(writer);
     }
     else
     {
         writer.Write("<null>");
     }
     writer.Write(",");
     writer.Write("_contactId=");
     writer.Write(this._contactId);
     writer.Write(",");
     writer.Write("GoogleMapUrl=");
     writer.Write(this.GoogleMapUrl);
     writer.Write(",");
     writer.Write("LiveMapUrl=");
     writer.Write(this.LiveMapUrl);
     writer.Write(", EntityState=");
     writer.Write(this.EntityState);
     writer.Write("]");
 }
예제 #28
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("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());
            }
        }
예제 #29
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());
            }
        }
예제 #30
0
 internal override void Write(System.CodeDom.Compiler.IndentedTextWriter writer, JsFormatter formatter)
 {
     Left.Write(writer, formatter);
     writer.Write(string.Format("{1}{0}{1}", Operator, " "));
     Right.Write(writer, formatter);
 }
예제 #31
0
 protected virtual void BaseTrace(System.CodeDom.Compiler.IndentedTextWriter writer)
 {
     writer.Write("[");
     writer.Write("Id=");
     writer.Write(this.Id);
     writer.Write(",");
     writer.Write("Email=");
     writer.Write(this.Email);
     writer.Write(",");
     writer.Write("FirstName=");
     writer.Write(this.FirstName);
     writer.Write(",");
     writer.Write("LastName=");
     writer.Write(this.LastName);
     writer.Write(",");
     writer.Write("FullName=");
     writer.Write(this.FullName);
     writer.Write(",");
     writer.Write("Photo=");
     ((CodeFluent.Runtime.Diagnostics.ITraceable)(this.Photo)).Trace(writer);
     writer.Write(",");
     writer.Write("Contacts=");
     if ((this._contacts != null))
     {
         ((CodeFluent.Runtime.ICodeFluentObject)(this._contacts)).Trace(writer);
     }
     else
     {
         writer.Write("<null>");
     }
     writer.Write(", EntityState=");
     writer.Write(this.EntityState);
     writer.Write("]");
 }
예제 #32
0
 protected virtual void BaseTrace(System.CodeDom.Compiler.IndentedTextWriter writer)
 {
     writer.Write("[");
     writer.Write("Id=");
     writer.Write(this.Id);
     writer.Write(",");
     writer.Write("Line1=");
     writer.Write(this.Line1);
     writer.Write(",");
     writer.Write("Line2=");
     writer.Write(this.Line2);
     writer.Write(",");
     writer.Write("City=");
     writer.Write(this.City);
     writer.Write(",");
     writer.Write("Zip=");
     writer.Write(this.Zip);
     writer.Write(",");
     writer.Write("Country=");
     writer.Write(this.Country);
     writer.Write(",");
     writer.Write("Contact=");
     writer.Write(this.Contact);
     writer.Write(",");
     writer.Write("GoogleMapUrl=");
     writer.Write(this.GoogleMapUrl);
     writer.Write(",");
     writer.Write("LiveMapUrl=");
     writer.Write(this.LiveMapUrl);
     writer.Write(", EntityState=");
     writer.Write(this.EntityState);
     writer.Write("]");
 }
예제 #33
0
 protected virtual void BaseTrace(System.CodeDom.Compiler.IndentedTextWriter writer)
 {
     writer.Write("[");
     writer.Write("Id=");
     writer.Write(this.Id);
     writer.Write(",");
     writer.Write("FullName=");
     writer.Write(this.FullName);
     writer.Write(",");
     writer.Write("DateOfBirth=");
     writer.Write(this.DateOfBirth);
     writer.Write(", EntityState=");
     writer.Write(this.EntityState);
     writer.Write("]");
 }
예제 #34
0
 protected virtual void BaseTrace(System.CodeDom.Compiler.IndentedTextWriter writer)
 {
     writer.Write("[");
     writer.Write("Id=");
     writer.Write(this.Id);
     writer.Write(",");
     writer.Write("Name=");
     writer.Write(this.Name);
     writer.Write(",");
     writer.Write("CardNumber=");
     writer.Write(this.CardNumber);
     writer.Write(", EntityState=");
     writer.Write(this.EntityState);
     writer.Write("]");
 }
예제 #35
0
 protected virtual void BaseTrace(System.CodeDom.Compiler.IndentedTextWriter writer)
 {
     writer.Write("[");
     writer.Write("Id=");
     writer.Write(this.Id);
     writer.Write(",");
     writer.Write("FirstName=");
     writer.Write(this.FirstName);
     writer.Write(",");
     writer.Write("LastName=");
     writer.Write(this.LastName);
     writer.Write(", EntityState=");
     writer.Write(this.EntityState);
     writer.Write("]");
 }
예제 #36
0
        static void Main(string[] args)
        {
            if (!args.Any())
            {
                Console.Error.WriteLine("Needs a file as an argument");
                return;
            }

            Debug.WriteLine("Input file is \"{0}\"", args.First());

            var file = new StreamReader(args.First());
            var levelstack = new Stack<int>();

            // Parse mlst file
            List<Function> functions = new List<Function>();
            List<string> @using = new List<string>();
            @using.Add("JsonApi.Client");
            @using.Add("JsonApi.Client.Classes");
            @using.Add("JsonApi.Client.DataTypes");
            @using.Add("System");
            @using.Add("System.Collections.Generic");
            @using.Add("System.Linq");
            @using.Add("System.Text");
            string @namespace = "JsonApi.Client.Extensions";
            string @class = "CustomRequests";

            Debug.WriteLine("Default imported namespaces: {0}", @using.Count);
            Debug.WriteLine("Default namespace: {0}", @namespace, null); // Yep, laziness found here.
            Debug.WriteLine("Default class: {0}", @class, null);

            string line = file.ReadLine().TrimEnd();
            while (!file.EndOfStream)
            {
                Debug.WriteLine("Current line, expecting new function or compiler directive: Level {1} => {0}", line.Trim(), GetLevel(line));

                if (string.IsNullOrWhiteSpace(line) || string.IsNullOrEmpty(line))
                {
                    Debug.WriteLine("Ignoring because empty.");
                    line = file.ReadLine().TrimEnd();
                    continue;
                }

                if (line.StartsWith("."))
                {
                    // compiler command
                    var lspl = line.Split(' ');
                    var argline = string.Join(" ", lspl.Skip(1));
                    var argarray = lspl.Skip(1);
                    Debug.WriteLine("Compiler command being processed: {0} (with {1} arguments)", lspl[0].ToLower().Substring(1), argarray.Count());
                    line = file.ReadLine().TrimEnd(); // for next processing, we should ignore that from now on.
                    switch (lspl[0].ToLower().Substring(1))
                    {
                        case "using":
                            if ([email protected](argline, StringComparer.OrdinalIgnoreCase))
                            {
                                Debug.WriteLine("Importing {0}", argline);
                                @using.Add(argline);
                            }
                            else
                                Console.Error.WriteLine("Warning: Tried adding \"using {0}\", but namespace has already been imported.", argline, null);
                            break;
                        case "namespace":
                            Debug.WriteLine("Changing to namespace {0}", argline, null);
                            @namespace = argline;
                            break;
                        case "class":
                            Debug.WriteLine("Changing to class {0}", argline, null);
                            @class = argline;
                            break;
                    }
                    continue;
                }

                var cFunction = new Function();
                cFunction.Name = line.Trim();
                Debug.WriteLine("Generating new function: {0}", cFunction.Name, null);

                levelstack.Push(GetLevel(line)); // root level push
                line = file.ReadLine().TrimEnd();
                while (line != null && !(line.TrimEnd() == "") && GetLevel(line) > levelstack.Peek())
                {
                    Debug.WriteLine("Current line, expecting new descriptive keyword: Level {1} => {0}", line.Trim(), GetLevel(line));
                    switch (line.Trim().ToLower())
                    {
                        default:
                            {
                                Console.Error.WriteLine("Warning: Found unknown descriptive keyword \"{0}\", ignoring", line.Trim().ToLower(), null);
                                line = file.ReadLine().TrimEnd();
                            } break;
                        case "description":
                            {
                                Debug.WriteLine("Found description for {0}", cFunction.Name, null);
                                if (!string.IsNullOrEmpty(cFunction.Description))
                                {
                                    throw new Exception(string.Format("Function \"{0}\" already contains a description. Can't define twice.", cFunction.Name));
                                }
                                StringBuilder descriptionBuilder = new StringBuilder();
                                levelstack.Push(GetLevel(line)); // command level push
                                while (GetLevel(line = file.ReadLine()) > levelstack.Peek())
                                {
                                    Debug.WriteLine("Adding 1 line to description");
                                    descriptionBuilder.AppendLine(line.Trim());
                                }
                                levelstack.Pop(); // command level pop
                                cFunction.Description = descriptionBuilder.ToString().Trim();
                                Debug.WriteLine("Description: {0}", cFunction.Description, null);
                            } break;
                        case "arguments":
                            {
                                Debug.WriteLine("Found arguments for {0}", cFunction.Name, null);
                                levelstack.Push(GetLevel(line)); // command level push
                                line = file.ReadLine().TrimEnd();
                                while (GetLevel(line) > levelstack.Peek())
                                {
                                    var spl = line.Trim().Split(' ');
                                    var type = new DataType() { TypeName = spl[0] };
                                    var name = string.Empty;
                                    if (spl.Length > 1)
                                        name = spl.Last();
                                    else
                                    {
                                        name = "arg" + cFunction.Arguments.Count;
                                    }
                                    Debug.WriteLine("Adding argument {0} of type {1}", name, type.TypeName);
                                    StringBuilder descriptionBuilder = new StringBuilder();
                                    levelstack.Push(GetLevel(line)); // argument level push
                                    while (GetLevel(line = file.ReadLine()) > levelstack.Peek())
                                    {
                                        Debug.WriteLine("Adding 1 line to description");
                                        descriptionBuilder.AppendLine(line.Trim());
                                    }
                                    levelstack.Pop(); // argument level pop
                                    type.Description = descriptionBuilder.ToString().Trim();
                                    cFunction.Arguments.Add(name, type);
                                }
                                levelstack.Pop(); // command level pop
                            } break;
                        case "return":
                        case "returns":
                            {
                                var type = new DataType() { TypeName = (line = file.ReadLine()).Trim() };
                                Debug.WriteLine("Found return type {0}", type.TypeName, null);
                                StringBuilder descriptionBuilder = new StringBuilder();
                                levelstack.Push(GetLevel(line)); // command level push
                                while (GetLevel(line = file.ReadLine()) > levelstack.Peek())
                                    descriptionBuilder.AppendLine(line.Trim());
                                levelstack.Pop(); // command level pop
                                type.Description = descriptionBuilder.ToString().Trim();
                                cFunction.ReturnType = type;
                            } break;
                    }
                }
                levelstack.Pop(); // root level pop

                functions.Add(cFunction);
            }

            // using directives
            var stream = Console.OpenStandardOutput();
            var streamwriter = new System.CodeDom.Compiler.IndentedTextWriter(new StreamWriter(stream));
            foreach (string importedNamespace in @using)
                streamwriter.WriteLine("using {0};", importedNamespace);

            // Start namespace
            streamwriter.WriteLine("namespace {0}", @namespace);
            streamwriter.WriteLine("{");
            streamwriter.Indent++;

            // Start class
            streamwriter.WriteLine("public static class {0}", @class);
            streamwriter.WriteLine("{");
            streamwriter.Indent++;

            // Functions
            foreach (var function in functions)
            {
                // Fix return type
                if (function.ReturnType == null)
                    function.ReturnType = new DataType() { TypeName = "void" };
                if (function.ReturnType.TypeName.Equals("boolean", StringComparison.OrdinalIgnoreCase))
                    function.ReturnType.TypeName = "bool";

                // Fix argument types
                foreach (var aName in function.Arguments.Keys)
                {
                    var aVal = function.Arguments[aName];
                    if (aVal.TypeName.Equals("boolean", StringComparison.OrdinalIgnoreCase))
                        aVal.TypeName = "bool";
                }

                // Request generation function
                foreach (string l in function.GetMetadataXml().Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries))
                    streamwriter.WriteLine("/// {0}", l.Trim(), null);
                streamwriter.Flush();
                streamwriter.WriteLine("public static StandardAPIRequest {0}({1})", function.NormalizedName, function.GetParameterSignature());
                streamwriter.Write("{ ");
                streamwriter.Write("return new StandardAPIRequest(\"{0}\"{1});", function.Name, function.Arguments.Count > 0 ? ", " + function.GetParameterPass() : "");
                streamwriter.WriteLine(" }");
                streamwriter.WriteLine();
                streamwriter.Flush();

                // Actual standard API request function
                foreach (string l in function.GetMetadataXml().Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries))
                    streamwriter.WriteLine("/// {0}", l.Trim(), null);
                streamwriter.Flush();
                streamwriter.WriteLine("public static {2} {0}(this Client client{1})", function.NormalizedName, function.Arguments.Count > 0 ? ", " + function.GetParameterSignature() : "", function.ReturnType == null ? "void" : function.ReturnType.TypeName);
                streamwriter.Write("{ ");
                if(function.ReturnType != null && function.ReturnType.TypeName != "void")
                    streamwriter.Write("return client.Request<{2}>({0}({1}));", function.NormalizedName, function.GetParameterPass(), function.ReturnType.TypeName);
                else
                    streamwriter.Write("client.Request({0}({1}));", function.NormalizedName, function.GetParameterPass());
                streamwriter.WriteLine(" }");
                streamwriter.WriteLine();
                streamwriter.Flush();
            }

            // End class
            streamwriter.Indent--;
            streamwriter.WriteLine("}");

            // End namespace
            streamwriter.Indent--;
            streamwriter.WriteLine("}");

            // Finalize
            streamwriter.Flush();
            streamwriter.Close();
            streamwriter.Dispose();
        }
예제 #37
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("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());
            }
        }
예제 #38
0
 protected virtual void BaseTrace(System.CodeDom.Compiler.IndentedTextWriter writer)
 {
     writer.Write("[");
     writer.Write("Id=");
     writer.Write(this.Id);
     writer.Write(",");
     writer.Write("Name=");
     writer.Write(this.Name);
     writer.Write(",");
     writer.Write("Users=");
     if ((this._users != null))
     {
         ((CodeFluent.Runtime.ICodeFluentObject)(this._users)).Trace(writer);
     }
     else
     {
         writer.Write("<null>");
     }
     writer.Write(", EntityState=");
     writer.Write(this.EntityState);
     writer.Write("]");
 }
예제 #39
0
 protected virtual void BaseTrace(System.CodeDom.Compiler.IndentedTextWriter writer)
 {
     writer.Write("[");
     writer.Write(string.Concat("Count=", this.Count));
     writer.Write("]");
 }
예제 #40
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 (_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());
            }
        }
예제 #41
0
 protected virtual void BaseTrace(System.CodeDom.Compiler.IndentedTextWriter writer)
 {
     writer.Write("[");
     writer.Write("Id=");
     writer.Write(this.Id);
     writer.Write(",");
     writer.Write("Email=");
     writer.Write(this.Email);
     writer.Write(",");
     writer.Write("FirstName=");
     writer.Write(this.FirstName);
     writer.Write(",");
     writer.Write("LastName=");
     writer.Write(this.LastName);
     writer.Write(",");
     writer.Write("ContactSource=");
     writer.Write(this.ContactSource);
     writer.Write(",");
     writer.Write("Status=");
     writer.Write(this.Status);
     writer.Write(",");
     writer.Write("Address=");
     writer.Write(this.Address);
     writer.Write(",");
     writer.Write("User="******",");
     writer.Write("Description=");
     writer.Write(this.Description);
     writer.Write(", EntityState=");
     writer.Write(this.EntityState);
     writer.Write("]");
 }
예제 #42
0
 protected virtual void BaseTrace(System.CodeDom.Compiler.IndentedTextWriter writer)
 {
     writer.Write("[");
     writer.Write("Id=");
     writer.Write(this.Id);
     writer.Write(",");
     writer.Write("FirstName=");
     writer.Write(this.FirstName);
     writer.Write(",");
     writer.Write("LastName=");
     writer.Write(this.LastName);
     writer.Write(",");
     writer.Write("Description=");
     writer.Write(this.Description);
     writer.Write(",");
     writer.Write("User="******"<null>");
     }
     writer.Write(",");
     writer.Write("_userId=");
     writer.Write(this._userId);
     writer.Write(", EntityState=");
     writer.Write(this.EntityState);
     writer.Write("]");
 }