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);
		}
		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())));
			}
		}
		protected override void CustomizeGetObjectData(AbstractCodeBuilder codebuilder, ArgumentReference arg1,
		                                               ArgumentReference arg2)
		{
			Type[] key_and_object = new Type[] {typeof(String), typeof(Object)};
			Type[] key_and_int = new Type[] {typeof(String), typeof(int)};
			Type[] key_and_string = new Type[] {typeof(String), typeof(string)};
			MethodInfo addValueMethod = typeof(SerializationInfo).GetMethod("AddValue", key_and_object);
			MethodInfo addIntMethod = typeof(SerializationInfo).GetMethod("AddValue", key_and_int);
			MethodInfo addStringMethod = typeof(SerializationInfo).GetMethod("AddValue", key_and_string);

			codebuilder.AddStatement(new ExpressionStatement(
			                         	new MethodInvocationExpression(arg1, addValueMethod,
			                         	                               new ConstReference("__target").ToExpression(),
			                         	                               targetField.ToExpression())));

			codebuilder.AddStatement (new ExpressionStatement (
			                         	new MethodInvocationExpression (arg1, addValueMethod,
			                         	                               new ConstReference ("__targetFieldType").ToExpression (),
			                         	                               new ConstReference (targetField.Reference.FieldType.AssemblyQualifiedName).ToExpression())));

			codebuilder.AddStatement(new ExpressionStatement(
			                         	new MethodInvocationExpression(arg1, addIntMethod,
			                         	                               new ConstReference("__interface_generator_type").
			                         	                               	ToExpression(),
			                         	                               new ConstReference((int) GeneratorType).ToExpression())));

			codebuilder.AddStatement(new ExpressionStatement(
			                         	new MethodInvocationExpression(arg1, addStringMethod,
			                         	                               new ConstReference("__theInterface").ToExpression(),
			                         	                               new ConstReference(targetType.AssemblyQualifiedName).
			                         	                               	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));
		}
		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())));
		}
		protected abstract void CustomizeGetObjectData(AbstractCodeBuilder builder, ArgumentReference serializationInfo,
		                                               ArgumentReference streamingContext, ClassEmitter emitter);
		protected virtual void CustomizeGetObjectData(
			AbstractCodeBuilder codebuilder, ArgumentReference arg1,
			ArgumentReference arg2)
		{
		}
示例#9
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 MethodInvocationExpression(arg1, addValueBoolMethod,
                                     	                               new ConstReference("__delegateToBase").ToExpression(),
                                     	                               new ConstReference(delegateToBaseGetObjectData ? 1 : 0).
                                     	                               	ToExpression())));

            if (delegateToBaseGetObjectData)
            {
                MethodInfo baseGetObjectData = targetType.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(targetType))));

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

                codebuilder.AddStatement(new ExpressionStatement(
                                         	new MethodInvocationExpression(arg1, addValueMethod,
                                         	                               new ConstReference("__data").ToExpression(),
                                         	                               data_ref.ToExpression())));
            }
        }