Esempio n. 1
0
        void ParsePropertyAttributes(Type type, InjectionInfo info)
        {
            var properties = type.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy);

            for (int i = 0; i < properties.Length; i++)
            {
                var property = properties[i];
                ParseAttributes(property, property.PropertyType, info);
            }
        }
Esempio n. 2
0
        void ParseFieldAttributes(Type type, InjectionInfo info)
        {
            var fields = type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy);

            for (int i = 0; i < fields.Length; i++)
            {
                var field = fields[i];
                ParseAttributes(field, field.FieldType, info);
            }
        }
Esempio n. 3
0
        public InjectionInfo Parse(Type type)
        {
            var info = new InjectionInfo();

            ParsePropertyAttributes(type, info);
            ParseFieldAttributes(type, info);
            ParseMethodAttributes <PostInjection>(type, info);
            ParseMethodAttributes <Cleanup>(type, info);

            return(info);
        }
Esempio n. 4
0
        void ParseAttributes(MemberInfo memberInfo, Type type, InjectionInfo info)
        {
            var customAttributes = memberInfo.GetCustomAttributes(true);

            for (int i = 0; i < customAttributes.Length; i++)
            {
                if (customAttributes[i] is Inject)
                {
                    info.AddInjection(memberInfo.Name, type);
                }
            }
        }
Esempio n. 5
0
        void ParseMethodAttributes <T> (Type type, InjectionInfo info) where T : Attribute
        {
            var methods = type.GetMethods();
            IList <MethodInfo> taggedMethods = null;

            for (int i = 0; i < methods.Length; i++)
            {
                var method     = methods[i];
                var attributes = method.GetCustomAttributes(true);

                for (int j = 0; j < attributes.Length; j++)
                {
                    if (attributes[j] is T)
                    {
                        taggedMethods = taggedMethods ?? info.GetCalls <T>();
                        taggedMethods.Add(method);
                    }
                }
            }
        }
Esempio n. 6
0
        InjectionInfo ParseInfo(Type type)
        {
            IDictionary <string, Type> properties = GetPropertyInjections(type.GetProperties());
            IDictionary <string, Type> fields     = GetFieldInjections(type.GetFields());
            IList <MethodInfo>         posts      = GetPostInjections(type.GetMethods());

            InjectionInfo info = null;

            if (properties != null || fields != null || posts != null)
            {
                info = new InjectionInfo
                {
                    properties     = properties,
                    fields         = fields,
                    postInjections = posts
                };
            }

            return(info);
        }