@@ -17,52 +17,39 @@ namespace Csla.Windows
1717 /// </summary>
1818 public class BindingSourceNode
1919 {
20+ internal BindingSource Source { get ; }
21+
22+ internal List < BindingSourceNode > Children { get ; } = [ ] ;
23+
24+ internal BindingSourceNode ? Parent { get ; set ; }
25+
2026 /// <summary>
2127 /// Creates an instance of the object.
2228 /// </summary>
2329 /// <param name="source">
2430 /// BindingSource object to be managed.
2531 /// </param>
32+ /// <exception cref="ArgumentNullException"><paramref name="source"/> is <see langword="null"/>.</exception>
2633 public BindingSourceNode ( BindingSource source )
2734 {
28- Source = source ;
35+ Source = source ?? throw new ArgumentNullException ( nameof ( source ) ) ;
2936 Source . CurrentChanged += BindingSource_CurrentChanged ;
3037 }
3138
32- private List < BindingSourceNode > _children ;
33-
34- private void BindingSource_CurrentChanged ( object sender , EventArgs e )
39+ private void BindingSource_CurrentChanged ( object ? sender , EventArgs e )
3540 {
36- if ( _children . Count > 0 )
37- foreach ( BindingSourceNode child in _children )
41+ if ( Children . Count > 0 )
42+ foreach ( BindingSourceNode child in Children )
3843 child . Source . EndEdit ( ) ;
3944 }
4045
41- internal BindingSource Source { get ; }
42-
43- internal List < BindingSourceNode > Children
44- {
45- get
46- {
47- if ( _children == null )
48- _children = new List < BindingSourceNode > ( ) ;
49-
50- return _children ;
51- }
52- }
53-
54- internal BindingSourceNode Parent { get ; set ; }
55-
5646 internal void Unbind ( bool cancel )
5747 {
58- if ( Source == null )
59- return ;
60-
61- if ( _children . Count > 0 )
62- foreach ( BindingSourceNode child in _children )
48+ if ( Children . Count > 0 )
49+ foreach ( BindingSourceNode child in Children )
6350 child . Unbind ( cancel ) ;
6451
65- IEditableObject current = Source . Current as IEditableObject ;
52+ IEditableObject ? current = Source . Current as IEditableObject ;
6653
6754 if ( ! ( Source . DataSource is BindingSource ) )
6855 Source . DataSource = null ;
@@ -75,41 +62,32 @@ internal void Unbind(bool cancel)
7562 current . EndEdit ( ) ;
7663 }
7764
78- if ( Source . DataSource is BindingSource )
65+ if ( Source . DataSource is BindingSource && Parent is not null )
7966 Source . DataSource = Parent . Source ;
8067 }
8168
8269 internal void EndEdit ( )
8370 {
84- if ( Source == null )
85- return ;
86-
87- if ( _children . Count > 0 )
88- foreach ( BindingSourceNode child in _children )
71+ if ( Children . Count > 0 )
72+ foreach ( BindingSourceNode child in Children )
8973 child . EndEdit ( ) ;
9074
9175 Source . EndEdit ( ) ;
9276 }
9377
9478 internal void SetEvents ( bool value )
9579 {
96- if ( Source == null )
97- return ;
98-
9980 Source . RaiseListChangedEvents = value ;
10081
101- if ( _children . Count > 0 )
102- foreach ( BindingSourceNode child in _children )
82+ if ( Children . Count > 0 )
83+ foreach ( BindingSourceNode child in Children )
10384 child . SetEvents ( value ) ;
10485 }
10586
10687 internal void ResetBindings ( bool refreshMetadata )
10788 {
108- if ( Source == null )
109- return ;
110-
111- if ( _children . Count > 0 )
112- foreach ( BindingSourceNode child in _children )
89+ if ( Children . Count > 0 )
90+ foreach ( BindingSourceNode child in Children )
11391 child . ResetBindings ( refreshMetadata ) ;
11492
11593 Source . ResetBindings ( refreshMetadata ) ;
@@ -121,7 +99,7 @@ internal void ResetBindings(bool refreshMetadata)
12199 /// <param name="objectToBind">
122100 /// Business object.
123101 /// </param>
124- public void Bind ( object objectToBind )
102+ public void Bind ( object ? objectToBind )
125103 {
126104 if ( objectToBind is ISupportUndo root )
127105 root . BeginEdit ( ) ;
@@ -138,7 +116,7 @@ public void Apply()
138116 {
139117 SetEvents ( false ) ;
140118
141- ISupportUndo root = Source . DataSource as ISupportUndo ;
119+ ISupportUndo ? root = Source . DataSource as ISupportUndo ;
142120
143121 Unbind ( false ) ;
144122 EndEdit ( ) ;
@@ -150,11 +128,11 @@ public void Apply()
150128 /// Cancels changes to the business object.
151129 /// </summary>
152130 /// <param name="businessObject"></param>
153- public void Cancel ( object businessObject )
131+ public void Cancel ( object ? businessObject )
154132 {
155133 SetEvents ( false ) ;
156134
157- ISupportUndo root = Source . DataSource as ISupportUndo ;
135+ ISupportUndo ? root = Source . DataSource as ISupportUndo ;
158136
159137 Unbind ( true ) ;
160138
0 commit comments