当前位置: 首页>>代码示例>>C#>>正文


C# CodeDomProvider.GenerateCodeFromStatement方法代码示例

本文整理汇总了C#中System.CodeDom.Compiler.CodeDomProvider.GenerateCodeFromStatement方法的典型用法代码示例。如果您正苦于以下问题:C# CodeDomProvider.GenerateCodeFromStatement方法的具体用法?C# CodeDomProvider.GenerateCodeFromStatement怎么用?C# CodeDomProvider.GenerateCodeFromStatement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.CodeDom.Compiler.CodeDomProvider的用法示例。


在下文中一共展示了CodeDomProvider.GenerateCodeFromStatement方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PostProcess

 /// <summary>Called when extension shall process generated code</summary>
 /// <param name="code">The code</param>
 /// <param name="provider">CodeDOM provider (the language)</param>
 /// <version version="1.5.3">Parameter <c>Provider</c> renamed to <c>provider</c></version>
 public void PostProcess(ref string code, CodeDomProvider provider)
 {
     System.IO.StringWriter tw = new System.IO.StringWriter();
     provider.GenerateCodeFromStatement(new CodeCommentStatement(FirtsLineOfAccessor), tw, new System.CodeDom.Compiler.CodeGeneratorOptions());
     string srch = tw.GetStringBuilder().ToString();
     if (srch.EndsWith("\r\n")) srch = srch.Substring(0, srch.Length - 2);
     else if (srch.EndsWith("\r") || srch.EndsWith("\n")) srch = srch.Substring(0, srch.Length - 1);
     tw = new System.IO.StringWriter();
     CodeTypeDeclaration foo = new CodeTypeDeclaration("foo");
     foo.CustomAttributes.Add(NewAttribute);
     provider.GenerateCodeFromType(foo, tw, new System.CodeDom.Compiler.CodeGeneratorOptions());
     string attr = new System.IO.StringReader(tw.GetStringBuilder().ToString()).ReadLine();
     System.IO.StringReader sr = new System.IO.StringReader(code);
     List<String> Lines = new List<string>();
     do {
         string line = sr.ReadLine();
         if (line == null) break;
         if (line.EndsWith(srch))
             Lines[Lines.Count - 1] = attr + "\r\n" + Lines[Lines.Count - 1];
         else
             Lines.Add(line);
     } while (true);
     System.Text.StringBuilder b = new System.Text.StringBuilder();
     foreach (string line in Lines)
         b.AppendLine(line);
     code = b.ToString();
 }
开发者ID:wskplho,项目名称:Tools,代码行数:31,代码来源:DebuggerStepThrough.cs

示例2: AddSpecFlowFooter

 private void AddSpecFlowFooter(CodeDomProvider codeProvider, TextWriter outputWriter)
 {
     codeProvider.GenerateCodeFromStatement(codeDomHelper.GetEnableWarningsPragma(), outputWriter, null);
     codeProvider.GenerateCodeFromStatement(codeDomHelper.GetEndRegionStatement(), outputWriter, null);
 }
开发者ID:ethanmoffat,项目名称:SpecFlow,代码行数:5,代码来源:TestGenerator.cs

示例3: AddSpecFlowHeader

        private void AddSpecFlowHeader(CodeDomProvider codeProvider, TextWriter outputWriter)
        {
            const string specFlowHeaderTemplate = @"------------------------------------------------------------------------------
 <auto-generated>
     This code was generated by SpecFlow (http://www.specflow.org/).
     SpecFlow Version:{0}
     SpecFlow Generator Version:{1}

     Changes to this file may cause incorrect behavior and will be lost if
     the code is regenerated.
 </auto-generated>
------------------------------------------------------------------------------";

            var headerReader = new StringReader(string.Format(specFlowHeaderTemplate,
                GetCurrentSpecFlowVersion(),
                TestGeneratorFactory.GeneratorVersion
                ));

            string line;
            while ((line = headerReader.ReadLine()) != null)
            {
                codeProvider.GenerateCodeFromStatement(new CodeCommentStatement(line), outputWriter, null);
            }

            codeProvider.GenerateCodeFromStatement(codeDomHelper.GetStartRegionStatement("Designer generated code"), outputWriter, null);
            codeProvider.GenerateCodeFromStatement(codeDomHelper.GetDisableWarningsPragma(), outputWriter, null);
        }
开发者ID:ethanmoffat,项目名称:SpecFlow,代码行数:27,代码来源:TestGenerator.cs

示例4: GenrateMeth

 private static void GenrateMeth(CodeGeneratorOptions opts, CodeDomProvider provider, 
     IndentedTextWriter tw, CodeStatementCollection statements, string methName)
 {
     tw.WriteLine(methName);
     tw.WriteLine("{");
     tw.Indent++;
     foreach (CodeStatement statement in statements)
     {
         provider.GenerateCodeFromStatement(statement, tw, opts);
     }
     tw.Indent--;
     tw.WriteLine("}");
 }
开发者ID:laymain,项目名称:CodeDomUtils,代码行数:13,代码来源:CodeCustomEvent.cs

示例5: GenerateMemberForBlock

 /// <summary>生成成员代码块</summary>
 /// <param name="block"></param>
 /// <param name="generatorType"></param>
 /// <param name="lineNumbers"></param>
 /// <param name="provider"></param>
 /// <param name="options"></param>
 /// <param name="firstMemberFound"></param>
 /// <returns></returns>
 private static Boolean GenerateMemberForBlock(Block block, CodeTypeDeclaration generatorType, Boolean lineNumbers, CodeDomProvider provider, CodeGeneratorOptions options, Boolean firstMemberFound)
 {
     CodeSnippetTypeMember member = null;
     if (!firstMemberFound)
     {
         // 发现第一个<#!后,认为是类成员代码的开始,直到下一个<#!作为结束
         if (block.Type == BlockType.Member)
         {
             firstMemberFound = true;
             if (!String.IsNullOrEmpty(block.Text)) member = new CodeSnippetTypeMember(block.Text);
         }
     }
     else
     {
         // 再次遇到<#!,此时,成员代码准备结束
         if (block.Type == BlockType.Member)
         {
             firstMemberFound = false;
             if (!String.IsNullOrEmpty(block.Text)) member = new CodeSnippetTypeMember(block.Text);
         }
         else if (block.Type == BlockType.Text)
         {
             CodeMethodInvokeExpression expression = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "Write", new CodeExpression[] { new CodePrimitiveExpression(block.Text) });
             CodeExpressionStatement statement = new CodeExpressionStatement(expression);
             using (StringWriter writer = new StringWriter())
             {
                 provider.GenerateCodeFromStatement(statement, writer, options);
                 member = new CodeSnippetTypeMember(writer.ToString());
             }
         }
         else if (block.Type == BlockType.Expression)
         {
             CodeMethodInvokeExpression expression = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "Write", new CodeExpression[] { new CodeArgumentReferenceExpression(block.Text.Trim()) });
             CodeExpressionStatement statement = new CodeExpressionStatement(expression);
             using (StringWriter writer = new StringWriter())
             {
                 provider.GenerateCodeFromStatement(statement, writer, options);
                 member = new CodeSnippetTypeMember(writer.ToString());
             }
         }
         else if (block.Type == BlockType.Statement)
         {
             member = new CodeSnippetTypeMember(block.Text);
         }
     }
     if (member != null)
     {
         if (lineNumbers)
         {
             Boolean flag = String.IsNullOrEmpty(block.Name);
             Int32 lineNumber = (block.StartLine > 0) ? block.StartLine : 1;
             if (flag)
                 generatorType.Members.Add(new CodeSnippetTypeMember("#line " + lineNumber));
             else
                 member.LinePragma = new CodeLinePragma(block.Name, lineNumber);
             generatorType.Members.Add(member);
             if (flag) generatorType.Members.Add(new CodeSnippetTypeMember("#line default"));
         }
         else
             generatorType.Members.Add(member);
     }
     return firstMemberFound;
 }
开发者ID:g992com,项目名称:esb,代码行数:71,代码来源:Template.cs

示例6: AddSpecFlowHeader

        private void AddSpecFlowHeader(CodeDomProvider codeProvider, TextWriter outputWriter)
        {
            var specFlowHeaderTemplate = @"------------------------------------------------------------------------------
             <auto-generated>
             This code was generated by SpecFlow (http://www.specflow.org/).
             SpecFlow Version:{0}
             Runtime Version:{1}

             Changes to this file may cause incorrect behavior and will be lost if
             the code is regenerated.
             </auto-generated>
            ------------------------------------------------------------------------------";

            var headerReader = new StringReader(string.Format(specFlowHeaderTemplate,
                GetCurrentSpecFlowVersion(),
                Environment.Version
                ));

            string line;
            while ((line = headerReader.ReadLine()) != null)
            {
                codeProvider.GenerateCodeFromStatement(new CodeCommentStatement(line), outputWriter, null);
            }
        }
开发者ID:x97mdr,项目名称:SpecFlow,代码行数:24,代码来源:SpecFlowGenerator.cs

示例7: GenerateErrorString

		public static string GenerateErrorString(Exception ex, CodeDomProvider codeProvider, string fileName, string baseNamespace)
		{
			CodeGeneratorOptions gen = new CodeGeneratorOptions();
			gen.BracingStyle = "C";
			gen.IndentString = "\t";
			gen.VerbatimOrder = true;
			gen.BlankLinesBetweenMembers = false;

			CodeCommentStatementCollection comments = new CodeCommentStatementCollection();
			GenerateHeader(comments, fileName, baseNamespace);

			if (ex is CompileException)
			{
				CompileException cx = (CompileException)ex;
				comments.Add(new CodeCommentStatement(string.Format("Error generating shader:{0}{1} (line: {2} col: {3})", Environment.NewLine, cx.Text, cx.Line, cx.Coloumn)));
			}
			else if (ex is CompileExceptionCollection)
			{
				CompileExceptionCollection cxc = (CompileExceptionCollection)ex;
				for (int i = 0; i < cxc.Count; i++)
				{
					CompileException cx = cxc.GetException(i);
					comments.Add(new CodeCommentStatement(string.Format("Error generating shader:{0}{1} (line: {2} col: {3})", Environment.NewLine, cx.Text, cx.Line, cx.Coloumn)));
				}
			}
			else
			{
				comments.Add(new CodeCommentStatement(string.Format("Unhandled exception in XenFX:{0}{1}", Environment.NewLine, ex.ToString())));
			}
			
			StringBuilder sb = new StringBuilder();
			using (TextWriter writer = new StringWriter(sb))
			{
				foreach (CodeCommentStatement comment in comments)
				{
					codeProvider.GenerateCodeFromStatement(comment, writer, gen);
				}
			}
			return sb.ToString();
		}
开发者ID:shadarath,项目名称:Wirtualna-rzeczywistosc,代码行数:40,代码来源:Dom.cs

示例8: GenerateCode

        private static string GenerateCode(CodeObject c, CodeDomProvider provider)
        {
            var sb = new StringBuilder();
            var writer = new StringWriter(sb);
            var options = new CodeGeneratorOptions();

            if (c is CodeStatement)
            {
                provider.GenerateCodeFromStatement((CodeStatement)c, writer, options);
            }
            else if (c is CodeCompileUnit)
            {
                provider.GenerateCodeFromCompileUnit((CodeCompileUnit)c, writer, options);
            }
            else if (c is CodeExpression)
            {
                provider.GenerateCodeFromExpression((CodeExpression)c, writer, options);
            }
            else if (c is CodeTypeMember)
            {
                provider.GenerateCodeFromMember((CodeTypeMember)c, writer, options);
            }
            else if (c is CodeTypeDeclaration)
            {
                provider.GenerateCodeFromType((CodeTypeDeclaration)c, writer, options);
            }
            else if (c is CodeNamespace)
            {
                provider.GenerateCodeFromNamespace((CodeNamespace)c, writer, options);
            }
            else
            {
                throw new ArgumentException($"Tests not set up for unexpected type: {c.GetType()}");
            }

            return sb.ToString();
        }
开发者ID:dotnet,项目名称:corefx,代码行数:37,代码来源:CodeGenerationTests.cs

示例9: GenerateCode

        private static string GenerateCode(CodeObject c, CodeDomProvider provider)
        {
            var sb = new StringBuilder();
            var writer = new StringWriter(sb);
            var options = new CodeGeneratorOptions();

            if (c is CodeStatement)
            {
                provider.GenerateCodeFromStatement((CodeStatement)c, writer, options);
            }
            else if (c is CodeCompileUnit)
            {
                provider.GenerateCodeFromCompileUnit((CodeCompileUnit)c, writer, options);
            }
            else if (c is CodeExpression)
            {
                provider.GenerateCodeFromExpression((CodeExpression)c, writer, options);
            }
            else if (c is CodeTypeMember)
            {
                provider.GenerateCodeFromMember((CodeTypeMember)c, writer, options);
            }
            else if (c is CodeTypeDeclaration)
            {
                provider.GenerateCodeFromType((CodeTypeDeclaration)c, writer, options);
            }
            else if (c is CodeNamespace)
            {
                provider.GenerateCodeFromNamespace((CodeNamespace)c, writer, options);
            }
            else
            {
                Assert.False(true, $"Unknown type: {c.GetType()}");
            }

            return sb.ToString();
        }
开发者ID:Corillian,项目名称:corefx,代码行数:37,代码来源:CodeGenerationTests.cs

示例10: GenerateStatemets

 public void GenerateStatemets(TextWriter tw, CodeDomProvider provider, CodeGeneratorOptions opts, CodeStatement[] statements)
 {
     foreach (var statement in statements)
     {
         provider.GenerateCodeFromStatement(statement, tw, opts);
     }
 }
开发者ID:laymain,项目名称:CodeDomUtils,代码行数:7,代码来源:CodeMemberOperatorOverride.cs


注:本文中的System.CodeDom.Compiler.CodeDomProvider.GenerateCodeFromStatement方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。