public bool ContainsSetting(string groupName, string entityName) { #region Contracts if (string.IsNullOrEmpty(groupName) == true) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(entityName) == true) { throw new ArgumentNullException(); } #endregion // Section ReflectConfigurationSection section = _configuration.GetSection(groupName) as ReflectConfigurationSection; if (section == null) { throw new InvalidOperationException(string.Format("Fail to Get ReflectConfigurationSection:{0}", groupName)); } // Element ReflectConfigurationElement element = section.ElementCollection.GetByName(entityName); if (element == null) { return(false); } // Return return(true); }
public void AddSetting(string groupName, string entityName, ReflectSetting setting) { #region Contracts if (string.IsNullOrEmpty(groupName) == true) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(entityName) == true) { throw new ArgumentNullException(); } if (setting == null) { throw new ArgumentNullException(); } #endregion // Section ReflectConfigurationSection section = _configuration.GetSection(groupName) as ReflectConfigurationSection; if (section == null) { throw new InvalidOperationException(string.Format("Fail to Get ReflectConfigurationSection:{0}", groupName)); } // Element ReflectConfigurationElement element = new ReflectConfigurationElement(); element.EntityName = entityName; element.BuilderType = setting.BuilderType; foreach (string parameterKey in setting.Parameters.Keys) { element.FreeAttributes.Add(parameterKey, setting.Parameters[parameterKey]); } // Add section.ElementCollection.Add(element); // Save section.CurrentConfiguration.Save(); }
public ReflectSetting GetSetting(string groupName, string entityName) { #region Contracts if (string.IsNullOrEmpty(groupName) == true) { throw new ArgumentNullException(); } if (string.IsNullOrEmpty(entityName) == true) { throw new ArgumentNullException(); } #endregion // Section ReflectConfigurationSection section = _configuration.GetSection(groupName) as ReflectConfigurationSection; if (section == null) { throw new InvalidOperationException(string.Format("Fail to Get ReflectConfigurationSection:{0}", groupName)); } // Element ReflectConfigurationElement element = section.ElementCollection.GetByName(entityName); if (element == null) { return(null); } // Setting ReflectSetting setting = new ReflectSetting(element.BuilderType); foreach (string parameterKey in element.FreeAttributes.Keys) { setting.Parameters.Add(parameterKey, element.FreeAttributes[parameterKey]); } // Return return(setting); }
public void AddSetting(string groupName, string entityName, ReflectSetting setting) { #region Contracts if (string.IsNullOrEmpty(groupName) == true) throw new ArgumentNullException(); if (string.IsNullOrEmpty(entityName) == true) throw new ArgumentNullException(); if (setting == null) throw new ArgumentNullException(); #endregion // Section ReflectConfigurationSection section = _configuration.GetSection(groupName) as ReflectConfigurationSection; if (section == null) throw new InvalidOperationException(string.Format("Fail to Get ReflectConfigurationSection:{0}", groupName)); // Element ReflectConfigurationElement element = new ReflectConfigurationElement(); element.EntityName = entityName; element.BuilderType = setting.BuilderType; foreach (string parameterKey in setting.Parameters.Keys) { element.FreeAttributes.Add(parameterKey, setting.Parameters[parameterKey]); } // Add section.ElementCollection.Add(element); // Save section.CurrentConfiguration.Save(); }