Exemple #1
0
        /// <summary>
        /// Gets the specified instance.
        /// </summary>
        /// <typeparam name="TResponder">The type of the responder.</typeparam>
        /// <param name="instance">The instance.</param>
        /// <returns></returns>
        public static TResponder Get <TResponder>(this ResponderCollection instance) where TResponder : IResponder
        {
            Invariant.IsNotNull(instance, "instance");

            Type responderType = typeof(TResponder);

            return(instance.Select(x => new { r = x, t = x.GetType() })
                   .Where(p => p.t == responderType)
                   .Select(p => p.r)
                   .Cast <TResponder>()
                   .FirstOrDefault());
        }
Exemple #2
0
        /// <summary>
        /// Includes the specified instance.
        /// </summary>
        /// <typeparam name="TResponder">The type of the responder.</typeparam>
        /// <param name="instance">The instance.</param>
        /// <param name="configure">The configure.</param>
        /// <returns></returns>
        public static ResponderCollection Include <TResponder>(this ResponderCollection instance, Action <TResponder> configure) where TResponder : IResponder, new()
        {
            Invariant.IsNotNull(instance, "instance");

            TResponder responder = new TResponder();

            instance.Add(responder);

            if (configure != null)
            {
                configure(responder);
            }

            return(instance);
        }
Exemple #3
0
 /// <summary>
 /// Includes the specified instance.
 /// </summary>
 /// <typeparam name="TResponder">The type of the responder.</typeparam>
 /// <param name="instance">The instance.</param>
 /// <returns></returns>
 public static ResponderCollection Include <TResponder>(this ResponderCollection instance) where TResponder : IResponder, new()
 {
     return(Include <TResponder>(instance, null));
 }
Exemple #4
0
        /// <summary>
        /// Gets the specified instance.
        /// </summary>
        /// <param name="instance">The instance.</param>
        /// <param name="format">The format.</param>
        /// <returns></returns>
        public static IResponder Get(this ResponderCollection instance, string format)
        {
            Invariant.IsNotNull(instance, "instance");

            return(instance.FirstOrDefault(r => r.CanRespondToFormat(format)));
        }