コード例 #1
0
 private string MethodCallMessageToString(IMethodCallMessage msg)
 {
     if (msg != null)
     {
         StringBuilder mDescription = new StringBuilder();
         if (msg.MethodName != null)
         {
             mDescription.AppendFormat("Method = {0}(", msg.MethodName);
         }
         for (int ix = 0; ix < msg.ArgCount; ix++)
         {
             mDescription.AppendFormat(" {0}=", msg.GetArgName(ix));
             string val = "null";
             if (msg.GetArg(ix) != null)
             {
                 val = msg.GetArg(ix).ToString();
             }
             mDescription.AppendFormat(" {0} ;", val);
         }
         mDescription.Append(")");
         return(mDescription.ToString());
     }
     else
     {
         return("Null message");
     }
 }
コード例 #2
0
 private void Before_Log(IMethodCallMessage callMsg)
 {
     if (callMsg == null)
     {
         return;
     }
     Console.WriteLine("Before {0}", callMsg.MethodName);
     Console.WriteLine("{0}({1},{2})", callMsg.MethodName, callMsg.GetArg(0), callMsg.GetArg(1));
 }
コード例 #3
0
ファイル: CallTraceSink.cs プロジェクト: HottDog/LittleTool
        //方法调用完返回结果时的后置处理
        public void PostProcess(IMessage msg, IMessage retMsg)
        {
            IMethodCallMessage call = msg as IMethodCallMessage;

            if (call == null)
            {
                return;
            }
            string product = call.GetArg(0).ToString();
            int    qty     = (int)call.GetArg(1);

            Console.WriteLine("产品" + product + "的质量是" + qty);
        }
コード例 #4
0
        private void TraitementPREappel(IMessage msg)
        {
            if (msg is IMethodCallMessage)
            {
                #region Traitement d'un IMethodCallMessage

                object[]           tabat = null;        // contiendra le tableau d'attribut
                IMethodCallMessage mcmsg = msg as IMethodCallMessage;

                if (mcmsg.MethodBase.IsSpecialName && mcmsg.MethodName.StartsWith("set_"))                      // propriété ?
                {
                    #region Appel d'une propriété
                    // recupération du nom de lapropriété
                    string pname = mcmsg.MethodName.Substring(4, mcmsg.MethodName.Length - 4);

                    // recupération des attributs posés sur cette propriété
                    tabat = mcmsg.MethodBase.ReflectedType.GetProperty(pname).GetCustomAttributes(typeof(IDataValidationConstraint), false);
                    foreach (IDataValidationConstraint chkatt in tabat)
                    {
                        if (!chkatt.DoCheck(mcmsg.GetArg(0)))                         // pour le setter d'une propriété : un seul param : value
                        {
                            string errMsg = "DataValidation failed on " + mcmsg.MethodBase.ReflectedType.Name + "." + pname + "\r\n";
                            errMsg += "property value : " + chkatt.GetValidationFailureMessage();
                            throw new DataValidationException(errMsg, pname, chkatt);
                        }
                    }
                    #endregion
                }
                else
                {
                    #region Appel d'une fonction
                    ParameterInfo[] pi = mcmsg.MethodBase.GetParameters();                             // on recupere la liste des parametres de la méthode
                    for (int pin = 0; pin < pi.Length; pin++)                                          // on vérifie les attributs posé sur chaque parametre
                    {
                        tabat = pi[pin].GetCustomAttributes(typeof(IDataValidationConstraint), false); // on recupère les attributs du paramètre
                        foreach (IDataValidationConstraint chkatt in tabat)
                        {
                            if (!chkatt.DoCheck(mcmsg.GetArg(pin)))
                            {
                                string errMsg = "DataValidation failed on " + mcmsg.MethodBase.ReflectedType.Name + "." + mcmsg.MethodBase.Name + "\r\n";
                                errMsg += "parameter " + pi[pin].Name + " : " + chkatt.GetValidationFailureMessage();
                                throw new DataValidationException(errMsg, mcmsg.MethodBase.Name, pi[pin].Name, chkatt);
                            }
                        }
                    }
                    #endregion
                }
                #endregion
            }
        }
コード例 #5
0
ファイル: AttributeAop.cs プロジェクト: ksc1711/C-_aop_Test
        private bool MethodEnterLog(IMethodCallMessage callMsg)
        {
            // reflection을 통해 Log 특성이 메쏘드에 존재하는지 확인한다.
            MethodBase method = callMsg.MethodBase;

            object[] attributes = method.GetCustomAttributes(typeof(LogAttribute), false);
            if (attributes == null || attributes.Length == 0)
            {
                return(false);  // Log 특성이 없다면 아무런 작업도 하지 않는다.
            }
            StringBuilder sb = new StringBuilder(128);

            if (callMsg is IConstructionCallMessage)
            {
                sb.Append(".ctor(");
            }
            else
            {
                sb.AppendFormat("{0} {1}(",
                                ((MethodInfo)method).ReturnType.Name, method.Name);
            }
            for (int i = 0; i < callMsg.ArgCount; i++)
            {
                sb.AppendFormat("{0}={1}",
                                callMsg.GetArgName(i), callMsg.GetArg(i));
                if (i < callMsg.ArgCount - 1)
                {
                    sb.Append(',');
                }
            }
            sb.Append(')');
            Console.WriteLine(sb.ToString(), "SM");
            return(true);
        }
コード例 #6
0
        private void CheckParameters(IMessage msg)
        {
            IMethodCallMessage methodCallMessage = (IMethodCallMessage)msg;

            ParameterInfo[] parameters = methodCallMessage.MethodBase.GetParameters();
            int             num        = 0;

            foreach (ParameterInfo parameterInfo in parameters)
            {
                object arg  = methodCallMessage.GetArg(num++);
                Type   type = parameterInfo.ParameterType;
                if (type.IsByRef)
                {
                    type = type.GetElementType();
                }
                if (arg != null && !type.IsInstanceOfType(arg))
                {
                    throw new RemotingException(string.Concat(new object[]
                    {
                        "Cannot cast argument ",
                        parameterInfo.Position,
                        " of type '",
                        arg.GetType().AssemblyQualifiedName,
                        "' to type '",
                        type.AssemblyQualifiedName,
                        "'"
                    }));
                }
            }
        }
コード例 #7
0
    public override IMessage Invoke(IMessage request)
    {
        IMethodCallMessage call = (IMethodCallMessage)request;

        Console.WriteLine("Invoke " + call.MethodName);

        Console.Write("ARGS(");
        for (int i = 0; i < call.ArgCount; i++)
        {
            if (i != 0)
            {
                Console.Write(", ");
            }
            Console.Write(call.GetArgName(i) + " " +
                          call.GetArg(i));
        }
        Console.WriteLine(")");
        Console.Write("INARGS(");
        for (int i = 0; i < call.InArgCount; i++)
        {
            if (i != 0)
            {
                Console.Write(", ");
            }
            Console.Write(call.GetInArgName(i) + " " +
                          call.GetInArg(i));
        }
        Console.WriteLine(")");

        ((R1)target).test_field = 1;

        IMethodReturnMessage res = RemotingServices.ExecuteMessage(target, call);

        Console.Write("RESARGS(");
        for (int i = 0; i < res.ArgCount; i++)
        {
            if (i != 0)
            {
                Console.Write(", ");
            }
            Console.Write(res.GetArgName(i) + " " +
                          res.GetArg(i));
        }
        Console.WriteLine(")");

        Console.Write("RESOUTARGS(");
        for (int i = 0; i < res.OutArgCount; i++)
        {
            if (i != 0)
            {
                Console.Write(", ");
            }
            Console.Write(res.GetOutArgName(i) + " " +
                          res.GetOutArg(i));
        }
        Console.WriteLine(")");

        return(res);
    }
		public CompositionException(IMethodCallMessage Message,string message, System.Exception innerException):this(String.Format("Exception:{0}\r\nAssembly:{1}\r\n{2}:{3}\r\nArgs:\r\n",message,Message.TypeName,Message.MethodBase.MemberType,Message.MethodName),innerException)
		{
			for(int i=0; i<Message.ArgCount; i+=2)
			{
				_message = String.Format("{0}\t{1}={2}\r\n",_message,Message.GetArgName(i),Message.GetArg(i).ToString());
			}
			
		}
コード例 #9
0
        protected virtual IDictionary <string, object> BuildParameters(IMethodCallMessage methodMessage)
        {
            var parameters = new Dictionary <string, object>();

            for (var i = 0; i < methodMessage.ArgCount; i++)
            {
                parameters.Add(methodMessage.GetArgName(i), methodMessage.GetArg(i));
            }
            return(parameters);
        }
コード例 #10
0
        //同步处理方法
        public IMessage SyncProcessMessage(IMessage msg)
        {
            IMessage          message = null;
            ServerCallContext context = null;
            //方法调用接口
            IMethodCallMessage callMessage = msg as IMethodCallMessage;

            for (int i = 0; i < callMessage.InArgCount; i++)
            {
                var item = callMessage.GetArg(i);
                if (item.GetType() == typeof(ServerCallContext))
                {
                    context = item as ServerCallContext;
                    break;
                }
            }
            if (Attribute.GetCustomAttribute(callMessage.MethodBase, typeof(MethodAttribute)) != null)
            {
                var headers     = context.RequestHeaders;
                var accessToken = "";
                foreach (var item in headers.Where(item => item.Key == "authorization"))
                {
                    accessToken = item.Value.Split(' ')[1];
                    break;
                }
                var checkToken = !string.IsNullOrEmpty(accessToken);
                if (checkToken)
                {
                    message = nextSink.SyncProcessMessage(msg);
                }
                else
                {
                    RpcException e = new RpcException(new Status(StatusCode.Unauthenticated, "Unauthenticated"));
                    message = new ReturnMessage(e, (IMethodCallMessage)msg);
                }
            }
            else
            {
                message = nextSink.SyncProcessMessage(msg);
            }
            //如果被调用的方法没打MyCalculatorMethodAttribute标签
            //if (callMessage == null || (Attribute.GetCustomAttribute(callMessage.MethodBase, typeof(MethodAttribute))) == null)
            //{
            //    message = nextSink.SyncProcessMessage(msg);
            //}
            //else
            //{
            //    PreProceed(msg);
            //    message = nextSink.SyncProcessMessage(msg);
            //    PostProceed(message);
            //}

            return(message);
        }
コード例 #11
0
        /// <summary>
        /// Handles unsubscription.
        /// </summary>
        /// <param name="methodCallMessage"><see cref="IMethodCallMessage"/> to process.</param>
        /// <param name="methodInfo"><see cref="MethodInfo"/> for the method being called.</param>
        /// <returns><see cref="ReturnMessage"/>, if the call is processed successfully, otherwise, false.</returns>
        private ReturnMessage HandleEventUnsubscription(IMethodCallMessage methodCallMessage, MethodInfo methodInfo)
        {
            if (methodInfo.ReturnType.Equals(typeof(void)) &&
                methodCallMessage.MethodName.StartsWith("remove_") &&
                methodCallMessage.InArgCount == 1 &&
                methodCallMessage.ArgCount == 1 &&
                methodCallMessage.Args[0] != null &&
                typeof(Delegate).IsAssignableFrom(methodCallMessage.Args[0].GetType()))
            {
                string propertyName = methodCallMessage.MethodName.Substring(7);
                var    inputMessage = methodCallMessage.GetArg(0) as Delegate;
                var    eventFilter  = default(IEventFilter);

                // Detach event filter, if it is attached
                ExtractEventHandlerDetails(ref inputMessage, ref eventFilter);

                if (_delegateCorrelationSet.Count > 0)
                {
                    // copy delegates
                    IEnumerable <DelegateCorrelationInfo> correlationSet;
                    lock (_delegateCorrelationSet)
                    {
                        correlationSet = _delegateCorrelationSet.ToArray();
                    }

                    var found = (
                        from correlationInfo in correlationSet
                        where correlationInfo.DelegateMemberName.Equals(propertyName) && correlationInfo.ClientDelegateInterceptor.ClientDelegate.Equals(inputMessage)
                        select correlationInfo).FirstOrDefault();

                    if (found != null)
                    {
                        OptionalAsync(ZyanSettings.LegacyBlockingSubscriptions, () =>
                                      RemoveRemoteEventHandlers(new List <DelegateCorrelationInfo> {
                            found
                        }));

                        // Remove delegate correlation info
                        lock (_delegateCorrelationSet)
                        {
                            _delegateCorrelationSet.Remove(found);
                            found.Dispose();
                        }
                    }
                }

                return(new ReturnMessage(null, null, 0, methodCallMessage.LogicalCallContext, methodCallMessage));
            }

            // This method doesn't represent event unsubscription
            return(null);
        }
コード例 #12
0
        /// <summary>
        /// Handles subscription to events.
        /// </summary>
        /// <param name="methodCallMessage"><see cref="IMethodCallMessage"/> to process.</param>
        /// <param name="methodInfo"><see cref="MethodInfo"/> for the method being called.</param>
        /// <returns><see cref="ReturnMessage"/>, if the call is processed successfully, otherwise, false.</returns>
        private ReturnMessage HandleEventSubscription(IMethodCallMessage methodCallMessage, MethodInfo methodInfo)
        {
            // Check for delegate parameters in properties and events
            if (methodInfo.ReturnType.Equals(typeof(void)) &&
                (methodCallMessage.MethodName.StartsWith("set_") || methodCallMessage.MethodName.StartsWith("add_")) &&
                methodCallMessage.InArgCount == 1 &&
                methodCallMessage.ArgCount == 1 &&
                methodCallMessage.Args[0] != null &&
                typeof(Delegate).IsAssignableFrom(methodCallMessage.Args[0].GetType()))
            {
                // Get client delegate
                var receiveMethodDelegate = methodCallMessage.GetArg(0) as Delegate;
                var eventFilter           = default(IEventFilter);

                // Get event filter, if it is attached
                ExtractEventHandlerDetails(ref receiveMethodDelegate, ref eventFilter);

                // Trim "set_" or "add_" prefix
                string propertyName = methodCallMessage.MethodName.Substring(4);

                // Create delegate interceptor and correlation info
                var wiring = new DelegateInterceptor()
                {
                    ClientDelegate         = receiveMethodDelegate,
                    SynchronizationContext = _synchronizationContext
                };

                var correlationInfo = new DelegateCorrelationInfo()
                {
                    IsEvent                   = methodCallMessage.MethodName.StartsWith("add_"),
                    DelegateMemberName        = propertyName,
                    ClientDelegateInterceptor = wiring,
                    EventFilter               = eventFilter
                };

                OptionalAsync(ZyanSettings.LegacyBlockingSubscriptions, () =>
                              AddRemoteEventHandlers(new List <DelegateCorrelationInfo> {
                    correlationInfo
                }));

                // Save delegate correlation info
                lock (_delegateCorrelationSet)
                {
                    _delegateCorrelationSet.Add(correlationInfo);
                }

                return(new ReturnMessage(null, null, 0, methodCallMessage.LogicalCallContext, methodCallMessage));
            }

            // This method doesn't represent event subscription
            return(null);
        }
コード例 #13
0
        /// <summary>
        /// Sets all parameters/properties as variables.
        /// </summary>
        /// <param name="setVariable">SessionStateProxy.SetVariable method</param>
        /// <param name="proxyInstance">SessionStateProxy instance</param>
        internal void SetAllParametersAsVariables(MethodInfo setVariable, object proxyInstance)
        {
            int argIndex = 0;

            //set all parameters as variables
            foreach (ParameterInfo pi in methodCallMessage.MethodBase.GetParameters())
            {
                string parameterName = pi.Name;
                object argumentValue = null;
                if (pi.ParameterType.IsByRef)
                {
                    if (pi.IsOut)
                    {
                        //sets all "out" parameters by default value
                        argumentValue = pi.DefaultValue;
                    }
                    else
                    {
                        argumentValue = methodCallMessage.GetArg(argIndex);
                    }

                    //stores all out/ref parameters
                    outParameterNames.Add(parameterName);
                }
                else
                {
                    argumentValue = methodCallMessage.GetArg(argIndex);
                }

                //sessionStateProxy.SetVariable
                setVariable.Invoke(
                    proxyInstance,
                    new object[] { parameterName, argumentValue });

                argIndex++;
            }
        }
コード例 #14
0
ファイル: CallTraceSink.cs プロジェクト: HottDog/LittleTool
        //方法调用的前置处理
        public void PreProcess(IMessage msg)
        {
            IMethodCallMessage call = msg as IMethodCallMessage;

            if (call == null)
            {
                return;
            }
            if (call.MethodName == "Submit")
            {
                string product = call.GetArg(0).ToString();
                int    qty     = (int)call.GetArg(1);

                //处理代码
                if (qty > 100)
                {
                    Console.WriteLine("产品" + product + "质量检查通过");
                }
                else
                {
                    Console.WriteLine("产品" + product + "质量检查不通过");
                }
            }
        }
コード例 #15
0
        void CheckParameters(IMessage msg)
        {
            IMethodCallMessage mcm = (IMethodCallMessage)msg;

            ParameterInfo[] parameters = mcm.MethodBase.GetParameters();
            int             narg       = 0;

            foreach (ParameterInfo pi in parameters)
            {
                object pval = mcm.GetArg(narg++);
                Type   pt   = pi.ParameterType;
                if (pt.IsByRef)
                {
                    pt = pt.GetElementType();
                }

                if (pval != null && !pt.IsInstanceOfType(pval))
                {
                    throw new RemotingException("Cannot cast argument " + pi.Position + " of type '" + pval.GetType().AssemblyQualifiedName +
                                                "' to type '" + pt.AssemblyQualifiedName + "'");
                }
            }
        }
コード例 #16
0
ファイル: ZyanProxy.cs プロジェクト: yallie/zyan
        /// <summary>
        /// Handles unsubscription.
        /// </summary>
        /// <param name="methodCallMessage"><see cref="IMethodCallMessage"/> to process.</param>
        /// <param name="methodInfo"><see cref="MethodInfo"/> for the method being called.</param>
        /// <returns><see cref="ReturnMessage"/>, if the call is processed successfully, otherwise, false.</returns>
        private ReturnMessage HandleEventUnsubscription(IMethodCallMessage methodCallMessage, MethodInfo methodInfo)
        {
            if (methodInfo.ReturnType.Equals(typeof(void)) &&
                methodCallMessage.MethodName.StartsWith("remove_") &&
                methodCallMessage.InArgCount == 1 &&
                methodCallMessage.ArgCount == 1 &&
                methodCallMessage.Args[0] != null &&
                typeof(Delegate).IsAssignableFrom(methodCallMessage.Args[0].GetType()))
            {
                string propertyName = methodCallMessage.MethodName.Substring(7);
                var inputMessage = methodCallMessage.GetArg(0) as Delegate;
                var eventFilter = default(IEventFilter);

                // Detach event filter, if it is attached
                ExtractEventHandlerDetails(ref inputMessage, ref eventFilter);

                if (_delegateCorrelationSet.Count > 0)
                {
                    // copy delegates
                    IEnumerable<DelegateCorrelationInfo> correlationSet;
                    lock (_delegateCorrelationSet)
                    {
                        correlationSet = _delegateCorrelationSet.ToArray();
                    }

                    var found = (
                        from correlationInfo in correlationSet
                        where correlationInfo.DelegateMemberName.Equals(propertyName) && correlationInfo.ClientDelegateInterceptor.ClientDelegate.Equals(inputMessage)
                        select correlationInfo).FirstOrDefault();

                    if (found != null)
                    {
                        OptionalAsync(ZyanSettings.LegacyBlockingSubscriptions, () =>
                            RemoveRemoteEventHandlers(new List<DelegateCorrelationInfo> { found }));

                        // Remove delegate correlation info
                        lock (_delegateCorrelationSet)
                        {
                            _delegateCorrelationSet.Remove(found);
                            found.Dispose();
                        }
                    }
                }

                return new ReturnMessage(null, null, 0, methodCallMessage.LogicalCallContext, methodCallMessage);
            }

            // This method doesn't represent event unsubscription
            return null;
        }
コード例 #17
0
ファイル: ZyanProxy.cs プロジェクト: yallie/zyan
        /// <summary>
        /// Handles subscription to events.
        /// </summary>
        /// <param name="methodCallMessage"><see cref="IMethodCallMessage"/> to process.</param>
        /// <param name="methodInfo"><see cref="MethodInfo"/> for the method being called.</param>
        /// <returns><see cref="ReturnMessage"/>, if the call is processed successfully, otherwise, false.</returns>
        private ReturnMessage HandleEventSubscription(IMethodCallMessage methodCallMessage, MethodInfo methodInfo)
        {
            // Check for delegate parameters in properties and events
            if (methodInfo.ReturnType.Equals(typeof(void)) &&
                (methodCallMessage.MethodName.StartsWith("set_") || methodCallMessage.MethodName.StartsWith("add_")) &&
                methodCallMessage.InArgCount == 1 &&
                methodCallMessage.ArgCount == 1 &&
                methodCallMessage.Args[0] != null &&
                typeof(Delegate).IsAssignableFrom(methodCallMessage.Args[0].GetType()))
            {
                // Get client delegate
                var receiveMethodDelegate = methodCallMessage.GetArg(0) as Delegate;
                var eventFilter = default(IEventFilter);

                // Get event filter, if it is attached
                ExtractEventHandlerDetails(ref receiveMethodDelegate, ref eventFilter);

                // Trim "set_" or "add_" prefix
                string propertyName = methodCallMessage.MethodName.Substring(4);

                // Create delegate interceptor and correlation info
                var wiring = new DelegateInterceptor()
                {
                    ClientDelegate = receiveMethodDelegate,
                    SynchronizationContext = _synchronizationContext
                };

                var correlationInfo = new DelegateCorrelationInfo()
                {
                    IsEvent = methodCallMessage.MethodName.StartsWith("add_"),
                    DelegateMemberName = propertyName,
                    ClientDelegateInterceptor = wiring,
                    EventFilter = eventFilter
                };

                OptionalAsync(ZyanSettings.LegacyBlockingSubscriptions, () =>
                    AddRemoteEventHandlers(new List<DelegateCorrelationInfo> { correlationInfo }));

                // Save delegate correlation info
                lock (_delegateCorrelationSet)
                {
                    _delegateCorrelationSet.Add(correlationInfo);
                }

                return new ReturnMessage(null, null, 0, methodCallMessage.LogicalCallContext, methodCallMessage);
            }

            // This method doesn't represent event subscription
            return null;
        }
コード例 #18
0
ファイル: RemotingServices.cs プロジェクト: gustavo-melo/mono
		internal static IMethodReturnMessage InternalExecuteMessage (
		        MarshalByRefObject target, IMethodCallMessage reqMsg)
		{
			ReturnMessage result;
			
			Type tt = target.GetType ();
			MethodBase method;
			if (reqMsg.MethodBase.DeclaringType == tt ||
			    reqMsg.MethodBase == FieldSetterMethod || 
			    reqMsg.MethodBase == FieldGetterMethod) {
				method = reqMsg.MethodBase;
			} else {
				method = GetVirtualMethod (tt, reqMsg.MethodBase);

				if (method == null)
					throw new RemotingException (
						String.Format ("Cannot resolve method {0}:{1}", tt, reqMsg.MethodName));
			}

			if (reqMsg.MethodBase.IsGenericMethod) {
				Type[] genericArguments = reqMsg.MethodBase.GetGenericArguments ();
				MethodInfo gmd = ((MethodInfo)method).GetGenericMethodDefinition ();
				method = gmd.MakeGenericMethod (genericArguments);
			}

			object oldContext = CallContext.SetCurrentCallContext (reqMsg.LogicalCallContext);
			
			try 
			{
				object [] out_args;
				object rval = InternalExecute (method, target, reqMsg.Args, out out_args);
			
				// Collect parameters with Out flag from the request message
				// FIXME: This can be done in the unmanaged side and will be
				// more efficient
				
				ParameterInfo[] parameters = method.GetParameters();
				object[] returnArgs = new object [parameters.Length];
				
				int n = 0;
				int noa = 0;
				foreach (ParameterInfo par in parameters)
				{
					if (par.IsOut && !par.ParameterType.IsByRef) 
						returnArgs [n++] = reqMsg.GetArg (par.Position);
					else if (par.ParameterType.IsByRef)
						returnArgs [n++] = out_args [noa++]; 
					else
						returnArgs [n++] = null; 
				}
				
				result = new ReturnMessage (rval, returnArgs, n, CallContext.CreateLogicalCallContext (true), reqMsg);
			} 
			catch (Exception e) 
			{
				result = new ReturnMessage (e, reqMsg);
			}
			
			CallContext.RestoreCallContext (oldContext);
			return result;
		}
コード例 #19
0
 public SqlParameter GetSqlParameter(SqlCommand command, IMethodCallMessage mcm, SqlParameter[] outArgs, IList<IDisposable> disposeList)
 {
     SqlParameter parameter = command.CreateParameter();
     parameter.ParameterName = parameterName;
     parameter.IsNullable = nullable;
     if (size > 0) {
         parameter.Size = size;
     }
     parameter.Direction = direction;
     object value = mcm.GetArg(position);
     switch (sqlType) {
     case SqlDbType.SmallInt:
         IIdentifiable<short> identifiableShort = value as IIdentifiable<short>;
         if (identifiableShort != null) {
             value = identifiableShort.Id;
         }
         break;
     case SqlDbType.Int:
         IIdentifiable<int> identifiableInt = value as IIdentifiable<int>;
         if (identifiableInt != null) {
             value = identifiableInt.Id;
         }
         break;
     case SqlDbType.BigInt:
         IIdentifiable<long> identifiableLong = value as IIdentifiable<long>;
         if (identifiableLong != null) {
             value = identifiableLong.Id;
         }
         break;
     case SqlDbType.UniqueIdentifier:
         IIdentifiable<Guid> identifiableGuid = value as IIdentifiable<Guid>;
         if (identifiableGuid != null) {
             value = identifiableGuid.Id;
         }
         break;
     case SqlDbType.Xml:
         value = GetXmlValue(value, disposeList);
         break;
     case SqlDbType.Udt:
         parameter.UdtTypeName = userDefinedTypeName;
         break;
     case SqlDbType.Structured:
         value = GetDataTableValue(value, disposeList);
         break;
     }
     ISerializationTypeInfo typeInfo = typeInfoProvider.GetSerializationTypeInfo(parameterType);
     if (typeInfo.SimpleConverter != null) {
         value = typeInfo.SimpleConverter.ProcessToDb(value);
     }
     parameter.Value = value ?? DBNull.Value;
     parameter.SqlDbType = sqlType;
     if (direction != ParameterDirection.Input) {
         outArgs[outArgPosition] = parameter;
     }
     return parameter;
 }
コード例 #20
0
 protected override object SetParameterValue(IMethodCallMessage mcm, IList<IDisposable> disposeList)
 {
     object value = mcm.GetArg(parameterInfo.Position);
     if (value != null) {
         switch (SqlType) {
         case SqlDbType.Xml:
             XmlReader reader = value as XmlReader;
             if (reader == null) {
                 XPathNavigator navigator = value as XPathNavigator;
                 if (navigator == null) {
                     IXPathNavigable navigable = value as IXPathNavigable;
                     if (navigable != null) {
                         navigator = navigable.CreateNavigator();
                     } else {
                         XNode node = value as XNode;
                         if (node != null) {
                             navigator = node.CreateNavigator();
                         }
                     }
                     if (navigator == null) {
                         throw new NotSupportedException(String.Format("XML could not be retrieved from value of type {0}.", value.GetType()));
                     }
                 }
                 reader = navigator.ReadSubtree();
                 disposeList.Add(reader);
             }
             value = new SqlXml(reader);
             break;
         case SqlDbType.SmallInt:
             IIdentifiable<short> identifiableShort = value as IIdentifiable<short>;
             if (identifiableShort != null) {
                 value = identifiableShort.Id;
             }
             break;
         case SqlDbType.Int:
             IIdentifiable<int> identifiableInt = value as IIdentifiable<int>;
             if (identifiableInt != null) {
                 value = identifiableInt.Id;
             }
             break;
         case SqlDbType.BigInt:
             IIdentifiable<long> identifiableLong = value as IIdentifiable<long>;
             if (identifiableLong != null) {
                 value = identifiableLong.Id;
             }
             break;
         case SqlDbType.UniqueIdentifier:
             IIdentifiable<Guid> identifiableGuid = value as IIdentifiable<Guid>;
             if (identifiableGuid != null) {
                 value = identifiableGuid.Id;
             }
             break;
             //				case SqlDbType.Udt:
             //					parameter.UdtTypeName = userDefinedTypeName;
             //					break;
         }
     }
     if (SqlType == SqlDbType.Structured) {
         IDataReader dataReader = new StructuredParameterReader(structuredSchema, (IEnumerable)value);
         disposeList.Add(dataReader);
         value = dataReader;
     }
     return value;
 }
コード例 #21
0
 public object GetArg(int argNum)
 {
     return(orig.GetArg(argNum));
 }
コード例 #22
0
 public Object GetArg(int argNum)
 {
     return(mcm.GetArg(argNum));
 }
コード例 #23
0
ファイル: RemotingServices.cs プロジェクト: zhufengGNSS/mono
        internal static IMethodReturnMessage InternalExecuteMessage(
            MarshalByRefObject target, IMethodCallMessage reqMsg)
        {
            ReturnMessage result;

            Type       tt = target.GetType();
            MethodBase method;

            if (reqMsg.MethodBase.DeclaringType == tt ||
                reqMsg.MethodBase == FieldSetterMethod ||
                reqMsg.MethodBase == FieldGetterMethod)
            {
                method = reqMsg.MethodBase;
            }
            else
            {
                method = GetVirtualMethod(tt, reqMsg.MethodBase);

                if (method == null)
                {
                    throw new RemotingException(
                              String.Format("Cannot resolve method {0}:{1}", tt, reqMsg.MethodName));
                }
            }

            if (reqMsg.MethodBase.IsGenericMethod)
            {
                Type[]     genericArguments = reqMsg.MethodBase.GetGenericArguments();
                MethodInfo gmd = ((MethodInfo)method).GetGenericMethodDefinition();
                method = gmd.MakeGenericMethod(genericArguments);
            }

            var oldContext = CallContext.SetLogicalCallContext(reqMsg.LogicalCallContext);

            try
            {
                object [] out_args;
                object    rval = InternalExecute(method, target, reqMsg.Args, out out_args);

                // Collect parameters with Out flag from the request message
                // FIXME: This can be done in the unmanaged side and will be
                // more efficient

                ParameterInfo[] parameters = method.GetParameters();
                object[]        returnArgs = new object [parameters.Length];

                int n   = 0;
                int noa = 0;
                foreach (ParameterInfo par in parameters)
                {
                    if (par.IsOut && !par.ParameterType.IsByRef)
                    {
                        returnArgs [n++] = reqMsg.GetArg(par.Position);
                    }
                    else if (par.ParameterType.IsByRef)
                    {
                        returnArgs [n++] = out_args [noa++];
                    }
                    else
                    {
                        returnArgs [n++] = null;
                    }
                }

                var latestCallContext = Thread.CurrentThread.GetMutableExecutionContext().LogicalCallContext;
                result = new ReturnMessage(rval, returnArgs, n, latestCallContext, reqMsg);
            }
            catch (Exception e)
            {
                result = new ReturnMessage(e, reqMsg);
            }

            CallContext.SetLogicalCallContext(oldContext);
            return(result);
        }
コード例 #24
0
ファイル: ZyanProxy.cs プロジェクト: yallie/zyan
        /// <summary>
        /// Handles unsubscription.
        /// </summary>
        /// <param name="methodCallMessage"><see cref="IMethodCallMessage"/> to process.</param>
        /// <param name="methodInfo"><see cref="MethodInfo"/> for the method being called.</param>
        /// <returns><see cref="ReturnMessage"/>, if the call is processed successfully, otherwise, false.</returns>
        private ReturnMessage HandleEventUnsubscription(IMethodCallMessage methodCallMessage, MethodInfo methodInfo)
        {
            if (methodInfo.ReturnType.Equals(typeof(void)) &&
                methodCallMessage.MethodName.StartsWith("remove_") &&
                methodCallMessage.InArgCount == 1 &&
                methodCallMessage.ArgCount == 1 &&
                methodCallMessage.Args[0] != null &&
                typeof(Delegate).IsAssignableFrom(methodCallMessage.Args[0].GetType()))
            {
                string propertyName = methodCallMessage.MethodName.Substring(7);
                var inputMessage = methodCallMessage.GetArg(0) as Delegate;
                var eventFilter = default(IEventFilter);

                // Detach event filter, if it is attached
                ExtractEventHandlerDetails(ref inputMessage, ref eventFilter);

                if (_delegateCorrelationSet.Count > 0)
                {
                    var found = (
                        from correlationInfo in _delegateCorrelationSet.ToArray()
                        where correlationInfo.DelegateMemberName.Equals(propertyName) && correlationInfo.ClientDelegateInterceptor.ClientDelegate.Equals(inputMessage)
                        select correlationInfo).FirstOrDefault();

                    if (found != null)
                    {
                        RemoveRemoteEventHandler(found);

                        // Remove delegate correlation info
                        _delegateCorrelationSet.Remove(found);
                    }
                }

                return new ReturnMessage(null, null, 0, methodCallMessage.LogicalCallContext, methodCallMessage);
            }

            // This method doesn't represent event subscription
            return null;
        }
コード例 #25
0
 public CompositionException(IMethodCallMessage Message, string message, System.Exception innerException) : this(String.Format("Exception:{0}\r\nAssembly:{1}\r\n{2}:{3}\r\nArgs:\r\n", message, Message.TypeName, Message.MethodBase.MemberType, Message.MethodName), innerException)
 {
     for (int i = 0; i < Message.ArgCount; i += 2)
     {
         _message = String.Format("{0}\t{1}={2}\r\n", _message, Message.GetArgName(i), Message.GetArg(i).ToString());
     }
 }
コード例 #26
0
        /// <summary>
        /// Entfernte Methode aufrufen.
        /// </summary>
        /// <param name="message">Remoting-Nachricht mit Details für den entfernten Methodenaufruf</param>
        /// <returns>Remoting Antwortnachricht</returns>
        public override IMessage Invoke(IMessage message)
        {
            // Wenn keine Nachricht angegeben wurde ...
            if (message == null)
            {
                // Ausnahme werfen
                throw new ArgumentNullException("message");
            }

            // Nachricht in benötigte Schnittstelle casten
            IMethodCallMessage methodCallMessage = (IMethodCallMessage)message;

            // Methoden-Metadaten abrufen
            MethodInfo methodInfo = (MethodInfo)methodCallMessage.MethodBase;

            methodInfo.GetParameters();

            // Wenn die Methode ein Delegat ist ...
            if (methodInfo.ReturnType.Equals(typeof(void)) &&
                methodCallMessage.InArgCount == 1 &&
                methodCallMessage.ArgCount == 1 &&
                methodCallMessage.Args[0] != null &&
                typeof(Delegate).IsAssignableFrom(methodCallMessage.Args[0].GetType()) &&
                (methodCallMessage.MethodName.StartsWith("set_") || methodCallMessage.MethodName.StartsWith("add_")))
            {
                // Delegat auf zu verdrahtende Client-Methode abrufen
                object receiveMethodDelegate = methodCallMessage.GetArg(0);

                // "set_" wegschneiden
                string propertyName = methodCallMessage.MethodName.Substring(4);

                // Verdrahtungskonfiguration festschreiben
                DelegateInterceptor wiring = new DelegateInterceptor()
                {
                    ClientDelegate = receiveMethodDelegate
                };
                // Korrelationsinformation zusammenstellen
                DelegateCorrelationInfo correlationInfo = new DelegateCorrelationInfo()
                {
                    IsEvent                   = methodCallMessage.MethodName.StartsWith("add_"),
                    DelegateMemberName        = propertyName,
                    ClientDelegateInterceptor = wiring
                };
                // Wenn die Serverkomponente Singletonaktiviert ist ...
                if (_activationType == ActivationType.Singleton)
                {
                    // Ereignis der Serverkomponente abonnieren
                    _connection.RemoteComponentFactory.AddEventHandler(_interfaceType.FullName, correlationInfo);
                }

                // Verdrahtung in der Sammlung ablegen
                _delegateCorrelationSet.Add(correlationInfo);

                // Leere Remoting-Antwortnachricht erstellen und zurückgeben
                return(new ReturnMessage(null, null, 0, methodCallMessage.LogicalCallContext, methodCallMessage));
            }
            else if (methodInfo.ReturnType.Equals(typeof(void)) &&
                     methodCallMessage.InArgCount == 1 &&
                     methodCallMessage.ArgCount == 1 &&
                     methodCallMessage.Args[0] != null &&
                     typeof(Delegate).IsAssignableFrom(methodCallMessage.Args[0].GetType()) &&
                     (methodCallMessage.MethodName.StartsWith("remove_")))
            {
                // EBC-Eingangsnachricht abrufen
                object inputMessage = methodCallMessage.GetArg(0);

                // "remove_" wegschneiden
                string propertyName = methodCallMessage.MethodName.Substring(7);

                // Wenn Verdrahtungen gespeichert sind ...
                if (_delegateCorrelationSet.Count > 0)
                {
                    // Verdrahtungskonfiguration suchen
                    DelegateCorrelationInfo found = (from correlationInfo in (DelegateCorrelationInfo[])_delegateCorrelationSet.ToArray()
                                                     where correlationInfo.DelegateMemberName.Equals(propertyName) && correlationInfo.ClientDelegateInterceptor.ClientDelegate.Equals(inputMessage)
                                                     select correlationInfo).FirstOrDefault();

                    // Wenn eine passende Verdrahtungskonfiguration gefunden wurde ...
                    if (found != null)
                    {
                        // Wenn die Serverkomponente SingleCallaktiviert ist ...
                        if (_activationType == ActivationType.SingleCall)
                        {
                            // Verdrahtungskonfiguration entfernen
                            _delegateCorrelationSet.Remove(found);
                        }
                        else
                        {
                            // Ereignisabo entfernen
                            _connection.RemoteComponentFactory.RemoveEventHandler(_interfaceType.FullName, found);
                        }
                    }
                }
                // Leere Remoting-Antwortnachricht erstellen und zurückgeben
                return(new ReturnMessage(null, null, 0, methodCallMessage.LogicalCallContext, methodCallMessage));
            }
            else
            {
                // Aufrufkontext vorbereiten
                _connection.PrepareCallContext(_implicitTransactionTransfer);

                // Entfernten Methodenaufruf durchführen und jede Antwortnachricht sofort über einen Rückkanal empfangen
                return(InvokeRemoteMethod(methodCallMessage));
            }
        }
コード例 #27
0
ファイル: GameObjectSink.cs プロジェクト: ikkentim/SAMemAPI
        private void PreProcess(ref IMethodCallMessage msg)
        {
            if (msg.MethodName.StartsWith("get_"))
            {
                PropertyInfo property  = _target.GetType().GetProperty(msg.MethodName.Substring(4));
                var          attribute = property.GetCustomAttribute <AddressAttribute>();

                if (property.CanWrite && attribute != null)
                {
                    ProcessMemory mem = _target.Memory[attribute.Address];

                    if (property.PropertyType == typeof(int))
                    {
                        property.SetValue(_target, mem.AsInteger());
                    }
                    if (property.PropertyType == typeof(byte))
                    {
                        property.SetValue(_target, mem.AsByte());
                    }
                    if (property.PropertyType == typeof(byte[]))
                    {
                        property.SetValue(_target, mem.AsBytes(attribute.Length));
                    }
                    if (property.PropertyType == typeof(float))
                    {
                        property.SetValue(_target, mem.AsFloat());
                    }
                    if (property.PropertyType == typeof(short))
                    {
                        property.SetValue(_target, mem.AsShort());
                    }
                    if (property.PropertyType == typeof(string))
                    {
                        property.SetValue(_target, mem.AsString(attribute.Length));
                    }
                    if (property.PropertyType.IsSubclassOf(typeof(MemoryObject)))
                    {
                        property.SetValue(_target, Activator.CreateInstance(property.PropertyType, mem.AsPointer()));
                    }
                }
            }

            if (msg.MethodName.StartsWith("set_"))
            {
                PropertyInfo property  = _target.GetType().GetProperty(msg.MethodName.Substring(4));
                var          attribute = property.GetCustomAttribute <AddressAttribute>();

                if (property.CanWrite && attribute != null)
                {
                    ProcessMemory mem = _target.Memory[attribute.Address];

                    if (property.PropertyType == typeof(int))
                    {
                        mem.Set((int)msg.GetArg(0));
                    }
                    if (property.PropertyType == typeof(byte))
                    {
                        mem.Set((byte)msg.GetArg(0));
                    }
                    if (property.PropertyType == typeof(byte[]))
                    {
                        mem.Set((byte[])msg.GetArg(0));
                    }
                    if (property.PropertyType == typeof(float))
                    {
                        mem.Set((float)msg.GetArg(0));
                    }
                    if (property.PropertyType == typeof(short))
                    {
                        mem.Set((short)msg.GetArg(0));
                    }
                    if (property.PropertyType == typeof(string))
                    {
                        mem.Set((string)msg.GetArg(0));
                    }
                    if (property.PropertyType.IsSubclassOf(typeof(MemoryObject)))
                    {
                        object value = msg.GetArg(0);
                        if (value != null)
                        {
                            var other = value as MemoryObject;
                            mem.Set(other.Memory.Address);
                        }
                    }
                }
            }
        }
コード例 #28
0
        public static void WriteMethodCall(BinaryWriter writer, object obj, Header[] headers, BinaryFormatter formatter)
        {
            IMethodCallMessage call = (IMethodCallMessage)obj;

            writer.Write((byte)BinaryElement.MethodCall);

            MethodFlags methodFlags;
            int         infoArraySize = 0;
            object      info          = null;

            object[] extraProperties = null;

            if (call.LogicalCallContext != null && call.LogicalCallContext.HasInfo)
            {
                methodFlags = MethodFlags.IncludesLogicalCallContext;
                infoArraySize++;
            }
            else
            {
                methodFlags = MethodFlags.ExcludeLogicalCallContext;
            }

            if (RemotingServices.IsMethodOverloaded(call))
            {
                infoArraySize++;
                methodFlags |= MethodFlags.IncludesSignature;
            }

            if (call.Properties.Count > MethodCallDictionary.InternalKeys.Length)
            {
                extraProperties = GetExtraProperties(call.Properties, MethodCallDictionary.InternalKeys);
                infoArraySize++;
            }

            if (call.MethodBase.IsGenericMethod)
            {
                infoArraySize++;
                methodFlags |= MethodFlags.GenericArguments;
            }
            if (call.ArgCount == 0)
            {
                methodFlags |= MethodFlags.NoArguments;
            }
            else
            {
                if (AllTypesArePrimitive(call.Args))
                {
                    methodFlags |= MethodFlags.PrimitiveArguments;
                }
                else
                {
                    if (infoArraySize == 0)
                    {
                        methodFlags |= MethodFlags.ArgumentsInSimpleArray;
                    }
                    else
                    {
                        methodFlags |= MethodFlags.ArgumentsInMultiArray;
                        infoArraySize++;
                    }
                }
            }

            writer.Write((int)methodFlags);

            // Method name
            writer.Write((byte)BinaryTypeCode.String);
            writer.Write(call.MethodName);

            // Class name
            writer.Write((byte)BinaryTypeCode.String);
            writer.Write(call.TypeName);

            // Arguments

            if ((methodFlags & MethodFlags.PrimitiveArguments) > 0)
            {
                writer.Write((uint)call.Args.Length);
                for (int n = 0; n < call.ArgCount; n++)
                {
                    object arg = call.GetArg(n);
                    if (arg != null)
                    {
                        writer.Write(BinaryCommon.GetTypeCode(arg.GetType()));
                        ObjectWriter.WritePrimitiveValue(writer, arg);
                    }
                    else
                    {
                        writer.Write((byte)BinaryTypeCode.Null);
                    }
                }
            }

            if (infoArraySize > 0)
            {
                object[] ainfo = new object[infoArraySize];
                int      n     = 0;
                if ((methodFlags & MethodFlags.ArgumentsInMultiArray) > 0)
                {
                    ainfo[n++] = call.Args;
                }
                if ((methodFlags & MethodFlags.GenericArguments) > 0)
                {
                    ainfo[n++] = call.MethodBase.GetGenericArguments();
                }
                if ((methodFlags & MethodFlags.IncludesSignature) > 0)
                {
                    ainfo[n++] = call.MethodSignature;
                }
                if ((methodFlags & MethodFlags.IncludesLogicalCallContext) > 0)
                {
                    ainfo[n++] = call.LogicalCallContext;
                }
                if (extraProperties != null)
                {
                    ainfo[n++] = extraProperties;
                }
                info = ainfo;
            }
            else if ((methodFlags & MethodFlags.ArgumentsInSimpleArray) > 0)
            {
                info = call.Args;
            }

            if (info != null)
            {
                ObjectWriter objectWriter = new ObjectWriter(formatter);
                objectWriter.WriteObjectGraph(writer, info, headers);
            }
            else
            {
                writer.Write((byte)BinaryElement.End);
            }
        }
コード例 #29
0
        internal static IMethodReturnMessage InternalExecuteMessage(
            MarshalByRefObject target, IMethodCallMessage reqMsg)
        {
            ReturnMessage result;

            Type       tt = target.GetType();
            MethodBase method;

            if (reqMsg.MethodBase.DeclaringType == tt ||
                reqMsg.MethodBase == FieldSetterMethod ||
                reqMsg.MethodBase == FieldGetterMethod
                /*|| reqMsg.MethodBase.DeclaringType.IsInterface*/)
            {
                method = reqMsg.MethodBase;
            }
            else
            {
                method = tt.GetMethod(reqMsg.MethodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, (Type[])reqMsg.MethodSignature, null);
            }

            object oldContext = CallContext.SetCurrentCallContext(reqMsg.LogicalCallContext);

            try
            {
                object [] out_args;
                object    rval = InternalExecute(method, target, reqMsg.Args, out out_args);

                // Collect parameters with Out flag from the request message
                // FIXME: This can be done in the unmanaged side and will be
                // more efficient

                ParameterInfo[] parameters = method.GetParameters();
                object[]        returnArgs = new object [parameters.Length];

                int n   = 0;
                int noa = 0;
                foreach (ParameterInfo par in parameters)
                {
                    if (par.IsOut && !par.ParameterType.IsByRef)
                    {
                        returnArgs [n++] = reqMsg.GetArg(par.Position);
                    }
                    else if (par.ParameterType.IsByRef)
                    {
                        returnArgs [n++] = out_args [noa++];
                    }
                    else
                    {
                        returnArgs [n++] = null;
                    }
                }

                result = new ReturnMessage(rval, returnArgs, n, CallContext.CreateLogicalCallContext(true), reqMsg);
            }
            catch (Exception e)
            {
                result = new ReturnMessage(e, reqMsg);
            }

            CallContext.RestoreCallContext(oldContext);
            return(result);
        }
コード例 #30
0
 public SqlCommand GetCommand(IMethodCallMessage mcm, SqlConnection connection, out SqlParameter returnParameter, out SqlParameter[] outArgs, out ISerializationTypeInfo procedureReturnTypeInfo, out ICallDeserializationInfo procedureInfo, out XmlNameTable xmlNameTable, IList<IDisposable> disposeList)
 {
     SqlCommand result = connection.CreateCommand();
     result.CommandText = ProcedureName;
     result.CommandType = CommandType.StoredProcedure;
     if (timeout > 0) {
         result.CommandTimeout = timeout;
     }
     outArgs = new SqlParameter[outArgCount];
     xmlNameTable = xmlNameTableParameter != null ? (XmlNameTable)mcm.GetArg(xmlNameTableParameter.Position) : null;
     foreach (SqlCallParameterInfo factory in parameters) {
         result.Parameters.Add(factory.GetSqlParameter(result, mcm, outArgs, disposeList));
     }
     if (useReturnValue) {
         returnParameter = result.CreateParameter();
         returnParameter.SqlDbType = SqlDbType.Int;
         returnParameter.Direction = ParameterDirection.ReturnValue;
         result.Parameters.Add(returnParameter);
     } else {
         returnParameter = null;
     }
     procedureReturnTypeInfo = returnTypeInfo;
     procedureInfo = this;
     return result;
 }
コード例 #31
0
        public static void WriteMethodCall(BinaryWriter writer, object obj, Header[] headers, ISurrogateSelector surrogateSelector, StreamingContext context, FormatterAssemblyStyle assemblyFormat, FormatterTypeStyle typeFormat)
        {
            IMethodCallMessage methodCallMessage = (IMethodCallMessage)obj;

            writer.Write(21);
            int    num  = 0;
            object obj2 = null;

            object[]    array = null;
            MethodFlags methodFlags;

            if (methodCallMessage.LogicalCallContext != null && methodCallMessage.LogicalCallContext.HasInfo)
            {
                methodFlags = MethodFlags.IncludesLogicalCallContext;
                num++;
            }
            else
            {
                methodFlags = MethodFlags.ExcludeLogicalCallContext;
            }
            if (RemotingServices.IsMethodOverloaded(methodCallMessage))
            {
                num++;
                methodFlags |= MethodFlags.IncludesSignature;
            }
            if (methodCallMessage.Properties.Count > MethodCallDictionary.InternalKeys.Length)
            {
                array = MessageFormatter.GetExtraProperties(methodCallMessage.Properties, MethodCallDictionary.InternalKeys);
                num++;
            }
            if (methodCallMessage.MethodBase.IsGenericMethod)
            {
                num++;
                methodFlags |= MethodFlags.GenericArguments;
            }
            if (methodCallMessage.ArgCount == 0)
            {
                methodFlags |= MethodFlags.NoArguments;
            }
            else if (MessageFormatter.AllTypesArePrimitive(methodCallMessage.Args))
            {
                methodFlags |= MethodFlags.PrimitiveArguments;
            }
            else if (num == 0)
            {
                methodFlags |= MethodFlags.ArgumentsInSimpleArray;
            }
            else
            {
                methodFlags |= MethodFlags.ArgumentsInMultiArray;
                num++;
            }
            writer.Write((int)methodFlags);
            writer.Write(18);
            writer.Write(methodCallMessage.MethodName);
            writer.Write(18);
            writer.Write(methodCallMessage.TypeName);
            if ((methodFlags & MethodFlags.PrimitiveArguments) > (MethodFlags)0)
            {
                writer.Write((uint)methodCallMessage.Args.Length);
                for (int i = 0; i < methodCallMessage.ArgCount; i++)
                {
                    object arg = methodCallMessage.GetArg(i);
                    if (arg != null)
                    {
                        writer.Write(BinaryCommon.GetTypeCode(arg.GetType()));
                        ObjectWriter.WritePrimitiveValue(writer, arg);
                    }
                    else
                    {
                        writer.Write(17);
                    }
                }
            }
            if (num > 0)
            {
                object[] array2 = new object[num];
                int      num2   = 0;
                if ((methodFlags & MethodFlags.ArgumentsInMultiArray) > (MethodFlags)0)
                {
                    array2[num2++] = methodCallMessage.Args;
                }
                if ((methodFlags & MethodFlags.GenericArguments) > (MethodFlags)0)
                {
                    array2[num2++] = methodCallMessage.MethodBase.GetGenericArguments();
                }
                if ((methodFlags & MethodFlags.IncludesSignature) > (MethodFlags)0)
                {
                    array2[num2++] = methodCallMessage.MethodSignature;
                }
                if ((methodFlags & MethodFlags.IncludesLogicalCallContext) > (MethodFlags)0)
                {
                    array2[num2++] = methodCallMessage.LogicalCallContext;
                }
                if (array != null)
                {
                    array2[num2++] = array;
                }
                obj2 = array2;
            }
            else if ((methodFlags & MethodFlags.ArgumentsInSimpleArray) > (MethodFlags)0)
            {
                obj2 = methodCallMessage.Args;
            }
            if (obj2 != null)
            {
                ObjectWriter objectWriter = new ObjectWriter(surrogateSelector, context, assemblyFormat, typeFormat);
                objectWriter.WriteObjectGraph(writer, obj2, headers);
            }
            else
            {
                writer.Write(11);
            }
        }