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(); }
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); } }
private static void CompileDeclaration(EvaluationContext context, string declaration, out DkmClrCompilationResultFlags flags, out CompilationTestData testData) { testData = new CompilationTestData(); ResultProperties resultProperties; string error; ImmutableArray<AssemblyIdentity> missingAssemblyIdentities; var result = context.CompileExpression( declaration, DkmEvaluationFlags.None, NoAliases, DebuggerDiagnosticFormatter.Instance, out resultProperties, out error, out missingAssemblyIdentities, EnsureEnglishUICulture.PreferredOrNull, testData); Assert.Null(error); Assert.Empty(missingAssemblyIdentities); flags = resultProperties.Flags; }
private static void CheckResultFlags(EvaluationContext context, string expr, DkmClrCompilationResultFlags expectedFlags, string expectedError = null) { ResultProperties resultProperties; string error; var testData = new CompilationTestData(); var result = context.CompileExpression(expr, out resultProperties, out error, testData); Assert.Equal(expectedError, error); Assert.NotEqual(expectedError == null, result == null); Assert.Equal(expectedFlags, resultProperties.Flags); }
private static ResultProperties GetResultProperties(EvaluationContext context, string expr) { ResultProperties resultProperties; string error; context.CompileExpression(expr, out resultProperties, out error); Assert.Null(error); return resultProperties; }
private static void VerifyErrorResultProperties(EvaluationContext context, string expr) { ResultProperties resultProperties; string error; context.CompileExpression(expr, out resultProperties, out error); Assert.NotNull(error); Assert.Equal(default(ResultProperties), resultProperties); }
private static string[] GetLocalNames(EvaluationContext context) { string unused; var locals = new ArrayBuilder<LocalAndMethod>(); context.CompileGetLocals(locals, argumentsOnly: false, typeName: out unused); return locals.Select(l => l.LocalName).ToArray(); }
internal CSharpMetadataContext(ImmutableArray<MetadataBlock> metadataBlocks, EvaluationContext evaluationContext) { this.MetadataBlocks = metadataBlocks; this.Compilation = evaluationContext.Compilation; this.EvaluationContext = evaluationContext; }
internal CSharpMetadataContext(ImmutableArray<MetadataBlock> metadataBlocks, CSharpCompilation compilation) { this.MetadataBlocks = metadataBlocks; this.Compilation = compilation; this.EvaluationContext = null; }
private static string CompileExpression(EvaluationContext context, string expr) { ResultProperties resultProperties; string error; var testData = new CompilationTestData(); var result = context.CompileExpression(expr, out resultProperties, out error, testData); Assert.NotNull(result.Assembly); Assert.Null(error); return testData.GetMethodData(result.TypeName + "." + result.MethodName).GetMethodIL(); }
internal CSharpMetadataContext(EvaluationContext evaluationContext) : base(evaluationContext.MetadataBlocks) { this.Compilation = evaluationContext.Compilation; this.EvaluationContext = evaluationContext; }