Example #1
0
        /// <summary>
        /// Determines whether the specified target type has methods decorated for interception.
        /// </summary>
        /// <param name="target">The target.</param>
        /// <param name="configuration">The configuration.</param>
        /// <returns>
        ///     <c>true</c> if the specified target is decorated; otherwise, <c>false</c>.
        /// </returns>
        public static bool IsDecorated(Type targetType, AspectConfiguration configuration)
        {
            var methods = targetType.Methods();

            var isDecorated = methods.Any(m => m.Attributes().Any(a => a is MethodInterceptAttribute)) || targetType.Attributes().Any(p => p is ClassInterceptAttribute);

            return(isDecorated);
        }
Example #2
0
        /// <summary>
        /// Specifies configuration for a configuration container.
        /// </summary>
        /// <param name="container">The AoP container.</param>
        public static SnapFluentConfiguration For(IAspectContainer container)
        {
            var config = new AspectConfiguration();

            container.SetConfiguration(config);

            return(new SnapFluentConfiguration(config));
        }
Example #3
0
        /// <summary>
        /// Determines the type of DynamicProxy that will be created over the given type.
        /// </summary>
        /// <param name="type"></param>
        /// <param name="configuration"></param>
        /// <returns></returns>
        public Type GetInterfaceToProxy(Type type, AspectConfiguration configuration)
        {
            var allInterfaces = type.GetInterfaces();

            var baseClassInterfaces = type.BaseType != null?type.BaseType.GetInterfaces() : new Type[0];

            var topLevelInterfaces = allInterfaces.Except(baseClassInterfaces);

            var levelInterfaces = topLevelInterfaces as Type[] ?? topLevelInterfaces.ToArray();

            if (!levelInterfaces.Any())
            {
                var types = new[] { type };
                return(types.FirstMatch(configuration.Namespaces));
            }

            return(levelInterfaces.ToArray().FirstMatch(configuration.Namespaces));
        }
Example #4
0
 /// <summary>
 /// Determines whether the specified target object has methods decorated for interception.
 /// </summary>
 /// <param name="target">The target.</param>
 /// <param name="configuration">The configuration.</param>
 /// <returns>
 ///     <c>true</c> if the specified target is decorated; otherwise, <c>false</c>.
 /// </returns>
 public static bool IsDecorated(this object target, AspectConfiguration configuration)
 {
     return(IsDecorated(target.GetType(), configuration));
 }
Example #5
0
 public TypeScanner(AspectConfiguration configuration)
 {
     _configuration = configuration;
 }