protected T GetValue <T>(string name, ParseSettingType <T> Parse, string defaultValue = "") { if (!this.Values.ContainsKey(name)) { XmlNode xmlNode = this.XmlNode.SelectSingleNode(string.Format( "*[@Name=\"{0}\"]", name )); if (xmlNode == null) { this.XmlNode.InnerXml += string.Format( "<Setting Name=\"{0}\">{1}</Setting>", name, defaultValue ); if (Parse != null) { this.Values.Add(name, Parse(defaultValue)); } else { this.Values.Add(name, defaultValue); } //this.Owner.Save(); } else { if (Parse != null) { this.Values.Add(name, Parse(xmlNode.InnerXml)); } else { this.Values.Add(name, xmlNode.InnerXml); } } //this.Owner.Save(); return(GetValue <T>(name, Parse, defaultValue)); } // return (T)this.Values[name]; return((T)System.ComponentModel.TypeDescriptor.GetConverter(typeof(T)).ConvertFrom(this.Values[name].ToString())); }
public T GetValue <T>(string key, ParseSettingType <T> Parse, object defaultValue = null) { lock (this.Properties) { if (!this.Properties.ContainsKey(key)) { if (this.Score.XmlNode.Attributes[key] != null) { if (Parse != null) { this.Properties.Add(key, Parse(this.Score.XmlNode.Attributes[key].Value)); } else { this.Properties.Add(key, this.Score.XmlNode.Attributes[key].Value); } } else { this.Properties.Add(key, defaultValue); if (defaultValue != null) { this.Score.XmlNode.AddAttribute(key, defaultValue); } } } } if (this.Properties[key] == null) { return(default(T)); } return((T)this.Properties[key]); }