Skip to content

Commit b188999

Browse files
Add NRT to Csla.Windows (#4678)
* Add NRT to Csla.Windows #1233 * Track nrt progress
1 parent 511ae3f commit b188999

18 files changed

+401
-302
lines changed

Source/Csla.Windows/ApplicationContextManager.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// </copyright>
66
// <summary>Provides consistent context information between the client</summary>
77
//-----------------------------------------------------------------------
8+
using System.Diagnostics.CodeAnalysis;
89
using System.Security.Principal;
910
using Csla.Configuration;
1011

@@ -16,7 +17,7 @@ namespace Csla.Windows
1617
/// <param name="securityOptions"></param>
1718
public class ApplicationContextManager(SecurityOptions securityOptions) : Csla.Core.ApplicationContextManager
1819
{
19-
private static IPrincipal _principal;
20+
private static IPrincipal _principal = default!;
2021
private SecurityOptions _securityOptions = securityOptions;
2122

2223
/// <summary>
@@ -37,6 +38,7 @@ public override IPrincipal GetUser()
3738
}
3839

3940
/// <inheritdoc />
41+
[MemberNotNull(nameof(_principal))]
4042
public override void SetUser(IPrincipal principal)
4143
{
4244
_principal = principal ?? throw new ArgumentNullException(nameof(principal));

Source/Csla.Windows/BindingSourceHelper.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace Csla.Windows;
1717
/// </summary>
1818
public static class BindingSourceHelper
1919
{
20-
private static BindingSourceNode _rootSourceNode;
20+
private static BindingSourceNode _rootSourceNode = default!;
2121

2222
/// <summary>
2323
/// Sets up BindingSourceNode objects for all
@@ -30,9 +30,11 @@ public static class BindingSourceHelper
3030
/// <param name="rootSource">
3131
/// Root BindingSource object.
3232
/// </param>
33-
public static BindingSourceNode InitializeBindingSourceTree(
34-
IContainer container, BindingSource rootSource)
33+
/// <exception cref="ArgumentNullException"><paramref name="rootSource"/> or <paramref name="container"/> is <see langword="null"/>.</exception>
34+
public static BindingSourceNode InitializeBindingSourceTree(IContainer container, BindingSource rootSource)
3535
{
36+
if (container is null)
37+
throw new ArgumentNullException(nameof(container));
3638
if (rootSource == null)
3739
throw new ApplicationException(Resources.BindingSourceNotProvided);
3840

@@ -42,13 +44,11 @@ public static BindingSourceNode InitializeBindingSourceTree(
4244
return _rootSourceNode;
4345
}
4446

45-
private static IEnumerable<BindingSourceNode> GetChildBindingSources(
46-
IContainer container, BindingSource parent, BindingSourceNode parentNode)
47+
private static IEnumerable<BindingSourceNode> GetChildBindingSources(IContainer container, BindingSource parent, BindingSourceNode parentNode)
4748
{
4849
foreach (Component component in container.Components)
4950
{
50-
if (component is BindingSource {DataSource: not null} source &&
51-
source.DataSource.Equals(parent))
51+
if (component is BindingSource { DataSource: not null } source && source.DataSource.Equals(parent))
5252
{
5353
var childNode = new BindingSourceNode(source)
5454
{

Source/Csla.Windows/BindingSourceNode.cs

Lines changed: 25 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)