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