Esempio 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());
        }