상속: TypeReference
예제 #1
0
		public static void InitializeArgumentsByPosition(ArgumentReference[] args, bool isStatic)
		{
			int offset = isStatic ? 0 : 1;
			for(int i = 0; i < args.Length; ++i)
			{
				args[i].Position = i + offset;
			}
		}
		public ConstructorEmitter CreateConstructor(ArgumentReference[] baseCtorArguments, AbstractTypeEmitter invocation)
		{
			var arguments = GetArguments(baseCtorArguments);
			var constructor = invocation.CreateConstructor(arguments);

			var delegateField = invocation.CreateField("delegate", delegateType);
			constructor.CodeBuilder.AddStatement(new AssignStatement(delegateField, new ReferenceExpression(arguments[0])));
			return constructor;
		}
예제 #3
0
		public static ArgumentReference[] ConvertToArgumentReference(Type[] args)
		{
			ArgumentReference[] arguments = new ArgumentReference[args.Length];

			for(int i = 0; i < args.Length; ++i)
			{
				arguments[i] = new ArgumentReference(args[i]);
			}

			return arguments;
		}
예제 #4
0
		public static Expression[] ConvertArgumentReferenceToExpression(ArgumentReference[] args)
		{
			var expressions = new Expression[args.Length];

			for (var i = 0; i < args.Length; ++i)
			{
				expressions[i] = args[i].ToExpression();
			}

			return expressions;
		}
예제 #5
0
		public static ArgumentReference[] ConvertToArgumentReference(ParameterInfo[] args)
		{
			var arguments = new ArgumentReference[args.Length];

			for (var i = 0; i < args.Length; ++i)
			{
				arguments[i] = new ArgumentReference(args[i].ParameterType);
			}

			return arguments;
		}
예제 #6
0
		public static Type[] InitializeAndConvert(ArgumentReference[] args)
		{
			Type[] types = new Type[args.Length];

			for(int i = 0; i < args.Length; ++i)
			{
				args[i].Position = i + 1;
				types[i] = args[i].Type;
			}

			return types;
		}
		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())));
			}
		}
		private ArgumentReference[] GetArguments(ArgumentReference[] baseCtorArguments)
		{
			var arguments = new ArgumentReference[baseCtorArguments.Length + 1];
			arguments[0] = new ArgumentReference(delegateType);
			baseCtorArguments.CopyTo(arguments, 1);
			return arguments;
		}
예제 #11
0
 public AssignArgumentStatement(ArgumentReference argument, Expression expression)
 {
     this.argument   = argument;
     this.expression = expression;
 }
예제 #12
0
		protected virtual void ImplementGetObjectData(ClassEmitter emitter, FieldReference interceptorsField,
		                                              Type[] interfaces)
		{
			if (interfaces == null)
			{
				interfaces = new Type[0];
			}

			Type[] get_type_args = new Type[] {typeof(String), typeof(bool), typeof(bool)};
			Type[] key_and_object = new Type[] {typeof(String), typeof(Object)};
			MethodInfo addValueMethod = typeof(SerializationInfo).GetMethod("AddValue", key_and_object);

			ArgumentReference arg1 = new ArgumentReference(typeof(SerializationInfo));
			ArgumentReference arg2 = new ArgumentReference(typeof(StreamingContext));
			MethodEmitter getObjectData = emitter.CreateMethod("GetObjectData",
			                                                   typeof(void), arg1, arg2);

			LocalReference typeLocal = getObjectData.CodeBuilder.DeclareLocal(typeof(Type));

			getObjectData.CodeBuilder.AddStatement(new AssignStatement(
			                                       	typeLocal,
			                                       	new MethodInvocationExpression(null,
			                                       	                               typeof(Type).GetMethod("GetType",
			                                       	                                                      get_type_args),
			                                       	                               new ConstReference(
			                                       	                               	typeof(ProxyObjectReference).
			                                       	                               		AssemblyQualifiedName).ToExpression(),
			                                       	                               new ConstReference(1).ToExpression(),
			                                       	                               new ConstReference(0).ToExpression())));

			getObjectData.CodeBuilder.AddStatement(new ExpressionStatement(
			                                       	new MethodInvocationExpression(
			                                       		arg1, typeof(SerializationInfo).GetMethod("SetType"),
			                                       		typeLocal.ToExpression())));

			getObjectData.CodeBuilder.AddStatement(new ExpressionStatement(
			                                       	new MethodInvocationExpression(arg1, addValueMethod,
			                                       	                               new ConstReference("__interceptors").
			                                       	                               	ToExpression(),
			                                       	                               interceptorsField.ToExpression())));

			LocalReference interfacesLocal =
				getObjectData.CodeBuilder.DeclareLocal(typeof(String[]));

			getObjectData.CodeBuilder.AddStatement(
				new AssignStatement(interfacesLocal,
				                    new NewArrayExpression(interfaces.Length, typeof(String))));

			for(int i = 0; i < interfaces.Length; i++)
			{
				getObjectData.CodeBuilder.AddStatement(new AssignArrayStatement(
				                                       	interfacesLocal, i,
				                                       	new ConstReference(interfaces[i].AssemblyQualifiedName).ToExpression()));
			}

			getObjectData.CodeBuilder.AddStatement(new ExpressionStatement(
			                                       	new MethodInvocationExpression(arg1, addValueMethod,
			                                       	                               new ConstReference("__interfaces").
			                                       	                               	ToExpression(),
			                                       	                               interfacesLocal.ToExpression())));

			getObjectData.CodeBuilder.AddStatement(new ExpressionStatement(
			                                       	new MethodInvocationExpression(arg1, addValueMethod,
			                                       	                               new ConstReference("__baseType").
			                                       	                               	ToExpression(),
			                                       	                               new ConstReference (emitter.BaseType.AssemblyQualifiedName).ToExpression())));

			getObjectData.CodeBuilder.AddStatement(new ExpressionStatement(
			                                       	new MethodInvocationExpression(arg1, addValueMethod,
			                                       	                               new ConstReference("__proxyGenerationOptions").
			                                       	                               	ToExpression(),
			                                       	                               proxyGenerationOptionsField.ToExpression())));

			CustomizeGetObjectData(getObjectData.CodeBuilder, arg1, arg2);

			getObjectData.CodeBuilder.AddStatement(new ReturnStatement());
		}
예제 #13
0
		protected virtual void AddAddValueInvocation(ArgumentReference serializationInfo, MethodEmitter getObjectData,
		                                             FieldReference field)
		{
			getObjectData.CodeBuilder.AddStatement(
				new ExpressionStatement(
					new MethodInvocationExpression(
						serializationInfo,
						SerializationInfoMethods.AddValue_Object,
						new ConstReference(field.Reference.Name).ToExpression(),
						field.ToExpression())));
			return;
		}
예제 #14
0
		protected void GenerateConstructor(ClassEmitter emitter, ConstructorInfo baseConstructor,
		                                   params FieldReference[] fields)
		{
			ArgumentReference[] args;
			ParameterInfo[] baseConstructorParams = null;

			if (baseConstructor != null)
			{
				baseConstructorParams = baseConstructor.GetParameters();
			}

			if (baseConstructorParams != null && baseConstructorParams.Length != 0)
			{
				args = new ArgumentReference[fields.Length + baseConstructorParams.Length];

				var offset = fields.Length;
				for (var i = offset; i < offset + baseConstructorParams.Length; i++)
				{
					var paramInfo = baseConstructorParams[i - offset];
					args[i] = new ArgumentReference(paramInfo.ParameterType);
				}
			}
			else
			{
				args = new ArgumentReference[fields.Length];
			}

			for (var i = 0; i < fields.Length; i++)
			{
				args[i] = new ArgumentReference(fields[i].Reference.FieldType);
			}

			var constructor = emitter.CreateConstructor(args);
			if (baseConstructorParams != null && baseConstructorParams.Length != 0)
			{
				var last = baseConstructorParams.Last();

#if !NETFX_CORE
				if (last.ParameterType.IsArray && last.HasAttribute<ParamArrayAttribute>())
#else
				if (last.ParameterType.IsArray && ParameterInfoExtender.HasAttribute<ParamArrayAttribute>(last))
#endif
				{
					var parameter = constructor.ConstructorBuilder.DefineParameter(args.Length, ParameterAttributes.None, last.Name);
					var builder = AttributeUtil.CreateBuilder<ParamArrayAttribute>();
					parameter.SetCustomAttribute(builder);
				}
			}

			for (var i = 0; i < fields.Length; i++)
			{
				constructor.CodeBuilder.AddStatement(new AssignStatement(fields[i], args[i].ToExpression()));
			}

			// Invoke base constructor

			if (baseConstructor != null)
			{
				Debug.Assert(baseConstructorParams != null);

				var slice = new ArgumentReference[baseConstructorParams.Length];
				Array.Copy(args, fields.Length, slice, 0, baseConstructorParams.Length);

				constructor.CodeBuilder.InvokeBaseConstructor(baseConstructor, slice);
			}
			else
			{
				constructor.CodeBuilder.InvokeBaseConstructor();
			}

			constructor.CodeBuilder.AddStatement(new ReturnStatement());
		}
예제 #15
0
        protected void GenerateSerializationConstructor(ClassEmitter emitter, FieldReference interceptorField,
		                                                bool delegateToBaseGetObjectData)
        {
            ArgumentReference arg1 = new ArgumentReference(typeof(SerializationInfo));
            ArgumentReference arg2 = new ArgumentReference(typeof(StreamingContext));

            ConstructorEmitter constr = emitter.CreateConstructor(arg1, arg2);

            constr.CodeBuilder.AddStatement(
                new ConstructorInvocationStatement(serializationConstructor,
                                                   arg1.ToExpression(), arg2.ToExpression()));

            Type[] object_arg = new Type[] {typeof(String), typeof(Type)};
            MethodInfo getValueMethod = typeof(SerializationInfo).GetMethod("GetValue", object_arg);

            MethodInvocationExpression getInterceptorInvocation =
                new MethodInvocationExpression(arg1, getValueMethod,
                                               new ConstReference("__interceptors").ToExpression(),
                                               new TypeTokenExpression(typeof(IInterceptor[])));

            constr.CodeBuilder.AddStatement(new AssignStatement(
                                                interceptorField,
                                                new ConvertExpression(typeof(IInterceptor[]), typeof(object),
                                                                      getInterceptorInvocation)));

            constr.CodeBuilder.AddStatement(new ReturnStatement());
        }
예제 #16
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())));
            }
        }
예제 #17
0
		protected virtual void CustomizeGetObjectData(
			AbstractCodeBuilder codebuilder, ArgumentReference arg1,
			ArgumentReference arg2)
		{
		}
		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 GenerateSerializationConstructor(ClassEmitter emitter)
		{
			var serializationInfo = new ArgumentReference(typeof(SerializationInfo));
			var streamingContext = new ArgumentReference(typeof(StreamingContext));

			var ctor = emitter.CreateConstructor(serializationInfo, streamingContext);

			ctor.CodeBuilder.AddStatement(
				new ConstructorInvocationStatement(serializationConstructor,
				                                   serializationInfo.ToExpression(),
				                                   streamingContext.ToExpression()));

			foreach (var field in serializedFields)
			{
				var getValue = new MethodInvocationExpression(serializationInfo,
				                                              SerializationInfoMethods.GetValue,
				                                              new ConstReference(field.Reference.Name).ToExpression(),
				                                              new TypeTokenExpression(field.Reference.FieldType));
				ctor.CodeBuilder.AddStatement(new AssignStatement(
				                              	field,
				                              	new ConvertExpression(field.Reference.FieldType,
				                              	                      typeof(object),
				                              	                      getValue)));
			}
			ctor.CodeBuilder.AddStatement(new ReturnStatement());
		}
예제 #20
0
		/// <summary>
		/// If callbackMethod is null the InvokeOnTarget implementation
		/// is just the code to throw an exception
		/// </summary>
		/// <param name="emitter"></param>
		/// <param name="targetType"></param>
		/// <param name="targetForInvocation"></param>
		/// <param name="methodInfo"></param>
		/// <param name="callbackMethod"></param>
		/// <param name="version"></param>
		/// <param name="allowChangeTarget">If true the invocation will implement the IChangeProxyTarget interface</param>
		/// <returns></returns>
		protected NestedClassEmitter BuildInvocationNestedType(
			ClassEmitter emitter,
			Type targetType,
			Type targetForInvocation,
			MethodInfo methodInfo,
			MethodInfo callbackMethod,
			ConstructorVersion version,
			bool allowChangeTarget)
		{
			CheckNotGenericTypeDefinition(targetType, "targetType");
			CheckNotGenericTypeDefinition(targetForInvocation, "targetForInvocation");

			nestedCounter++;

			Type[] interfaces = new Type[0];

			if (allowChangeTarget)
			{
				interfaces = new Type[] {typeof(IChangeProxyTarget)};
			}

			NestedClassEmitter nested =
				new NestedClassEmitter(emitter,
				                       "Invocation" + methodInfo.Name + "_" + nestedCounter.ToString(),
				                       typeof(AbstractInvocation),
				                       interfaces);

			// invocation only needs to mirror the generic parameters of the MethodInfo
			// targetType cannot be a generic type definition
			nested.CreateGenericParameters(methodInfo.GetGenericArguments());

			// Create the invocation fields

			FieldReference targetRef = nested.CreateField("target", targetForInvocation);

			// Create constructor

			CreateIInvocationConstructor(targetForInvocation, nested, targetRef, version);

			if (allowChangeTarget)
			{
				ArgumentReference argument1 = new ArgumentReference(typeof(object));
				MethodEmitter methodEmitter =
					nested.CreateMethod("ChangeInvocationTarget", MethodAttributes.Public | MethodAttributes.Virtual,
					                    typeof(void), argument1);
				methodEmitter.CodeBuilder.AddStatement(
					new AssignStatement(targetRef,
					                    new ConvertExpression(targetType, argument1.ToExpression())
						)
					);
				methodEmitter.CodeBuilder.AddStatement(new ReturnStatement());
			}

			// InvokeMethodOnTarget implementation

			if (callbackMethod != null)
			{
				ParameterInfo[] parameters = methodInfo.GetParameters();

				CreateIInvocationInvokeOnTarget(emitter, nested, parameters, targetRef, callbackMethod);
			}
			else
			{
				CreateEmptyIInvocationInvokeOnTarget(nested);
			}

			nested.DefineCustomAttribute(new SerializableAttribute());

			return nested;
		}
		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())));
		}
예제 #22
0
		public void SetParameters(Type[] paramTypes)
		{
			builder.SetParameters(paramTypes);

			arguments = new ArgumentReference[paramTypes.Length];

			for(int i = 0; i < paramTypes.Length; i++)
			{
				arguments[i] = new ArgumentReference(paramTypes[i]);
			}

			ArgumentsUtil.InitializeArgumentsByPosition (arguments, MethodBuilder.IsStatic);
		}
예제 #23
0
		protected abstract void CustomizeGetObjectData(AbstractCodeBuilder builder, ArgumentReference serializationInfo,
		                                               ArgumentReference streamingContext, ClassEmitter emitter);
예제 #24
0
		/// <summary>
		/// Builds the adapter.
		/// </summary>
		/// <returns></returns>
		public Type Build()
		{

			//Setup emitter 
			ClassEmitter classEmitter = new ClassEmitter(ModuleScope,
				OriginalObject.Name + "Adapter",
				typeof(AdapterBase),
				new Type[] { }, TypeAttributes.Class,
				true);

			//Add a field to hold a reference to the original object that is being adapter.
			FieldReference adaptedObjectReference = classEmitter.CreateField("_Original", OriginalObject);

			//Add a constructor that accepts a reference to the original object and
			//assigns that reference to the field.
			ArgumentReference parameter = new ArgumentReference(OriginalObject);
			ConstructorEmitter constructor = classEmitter.CreateConstructor(parameter);
			constructor.CodeBuilder.AddStatement(
				new AssignStatement(adaptedObjectReference, new ReferenceExpression(parameter)));
			constructor.CodeBuilder.AddStatement(new ReturnStatement());

			//For each method, walk the pipeline
			foreach (MethodInfo method in OriginalObject.GetMethods())
			{
				AdapterBuilderStageContext context =
					new AdapterBuilderStageContext(OriginalObject, classEmitter, adaptedObjectReference, method);
				WalkPipeline(context);
			}

			//build the type			
			return classEmitter.BuildType();

		}
		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 bool HasByRefArguments(ArgumentReference[] arguments)
        {
            for (int i = 0; i < arguments.Length; i++ )
            {
                if (arguments[i].Type.IsByRef)
                {
                    return true;
                }
            }

            return false;
        }
		public ConstructorEmitter CreateConstructor(ArgumentReference[] baseCtorArguments, AbstractTypeEmitter invocation)
		{
			return invocation.CreateConstructor(baseCtorArguments);
		}
예제 #28
0
		private void GenerateConstructor(ClassEmitter emitter, ConstructorInfo baseConstructor, params FieldReference[] fields)
		{
			ArgumentReference[] args;
			ParameterInfo[] baseConstructorParams = null;

			if (baseConstructor != null)
			{
				baseConstructorParams = baseConstructor.GetParameters();
			}

			if (baseConstructorParams != null && baseConstructorParams.Length != 0)
			{
				args = new ArgumentReference[fields.Length + baseConstructorParams.Length];

				int offset = fields.Length;

				for (int i = offset; i < offset + baseConstructorParams.Length; i++)
				{
					ParameterInfo paramInfo = baseConstructorParams[i - offset];
					args[i] = new ArgumentReference(paramInfo.ParameterType);
				}
			}
			else
			{
				args = new ArgumentReference[fields.Length];
			}

			for (int i = 0; i < fields.Length; i++)
			{
				args[i] = new ArgumentReference(fields[i].Reference.FieldType);
			}

			ConstructorEmitter constructor = emitter.CreateConstructor(args);

			for (int i = 0; i < fields.Length; i++)
			{
				constructor.CodeBuilder.AddStatement(new AssignStatement(fields[i], args[i].ToExpression()));
			}

			// Invoke base constructor

			if (baseConstructor != null)
			{
				Debug.Assert(baseConstructorParams != null);

				var slice = new ArgumentReference[baseConstructorParams.Length];
				Array.Copy(args, fields.Length, slice, 0, baseConstructorParams.Length);

				constructor.CodeBuilder.InvokeBaseConstructor(baseConstructor, slice);
			}
			else
			{
				constructor.CodeBuilder.InvokeBaseConstructor();
			}

			constructor.CodeBuilder.AddStatement(new ReturnStatement());
		}
예제 #29
0
 public AssignArgumentStatement(ArgumentReference argument, Expression expression)
 {
     this.argument = argument;
     this.expression = expression;
 }
		protected override void AddAddValueInvocation(ArgumentReference serializationInfo, MethodEmitter getObjectData,
		                                              FieldReference field)
		{
			serializedFields.Add(field);
			base.AddAddValueInvocation(serializationInfo, getObjectData, field);
		}
예제 #31
0
		/// <summary>
		/// Generates the constructor for the nested class that extends
		/// <see cref="AbstractInvocation"/>
		/// </summary>
		/// <param name="targetFieldType"></param>
		/// <param name="nested"></param>
		/// <param name="targetField"></param>
		/// <param name="version"></param>
		protected void CreateIInvocationConstructor(
			Type targetFieldType, NestedClassEmitter nested, FieldReference targetField, ConstructorVersion version)
		{
			ArgumentReference cArg0 = new ArgumentReference(targetFieldType);
			ArgumentReference cArg1 = new ArgumentReference(typeof(IInterceptor[]));
			ArgumentReference cArg2 = new ArgumentReference(typeof(Type));
			ArgumentReference cArg3 = new ArgumentReference(typeof(MethodInfo));
			ArgumentReference cArg4 = null;
			ArgumentReference cArg6 = new ArgumentReference(typeof(object));

			if (version == ConstructorVersion.WithTargetMethod)
			{
				cArg4 = new ArgumentReference(typeof(MethodInfo));
			}

			ArgumentReference cArg5 = new ArgumentReference(typeof(object[]));

			ConstructorEmitter constructor;

			if (cArg4 == null)
			{
				constructor = nested.CreateConstructor(cArg0, cArg1, cArg2, cArg3, cArg5, cArg6);
			}
			else
			{
				constructor = nested.CreateConstructor(cArg0, cArg1, cArg2, cArg3, cArg4, cArg5, cArg6);
			}

			constructor.CodeBuilder.AddStatement(new AssignStatement(targetField, cArg0.ToExpression()));

			if (cArg4 == null)
			{
				constructor.CodeBuilder.InvokeBaseConstructor(Constants.AbstractInvocationConstructorWithoutTargetMethod,
				                                              cArg0,
				                                              cArg6,
				                                              cArg1,
				                                              cArg2,
				                                              cArg3,
				                                              cArg5);
			}
			else
			{
				constructor.CodeBuilder.InvokeBaseConstructor(Constants.AbstractInvocationConstructorWithTargetMethod,
				                                              cArg0,
				                                              cArg6,
				                                              cArg1,
				                                              cArg2,
				                                              cArg3,
				                                              cArg4,
				                                              cArg5);
			}

			constructor.CodeBuilder.AddStatement(new ReturnStatement());
		}