Ejemplo n.º 1
0
        private void GenerateConstructor()
        {
            ArgumentReference reference  = new ArgumentReference(typeof(object));
            ArgumentReference reference2 = new ArgumentReference(typeof(IntPtr));

            this._constructor = base.CreateRuntimeConstructor(new ArgumentReference[] { reference, reference2 });
        }
Ejemplo n.º 2
0
        protected virtual MethodInfo GenerateCallbackMethodIfNecessary(MethodInfo method, Reference invocationTarget)
        {
            if (this.Context.HasMixins && this._interface2mixinIndex.Contains(method.DeclaringType))
            {
                return(method);
            }
            string name = string.Format("callback__{0}", method.Name);

            ParameterInfo[]     parameters = method.GetParameters();
            ArgumentReference[] arguments  = new ArgumentReference[parameters.Length];
            for (int i = 0; i < arguments.Length; i++)
            {
                arguments[i] = new ArgumentReference(parameters[i].ParameterType);
            }
            EasyMethod method2 = this.MainTypeBuilder.CreateMethod(name, new ReturnReferenceExpression(method.ReturnType), MethodAttributes.HideBySig | MethodAttributes.Public, arguments);

            Expression[] args = new Expression[parameters.Length];
            for (int j = 0; j < arguments.Length; j++)
            {
                args[j] = arguments[j].ToExpression();
            }
            if (invocationTarget == null)
            {
                method2.CodeBuilder.AddStatement(new ReturnStatement(new MethodInvocationExpression(method, args)));
            }
            else
            {
                method2.CodeBuilder.AddStatement(new ReturnStatement(new MethodInvocationExpression(invocationTarget, method, args)));
            }
            return(method2.MethodBuilder);
        }
Ejemplo 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());
        }
Ejemplo n.º 4
0
 public static ArgumentReference[] ConvertToArgumentReference(Type[] args)
 {
     ArgumentReference[] referenceArray = new ArgumentReference[args.Length];
     for (int i = 0; i < args.Length; i++)
     {
         referenceArray[i] = new ArgumentReference(args[i]);
     }
     return(referenceArray);
 }
Ejemplo n.º 5
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));
        }
Ejemplo n.º 6
0
        /// <summary>
        ///
        /// </summary>
        protected void GenerateSerializationConstructor()
        {
            ArgumentReference owner       = new ArgumentReference(typeof(SerializationInfo));
            ArgumentReference reference2  = new ArgumentReference(typeof(StreamingContext));
            EasyConstructor   constructor = base.MainTypeBuilder.CreateConstructor(new ArgumentReference[] { owner, reference2 });

            constructor.CodeBuilder.AddStatement(new ExpressionStatement(new ConstructorInvocationExpression(this._serializationConstructor, new Expression[] { owner.ToExpression(), reference2.ToExpression() })));
            Type[]     types  = new Type[] { typeof(string), typeof(Type) };
            MethodInfo method = typeof(SerializationInfo).GetMethod("GetValue", types);
            VirtualMethodInvocationExpression expression  = new VirtualMethodInvocationExpression(owner, method, new Expression[] { new FixedReference("__interceptor").ToExpression(), new TypeTokenExpression(base.Context.Interceptor) });
            VirtualMethodInvocationExpression expression2 = new VirtualMethodInvocationExpression(owner, method, new Expression[] { new FixedReference("__mixins").ToExpression(), new TypeTokenExpression(typeof(object[])) });

            constructor.CodeBuilder.AddStatement(new AssignStatement(base.InterceptorField, expression));
            constructor.CodeBuilder.AddStatement(new AssignStatement(base.CacheField, new NewInstanceExpression(typeof(HybridDictionary).GetConstructor(new Type[0]), new Expression[0])));
            constructor.CodeBuilder.AddStatement(new AssignStatement(base.MixinField, expression2));
            foreach (CallableField field in base._cachedFields)
            {
                field.WriteInitialization(constructor.CodeBuilder, SelfReference.Self, base.MixinField);
            }
            constructor.CodeBuilder.AddStatement(new ReturnStatement());
        }
Ejemplo n.º 7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="baseConstructor"></param>
        /// <returns></returns>
        protected virtual EasyConstructor GenerateConstructor(ConstructorInfo baseConstructor)
        {
            ArrayList         list       = new ArrayList();
            ArgumentReference reference  = new ArgumentReference(base.Context.Interceptor);
            ArgumentReference reference2 = new ArgumentReference(typeof(object[]));

            list.Add(reference);
            ParameterInfo[] parameters = baseConstructor.GetParameters();
            if (base.Context.HasMixins)
            {
                list.Add(reference2);
            }
            ArgumentReference[] c = ArgumentsUtil.ConvertToArgumentReference(parameters);
            list.AddRange(c);
            EasyConstructor constructor = base.MainTypeBuilder.CreateConstructor((ArgumentReference[])list.ToArray(typeof(ArgumentReference)));

            this.GenerateConstructorCode(constructor.CodeBuilder, reference, SelfReference.Self, reference2);
            constructor.CodeBuilder.InvokeBaseConstructor(baseConstructor, c);
            constructor.CodeBuilder.AddStatement(new ReturnStatement());
            return(constructor);
        }
Ejemplo n.º 8
0
        protected override EasyConstructor GenerateConstructor()
        {
            EasyConstructor   constructor;
            ArgumentReference interceptorArg = new ArgumentReference(base.Context.Interceptor);
            ArgumentReference reference2     = new ArgumentReference(typeof(object));
            ArgumentReference mixinArray     = new ArgumentReference(typeof(object[]));

            if (base.Context.HasMixins)
            {
                constructor = base.MainTypeBuilder.CreateConstructor(new ArgumentReference[] { interceptorArg, reference2, mixinArray });
            }
            else
            {
                constructor = base.MainTypeBuilder.CreateConstructor(new ArgumentReference[] { interceptorArg, reference2 });
            }
            this.GenerateConstructorCode(constructor.CodeBuilder, interceptorArg, SelfReference.Self, mixinArray);
            constructor.CodeBuilder.InvokeBaseConstructor();
            constructor.CodeBuilder.AddStatement(new AssignStatement(this._targetField, reference2.ToExpression()));
            constructor.CodeBuilder.AddStatement(new ReturnStatement());
            return(constructor);
        }
Ejemplo n.º 9
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));
        }
Ejemplo n.º 10
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() })));
            }
        }
Ejemplo n.º 11
0
        protected override void CustomizeGetObjectData(AbstractCodeBuilder codebuilder, ArgumentReference arg1, ArgumentReference arg2)
        {
            Type[]     types  = new Type[] { typeof(string), typeof(object) };
            MethodInfo method = typeof(SerializationInfo).GetMethod("AddValue", types);

            codebuilder.AddStatement(new ExpressionStatement(new VirtualMethodInvocationExpression(arg1, method, new Expression[] { new FixedReference("__target").ToExpression(), this._targetField.ToExpression() })));
        }
Ejemplo n.º 12
0
 protected virtual void CustomizeGetObjectData(AbstractCodeBuilder codebuilder, ArgumentReference arg1, ArgumentReference arg2)
 {
 }