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


C# EvaluationContext.CompileGetLocals方法代码示例

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


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

示例1: VerifyNoThis

        private static void VerifyNoThis(EvaluationContext context)
        {
            string error;
            var testData = new CompilationTestData();
            context.CompileExpression("this", out error, testData);
            Assert.Contains(error, new[]
            {
                "error CS0026: Keyword 'this' is not valid in a static property, static method, or static field initializer",
                "error CS0027: Keyword 'this' is not available in the current context",
            });

            testData = new CompilationTestData();
            context.CompileExpression("base.ToString()", out error, testData);
            Assert.Contains(error, new[]
            {
                "error CS1511: Keyword 'base' is not available in a static method",
                "error CS1512: Keyword 'base' is not available in the current context",
            });

            var locals = ArrayBuilder<LocalAndMethod>.GetInstance();
            string typeName;
            testData = new CompilationTestData();
            var assembly = context.CompileGetLocals(locals, argumentsOnly: false, typeName: out typeName, testData: testData);
            Assert.NotNull(assembly);
            AssertEx.None(locals, l => l.LocalName.Contains("this"));
            locals.Free();
        }
开发者ID:hyldrim,项目名称:roslyn,代码行数:27,代码来源:HoistedThisTests.cs

示例2: VerifyHasThis

        private static void VerifyHasThis(EvaluationContext context, string expectedType, string expectedIL)
        {
            var locals = ArrayBuilder<LocalAndMethod>.GetInstance();
            string typeName;
            var testData = new CompilationTestData();
            var assembly = context.CompileGetLocals(locals, argumentsOnly: false, typeName: out typeName, testData: testData);
            Assert.NotNull(assembly);
            Assert.NotEqual(assembly.Count, 0);
            var localAndMethod = locals.Single(l => l.LocalName == "this");
            if (expectedIL != null)
            {
                VerifyMethodData(testData.Methods.Single(m => m.Key.Contains(localAndMethod.MethodName)).Value, expectedType, expectedIL);
            }
            locals.Free();

            string error;
            testData = new CompilationTestData();
            context.CompileExpression("this", out error, testData);
            Assert.Null(error);
            if (expectedIL != null)
            {
                VerifyMethodData(testData.Methods.Single(m => m.Key.Contains("<>m0")).Value, expectedType, expectedIL);
            }
        }
开发者ID:hyldrim,项目名称:roslyn,代码行数:24,代码来源:HoistedThisTests.cs

示例3: GetLocalNames

 private static string[] GetLocalNames(EvaluationContext context)
 {
     string unused;
     var locals = new ArrayBuilder<LocalAndMethod>();
     context.CompileGetLocals(locals, argumentsOnly: false, typeName: out unused, testData: null);
     return locals.Select(l => l.LocalName).ToArray();
 }
开发者ID:hyldrim,项目名称:roslyn,代码行数:7,代码来源:HoistedStateMachineLocalTests.cs


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