Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup BindingSourceHelper #4544

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 37 additions & 43 deletions Source/Csla.Windows/BindingSourceHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,60 +9,54 @@
using System.ComponentModel;
using Csla.Properties;

namespace Csla.Windows
namespace Csla.Windows;

/// <summary>
/// Helper methods for dealing with BindingSource
/// objects and data binding.
/// </summary>
public static class BindingSourceHelper
{
private static BindingSourceNode _rootSourceNode;

/// <summary>
/// Helper methods for dealing with BindingSource
/// objects and data binding.
/// Sets up BindingSourceNode objects for all
/// BindingSource objects related to the provided
/// root source.
/// </summary>
public static class BindingSourceHelper
/// <param name="container">
/// Container for the components.
/// </param>
/// <param name="rootSource">
/// Root BindingSource object.
/// </param>
public static BindingSourceNode InitializeBindingSourceTree(
IContainer container, BindingSource rootSource)
{
private static BindingSourceNode _rootSourceNode;
if (rootSource == null)
throw new ApplicationException(Resources.BindingSourceNotProvided);

/// <summary>
/// Sets up BindingSourceNode objects for all
/// BindingSource objects related to the provided
/// root source.
/// </summary>
/// <param name="container">
/// Container for the components.
/// </param>
/// <param name="rootSource">
/// Root BindingSource object.
/// </param>
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<BindingSourceNode> GetChildBindingSources(
IContainer container, BindingSource parent, BindingSourceNode parentNode)
private static IEnumerable<BindingSourceNode> GetChildBindingSources(
IContainer container, BindingSource parent, BindingSourceNode parentNode)
{
foreach (Component component in container.Components)
{
List<BindingSourceNode> children = new List<BindingSourceNode>();

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;
}

}
}
Loading