Example #1
0
        private void RemoveResponderInternal(Type typeReturn, Type typeArgument, Delegate handler)
        {
            ResponderTypeInfo typeInfo = new ResponderTypeInfo(typeReturn, typeArgument);

            if (_responders.ContainsKey(typeInfo))
            {
                _responders.Remove(typeInfo);
            }
        }
Example #2
0
        /// <summary>
        /// Requests a resource of type <typeparamref name="TReturn"/> with argument of type <typeparamref name="TArgument"/>.
        /// </summary>
        /// <param name="argument">
        /// The argument that will be passed to the responder.
        /// </param>
        /// <typeparam name="TArgument">
        /// The type of argument that will be passed to the responder.
        /// </typeparam>
        /// <typeparam name="TReturn">
        /// The type of resource being requested.
        /// </typeparam>
        /// <returns>
        /// The instance of <see cref="TReturn"/>.
        /// </returns>
        /// <exception cref="ResponderNotFoundException">
        /// Thrown if not responders capable of returning <typeparamref name="TReturn"/> (given parameter of type <typeparamref name="TArgument"/>) was registered at the moment of call.
        /// </exception>
        public TReturn Request <TArgument, TReturn>(TArgument argument)
        {
            ResponderTypeInfo typeInfo = new ResponderTypeInfo(typeof(TReturn), typeof(TArgument));

            Delegate baseHandler;
            bool     isFound = _responders.TryGetValue(typeInfo, out baseHandler);

            if (isFound)
            {
                Func <TArgument, TReturn> handler = (Func <TArgument, TReturn>)baseHandler;
                return(handler(argument));
            }

            throw new ResponderNotFoundException(typeof(TReturn), typeof(TArgument));
        }
Example #3
0
        private void AddResponderInternal(Type typeReturn, Type typeArgument, Delegate handler)
        {
            ResponderTypeInfo typeInfo = new ResponderTypeInfo(typeReturn, typeArgument);

            if (_responders.ContainsKey(typeInfo))
            {
                Debug.LogError(
                    string.Format(
                        "An attempt to attach multiple responders with argument of type '{0}' and return type '{1}' was detected. " +
                        "Only suitable responder can registered at the same time",
                        typeArgument,
                        typeReturn));
            }
            else
            {
                _responders.Add(typeInfo, handler);
            }
        }
Example #4
0
 public bool Equals(ResponderTypeInfo other)
 {
     return(ArgumentType == other.ArgumentType && ReturnType == other.ReturnType);
 }