9
9
using System . ComponentModel ;
10
10
using Csla . Properties ;
11
11
12
- namespace Csla . Windows
12
+ namespace Csla . Windows ;
13
+
14
+ /// <summary>
15
+ /// Helper methods for dealing with BindingSource
16
+ /// objects and data binding.
17
+ /// </summary>
18
+ public static class BindingSourceHelper
13
19
{
20
+ private static BindingSourceNode _rootSourceNode ;
21
+
14
22
/// <summary>
15
- /// Helper methods for dealing with BindingSource
16
- /// objects and data binding.
23
+ /// Sets up BindingSourceNode objects for all
24
+ /// BindingSource objects related to the provided
25
+ /// root source.
17
26
/// </summary>
18
- public static class BindingSourceHelper
27
+ /// <param name="container">
28
+ /// Container for the components.
29
+ /// </param>
30
+ /// <param name="rootSource">
31
+ /// Root BindingSource object.
32
+ /// </param>
33
+ public static BindingSourceNode InitializeBindingSourceTree (
34
+ IContainer container , BindingSource rootSource )
19
35
{
20
- private static BindingSourceNode _rootSourceNode ;
36
+ if ( rootSource == null )
37
+ throw new ApplicationException ( Resources . BindingSourceNotProvided ) ;
21
38
22
- /// <summary>
23
- /// Sets up BindingSourceNode objects for all
24
- /// BindingSource objects related to the provided
25
- /// root source.
26
- /// </summary>
27
- /// <param name="container">
28
- /// Container for the components.
29
- /// </param>
30
- /// <param name="rootSource">
31
- /// Root BindingSource object.
32
- /// </param>
33
- public static BindingSourceNode InitializeBindingSourceTree (
34
- IContainer container , BindingSource rootSource )
35
- {
36
- if ( rootSource == null )
37
- throw new ApplicationException ( Resources . BindingSourceNotProvided ) ;
39
+ _rootSourceNode = new BindingSourceNode ( rootSource ) ;
40
+ _rootSourceNode . Children . AddRange ( GetChildBindingSources ( container , rootSource , _rootSourceNode ) ) ;
38
41
39
- _rootSourceNode = new BindingSourceNode ( rootSource ) ;
40
- _rootSourceNode . Children . AddRange ( GetChildBindingSources ( container , rootSource , _rootSourceNode ) ) ;
41
-
42
- return _rootSourceNode ;
43
- }
42
+ return _rootSourceNode ;
43
+ }
44
44
45
- private static List < BindingSourceNode > GetChildBindingSources (
46
- IContainer container , BindingSource parent , BindingSourceNode parentNode )
45
+ private static IEnumerable < BindingSourceNode > GetChildBindingSources (
46
+ IContainer container , BindingSource parent , BindingSourceNode parentNode )
47
+ {
48
+ foreach ( Component component in container . Components )
47
49
{
48
- List < BindingSourceNode > children = new List < BindingSourceNode > ( ) ;
49
-
50
- foreach ( Component component in container . Components )
50
+ if ( component is BindingSource { DataSource : not null } source &&
51
+ source . DataSource . Equals ( parent ) )
51
52
{
52
- if ( component is BindingSource temp )
53
+ var childNode = new BindingSourceNode ( source )
53
54
{
54
- if ( temp . DataSource != null && temp . DataSource . Equals ( parent ) )
55
- {
56
- BindingSourceNode childNode = new BindingSourceNode ( temp ) ;
57
- children . Add ( childNode ) ;
58
- childNode . Children . AddRange ( GetChildBindingSources ( container , temp , childNode ) ) ;
59
- childNode . Parent = parentNode ;
60
- }
61
- }
55
+ Parent = parentNode
56
+ } ;
57
+ childNode . Children . AddRange ( GetChildBindingSources ( container , source , childNode ) ) ;
58
+ yield return childNode ;
62
59
}
63
-
64
- return children ;
65
60
}
66
-
67
61
}
68
62
}
0 commit comments