diff --git a/Source/Csla.Windows/BindingSourceHelper.cs b/Source/Csla.Windows/BindingSourceHelper.cs
index d74f014752..9699fa785a 100644
--- a/Source/Csla.Windows/BindingSourceHelper.cs
+++ b/Source/Csla.Windows/BindingSourceHelper.cs
@@ -9,60 +9,54 @@
using System.ComponentModel;
using Csla.Properties;
-namespace Csla.Windows
+namespace Csla.Windows;
+
+///
+/// Helper methods for dealing with BindingSource
+/// objects and data binding.
+///
+public static class BindingSourceHelper
{
+ private static BindingSourceNode _rootSourceNode;
+
///
- /// Helper methods for dealing with BindingSource
- /// objects and data binding.
+ /// Sets up BindingSourceNode objects for all
+ /// BindingSource objects related to the provided
+ /// root source.
///
- public static class BindingSourceHelper
+ ///
+ /// Container for the components.
+ ///
+ ///
+ /// Root BindingSource object.
+ ///
+ public static BindingSourceNode InitializeBindingSourceTree(
+ IContainer container, BindingSource rootSource)
{
- private static BindingSourceNode _rootSourceNode;
+ if (rootSource == null)
+ throw new ApplicationException(Resources.BindingSourceNotProvided);
- ///
- /// Sets up BindingSourceNode objects for all
- /// BindingSource objects related to the provided
- /// root source.
- ///
- ///
- /// Container for the components.
- ///
- ///
- /// Root BindingSource object.
- ///
- public static BindingSourceNode InitializeBindingSourceTree(
- IContainer container, BindingSource rootSource)
- {
- if (rootSource == null)
- throw new ApplicationException(Resources.BindingSourceNotProvided);
+ _rootSourceNode = new BindingSourceNode(rootSource);
+ _rootSourceNode.Children.AddRange(GetChildBindingSources(container, rootSource, _rootSourceNode));
- _rootSourceNode = new BindingSourceNode(rootSource);
- _rootSourceNode.Children.AddRange(GetChildBindingSources(container, rootSource, _rootSourceNode));
-
- return _rootSourceNode;
- }
+ return _rootSourceNode;
+ }
- private static List GetChildBindingSources(
- IContainer container, BindingSource parent, BindingSourceNode parentNode)
+ private static IEnumerable GetChildBindingSources(
+ IContainer container, BindingSource parent, BindingSourceNode parentNode)
+ {
+ foreach (Component component in container.Components)
{
- List children = new List();
-
- foreach (Component component in container.Components)
+ if (component is BindingSource {DataSource: not null} source &&
+ source.DataSource.Equals(parent))
{
- if (component is BindingSource temp)
+ var childNode = new BindingSourceNode(source)
{
- if (temp.DataSource != null && temp.DataSource.Equals(parent))
- {
- BindingSourceNode childNode = new BindingSourceNode(temp);
- children.Add(childNode);
- childNode.Children.AddRange(GetChildBindingSources(container, temp, childNode));
- childNode.Parent = parentNode;
- }
- }
+ Parent = parentNode
+ };
+ childNode.Children.AddRange(GetChildBindingSources(container, source, childNode));
+ yield return childNode;
}
-
- return children;
}
-
}
}
\ No newline at end of file