public IndirectReference(TypeReference byRefReference) :
			base(byRefReference, byRefReference.Type.GetElementType())
		{
			if (!byRefReference.Type.IsByRef)
			{
				throw new ArgumentException("Expected an IsByRef reference", "byRefReference");
			}
		}
		// TODO: Better name
		public static TypeReference[] WrapIfByRef(TypeReference[] references)
		{
			TypeReference[] result = new TypeReference[references.Length];

			for(int i = 0; i < references.Length; i++)
			{
				result[i] = WrapIfByRef(references[i]);
			}

			return result;
		}
		public static void CopyOutAndRefParameters(TypeReference[] dereferencedArguments, LocalReference invocation, MethodInfo method, MethodEmitter emitter)
		{
			var parameters = method.GetParameters();
			if (!ArgumentsUtil.IsAnyByRef(parameters))
			{
				return; //saving the need to create locals if there is no need
			}

			var arguments = StoreInvocationArgumentsInLocal(emitter, invocation);

			for (int i = 0; i < parameters.Length; i++)
			{
				if (!parameters[i].ParameterType.IsByRef) continue;

				emitter.CodeBuilder.AddStatement(AssignArgument(dereferencedArguments, i, arguments));
			}
		}
		private Expression[] GetCtorArguments(ClassEmitter @class, INamingScope namingScope, Expression proxiedMethodTokenExpression, TypeReference[] dereferencedArguments)
		{
			var selector = @class.GetField("__selector");
			if (selector != null)
			{
				return new[]
				{
					getTargetExpression(@class, MethodToOverride),
					SelfReference.Self.ToExpression(),
					interceptors.ToExpression(),
					proxiedMethodTokenExpression,
					new ReferencesToObjectArrayExpression(dereferencedArguments),
					selector.ToExpression(),
					new AddressOfReferenceExpression(BuildMethodInterceptorsField(@class, MethodToOverride, namingScope))
				};
			}
			return new[]
			{
				getTargetExpression(@class, MethodToOverride),
				SelfReference.Self.ToExpression(),
				interceptors.ToExpression(),
				proxiedMethodTokenExpression,
				new ReferencesToObjectArrayExpression(dereferencedArguments)
			};
		}
Exemple #5
0
 private static AssignStatement AssignArgument(TypeReference[] dereferencedArguments, int i,
                                               LocalReference invocationArgs)
 {
     return new AssignStatement(dereferencedArguments[i], Argument(i, invocationArgs, dereferencedArguments));
 }
Exemple #6
0
 private static ConvertExpression Argument(int i, LocalReference invocationArgs, TypeReference[] arguments)
 {
     return new ConvertExpression(arguments[i].Type, new LoadRefArrayElementExpression(i, invocationArgs));
 }
		// TODO: Better name
		public static TypeReference WrapIfByRef(TypeReference reference)
		{
			return reference.Type.IsByRef ? new IndirectReference(reference) : reference;
		}
		private static void CopyOutAndRefParameters(
			TypeReference[] dereferencedArguments, LocalReference invocationImplLocal, MethodInfo method,
			MethodEmitter methodEmitter)
		{
			ParameterInfo[] parameters = method.GetParameters();
			bool hasByRefParam = false;
			for(int i = 0; i < parameters.Length; i++)
			{
				if (parameters[i].ParameterType.IsByRef)
					hasByRefParam = true;
			}
			if (!hasByRefParam)
				return; //saving the need to create locals if there is no need
			LocalReference invocationArgs = methodEmitter.CodeBuilder.DeclareLocal(typeof(object[]));
			methodEmitter.CodeBuilder.AddStatement(
				new AssignStatement(invocationArgs,
				                    new MethodInvocationExpression(invocationImplLocal, invocation_getArgumentsMethod)
					)
				);
			for(int i = 0; i < parameters.Length; i++)
			{
				if (parameters[i].ParameterType.IsByRef)
				{
					methodEmitter.CodeBuilder.AddStatement(
						new AssignStatement(dereferencedArguments[i],
						                    new ConvertExpression(dereferencedArguments[i].Type,
						                                          new LoadRefArrayElementExpression(i, invocationArgs)
						                    	)
							));
				}
			}
		}
		private Expression[] GetCtorArguments(ClassEmitter @class, Expression proxiedMethodTokenExpression, TypeReference[] dereferencedArguments, Expression methodInterceptors)
		{
			return new[]
			{
				getTargetExpression(@class, MethodToOverride),
				SelfReference.Self.ToExpression(),
				methodInterceptors ?? interceptors.ToExpression(),
				proxiedMethodTokenExpression,
				new ReferencesToObjectArrayExpression(dereferencedArguments)
			};
		}