Ejemplo n.º 1
0
        public void StructBoxing()
        {
            cx.AddType(MyStructDef);
            var p = ParameterExpression.Create(MyStruct, "p");

            cx.AddTestExpr(Expression.ReferenceConversion(p, TypeSignature.Object), p);
            cx.AddTestExpr(Expression.MethodCall(
                               cx.GetMemberMethods(TypeSignature.Object.NotGeneric()).Single(m => m.Signature.Name == "GetHashCode"),
                               args: ImmutableArray <Expression> .Empty,
                               Expression.ReferenceConversion(p, TypeSignature.Object)
                               ), p);
            check.CheckOutput(cx);
        }
Ejemplo n.º 2
0
        public void MethodInvocation()
        {
            var intParse     = cx.GetMemberMethods(TypeSignature.Int32.NotGeneric()).Single(m => m.Name() == "Parse" && m.Signature.Params.Length == 1 && m.Signature.Params[0].Type == TypeSignature.String);
            var stringConcat = cx.GetMemberMethods(TypeSignature.String.NotGeneric()).Single(m => m.Name() == "Concat" && m.Signature.Params.Length == 2 && m.Signature.Params[0].Type == TypeSignature.String);

            var concatCall = Expression.MethodCall(stringConcat, ImmutableArray.Create(Expression.Constant("123456789"), pString1), null);
            var intMethod  = Expression.MethodCall(intParse, ImmutableArray.Create(concatCall), null);
            var voidMethod = Expression.Block(ImmutableArray.Create(intMethod), Expression.Nop);

            cx.AddTestExpr(intMethod, pString1);
            cx.AddTestExpr(Expression.LetIn(pString1, Expression.Constant("5"), intMethod));
            cx.AddTestExpr(voidMethod, pString1);
            cx.AddTestExpr(Expression.Block(ImmutableArray.Create(concatCall), Expression.Nop), pString1);

            check.CheckOutput(cx);
        }
Ejemplo n.º 3
0
        public void LoadCoreMethods()
        {
            var stringT = TypeSignature.FromType(typeof(string));

            var methods = cx.GetMemberMethods(stringT.NotGeneric()).ToArray();

            var toUpperInvariantM = methods.Single(s => s.Name() == "ToUpperInvariant");

            check.CheckJsonObject(new { toUpperInvariantM });
        }
Ejemplo n.º 4
0
        public void IEquatableImplementation(bool isStruct, bool isExplicit)
        {
            var type = isStruct ? TypeSignature.Struct("MyType", ns, Accessibility.APublic)
                                : TypeSignature.Class("MyType", ns, Accessibility.APublic);
            var iequatableT     = TypeSignature.FromType(typeof(IEquatable <>)).Specialize(type);
            var interfaceMethod = cx.GetMemberMethods(iequatableT, "Equals").Single();
            var method          = new MethodSignature(type, ImmutableArray.Create(new MethodParameter(type, "obj")), "Equals", TypeReference.FromType(typeof(bool)), false, isExplicit ? Accessibility.APrivate : Accessibility.APublic, false, false, false, false, ImmutableArray <GenericParameter> .Empty);
            var methodDef       = MethodDef.Create(method, (_thisP, _objP) => new ConstantExpression(true, TypeReference.FromType(typeof(bool))))
                                  .AddImplements(interfaceMethod);
            var typeDef = TypeDef.Empty(type).With(
                implements: ImmutableArray.Create(iequatableT),
                members: ImmutableArray.Create <MemberDef>(methodDef));

            cx.AddType(typeDef);


            check.CheckOutput(cx, $"{(isStruct ? "struct" : "class")}{(isExplicit ? "-explicit" : "")}");
        }
Ejemplo n.º 5
0
        static Expression ExampleMethodCall(MetadataContext cx)
        {
            var intParse = cx.GetMemberMethods(TypeSignature.Int32.NotGeneric()).Single(m => m.Signature.Name == "Parse" && m.Signature.Params.Length == 1 && m.Signature.Params[0].Type == TypeSignature.String);

            return(Expression.MethodCall(intParse, ImmutableArray.Create(Expression.Constant("123456789")), null));
        }