Esempio n. 1
0
        private void Initialize(IConfigurationPropertyProvider provider)
        {
            var bindingFlags = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public;

            foreach (var item in provider.GetType().GetProperties(bindingFlags))
            {
                var attr = item.GetCustomAttribute <ConfigurationPropertyAttribute>();
                if (attr == null)
                {
                    continue;
                }
                this.ValidateProperty(item);

                if (this.filterType != null && this.filterType != attr.ScopeType)
                {
                    continue;
                }

                var configDescriptor = new ConfigurationPropertyProviderDescriptor(provider, item);
                if (this.ContainsKey(configDescriptor.PropertyName) == true)
                {
                    throw new ArgumentException(string.Format(Resources.Exception_AlreadyRegisteredProperty_Format, configDescriptor.PropertyName));
                }
                this.Add(configDescriptor);
            }
        }
        internal ConfigurationPropertyDescriptor(IConfigurationPropertyProvider target, PropertyDescriptor descriptor)
        {
            this.target     = target;
            this.descriptor = descriptor;
            var attr = descriptor.Attributes[typeof(ConfigurationPropertyAttribute)] as ConfigurationPropertyAttribute;

            this.propertyName = $"{target.Name}.{attr.PropertyName ?? StringUtility.ToCamelCase(descriptor.Name)}";
            this.ScopeType    = attr.ScopeType;
        }
Esempio n. 3
0
        internal ConfigurationPropertyProviderDescriptor(IConfigurationPropertyProvider target, PropertyInfo propertyInfo)
        {
            this.target       = target;
            this.propertyInfo = propertyInfo;

            if (propertyInfo.GetCustomAttribute <ConfigurationPropertyAttribute>() is ConfigurationPropertyAttribute propAttr)
            {
                this.PropertyName = $"{target.Name}.{propAttr.GetPropertyName(propertyInfo.Name)}";
                this.ScopeType    = propAttr.ScopeType;
            }

            if (propertyInfo.GetCustomAttribute <DefaultValueAttribute>() is DefaultValueAttribute defaultAttr)
            {
                this.DefaultValue = defaultAttr.Value;
            }

            this.PropertyType = propertyInfo.PropertyType;

            if (propertyInfo.GetCustomAttribute <DescriptionAttribute>() is DescriptionAttribute descriptionAttr)
            {
                this.Comment = descriptionAttr.Description;
            }
        }