Example #1
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();

            IEnumerable<Type> baseClassInterfaces = type.BaseType != null ? type.BaseType.GetInterfaces() : new Type[0];
            IEnumerable<Type> topLevelInterfaces = allInterfaces.Except(baseClassInterfaces);

            if (topLevelInterfaces.Count() == 0)
            {
                var types = new[] { type };
                return types.FirstMatch(configuration.Namespaces);
            }

            return allInterfaces.FirstMatch(configuration.Namespaces);
        }
Example #2
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 #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();

            IEnumerable<Type> baseClassInterfaces = type.BaseType != null ? type.BaseType.GetInterfaces() : new Type[0];
            IEnumerable<Type> topLevelInterfaces = allInterfaces.Except(baseClassInterfaces);

            if (topLevelInterfaces.Count() == 0)
            {
                var types = new[] { type };
                return types.FirstMatch(configuration.Namespaces);
            }
            else
            {
                //If the top level interface inherits from the baseclassinterface, then return the top one since that's more specific
                var top = topLevelInterfaces.ToArray().FirstMatch(configuration.Namespaces);
                var bi = baseClassInterfaces.ToArray().FirstMatch(configuration.Namespaces);
                if (top != null && bi != null && top.GetInterfaces().Contains(bi))
                    return top;
            }

            return allInterfaces.FirstMatch(configuration.Namespaces);
        }
Example #4
0
        /// <summary>
        /// Determines the type of DynamicProxy that will be created over the given type.
        /// </summary>
        /// <param name="type"></param>
        /// <param name="namespaces"></param>
        /// <returns></returns>
        public static Type GetTypeToDynamicProxy(this Type type, IList<string> namespaces )
        {
            var allInterfaces = type.GetInterfaces();

            IEnumerable<Type> baseClassInterfaces = type.BaseType != null ? type.BaseType.GetInterfaces() : new Type[0];
            IEnumerable<Type> topLevelInterfaces = allInterfaces.Except(baseClassInterfaces);

            if (topLevelInterfaces.Count() == 0)
            {
                var types = new[] { type };
                return types.FirstMatch(namespaces);
            }

            return allInterfaces.FirstMatch(namespaces);
        }