示例#1
0
        public virtual object PushToProperty(IConfiguration target,
                                             PropertyInfo property,
                                             ConfigurationSourceAttribute configSourceAttr)
        {
            var key   = ResolveConfigurationKey(property, configSourceAttr);
            var value = GetConfigurationValue(key, property.PropertyType);

            if (property.CanWrite && value != ConfigurationValueNotFound.Instance)
            {
                property.SetValue(target, value);
            }

            return(value);
        }
示例#2
0
        public virtual void PushToConfiguration(IConfiguration target, PropertyInfo[] properties)
        {
            if (!_targets.ContainsKey(target))
            {
                _targets[target] = properties;
            }

            foreach (var property in properties.Where(x => x.CanWrite))
            {
                var configurationSourceAttr = property.GetCustomAttribute <ConfigurationSourceAttribute>();
                var configurationKeyAttr    = property.GetCustomAttribute <ConfigurationKeyAttribute>();
                if (configurationKeyAttr != null)
                {
                    if (configurationSourceAttr == null)
                    {
                        configurationSourceAttr = new ConfigurationSourceAttribute(null);
                    }

                    configurationSourceAttr.Key = configurationKeyAttr.Key;
                }
                PushToProperty(target, property, configurationSourceAttr);
            }
        }
示例#3
0
 protected virtual string ResolveConfigurationKey(PropertyInfo property, ConfigurationSourceAttribute configurationSourceAttr)
 {
     return(configurationSourceAttr?.Key ?? property.Name);
 }