Пример #1
0
 /// <summary>
 /// Take an array of ParamSplitter objects and add listeners
 /// </summary>
 /// <param name="parameters"></param>
 private void ListenToParams(object[] parameters)
 {
     _mostRecentIDs = new int[parameters.Length];
     for (int i = 0; i < parameters.Length; i++)
     {
         ParamSplitter param = parameters[i] as ParamSplitter;
         if (param == null)
         {
             throw new Exception("Parameters must be wrapped in ParamSplitters to be listened to");
         }
         _mostRecentIDs[i]   = param.ID;
         param.OnMethodCall += (paramID, name, callID, @params) => {
             MethodInfo method = _toSplitType.GetMethod(name, GetTypes(@params));
             if (method.IsSpecialName && method.Name.StartsWith("add_"))
             {
                 AddListener(param.ID, name, (@params[0] as MulticastDelegate).Method);
             }
             else if (method.IsSpecialName && method.Name.StartsWith("remove_"))
             {
                 RemoveListener(param.ID, name, (@params[0] as MulticastDelegate).Method);
             }
             else
             {
                 QueueLocalCall(param.ID, name, callID, @params);
             }
         };
     }
 }
Пример #2
0
        /// <summary>
        /// Take an array of parameters passed as objects to a method call and wrap each object in a ParamSplitter.
        /// The values in the original array are replaced with param splitter wrappers and an array of the instances
        /// wrapped by the param splitters is returned.
        /// Any method calls made to the objects in the returned aray will trigger events on the objects in the original array.
        /// </summary>
        /// <param name="parameters">The original array of constructor parameters to replace. After the method call this will be an array of ParamSplitters.</param>
        /// <returns>An array of objects which wrap and listen to method calls on the original parameters.</returns>
        private static object[] ReplaceParameters(object[] parameters)
        {
            object[] args = new object[parameters.Length];
            for (int i = 0; i < parameters.Length; i++)
            {
                ParamSplitter param = new ParamSplitter(parameters[i]);;
                parameters[i] = param;
                args[i]       = param.Instance;
            }

            return(args);
        }