Beispiel #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 SetterInfo[] ResolveFields(Type type)
        {
            var setters = new List <SetterInfo>();

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

            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 method    = MethodUtils.CreateFieldSetter(type, field);
                    var info      = new SetterInfo(field.FieldType, attribute.identifier, method);
                    setters.Add(info);
                }
            }

            return(setters.ToArray());
        }
Beispiel #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 SetterInfo[] ResolveProperties(Type type)
        {
            var setters = new List <SetterInfo>();

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

            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 method    = MethodUtils.CreatePropertySetter(type, property);
                    var info      = new SetterInfo(property.PropertyType, attribute.identifier, method);
                    setters.Add(info);
                }
            }

            return(setters.ToArray());
        }
Beispiel #3
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 SetterInfo[] ResolveProperties(Type type)
        {
            var setters = new List<SetterInfo>();

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

            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 method = MethodUtils.CreatePropertySetter(type, property);
                    var info = new SetterInfo(property.PropertyType, attribute.identifier, method);
                    setters.Add(info);
                }
            }

            return setters.ToArray();
        }
Beispiel #4
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 SetterInfo[] ResolveFields(Type type)
        {
            var setters = new List<SetterInfo>();

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

            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 method = MethodUtils.CreateFieldSetter(type, field);
                    var info = new SetterInfo(field.FieldType, attribute.identifier, method);
                    setters.Add(info);
                }
            }

            return setters.ToArray();
        }