protected virtual ISettings GetDefaultSection(string name, IConfigurationSource source) { if (source.HasSection(name) == false) { source.AddStorage(new RuntimeStorage(name)); } return(source.GetSection(name)); }
//protected bool TryGetSectionForProperty(string propertyName, out string section) //{ // return TryGetSectionForMember(this.GetType().GetProperty(propertyName), out section); //} protected ConfigurationSettingProperty CreateProperty(string propertyName, object defaultValue, IConfigurationSource source, string sectionName = null) { propertyName.ThrowIfNull(String.IsNullOrWhiteSpace, nameof(propertyName)); var property = this.GetType() .GetProperty(propertyName) .ThrowIfNull(() => new ArgumentException($"Property {propertyName} is not defined.")); ISettings section; if ((String.IsNullOrWhiteSpace(sectionName) == false || TryGetSectionFromMemberAttribute(property, out sectionName)) && source.HasSection(sectionName)) { section = source.GetSection(sectionName); } else { section = DefaultSection; } return(new ConfigurationSettingProperty(propertyName, property.PropertyType, defaultValue, section)); }
public void TestHasSection_SingleRuntimeStorage() { MockConfigurationInitializer_SingleRuntimeStorage1 initializer = new MockConfigurationInitializer_SingleRuntimeStorage1(source); Assert.IsTrue(source.HasSection(initializer.Section1)); }