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() })));
        }
        private void EmitCallToBaseGetObjectData(AbstractCodeBuilder codebuilder, ArgumentReference serializationInfo,
                                                 ArgumentReference streamingContext)
        {
            var baseGetObjectData = targetType.GetMethod("GetObjectData",
                                                         new[] { typeof(SerializationInfo), typeof(StreamingContext) });

            codebuilder.AddStatement(new ExpressionStatement(
                                         new MethodInvocationExpression(baseGetObjectData,
                                                                        serializationInfo.ToExpression(),
                                                                        streamingContext.ToExpression())));
        }
Ejemplo n.º 3
0
        public void WriteInitialization(AbstractCodeBuilder codebuilder, Reference targetArgument, Reference mixinArray)
        {
            NewInstanceExpression expression = null;

            if (this.SourceArgIndex == EmptyIndex)
            {
                expression = new NewInstanceExpression(this.Callable, new Expression[] { targetArgument.ToExpression(), new MethodPointerExpression(this._callback) });
            }
            else
            {
                expression = new NewInstanceExpression(this.Callable, new Expression[] { new LoadRefArrayElementExpression(this.SourceArgIndex, mixinArray), new MethodPointerExpression(this._callback) });
            }
            codebuilder.AddStatement(new AssignStatement(this.Field, expression));
        }
Ejemplo n.º 4
0
        protected override void CustomizeGetObjectData(AbstractCodeBuilder codebuilder,
                                                       ArgumentReference arg1, ArgumentReference arg2)
        {
            Type[]     key_and_object     = new Type[] { typeof(String), typeof(Object) };
            Type[]     key_and_bool       = new Type[] { typeof(String), typeof(bool) };
            MethodInfo addValueMethod     = typeof(SerializationInfo).GetMethod("AddValue", key_and_object);
            MethodInfo addValueBoolMethod = typeof(SerializationInfo).GetMethod("AddValue", key_and_bool);

            codebuilder.AddStatement(new ExpressionStatement(
                                         new VirtualMethodInvocationExpression(arg1, addValueBoolMethod,
                                                                               new FixedReference("__delegateToBase").ToExpression(),
                                                                               new FixedReference(_delegateToBaseGetObjectData ? 1 : 0).ToExpression())));

            if (_delegateToBaseGetObjectData)
            {
                MethodInfo baseGetObjectData = _baseType.GetMethod("GetObjectData",
                                                                   new Type[] { typeof(SerializationInfo), typeof(StreamingContext) });

                codebuilder.AddStatement(new ExpressionStatement(
                                             new MethodInvocationExpression(baseGetObjectData,
                                                                            arg1.ToExpression(), arg2.ToExpression())));
            }
            else
            {
                LocalReference members_ref = codebuilder.DeclareLocal(typeof(MemberInfo[]));
                LocalReference data_ref    = codebuilder.DeclareLocal(typeof(object[]));

                MethodInfo getSerMembers = typeof(FormatterServices).GetMethod("GetSerializableMembers",
                                                                               new Type[] { typeof(Type) });
                MethodInfo getObjData = typeof(FormatterServices).GetMethod("GetObjectData",
                                                                            new Type[] { typeof(object), typeof(MemberInfo[]) });

                codebuilder.AddStatement(new AssignStatement(members_ref,
                                                             new MethodInvocationExpression(null, getSerMembers,
                                                                                            new TypeTokenExpression(_baseType))));

                codebuilder.AddStatement(new AssignStatement(data_ref,
                                                             new MethodInvocationExpression(null, getObjData,
                                                                                            SelfReference.Self.ToExpression(), members_ref.ToExpression())));

                codebuilder.AddStatement(new ExpressionStatement(
                                             new VirtualMethodInvocationExpression(arg1, addValueMethod,
                                                                                   new FixedReference("__data").ToExpression(),
                                                                                   data_ref.ToExpression())));
            }
        }
        protected override void CustomizeGetObjectData(AbstractCodeBuilder codebuilder, ArgumentReference serializationInfo, ArgumentReference streamingContext, ClassEmitter emitter)
        {
            var targetField = emitter.GetField("__target");

            codebuilder.AddStatement(new ExpressionStatement(
                                         new MethodInvocationExpression(serializationInfo, SerializationInfoMethods.AddValue_Object,
                                                                        new ConstReference("__targetFieldType").ToExpression(),
                                                                        new ConstReference(
                                                                            targetField.Reference.FieldType.AssemblyQualifiedName).
                                                                        ToExpression())));

            codebuilder.AddStatement(new ExpressionStatement(
                                         new MethodInvocationExpression(serializationInfo, SerializationInfoMethods.AddValue_Object,
                                                                        new ConstReference("__theInterface").ToExpression(),
                                                                        new ConstReference(targetType.AssemblyQualifiedName).
                                                                        ToExpression())));
        }
        protected override void CustomizeGetObjectData(AbstractCodeBuilder codebuilder, ArgumentReference serializationInfo,
                                                       ArgumentReference streamingContext, ClassEmitter emitter)
        {
            codebuilder.AddStatement(new ExpressionStatement(
                                         new MethodInvocationExpression(
                                             serializationInfo,
                                             SerializationInfoMethods.AddValue_Bool,
                                             new ConstReference("__delegateToBase").ToExpression(),
                                             new ConstReference(delegateToBaseGetObjectData).
                                             ToExpression())));

            if (delegateToBaseGetObjectData == false)
            {
                EmitCustomGetObjectData(codebuilder, serializationInfo);
                return;
            }

            EmitCallToBaseGetObjectData(codebuilder, serializationInfo, streamingContext);
        }
Ejemplo n.º 7
0
        public void WriteInitialization(AbstractCodeBuilder codebuilder,
                                        Reference targetArgument, Reference mixinArray)
        {
            NewInstanceExpression newInst = null;

            if (SourceArgIndex == EmptyIndex)
            {
                newInst = new NewInstanceExpression(Callable,
                                                    targetArgument.ToExpression(), new MethodPointerExpression(_callback));
            }
            else
            {
                newInst = new NewInstanceExpression(Callable,
                                                    new LoadRefArrayElementExpression(SourceArgIndex, mixinArray),
                                                    new MethodPointerExpression(_callback));
            }

            codebuilder.AddStatement(new AssignStatement(
                                         Field, newInst));
        }
Ejemplo n.º 8
0
        protected override void CustomizeGetObjectData(AbstractCodeBuilder codebuilder, ArgumentReference serializationInfo, ArgumentReference streamingContext, ClassEmitter emitter)
        {
            codebuilder.AddStatement(new ExpressionStatement(
                                         new MethodInvocationExpression(serializationInfo, SerializationInfoMethods.AddValue_Bool,
                                                                        new ConstReference("__delegateToBase").ToExpression(),
                                                                        new ConstReference(delegateToBaseGetObjectData ? 1 : 0).
                                                                        ToExpression())));

            if (delegateToBaseGetObjectData)
            {
                MethodInfo baseGetObjectData = targetType.GetMethod("GetObjectData",
                                                                    new[] { typeof(SerializationInfo), typeof(StreamingContext) });

                codebuilder.AddStatement(new ExpressionStatement(
                                             new MethodInvocationExpression(baseGetObjectData,
                                                                            serializationInfo.ToExpression(),
                                                                            streamingContext.ToExpression())));
            }
            else
            {
                LocalReference members_ref = codebuilder.DeclareLocal(typeof(MemberInfo[]));
                LocalReference data_ref    = codebuilder.DeclareLocal(typeof(object[]));

                codebuilder.AddStatement(new AssignStatement(members_ref,
                                                             new MethodInvocationExpression(null,
                                                                                            FormatterServicesMethods.
                                                                                            GetSerializableMembers,
                                                                                            new TypeTokenExpression(targetType))));

                codebuilder.AddStatement(new AssignStatement(data_ref,
                                                             new MethodInvocationExpression(null,
                                                                                            FormatterServicesMethods.GetObjectData,
                                                                                            SelfReference.Self.ToExpression(),
                                                                                            members_ref.ToExpression())));

                codebuilder.AddStatement(new ExpressionStatement(
                                             new MethodInvocationExpression(serializationInfo, SerializationInfoMethods.AddValue_Object,
                                                                            new ConstReference("__data").ToExpression(),
                                                                            data_ref.ToExpression())));
            }
        }
        private void EmitCustomGetObjectData(AbstractCodeBuilder codebuilder, ArgumentReference serializationInfo)
        {
            var members = codebuilder.DeclareLocal(typeof(MemberInfo[]));
            var data    = codebuilder.DeclareLocal(typeof(object[]));

            var getSerializableMembers = new MethodInvocationExpression(
                null,
                FormatterServicesMethods.GetSerializableMembers,
                new TypeTokenExpression(targetType));

            codebuilder.AddStatement(new AssignStatement(members, getSerializableMembers));

            // Sort to keep order on both serialize and deserialize side the same, c.f DYNPROXY-ISSUE-127
            var callSort = new MethodInvocationExpression(
                null,
                TypeUtilMethods.Sort,
                members.ToExpression());

            codebuilder.AddStatement(new AssignStatement(members, callSort));

            var getObjectData = new MethodInvocationExpression(
                null,
                FormatterServicesMethods.GetObjectData,
                SelfReference.Self.ToExpression(),
                members.ToExpression());

            codebuilder.AddStatement(new AssignStatement(data, getObjectData));

            var addValue = new MethodInvocationExpression(
                serializationInfo,
                SerializationInfoMethods.AddValue_Object,
                new ConstReference("__data").ToExpression(),
                data.ToExpression());

            codebuilder.AddStatement(new ExpressionStatement(addValue));
        }
        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 abstract void CustomizeGetObjectData(AbstractCodeBuilder builder, ArgumentReference serializationInfo,
                                                ArgumentReference streamingContext, ClassEmitter emitter);
Ejemplo n.º 12
0
 protected virtual void CustomizeGetObjectData(AbstractCodeBuilder codebuilder, ArgumentReference arg1,
                                               ArgumentReference arg2)
 {
 }