Exemplo n.º 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);
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 3
0
 protected virtual string ResolveConfigurationKey(PropertyInfo property, ConfigurationSourceAttribute configurationSourceAttr)
 {
     return(configurationSourceAttr?.Key ?? property.Name);
 }