예제 #1
0
        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 methods        = testData.GetMethodsByName();
            var localAndMethod = locals.Single(l => l.LocalName == "this");

            if (expectedIL != null)
            {
                VerifyMethodData(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(methods.Single(m => m.Key.Contains("<>m0")).Value, expectedType, expectedIL);
            }
        }
예제 #2
0
        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 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());
        }
예제 #4
0
        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);
            }
        }
예제 #5
0
        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 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();
 }