Ejemplo n.º 1
0
        public void Variables()
        {
            var myVar = ParameterExpression.Create(TypeSignature.Int32, "myVar");

            cx.AddTestExpr(Expression.LetIn(
                               myVar, Expression.Constant(42),
                               target: Expression.Binary("+", myVar, myVar)
                               ));

            var mutableVar = ParameterExpression.CreateMutable(TypeSignature.Int32, "mutableVar");

            cx.AddTestExpr(Expression.LetIn(
                               mutableVar, Expression.Constant(42),
                               target: Expression.Binary("+",
                                                         mutableVar,
                                                         new [] {
                mutableVar.Assign(Expression.Constant(30))
            }.ToBlock(mutableVar)
                                                         )
                               ));

            var declaringType = TypeSignature.StaticClass("TestClass", NamespaceSignature.Parse("NS"), Accessibility.APublic);
            var method        = MethodSignature.Static(
                "M",
                declaringType,
                Accessibility.APublic,
                TypeSignature.Int32,
                new MethodParameter(TypeSignature.Int32, "a"));
            var argA = ParameterExpression.CreateMutable(TypeSignature.Int32, "a");
            var body = new [] {
                argA.Assign(Expression.Binary("+", argA, Expression.Constant(1)))
            }.ToBlock(result: argA);
            var methodDef = new MethodDef(method, new [] { argA }, body);

            cx.AddType(TypeDef.Empty(declaringType).AddMember(methodDef));

            check.CheckOutput(cx);
        }