Exemple #1
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() })));
            }
        }
        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);
        }
Exemple #3
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());
        }
        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));
        }