Пример #1
0
 /// <summary>
 ///     The add aspect.
 /// </summary>
 /// <param name="aspectRegistrationBuilder">
 ///     The aspect registration builder.
 /// </param>
 /// <param name="sortOrder">
 ///     The sort order.
 /// </param>
 /// <param name="methodsToIntercept">
 ///     The methods to intercept.
 /// </param>
 /// <typeparam name="T">
 /// </typeparam>
 /// <returns>
 ///     The <see cref="IAspectRegistrationBuilder" />.
 /// </returns>
 /// <exception cref="ArgumentNullException">
 /// </exception>
 public static IAspectRegistrationBuilder AddAspectViaFactory <T>(this IAspectRegistrationBuilder aspectRegistrationBuilder, int?sortOrder = null, params MethodInfo[] methodsToIntercept)
     where T : IAspectFactory
 {
     if (aspectRegistrationBuilder == null)
     {
         throw new ArgumentNullException(nameof(aspectRegistrationBuilder));
     }
     aspectRegistrationBuilder.AddAspect(typeof(T), sortOrder, methodsToIntercept);
     return(aspectRegistrationBuilder);
 }
Пример #2
0
        /// <summary>
        /// The with logging.
        /// </summary>
        /// <param name="aspectRegistrationBuilder">
        /// The aspect registration builder.
        /// </param>
        /// <param name="methodsToIntercept">
        /// The methods To Intercept.
        /// </param>
        /// <returns>
        /// The <see cref="IAspectRegistrationBuilder"/>.
        /// </returns>
        public static IAspectRegistrationBuilder AddLoggingAspect(this IAspectRegistrationBuilder aspectRegistrationBuilder, params MethodInfo[] methodsToIntercept)
        {
            if (aspectRegistrationBuilder == null)
            {
                throw new ArgumentNullException(nameof(aspectRegistrationBuilder));
            }

            aspectRegistrationBuilder.AddAspect(LoggingAspectFactory.LoggingAspectFactoryType, methodsToIntercept: methodsToIntercept);
            return(aspectRegistrationBuilder);
        }
        /// <summary>
        ///     Registers the aspect of Type {type:T}
        /// </summary>
        /// <param name="aspectRegistrationBuilder"></param>
        /// <param name="sortOrder"></param>
        /// <param name="methodsToIntercept"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException"></exception>
        public static IAspectRegistrationBuilder AddAspect <T>(this IAspectRegistrationBuilder aspectRegistrationBuilder,
                                                               int?sortOrder = null, params MethodInfo[] methodsToIntercept)
        {
            var type = typeof(T);

            if (aspectRegistrationBuilder == null)
            {
                throw new ArgumentNullException(nameof(aspectRegistrationBuilder));
            }
            if (type.GetCustomAttribute(typeof(AspectAttribute), true) == null)
            {
                throw new ArgumentException(
                          "The given type T must be decorated with the AspectAttribute or inherit from a type decorated with it");
            }
            return(aspectRegistrationBuilder.AddAspect(type, sortOrder, methodsToIntercept));
        }