/// <summary> /// 清空控件中的值 /// </summary> public void ClearValue() { foreach (var dataBindingItem in dataBindingItems) { ControlValueWriter.Write(dataBindingItem.Control, null); } }
/// <summary> /// 将指定对象的属性值设置到控件中 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="value"></param> public void SetValue <T>(T value) { if (value == null) { ClearValue(); return; } foreach (var property in typeof(T).GetProperties().Where(p => p.CanRead)) { foreach (var dataBindingItem in dataBindingItems.Where(item => string.Compare(item.DataMember, property.Name, true) == 0)) { ControlValueWriter.Write(dataBindingItem.Control, property.GetValue(value, null)); } } }