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


C# CodeDomProvider.GenerateCodeFromExpression方法代码示例

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


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

示例1: ExpressionToString

 // courtesy of http://metasharp.net/index.php?title=More_technical_Csharp#Generating_the_.27is.27_operator
 public static string ExpressionToString(CodeExpression expr, CodeDomProvider provider)
 {
     using (TextWriter m = new StringWriter())
     {
         provider.GenerateCodeFromExpression(expr, m, new CodeGeneratorOptions());
         return m.ToString();
     }
 }
开发者ID:smoothfriction,项目名称:SmoothReflections,代码行数:9,代码来源:IltoCSharpConverter.cs

示例2: BuildCodeExtractingModelType

        private static string BuildCodeExtractingModelType(CodeDomProvider provider)
        {
            var getType = new CodeMethodInvokeExpression
                (
                    new CodeThisReferenceExpression(),
                    "GetType"
                );

            var baseType = new CodeFieldReferenceExpression
                (
                    getType,
                    "BaseType"
                );

            var getFirstGenericArgument = new CodeArrayIndexerExpression
                (
                    new CodeMethodInvokeExpression
                        (
                        baseType,
                        "GetGenericArguments"
                        ),
                    new CodePrimitiveExpression(0)
                );

            var fullName = new CodeFieldReferenceExpression
                (
                    getFirstGenericArgument,
                    "FullName"
                );

            string modelTypeCode;
            using (var writer = new StringWriter())
            {
                provider.GenerateCodeFromExpression(fullName, writer, new CodeGeneratorOptions());
                modelTypeCode = writer.ToString();
            }
            return modelTypeCode;
        }
开发者ID:l3m,项目名称:Nancy,代码行数:38,代码来源:RazorViewEngineFixture.cs

示例3: 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

示例4: 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

示例5: GenerateDeclaration

            public void GenerateDeclaration(TextWriter tw, CodeDomProvider provider, CodeGeneratorOptions opts, CodeTypeReference returnType, CodeParameterDeclarationExpression[] parameters)
            {
                tw.Write(string.Format("Public Shared {0} Operator CType", OperatorName));
                tw.Write("(");
                for (int i = 0; i < parameters.Length; i++)
                {
                    var parameter = parameters[i];
                    provider.GenerateCodeFromExpression(parameter, tw, opts);
                    if (i != (parameters.Length - 1))
                        tw.Write(", ");
                }

                tw.Write(") As ");
                provider.GenerateCodeFromExpression(new CodeTypeReferenceExpression(returnType), tw, opts);
                tw.WriteLine();
            }
开发者ID:laymain,项目名称:CodeDomUtils,代码行数:16,代码来源:CodeMemberOperatorOverride.cs


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