1:Public Abstract ClassMyxxx: inotifypropertychanged, inotifydataerrorinfo
2 :{
3:PrivateErrorscontainer <validationresult> errorscontainer;
4:
5:/// <Summary>
6:/// Initializes a new instance of the <see CREF = "domainobject"/> class.
7:/// </Summary>
8:ProtectedMyxxx ()
9 :{
10 :}
11:
12:/// <Summary>
13:/// Event raised when a property value changes.
14:/// </Summary>
15:/// <Seealso CREF = "inotifypropertychanged"/>
16:Public EventPropertychangedeventhandler propertychanged;
17:
18:/// <Summary>
19:/// Event raised when the validation status changes.
20:/// </Summary>
21:/// <Seealso CREF = "inotifydataerrorinfo"/>
22:Public EventEventhandler <dataerrorschangedeventargs> errorschanged;
23:
24:/// <Summary>
25:/// Gets the error status.
26:/// </Summary>
27:/// <Seealso CREF = "inotifydataerrorinfo"/>
28:Public BoolHaserrors
29 :{
30:Get{Return This. Errorscontainer. haserrors ;}
31 :}
32:
33:/// <Summary>
34:/// Gets the container for errors in the properties of the domain object.
35:/// </Summary>
36:ProtectedErrorscontainer <validationresult> errorscontainer
37 :{
38:Get
39 :{
40:If(This. Errorscontainer =Null)
41 :{
42:This. Errorscontainer =
43:NewErrorscontainer <validationresult> (Pn =>This. Raiseerrorschanged (PN ));
44 :}
45:
46:Return This. Errorscontainer;
47 :}
48 :}
49:
50:/// <Summary>
51:/// Returns the Errors for <paramref name = "propertyname"/>.
52:/// </Summary>
53:/// <Param name = "propertyname"> the name of the property for which the errors are requested. </param>
54:/// <Returns> An enumerable with the errors. </returns>
55:/// <Seealso CREF = "inotifydataerrorinfo"/>
56:PublicIenumerable geterrors (StringPropertyname)
57 :{
58:Return This. Errorscontainer. geterrors (propertyname );
59 :}
60:
61:/// <Summary>
62:/// Raises the <see CREF = "propertychanged"/> event.
63:/// </Summary>
64:/// <Param name = "propertyname"> the name of the changed property. </param>
65: [suppressmessage ("Microsoft. Design","Ca1030: useeventswhereappropriate", Justification ="Method supports event.")]
66:Protected VoidRaisepropertychanged (StringPropertyname)
67 :{
68:This. Onpropertychanged (NewPropertychangedeventargs (propertyname ));
69 :}
70:
71:/// <Summary>
72:/// Raises the <see CREF = "propertychanged"/> event.
73:/// </Summary>
74:/// <Param name = "E"> the argument for the event. </param>
75:Protected Virtual VoidOnpropertychanged (propertychangedeventargs E)
76 :{
77: var handler =This. Propertychanged;
78:If(Handler! =Null)
79 :{
80: handler (This, E );
81 :}
82 :}
83:
84:/// <Summary>
85:/// Validates <paramref name = "value"/> as the value for the property named <paramref name = "propertyname"/>.
86:/// </Summary>
87:/// <Param name = "propertyname"> The Name Of The property. </param>
88:/// <Param name = "value"> the value for the property. </param>
89:Protected VoidValidateproperty (StringPropertyname,Object Value)
90 :{
91:If(String. Isnullorempty (propertyname ))
92 :{
93:Throw NewArgumentnullexception ("Propertyname");
94 :}
95:
96:This. Validateproperty (NewValidationcontext (This,Null,Null) {Membername = propertyname },Value);
97 :}
98:
99:/// <Summary>
100:/// Validates <paramref name = "value"/> as the value for the property specified
101:/// <Paramref name = "validationcontext"/> using data annotations validation attributes.
102:/// </Summary>
103:/// <Param name = "validationcontext"> the context for the validation. </param>
104:/// <Param name = "value"> the value for the property. </param>
105:Protected Virtual VoidValidateproperty (validationcontext,Object Value)
106 :{
107:If(Validationcontext =Null)
108 :{
109:Throw NewArgumentnullexception ("Validationcontext");
110 :}
111:
112: List <validationresult> validationresults =NewList <validationresult> ();
113: validator. tryvalidateproperty (Value, Validationcontext, validationresults );
114:
115:This. Errorscontainer. seterrors (validationcontext. membername, validationresults );
116 :}
117:
118:/// <Summary>
119:/// Raises the <see CREF = "errorschanged"/> event.
120:/// </Summary>
121:/// <Param name = "propertyname"> the name of the property which changed its error status. </param>
122: [suppressmessage ("Microsoft. Design","Ca1030: useeventswhereappropriate", Justification ="Method supports event.")]
123:Protected VoidRaiseerrorschanged (StringPropertyname)
124 :{
125:This. Onerrorschanged (NewDataerrorschangedeventargs (propertyname ));
126 :}
127:
128:/// <Summary>
129:/// Raises the <see CREF = "errorschanged"/> event.
130:/// </Summary>
131:/// <Param name = "E"> the argument for the event. </param>
132:Protected Virtual VoidOnerrorschanged (dataerrorschangedeventargs E)
133 :{
134: var handler =This. Errorschanged;
135:If(Handler! =Null)
136 :{
137: handler (This, E );
138 :}
139 :}
140 :}