Ejemplo n.º 1
0
        /// <summary>
        /// Resolves the fields that can be injected.
        /// </summary>
        /// <param name="type">Type from which reflection will be resolved.</param>
        /// <returns>The fields.</returns>
        protected AcessorInfo[] ResolveFields(Type type)
        {
            var setters = new List <AcessorInfo>();

            var fields = type.GetFields(BindingFlags.Instance |
                                        BindingFlags.Static |
                                        BindingFlags.Public |
                                        BindingFlags.NonPublic);

            for (int fieldIndex = 0; fieldIndex < fields.Length; fieldIndex++)
            {
                var field      = fields[fieldIndex] as FieldInfo;
                var attributes = field.GetCustomAttributes(typeof(Inject), true);

                if (attributes.Length > 0)
                {
                    var attribute = attributes[0] as Inject;
                    var getter    = MethodUtils.CreateFieldGetter(type, field);
                    var setter    = MethodUtils.CreateFieldSetter(type, field);
                    var info      = new AcessorInfo(field.FieldType, field.Name, attribute.identifier, getter, setter);
                    setters.Add(info);
                }
            }

            return(setters.ToArray());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Resolves the properties that can be injected.
        /// </summary>
        /// <param name="type">Type from which reflection will be resolved.</param>
        /// <returns>The properties.</returns>
        protected AcessorInfo[] ResolveProperties(Type type)
        {
            var setters = new List <AcessorInfo>();

            var properties = type.GetProperties(BindingFlags.Instance |
                                                BindingFlags.Static |
                                                BindingFlags.Public |
                                                BindingFlags.NonPublic);

            for (int propertyIndex = 0; propertyIndex < properties.Length; propertyIndex++)
            {
                var property   = properties[propertyIndex] as PropertyInfo;
                var attributes = property.GetCustomAttributes(typeof(Inject), true);

                if (attributes.Length > 0)
                {
                    var attribute = attributes[0] as Inject;
                    var getter    = MethodUtils.CreatePropertyGetter(type, property);
                    var setter    = MethodUtils.CreatePropertySetter(type, property);
                    var info      = new AcessorInfo(property.PropertyType, property.Name, attribute.identifier, getter,
                                                    setter);
                    setters.Add(info);
                }
            }

            return(setters.ToArray());
        }