Exemplo n.º 1
0
            internal InvokeBeginDelegate GenerateInvokeBeginDelegate(MethodInfo method, out int inputParameterCount)
            {
                bool allowPrivateMemberAccess = MethodRequiresMemberAccess(method);

                this.ilg = new CodeGenerator();
                try
                {
                    this.ilg.BeginMethod("AsyncInvokeBegin" + method.Name, typeof(InvokeBeginDelegate), allowPrivateMemberAccess);
                }
                catch (SecurityException exception)
                {
                    if (!allowPrivateMemberAccess || !exception.PermissionType.Equals(typeof(ReflectionPermission)))
                    {
                        throw;
                    }
                    if (DiagnosticUtility.ShouldTraceWarning)
                    {
                        DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Warning);
                    }
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityException(System.ServiceModel.SR.GetString("PartialTrustServiceMethodNotVisible", new object[] { method.DeclaringType.FullName, method.Name })));
                }
                ArgBuilder arg = this.ilg.GetArg(0);
                ArgBuilder inputParametersArg = this.ilg.GetArg(1);
                ArgBuilder builder3           = this.ilg.GetArg(2);
                ArgBuilder builder4           = this.ilg.GetArg(3);

                ParameterInfo[] parameters  = method.GetParameters();
                LocalBuilder    returnLocal = this.ilg.DeclareLocal(this.ilg.CurrentMethod.ReturnType, "returnParam");

                LocalBuilder[] parameterLocals = new LocalBuilder[parameters.Length - 2];
                this.DeclareParameterLocals(parameters, parameterLocals);
                this.LoadInputParametersIntoLocals(parameters, parameterLocals, inputParametersArg, out inputParameterCount);
                this.LoadTarget(arg, method.ReflectedType);
                this.LoadParameters(parameters, parameterLocals);
                this.ilg.Load(builder3);
                this.ilg.Load(builder4);
                this.InvokeMethod(method, returnLocal);
                this.ilg.Load(returnLocal);
                return((InvokeBeginDelegate)this.ilg.EndMethod());
            }
 void LoadOutputParametersIntoArray(ParameterInfo[] parameters, LocalBuilder[] parameterLocals, ArgBuilder outputParametersArg, out int outputParameterCount)
 {
     outputParameterCount = 0;
     for (int i = 0; i < parameterLocals.Length; i++)
     {
         if (ServiceReflector.FlowsOut(parameters[i]))
         {
             ilg.Load(outputParametersArg);
             ilg.Load(outputParameterCount);
             ilg.Load(parameterLocals[i]);
             ilg.ConvertValue(parameterLocals[i].LocalType, TypeOfObject);
             ilg.Stelem(TypeOfObject);
             outputParameterCount++;
         }
     }
 }
 void LoadInputParametersIntoLocals(ParameterInfo[] parameters, LocalBuilder[] parameterLocals, ArgBuilder inputParametersArg, out int inputParameterCount)
 {
     inputParameterCount = 0;
     for (int i = 0; i < parameterLocals.Length; i++)
     {
         if (ServiceReflector.FlowsIn(parameters[i]))
         {
             Type parameterType = parameterLocals[i].LocalType;
             ilg.LoadArrayElement(inputParametersArg, inputParameterCount);
             if (!parameterType.IsValueType)
             {
                 ilg.ConvertValue(TypeOfObject, parameterType);
                 ilg.Store(parameterLocals[i]);
             }
             else
             {
                 ilg.Dup();
                 ilg.If();
                 ilg.ConvertValue(TypeOfObject, parameterType);
                 ilg.Store(parameterLocals[i]);
                 ilg.Else();
                 ilg.Pop();
                 ilg.LoadZeroValueIntoLocal(parameterType, parameterLocals[i]);
                 ilg.EndIf();
             }
             inputParameterCount++;
         }
     }
 }
Exemplo n.º 4
0
 internal void Ldarga(ArgBuilder argBuilder)
 {
     Ldarga(argBuilder.Index);
 }
Exemplo n.º 5
0
 internal void Starg(ArgBuilder arg)
 {
     Starg(arg.Index);
 }
Exemplo n.º 6
0
 internal void Ldarg(ArgBuilder arg)
 {
     Ldarg(arg.Index);
 }