Beispiel #1
0
        /// <summary>
        ///     Concatenates the handlers of this projection with the specified projection handlers.
        /// </summary>
        /// <param name="handlers">The projection handlers to concatenate.</param>
        /// <returns>A <see cref="SqlProjection"/> containing the concatenated handlers.</returns>
        /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="handlers"/> are <c>null</c>.</exception>
        public SqlProjection Concat(SqlProjectionHandler[] handlers)
        {
            if (handlers == null)
            {
                throw new ArgumentNullException("handlers");
            }

            var concatenated = new SqlProjectionHandler[Handlers.Length + handlers.Length];

            Handlers.CopyTo(concatenated, 0);
            handlers.CopyTo(concatenated, Handlers.Length);
            return(new SqlProjection(concatenated));
        }
Beispiel #2
0
        /// <summary>
        ///     Concatenates the handlers of this projection with the specified projection handler.
        /// </summary>
        /// <param name="handler">The projection handler to concatenate.</param>
        /// <returns>A <see cref="SqlProjection"/> containing the concatenated handlers.</returns>
        /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="handler"/> is <c>null</c>.</exception>
        public SqlProjection Concat(SqlProjectionHandler handler)
        {
            if (handler == null)
            {
                throw new ArgumentNullException("handler");
            }

            var concatenated = new SqlProjectionHandler[Handlers.Length + 1];

            Handlers.CopyTo(concatenated, 0);
            concatenated[Handlers.Length] = handler;
            return(new SqlProjection(concatenated));
        }
Beispiel #3
0
 /// <summary>
 /// Resolves the <see cref="SqlProjectionHandler">handlers</see> that match the type of the message exactly.
 /// </summary>
 /// <param name="handlers">The set of resolvable handlers.</param>
 /// <returns>A <see cref="SqlProjectionHandlerResolver">resolver</see>.</returns>
 public static SqlProjectionHandlerResolver WhenEqualToHandlerMessageType(SqlProjectionHandler[] handlers)
 {
     if (handlers == null)
         throw new ArgumentNullException("handlers");
     var cache = handlers.
         GroupBy(handler => handler.Message).
         ToDictionary(@group => @group.Key, @group => @group.ToArray());
     return message =>
     {
         if(message == null)
             throw new ArgumentNullException("message");
         SqlProjectionHandler[] result;
         return cache.TryGetValue(message.GetType(), out result) ?
             result :
             new SqlProjectionHandler[0];
     };
 }
Beispiel #4
0
 /// <summary>
 /// Resolves the <see cref="SqlProjectionHandler">handlers</see> to which the message instance is assignable.
 /// </summary>
 /// <param name="handlers">The set of resolvable handlers.</param>
 /// <returns>A <see cref="SqlProjectionHandlerResolver">resolver</see>.</returns>
 public static SqlProjectionHandlerResolver WhenAssignableToHandlerMessageType(SqlProjectionHandler[] handlers)
 {
     if (handlers == null)
         throw new ArgumentNullException("handlers");
     var cache = new ConcurrentDictionary<Type, SqlProjectionHandler[]>();
     return message =>
     {
         if (message == null)
             throw new ArgumentNullException("message");
         SqlProjectionHandler[] result;
         if (!cache.TryGetValue(message.GetType(), out result))
         {
             result = cache.GetOrAdd(message.GetType(),
                 Array.FindAll(handlers,
                     handler => handler.Message.IsInstanceOfType(message)));
         }
         return result;
     };
 }
Beispiel #5
0
 /// <summary>
 /// Resolves the <see cref="SqlProjectionHandler">handlers</see> that match the type of the message exactly.
 /// </summary>
 /// <param name="handlers">The set of resolvable handlers.</param>
 /// <returns>A <see cref="SqlProjectionHandlerResolver">resolver</see>.</returns>
 public static SqlProjectionHandlerResolver WhenEqualToHandlerMessageType(SqlProjectionHandler[] handlers)
 {
     return Resolve.WhenEqualToHandlerMessageType(handlers);
 }