public ClientPropertyValue(ClientPropertyDefine def, ClientPropertyDataType dataType, string stringValue) { InitFromPropertyDefine(def); this._DataType = dataType; this._StringValue = InitDefaultValue(dataType, stringValue); }
private void InitFromPropertyDefine(ClientPropertyDefine def) { ExceptionHelper.FalseThrow<ArgumentNullException>(def != null, "def"); this._AlterKey = def.Name; this._StringValue = def.DefaultValue; this._DataType = def.DataType; this._StringValue = InitDefaultValue(this._DataType, def.DefaultValue); }
/// <summary> /// 获取集合中指定键所对应的值 /// </summary> /// <typeparam name="T">默认值的类型</typeparam> /// <param name="defaultValue">缺省值</param> /// <returns> 属性的值 或 缺省值</returns> public T GetValue <T>(ClientPropertyDefine def, T defaultValue) { T result = defaultValue; def.NullCheck("def"); ClientPropertyValue v = this[def.Name]; if (v != null) { result = (T)DataConverter.ChangeType(v.StringValue, result.GetType()); } return(result); }
/// <summary> /// 设置属性的值。如果该属性不存在,则抛出异常 /// </summary> /// <param name="def">属性定义</param> /// <param name="name"></param> /// <param name="stringValue"></param> public void SetValue(ClientPropertyDefine def, string stringValue) { this.TrySetValue(def, stringValue).FalseThrow(Translator.Translate(Define.DefaultCulture, "不能找到名称为{0}的属性", def.Name)); }
/// <summary> /// 尝试去设置属性。如果该属性不存在,则返回false,否则返回true /// </summary> /// <param name="def"></param> /// <param name="stringValue">空值,将取默认值</param> /// <returns></returns> public bool TrySetValue(ClientPropertyDefine def, string stringValue) { return(TrySetValue(def.Name, stringValue)); }
public ClientPropertyValue(ClientPropertyDefine def) { InitFromPropertyDefine(def); }