コード例 #1
0
        /// <summary>
        /// Gets a collection of type candidate results for types containing members which implement property interceptors.
        /// </summary>
        /// <returns></returns>
        public List <TypeInterceptorInfo> FindTypeByFieldInterceptors()
        {
            var list = new List <TypeInterceptorInfo>();

            foreach (var type in Types.Select(a => a.Resolve()).Where(a => !a.IsEnum && !a.IsInterface))
            {
                var item = new TypeInterceptorInfo {
                    Type = type
                };
                var fields = new List <FieldInterceptorInfo>();

                foreach (var field in type.Fields)
                {
                    var attributes = field.GetCustomAttributes().Where(a => a.HasInterface(finder.IPropertyGetInterceptor) || a.HasInterface(finder.IPropertySetInterceptor));

                    if (attributes.Any())
                    {
                        fields.Add(new FieldInterceptorInfo {
                            Field = field, Interceptors = attributes.ToArray()
                        });
                    }
                }

                if (fields.Count > 0)
                {
                    item.Fields = fields.ToArray();
                    list.Add(item);
                }
            }

            return(list);
        }
コード例 #2
0
        /// <summary>
        /// Gets a collection of type candidate results for types containing members which implement property interceptors.
        /// </summary>
        /// <returns></returns>
        public List <TypeInterceptorInfo> FindTypeByPropertyInterceptors()
        {
            var list = new List <TypeInterceptorInfo>();

            foreach (var type in Types.Select(a => a.Resolve()).Where(a => !a.IsEnum && !a.IsInterface))
            {
                var item = new TypeInterceptorInfo {
                    Type = type
                };
                var properties = new List <PropertyInterceptorInfo>();

                var top = type.GetCustomAttributes().Where(a => a.HasInterface(finder.IPropertyGetInterceptor) || a.HasInterface(finder.IPropertySetInterceptor));

                foreach (var property in type.Properties)
                {
                    var attributes = property.GetCustomAttributes().Where(a => a.HasInterface(finder.IPropertyGetInterceptor) || a.HasInterface(finder.IPropertySetInterceptor)).Concat(top);

                    if (attributes.Any())
                    {
                        properties.Add(new PropertyInterceptorInfo {
                            Interceptors = attributes.ToArray(), Property = property
                        });
                    }
                }

                if (properties.Count > 0)
                {
                    item.Properties = properties.ToArray();
                    list.Add(item);
                }
            }

            return(list);
        }
コード例 #3
0
        /// <summary>
        /// Gets a collection of type candidate results for types containing members which implement method interceptors.
        /// </summary>
        /// <returns></returns>
        public List <TypeInterceptorInfo> FindTypeByMethodInterceptors()
        {
            var list = new List <TypeInterceptorInfo>();

            foreach (var type in Types.Select(a => a.Resolve()).Where(a => !a.IsEnum && !a.IsInterface))
            {
                var item = new TypeInterceptorInfo {
                    Type = type
                };
                var methods = new List <MethodInterceptorInfo>();

                var top = type.GetCustomAttributes().Where(a => a.HasInterface(finder.IMethodInterceptor));

                foreach (var method in type.Methods.Where(m => !m.IsAbstract))
                {
                    var these      = method.GetCustomAttributes().Where(a => a.HasInterface(finder.IMethodInterceptor)).Concat(top);
                    var parameters = method.Parameters.Where(p => p.GetCustomAttributes().Any(a => a.HasInterface(finder.IParameterInterceptor))).Select(p => new ParameterInterceptorInfo {
                        Index = p.Index, Attributes = p.GetCustomAttributes().Where(a => a.HasInterface(finder.IParameterInterceptor)).ToArray()
                    });
                    var allParameters = new ParameterInterceptorInfo {
                        Index = -1, Attributes = method.GetCustomAttributes().Where(a => a.HasInterface(finder.IParameterInterceptor)).ToArray()
                    };
                    var returns = method.MethodReturnType.CustomAttributes.Where(a => a.HasInterface(finder.IMethodReturnInterceptor));

                    if (these.Any() || parameters.Any() || returns.Any() || allParameters.Attributes.Length > 0)
                    {
                        var generic = type.HasGenericParameters ? method.MakeGeneric(type.GenericParameters.ToArray()) : method;

                        if (allParameters.Attributes.Length > 0)
                        {
                            parameters = parameters.Concat(new[] { allParameters });
                        }

                        methods.Add(new MethodInterceptorInfo
                        {
                            Method             = generic.Resolve(),
                            MethodInterceptors = these.ToArray(),
                            Parameters         = parameters.ToArray(),
                            ReturnInterceptors = returns.ToArray()
                        });
                    }
                }

                if (methods.Count > 0)
                {
                    item.Methods = methods.ToArray();
                    list.Add(item);
                }
            }

            return(list);
        }
コード例 #4
0
        /// <summary>
        /// Gets a collection of type candidate results for types containing members which implement constructor interceptors.
        /// </summary>
        /// <returns></returns>
        public List <TypeInterceptorInfo> FindTypeByConstructorInterceptors()
        {
            var list = new List <TypeInterceptorInfo>();

            foreach (var type in Types.Select(a => a.Resolve()).Where(a => !a.IsEnum && !a.IsInterface))
            {
                var ctors = new ConstructorInterceptorInfo {
                    Initializers = new MethodDefinition[0]
                };
                var item = new TypeInterceptorInfo {
                    Constructors = ctors, Type = type
                };

                ctors.Initializers = type.Methods.Where(m => !m.IsAbstract).Where(m => m.GetCustomAttributes().Any(a => a.HasInterface(finder.IInjectBeforeInitializer) || a.HasInterface(finder.IInjectAfterInitializer))).ToArray();

                if (ctors.Initializers.Length > 0)
                {
                    list.Add(item);
                }
            }

            return(list);
        }