コード例 #1
0
        /// <summary>
        /// The create delegates.
        /// </summary>
        /// <param name="cache">The cache.</param>
        /// <param name="handler">The handler.</param>
        private void CreateDelegates(OperationMethodInfoCache cache, IOperationHandler handler)
        {
            Dictionary <byte, MethodInfo> operationMethodInfos = cache.OperationMethodInfos;
            Type type = handler.GetType();

            foreach (KeyValuePair <byte, MethodInfo> pair in operationMethodInfos)
            {
                MethodInfo method = pair.Value;
                if (method.ReflectedType != type)
                {
                    throw new ArgumentException(string.Format("Type {0} does not support method {1}.{2}", type.Name, method.ReflectedType, method.Name));
                }
                Func <PeerBase, OperationRequest, SendParameters, OperationResponse> func = (Func <PeerBase, OperationRequest, SendParameters, OperationResponse>)Delegate.CreateDelegate(OperationMethodInfoCache.OperationDelegateType, handler, method);
                this.operations.Add(pair.Key, func);
            }
        }
コード例 #2
0
 /// <summary>
 ///   Initializes a new instance of the <see cref="T:Photon.SocketServer.Rpc.Reflection.OperationDispatcher"/> class.
 /// </summary>
 /// <param name="operations">The operations.</param>
 /// <param name="operationHandler">The operation Handler.</param>
 public OperationDispatcher(OperationMethodInfoCache operations, IOperationHandler operationHandler)
 {
     this.operations = new Dictionary <byte, Func <PeerBase, OperationRequest, SendParameters, OperationResponse> >(operations.OperationFunctions);
     this.CreateDelegates(operations, operationHandler);
 }