comparison Source/EditableObjects/EditableValue.cs @ 0:f990fcb411a9

Копия текущей версии из github
author cin
date Thu, 27 Mar 2014 21:46:09 +0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f990fcb411a9
1 using System;
2 using System.Collections;
3 using System.Reflection;
4
5 using BLToolkit.TypeBuilder;
6
7 namespace BLToolkit.EditableObjects
8 {
9 [Serializable]
10 public struct EditableValue<T>: IEditable, IMemberwiseEditable, IPrintDebugState
11 {
12 private T _original;
13 private T _current;
14
15 public EditableValue(T value)
16 {
17 _original = value;
18 _current = value;
19 }
20
21 [GetValue, SetValue]
22 public T Value
23 {
24 get { return _current; }
25 set { _current = value; }
26 }
27
28 #region IEditable Members
29
30 public void AcceptChanges()
31 {
32 _original = _current;
33 }
34
35 public void RejectChanges()
36 {
37 _current = _original;
38 }
39
40 public bool IsDirty
41 {
42 get
43 {
44 object o = _original;
45 object c = _current;
46
47 return o == null? c != null: o.Equals(c) == false;
48 }
49 }
50
51 #endregion
52
53 #region IMemberwiseEditable Members
54
55 public bool AcceptMemberChanges(PropertyInfo propertyInfo, string memberName)
56 {
57 if (memberName != propertyInfo.Name)
58 return false;
59
60 AcceptChanges();
61
62 return true;
63 }
64
65 public bool RejectMemberChanges(PropertyInfo propertyInfo, string memberName)
66 {
67 if (memberName != propertyInfo.Name)
68 return false;
69
70 RejectChanges();
71
72 return true;
73 }
74
75 public bool IsDirtyMember(PropertyInfo propertyInfo, string memberName, ref bool isDirty)
76 {
77 if (memberName != propertyInfo.Name)
78 return false;
79
80 isDirty = IsDirty;
81
82 return true;
83 }
84
85 public void GetDirtyMembers(PropertyInfo propertyInfo, ArrayList list)
86 {
87 if (IsDirty)
88 list.Add(propertyInfo);
89 }
90
91 #endregion
92
93 #region IPrintDebugState Members
94
95 public void PrintDebugState(PropertyInfo propertyInfo, ref string str)
96 {
97 str += string.Format("{0,-20} {1} {2,-40} {3,-40} \r\n",
98 propertyInfo.Name, IsDirty? "*": " ", _original, _current);
99 }
100
101 #endregion
102 }
103 }