Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public LocalReference DeclareLocal(Type type)
        {
            LocalReference reference = new LocalReference(type);

            this._ilmarkers.Add(reference);
            return(reference);
        }
Esempio n. 2
0
        protected virtual void WriteInterceptorInvocationMethod(MethodInfo method, EasyMethod builder)
        {
            ArgumentReference[] arguments  = builder.Arguments;
            TypeReference[]     args       = IndirectReference.WrapIfByRef(builder.Arguments);
            LocalReference      target     = builder.CodeBuilder.DeclareLocal(this.Context.Invocation);
            EasyCallable        callable   = this._method2Delegate[method] as EasyCallable;
            FieldReference      reference2 = this.ObtainCallableFieldBuilderDelegate(callable);

            builder.CodeBuilder.AddStatement(new AssignStatement(target, new MethodInvocationExpression(this._method2Invocation, new Expression[] { reference2.ToExpression(), new MethodTokenExpression(this.GetCorrectMethod(method)), this.GetPseudoInvocationTarget(method) })));
            LocalReference reference3 = builder.CodeBuilder.DeclareLocal(typeof(object));
            LocalReference reference4 = builder.CodeBuilder.DeclareLocal(typeof(object[]));

            builder.CodeBuilder.AddStatement(new AssignStatement(reference4, new ReferencesToObjectArrayExpression(args)));
            builder.CodeBuilder.AddStatement(new AssignStatement(reference3, new VirtualMethodInvocationExpression(this.InterceptorField, this.Context.Interceptor.GetMethod("Intercept"), new Expression[] { target.ToExpression(), reference4.ToExpression() })));
            for (int i = 0; i < arguments.Length; i++)
            {
                if (arguments[i].Type.IsByRef)
                {
                    builder.CodeBuilder.AddStatement(new AssignStatement(args[i], new ConvertExpression(args[i].Type, new LoadRefArrayElementExpression(i, reference4))));
                }
            }
            if (builder.ReturnType == typeof(void))
            {
                builder.CodeBuilder.AddStatement(new ReturnStatement());
            }
            else
            {
                builder.CodeBuilder.AddStatement(new ReturnStatement(new ConvertExpression(builder.ReturnType, reference3.ToExpression())));
            }
        }
Esempio n. 3
0
        protected virtual void ImplementGetObjectData(Type[] interfaces)
        {
            this._generated.Add(typeof(ISerializable));
            Type[]            types      = new Type[] { typeof(string), typeof(bool), typeof(bool) };
            Type[]            typeArray2 = new Type[] { typeof(string), typeof(object) };
            MethodInfo        info       = typeof(SerializationInfo).GetMethod("AddValue", typeArray2);
            ArgumentReference owner      = new ArgumentReference(typeof(SerializationInfo));
            ArgumentReference reference2 = new ArgumentReference(typeof(StreamingContext));
            EasyMethod        method     = this.MainTypeBuilder.CreateMethod("GetObjectData", new ReturnReferenceExpression(typeof(void)), new ArgumentReference[] { owner, reference2 });
            LocalReference    target     = method.CodeBuilder.DeclareLocal(typeof(Type));

            method.CodeBuilder.AddStatement(new AssignStatement(target, new MethodInvocationExpression(null, typeof(Type).GetMethod("GetType", types), new Expression[] { new FixedReference(this.Context.ProxyObjectReference.AssemblyQualifiedName).ToExpression(), new FixedReference(1).ToExpression(), new FixedReference(0).ToExpression() })));
            method.CodeBuilder.AddStatement(new ExpressionStatement(new VirtualMethodInvocationExpression(owner, typeof(SerializationInfo).GetMethod("SetType"), new Expression[] { target.ToExpression() })));
            method.CodeBuilder.AddStatement(new ExpressionStatement(new VirtualMethodInvocationExpression(owner, info, new Expression[] { new FixedReference("__interceptor").ToExpression(), this.InterceptorField.ToExpression() })));
            method.CodeBuilder.AddStatement(new ExpressionStatement(new VirtualMethodInvocationExpression(owner, info, new Expression[] { new FixedReference("__mixins").ToExpression(), this.MixinField.ToExpression() })));
            LocalReference reference4 = method.CodeBuilder.DeclareLocal(typeof(string[]));

            method.CodeBuilder.AddStatement(new AssignStatement(reference4, new NewArrayExpression(interfaces.Length, typeof(string))));
            for (int i = 0; i < interfaces.Length; i++)
            {
                method.CodeBuilder.AddStatement(new AssignArrayStatement(reference4, i, new FixedReference(interfaces[i].AssemblyQualifiedName).ToExpression()));
            }
            method.CodeBuilder.AddStatement(new ExpressionStatement(new VirtualMethodInvocationExpression(owner, info, new Expression[] { new FixedReference("__interfaces").ToExpression(), reference4.ToExpression() })));
            method.CodeBuilder.AddStatement(new ExpressionStatement(new VirtualMethodInvocationExpression(owner, info, new Expression[] { new FixedReference("__baseType").ToExpression(), new TypeTokenExpression(this._baseType) })));
            this.CustomizeGetObjectData(method.CodeBuilder, owner, reference2);
            method.CodeBuilder.AddStatement(new ReturnStatement());
        }
Esempio n. 4
0
        private void GenerateCall()
        {
            ArgumentReference arrayReference = new ArgumentReference(typeof(object[]));

            this._callmethod = base.CreateMethod("Call", new ReturnReferenceExpression(typeof(object)), new ArgumentReference[] { arrayReference });
            TypeReference[]  referenceArray  = IndirectReference.WrapIfByRef(this._args);
            LocalReference[] referenceArray2 = new LocalReference[this._args.Length];
            Expression[]     args            = new Expression[this._args.Length];
            for (int i = 0; i < this._args.Length; i++)
            {
                if (this._args[i].Type.IsByRef)
                {
                    referenceArray2[i] = this._callmethod.CodeBuilder.DeclareLocal(referenceArray[i].Type);
                    this._callmethod.CodeBuilder.AddStatement(new AssignStatement(referenceArray2[i], new ConvertExpression(referenceArray[i].Type, new LoadRefArrayElementExpression(i, arrayReference))));
                    args[i] = referenceArray2[i].ToAddressOfExpression();
                }
                else
                {
                    args[i] = new ConvertExpression(referenceArray[i].Type, new LoadRefArrayElementExpression(i, arrayReference));
                }
            }
            MethodInvocationExpression expression = new MethodInvocationExpression(this._invokeMethod, args);
            Expression instance = null;

            if (this._returnType.Type == typeof(void))
            {
                this._callmethod.CodeBuilder.AddStatement(new ExpressionStatement(expression));
                instance = NullExpression.Instance;
            }
            else
            {
                LocalReference target = this._callmethod.CodeBuilder.DeclareLocal(typeof(object));
                this._callmethod.CodeBuilder.AddStatement(new AssignStatement(target, new ConvertExpression(typeof(object), this._returnType.Type, expression)));
                instance = target.ToExpression();
            }
            for (int j = 0; j < this._args.Length; j++)
            {
                if (this._args[j].Type.IsByRef)
                {
                    this._callmethod.CodeBuilder.AddStatement(new AssignArrayStatement(arrayReference, j, new ConvertExpression(typeof(object), referenceArray[j].Type, referenceArray2[j].ToExpression())));
                }
            }
            this._callmethod.CodeBuilder.AddStatement(new ReturnStatement(instance));
        }
Esempio n. 5
0
        protected virtual void ImplementCacheInvocationCache()
        {
            MethodInfo method = typeof(HybridDictionary).GetMethod("get_Item", new Type[] { typeof(object) });
            MethodInfo info2  = typeof(HybridDictionary).GetMethod("Add", new Type[] { typeof(object), typeof(object) });

            Type[]            types      = new Type[] { typeof(ICallable), typeof(object), typeof(MethodInfo), typeof(object) };
            ArgumentReference reference  = new ArgumentReference(typeof(ICallable));
            ArgumentReference reference2 = new ArgumentReference(typeof(MethodInfo));
            ArgumentReference reference3 = new ArgumentReference(typeof(object));

            this._method2Invocation = this.MainTypeBuilder.CreateMethod("_Method2Invocation", new ReturnReferenceExpression(this.Context.Invocation), MethodAttributes.HideBySig | MethodAttributes.Family, new ArgumentReference[] { reference, reference2, reference3 });
            LocalReference      target     = this._method2Invocation.CodeBuilder.DeclareLocal(this.Context.Invocation);
            LockBlockExpression expression = new LockBlockExpression(SelfReference.Self);

            expression.AddStatement(new AssignStatement(target, new ConvertExpression(this.Context.Invocation, new VirtualMethodInvocationExpression(this.CacheField, method, new Expression[] { reference2.ToExpression() }))));
            ConditionExpression expression2 = new ConditionExpression(OpCodes.Brfalse_S, target.ToExpression());

            expression2.AddTrueStatement(new AssignStatement(target, new NewInstanceExpression(this.InvocationType.GetConstructor(types), new Expression[] { reference.ToExpression(), SelfReference.Self.ToExpression(), reference2.ToExpression(), reference3.ToExpression() })));
            expression2.AddTrueStatement(new ExpressionStatement(new VirtualMethodInvocationExpression(this.CacheField, info2, new Expression[] { reference2.ToExpression(), target.ToExpression() })));
            expression.AddStatement(new ExpressionStatement(expression2));
            this._method2Invocation.CodeBuilder.AddStatement(new ExpressionStatement(expression));
            this._method2Invocation.CodeBuilder.AddStatement(new ReturnStatement(target));
        }
Esempio n. 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="codebuilder"></param>
        /// <param name="arg1"></param>
        /// <param name="arg2"></param>
        protected override void CustomizeGetObjectData(AbstractCodeBuilder codebuilder, ArgumentReference arg1, ArgumentReference arg2)
        {
            Type[]     types      = new Type[] { typeof(string), typeof(object) };
            Type[]     typeArray2 = new Type[] { typeof(string), typeof(bool) };
            MethodInfo method     = typeof(SerializationInfo).GetMethod("AddValue", types);
            MethodInfo info2      = typeof(SerializationInfo).GetMethod("AddValue", typeArray2);

            codebuilder.AddStatement(new ExpressionStatement(new VirtualMethodInvocationExpression(arg1, info2, new Expression[] { new FixedReference("__delegateToBase").ToExpression(), new FixedReference(this._delegateToBaseGetObjectData ? 1 : 0).ToExpression() })));
            if (this._delegateToBaseGetObjectData)
            {
                MethodInfo info3 = base._baseType.GetMethod("GetObjectData", new Type[] { typeof(SerializationInfo), typeof(StreamingContext) });
                codebuilder.AddStatement(new ExpressionStatement(new MethodInvocationExpression(info3, new Expression[] { arg1.ToExpression(), arg2.ToExpression() })));
            }
            else
            {
                LocalReference target     = codebuilder.DeclareLocal(typeof(MemberInfo[]));
                LocalReference reference2 = codebuilder.DeclareLocal(typeof(object[]));
                MethodInfo     info4      = typeof(FormatterServices).GetMethod("GetSerializableMembers", new Type[] { typeof(Type) });
                MethodInfo     info5      = typeof(FormatterServices).GetMethod("GetObjectData", new Type[] { typeof(object), typeof(MemberInfo[]) });
                codebuilder.AddStatement(new AssignStatement(target, new MethodInvocationExpression(null, info4, new Expression[] { new TypeTokenExpression(base._baseType) })));
                codebuilder.AddStatement(new AssignStatement(reference2, new MethodInvocationExpression(null, info5, new Expression[] { SelfReference.Self.ToExpression(), target.ToExpression() })));
                codebuilder.AddStatement(new ExpressionStatement(new VirtualMethodInvocationExpression(arg1, method, new Expression[] { new FixedReference("__data").ToExpression(), reference2.ToExpression() })));
            }
        }