Skip to content

Commit c5f3d6f

Browse files
StefanOssendorfrockfordlhotkaCopilot
authored
Minor code clean up (#4711)
* - Renamed fields to have a _ as prefix - Changed private readonly property to readonly field - Use ??= insteaf if if(.. == null) - Remove unused ctor parameters * Fix compile error in tests * Update docs/Upgrading to CSLA 10.md Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Rockford Lhotka <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent 6431a64 commit c5f3d6f

17 files changed

+133
-146
lines changed

Source/Csla.test/Fakes/Server/DataPortal/TestableDataPortal.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ public TestableDataPortal(
2424
CslaOptions options,
2525
IAuthorizeDataPortal authorizer,
2626
InterceptorManager interceptors,
27-
IObjectFactoryLoader factoryLoader,
28-
IDataPortalActivator activator,
29-
IDataPortalExceptionInspector exceptionInspector,
3027
DataPortalExceptionHandler exceptionHandler,
3128
SecurityOptions securityOptions
3229
) : base(
@@ -35,9 +32,6 @@ SecurityOptions securityOptions
3532
options,
3633
authorizer,
3734
interceptors,
38-
factoryLoader,
39-
activator,
40-
exceptionInspector,
4135
exceptionHandler,
4236
securityOptions
4337
)

Source/Csla/Configuration/Fluent/DataOptions.cs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,54 +19,55 @@ public class DataOptions
1919
/// <summary>
2020
/// Sets the default transaction isolation level.
2121
/// </summary>
22-
public TransactionIsolationLevel DefaultTransactionIsolationLevel
22+
public TransactionIsolationLevel DefaultTransactionIsolationLevel
2323
{
24-
get => defaultTransactionIsolationLevel;
25-
set => defaultTransactionIsolationLevel = value;
24+
get => _defaultTransactionIsolationLevel;
25+
set => _defaultTransactionIsolationLevel = value;
2626
}
2727

2828
/// <summary>
2929
/// Sets the default transaction timeout in seconds.
3030
/// </summary>
3131
public int DefaultTransactionTimeoutInSeconds
3232
{
33-
get => defaultTransactionTimeoutInSeconds;
34-
set => defaultTransactionTimeoutInSeconds = value;
33+
get => _defaultTransactionTimeoutInSeconds;
34+
set => _defaultTransactionTimeoutInSeconds = value;
3535
}
3636

3737
/// <summary>
3838
/// Sets the default transaction async flow option
3939
/// used to create new TransactionScope objects.
4040
/// </summary>
41-
public TransactionScopeAsyncFlowOption DefaultTransactionAsyncFlowOption {
42-
get => defaultTransactionScopeAsyncFlowOption;
43-
set => defaultTransactionScopeAsyncFlowOption = value;
41+
public TransactionScopeAsyncFlowOption DefaultTransactionAsyncFlowOption
42+
{
43+
get => _defaultTransactionScopeAsyncFlowOption;
44+
set => _defaultTransactionScopeAsyncFlowOption = value;
4445
}
4546

46-
private static TransactionIsolationLevel defaultTransactionIsolationLevel = TransactionIsolationLevel.Unspecified;
47-
private static int defaultTransactionTimeoutInSeconds = 30;
48-
private static TransactionScopeAsyncFlowOption defaultTransactionScopeAsyncFlowOption = TransactionScopeAsyncFlowOption.Suppress;
47+
private static TransactionIsolationLevel _defaultTransactionIsolationLevel = TransactionIsolationLevel.Unspecified;
48+
private static int _defaultTransactionTimeoutInSeconds = 30;
49+
private static TransactionScopeAsyncFlowOption _defaultTransactionScopeAsyncFlowOption = TransactionScopeAsyncFlowOption.Suppress;
4950

5051
/// <summary>
5152
/// Gets the default transaction isolation level.
5253
/// </summary>
5354
/// <value>
5455
/// The default transaction isolation level.
5556
/// </value>
56-
internal static TransactionIsolationLevel GetDefaultTransactionIsolationLevel() => defaultTransactionIsolationLevel;
57+
internal static TransactionIsolationLevel GetDefaultTransactionIsolationLevel() => _defaultTransactionIsolationLevel;
5758

5859
/// <summary>
5960
/// Gets default transaction timeout in seconds.
6061
/// </summary>
6162
/// <value>
6263
/// The default transaction timeout in seconds.
6364
/// </value>
64-
internal static int GetDefaultTransactionTimeoutInSeconds() => defaultTransactionTimeoutInSeconds;
65+
internal static int GetDefaultTransactionTimeoutInSeconds() => _defaultTransactionTimeoutInSeconds;
6566

6667
/// <summary>
6768
/// Gets the default transaction scope async flow option.
6869
/// </summary>
6970
/// <returns>The default transaction scope async flow option.</returns>
70-
internal static TransactionScopeAsyncFlowOption GetDefaultTransactionScopeAsyncFlowOption() => defaultTransactionScopeAsyncFlowOption;
71+
internal static TransactionScopeAsyncFlowOption GetDefaultTransactionScopeAsyncFlowOption() => _defaultTransactionScopeAsyncFlowOption;
7172
}
7273
}

Source/Csla/Core/ApplicationContextManagerStatic.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
// <summary>Default context manager for the user property</summary>
77
//-----------------------------------------------------------------------
88

9-
using System.Security.Principal;
109
using System.Security.Claims;
10+
using System.Security.Principal;
1111

1212
namespace Csla.Core
1313
{
@@ -30,35 +30,35 @@ public class ApplicationContextManagerStatic : IContextManager
3030
/// </summary>
3131
public bool IsValid => true;
3232

33-
private static IContextDictionary? currentLocalContext = new ContextDictionary();
34-
private static IContextDictionary? currentClientContext = new ContextDictionary();
35-
private static IPrincipal currentPrincipal = new ClaimsPrincipal();
36-
private static IServiceProvider? currentDefaultServiceProvider;
37-
private static IServiceProvider? currentServiceProvider;
33+
private static IContextDictionary? _currentLocalContext = new ContextDictionary();
34+
private static IContextDictionary? _currentClientContext = new ContextDictionary();
35+
private static IPrincipal _currentPrincipal = new ClaimsPrincipal();
36+
private static IServiceProvider? _currentDefaultServiceProvider;
37+
private static IServiceProvider? _currentServiceProvider;
3838

3939
/// <summary>
4040
/// Gets the client context dictionary.
4141
/// </summary>
4242
/// <param name="executionLocation"></param>
4343
public IContextDictionary? GetClientContext(ApplicationContext.ExecutionLocations executionLocation)
4444
{
45-
return currentClientContext;
45+
return _currentClientContext;
4646
}
4747

4848
/// <summary>
4949
/// Gets the default IServiceProvider
5050
/// </summary>
5151
public IServiceProvider? GetDefaultServiceProvider()
5252
{
53-
return currentDefaultServiceProvider;
53+
return _currentDefaultServiceProvider;
5454
}
5555

5656
/// <summary>
5757
/// Gets the local context dictionary.
5858
/// </summary>
5959
public IContextDictionary? GetLocalContext()
6060
{
61-
return currentLocalContext;
61+
return _currentLocalContext;
6262
}
6363

6464
/// <summary>
@@ -67,7 +67,7 @@ public class ApplicationContextManagerStatic : IContextManager
6767
/// <returns>The current user principal</returns>
6868
public IPrincipal GetUser()
6969
{
70-
return currentPrincipal;
70+
return _currentPrincipal;
7171
}
7272

7373
/// <summary>
@@ -77,7 +77,7 @@ public IPrincipal GetUser()
7777
/// <param name="executionLocation"></param>
7878
public void SetClientContext(IContextDictionary? clientContext, ApplicationContext.ExecutionLocations executionLocation)
7979
{
80-
currentClientContext = clientContext;
80+
_currentClientContext = clientContext;
8181
}
8282

8383
/// <summary>
@@ -87,7 +87,7 @@ public void SetClientContext(IContextDictionary? clientContext, ApplicationConte
8787
/// <exception cref="ArgumentNullException"><paramref name="serviceProvider"/> is <see langword="null"/>.</exception>
8888
public void SetDefaultServiceProvider(IServiceProvider serviceProvider)
8989
{
90-
currentDefaultServiceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
90+
_currentDefaultServiceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
9191
}
9292

9393
/// <summary>
@@ -96,15 +96,15 @@ public void SetDefaultServiceProvider(IServiceProvider serviceProvider)
9696
/// <param name="localContext">Context dictionary</param>
9797
public void SetLocalContext(IContextDictionary? localContext)
9898
{
99-
currentLocalContext = localContext;
99+
_currentLocalContext = localContext;
100100
}
101101

102102
/// <summary>
103103
/// Gets the service provider for current scope
104104
/// </summary>
105105
public IServiceProvider? GetServiceProvider()
106106
{
107-
return currentServiceProvider ?? GetDefaultServiceProvider();
107+
return _currentServiceProvider ?? GetDefaultServiceProvider();
108108
}
109109

110110
/// <summary>
@@ -114,13 +114,13 @@ public void SetLocalContext(IContextDictionary? localContext)
114114
/// <exception cref="ArgumentNullException"><paramref name="scope"/> is <see langword="null"/>.</exception>
115115
public void SetServiceProvider(IServiceProvider scope)
116116
{
117-
currentServiceProvider = scope ?? throw new ArgumentNullException(nameof(scope));
117+
_currentServiceProvider = scope ?? throw new ArgumentNullException(nameof(scope));
118118
}
119119

120120
/// <inheritdoc />
121121
public void SetUser(IPrincipal principal)
122122
{
123-
currentPrincipal = principal ?? throw new ArgumentNullException(nameof(principal));
123+
_currentPrincipal = principal ?? throw new ArgumentNullException(nameof(principal));
124124
}
125125

126126
private static ApplicationContext? _applicationContext;

Source/Csla/Core/InvalidQueryExpression.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ namespace Csla.Core
1212
{
1313
class InvalidQueryException : Exception
1414
{
15-
private string message;
15+
private string _message;
1616

1717
public InvalidQueryException(string message)
1818
{
19-
this.message = message + " ";
19+
this._message = message + " ";
2020
}
2121

22-
public override string Message => Resources.ClientQueryIsInvalid + message;
22+
public override string Message => Resources.ClientQueryIsInvalid + _message;
2323
}
2424
}

Source/Csla/DataPortalClient/LocalProxy.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ namespace Csla.Channels.Local
2323
/// </summary>
2424
public class LocalProxy : DataPortalProxy
2525
{
26+
private readonly LocalProxyOptions _options;
27+
2628
/// <summary>
2729
/// Creates an instance of the type
2830
/// </summary>
@@ -31,7 +33,7 @@ public class LocalProxy : DataPortalProxy
3133
public LocalProxy(ApplicationContext applicationContext, LocalProxyOptions options)
3234
: base(applicationContext)
3335
{
34-
Options = options;
36+
_options = options;
3537
}
3638

3739
/// <summary>
@@ -40,13 +42,11 @@ public LocalProxy(ApplicationContext applicationContext, LocalProxyOptions optio
4042
/// </summary>
4143
protected ApplicationContext CallerApplicationContext => ApplicationContext;
4244

43-
private readonly LocalProxyOptions Options;
44-
4545
private void InitializeContext(out IDataPortalServer _portal, out IServiceScope? _logicalServerScope, out ApplicationContext _logicalServerApplicationContext)
4646
{
4747
var logicalServerServiceProvider = CallerApplicationContext.CurrentServiceProvider;
4848

49-
if (Options.UseLocalScope
49+
if (_options.UseLocalScope
5050
&& CallerApplicationContext.LogicalExecutionLocation == ApplicationContext.LogicalExecutionLocations.Client
5151
&& CallerApplicationContext.IsAStatefulContextManager)
5252
{
@@ -73,7 +73,7 @@ private void SetApplicationContext(object? obj, ApplicationContext applicationCo
7373
{
7474
// if there's no isolated scope, there's no reason to
7575
// change the object graph's ApplicationContext
76-
if (!Options.UseLocalScope)
76+
if (!_options.UseLocalScope)
7777
return;
7878

7979
if (obj is IUseApplicationContext useApplicationContext)
@@ -84,7 +84,7 @@ private void SetApplicationContext(IUseApplicationContext? obj, ApplicationConte
8484
{
8585
// if there's no isolated scope, there's no reason to
8686
// change the object graph's ApplicationContext
87-
if (!Options.UseLocalScope)
87+
if (!_options.UseLocalScope)
8888
return;
8989

9090
if (obj != null && !ReferenceEquals(obj.ApplicationContext, applicationContext))
@@ -147,7 +147,7 @@ private void SetApplicationContext(IUseApplicationContext? obj, ApplicationConte
147147
/// </summary>
148148
private void ResetApplicationContext(ApplicationContext logicalServerApplicationContext)
149149
{
150-
if (Options.UseLocalScope)
150+
if (_options.UseLocalScope)
151151
{
152152
if (logicalServerApplicationContext.LogicalExecutionLocation == ApplicationContext.LogicalExecutionLocations.Client)
153153
{
@@ -185,7 +185,7 @@ public override async Task<DataPortalResult> Create([DynamicallyAccessedMembers(
185185
}
186186
else
187187
{
188-
if (!Options.FlowSynchronizationContext || SynchronizationContext.Current == null)
188+
if (!_options.FlowSynchronizationContext || SynchronizationContext.Current == null)
189189
result = await Task.Run(() => _portal.Create(objectType, criteria, context, isSync));
190190
else
191191
result = await await Task.Factory.StartNew(() => _portal.Create(objectType, criteria, context, isSync),
@@ -229,7 +229,7 @@ public override async Task<DataPortalResult> Fetch([DynamicallyAccessedMembers(D
229229
}
230230
else
231231
{
232-
if (!Options.FlowSynchronizationContext || SynchronizationContext.Current == null)
232+
if (!_options.FlowSynchronizationContext || SynchronizationContext.Current == null)
233233
result = await Task.Run(() => _portal.Fetch(objectType, criteria, context, isSync));
234234
else
235235
result = await await Task.Factory.StartNew(() => _portal.Fetch(objectType, criteria, context, isSync),
@@ -273,7 +273,7 @@ public override async Task<DataPortalResult> Update(object obj, DataPortalContex
273273
}
274274
else
275275
{
276-
if (!Options.FlowSynchronizationContext || SynchronizationContext.Current == null)
276+
if (!_options.FlowSynchronizationContext || SynchronizationContext.Current == null)
277277
result = await Task.Run(() => _portal.Update(obj, context, isSync));
278278
else
279279
result = await await Task.Factory.StartNew(() => _portal.Update(obj, context, isSync),
@@ -317,7 +317,7 @@ public override async Task<DataPortalResult> Delete([DynamicallyAccessedMembers(
317317
}
318318
else
319319
{
320-
if (!Options.FlowSynchronizationContext || SynchronizationContext.Current == null)
320+
if (!_options.FlowSynchronizationContext || SynchronizationContext.Current == null)
321321
result = await Task.Run(() => _portal.Delete(objectType, criteria, context, isSync));
322322
else
323323
result = await await Task.Factory.StartNew(() => _portal.Delete(objectType, criteria, context, isSync),

0 commit comments

Comments
 (0)