Exemplo n.º 1
0
        public void InstanceParameterTests()
        {
            ExpressionCompiler <string, TestParams> instPropTest = new ExpressionCompiler <string, TestParams>("Instance.RadarProperty.Substring(0, 5)");
            ExpressionCompiler instMethodTest = new ExpressionCompiler("Instance.ShowData()");

            TestParams testParams = new TestParams {
                Instance = this
            };

            Assert.IsTrue(instPropTest.ExecuteFunction(testParams).Equals("RADAR"));

            instMethodTest.InstanceParameterType = typeof(TestParams);
            instMethodTest.ExecuteAction(testParams);

            // When instance parameter type is defined, expressions expecting parameter should fail:
            Assert.ThrowsException <TargetException>(() => instMethodTest.ExecuteAction()); // This creates a new context type

            System.Console.WriteLine($"Context Type for '{nameof(instPropTest)}': {instPropTest.TypeRegistry.GetContextType<string, TestParams>()?.FullName}");
            System.Console.WriteLine($"Expression for '{nameof(instPropTest)}': {instPropTest}");

            System.Console.WriteLine($"Context Type for '{nameof(instMethodTest)}': {instMethodTest.TypeRegistry.GetContextType<object, TestParams>()?.FullName}");
            System.Console.WriteLine($"Expression for '{nameof(instMethodTest)}': {instMethodTest}");

            System.Console.WriteLine($"Generated Context Type Count = {TypeRegistry.GeneratedContextTypeCount:N0}");
        }