本文整理汇总了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();
}
示例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);
}
}
示例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();
}