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

use some null coalescing #4557

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,8 @@ public virtual async Task<HttpResponseMessage> PostAsync(string operation)
/// </summary>
public HttpPortal Portal
{
get
{
if (_portal == null)
_portal = _applicationContext.CreateInstanceDI<HttpPortal>();
return _portal;
}
set { _portal = value; }
get => _portal ??= _applicationContext.CreateInstanceDI<HttpPortal>();
set => _portal = value;
}

#if NETSTANDARD2_0 || NET8_0_OR_GREATER
Expand Down
8 changes: 2 additions & 6 deletions Source/Csla.Web/CslaDataSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,8 @@ public class CslaDataSource : DataSourceControl
/// </summary>
/// <param name="viewName">Ignored.</param>
/// <remarks>This control only contains a "Default" view.</remarks>
protected override DataSourceView GetView(string viewName)
{
if (_defaultView == null)
_defaultView = new CslaDataSourceView(this, "Default");
return _defaultView;
}
protected override DataSourceView GetView(string viewName) =>
_defaultView ??= new CslaDataSourceView(this, "Default");

/// <summary>
/// Get or set the name of the assembly (no longer used).
Expand Down
10 changes: 2 additions & 8 deletions Source/Csla.Web/Design/CslaDataSourceDesigner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,8 @@ internal ISite Site
/// <remarks>
/// This designer supports only a "Default" view.
/// </remarks>
public override DesignerDataSourceView GetView(string viewName)
{
if (_view == null)
{
_view = new CslaDesignerDataSourceView(this, "Default");
}
return _view;
}
public override DesignerDataSourceView GetView(string viewName) =>
_view ??= new CslaDesignerDataSourceView(this, "Default");

/// <summary>
/// Return a list of available views.
Expand Down
12 changes: 2 additions & 10 deletions Source/Csla.Windows/BindingSourceNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,8 @@ private void BindingSource_CurrentChanged(object sender, EventArgs e)

internal BindingSource Source { get; }

internal List<BindingSourceNode> Children
{
get
{
if (_children == null)
_children = new List<BindingSourceNode>();

return _children;
}
}
internal List<BindingSourceNode> Children =>
_children ??= [];

internal BindingSourceNode Parent { get; set; }

Expand Down
10 changes: 1 addition & 9 deletions Source/Csla/BusinessBindingListBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,7 @@ public T Clone()
[System.Diagnostics.CodeAnalysis.SuppressMessage(
"Microsoft.Design", "CA1002:DoNotExposeGenericLists")]
[EditorBrowsable(EditorBrowsableState.Advanced)]
protected MobileList<C> DeletedList
{
get
{
if (_deletedList == null)
_deletedList = new MobileList<C>();
return _deletedList;
}
}
protected MobileList<C> DeletedList => _deletedList ??= [];

[System.Diagnostics.CodeAnalysis.SuppressMessage(
"Microsoft.Design", "CA1002:DoNotExposeGenericLists")]
Expand Down
10 changes: 1 addition & 9 deletions Source/Csla/BusinessListBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,7 @@ public T Clone()
[System.Diagnostics.CodeAnalysis.SuppressMessage(
"Microsoft.Design", "CA1002:DoNotExposeGenericLists")]
[EditorBrowsable(EditorBrowsableState.Advanced)]
protected MobileList<C> DeletedList
{
get
{
if (_deletedList == null)
_deletedList = new MobileList<C>();
return _deletedList;
}
}
protected MobileList<C> DeletedList => _deletedList ??= [];

[System.Diagnostics.CodeAnalysis.SuppressMessage(
"Microsoft.Design", "CA1002:DoNotExposeGenericLists")]
Expand Down
11 changes: 2 additions & 9 deletions Source/Csla/Core/FieldManager/PropertyInfoFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,7 @@ public static class PropertyInfoFactory
/// Gets the factory object that
/// creates PropertyInfo objects.
/// </summary>
public static IPropertyInfoFactory Factory
{
get
{
if (_factory == null)
_factory = (IPropertyInfoFactory)Activator.CreateInstance(FactoryType);
return _factory;
}
}
public static IPropertyInfoFactory Factory =>
_factory ??= (IPropertyInfoFactory) Activator.CreateInstance(FactoryType);
}
}
11 changes: 2 additions & 9 deletions Source/Csla/Core/ManagedObjectBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,8 @@ public abstract class ManagedObjectBase : MobileObject,
/// Gets a reference to the field mananger
/// for this object.
/// </summary>
protected FieldDataManager FieldManager
{
get
{
if (_fieldManager == null)
_fieldManager = new FieldDataManager(ApplicationContext, GetType());
return _fieldManager;
}
}
protected FieldDataManager FieldManager =>
_fieldManager ??= new(ApplicationContext, GetType());

FieldDataManager IUseFieldManager.FieldManager => FieldManager;

Expand Down
12 changes: 3 additions & 9 deletions Source/Csla/Core/MobileObservableCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,9 @@ public class MobileObservableCollection<T> : System.Collections.ObjectModel.Obse
/// and checking user rights.
/// </summary>
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
protected LoadListModeObject LoadListMode
{
get
{
if (_loadListModeObject == null)
_loadListModeObject = new LoadListModeObject(this);
return _loadListModeObject;
}
}
protected LoadListModeObject LoadListMode =>
_loadListModeObject ??= new(this);

void IMobileList.SetLoadListMode(bool enabled)
{
_loadListModeObject = null;
Expand Down
11 changes: 2 additions & 9 deletions Source/Csla/DataPortalT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,8 @@ public DataPortalAsyncResult(T result, Exception error, object userState)
}

private Reflection.ServiceProviderMethodCaller serviceProviderMethodCaller;
private Reflection.ServiceProviderMethodCaller ServiceProviderMethodCaller
{
get
{
if (serviceProviderMethodCaller == null)
serviceProviderMethodCaller = (Reflection.ServiceProviderMethodCaller)_applicationContext.CreateInstanceDI(typeof(Reflection.ServiceProviderMethodCaller));
return serviceProviderMethodCaller;
}
}
private Reflection.ServiceProviderMethodCaller ServiceProviderMethodCaller =>
serviceProviderMethodCaller ??= (Reflection.ServiceProviderMethodCaller) _applicationContext.CreateInstanceDI(typeof(Reflection.ServiceProviderMethodCaller));

private async Task<object> DoCreateAsync(
#if NET8_0_OR_GREATER
Expand Down
13 changes: 2 additions & 11 deletions Source/Csla/ReadOnlyBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1593,17 +1593,8 @@ protected void LoadPropertyAsync<
/// Gets the PropertyManager object for this
/// business object.
/// </summary>
protected FieldDataManager FieldManager
{
get
{
if (_fieldManager == null)
{
_fieldManager = new FieldDataManager(ApplicationContext, GetType());
}
return _fieldManager;
}
}
protected FieldDataManager FieldManager =>
_fieldManager ??= new(ApplicationContext, GetType());

FieldDataManager IUseFieldManager.FieldManager => FieldManager;

Expand Down
11 changes: 2 additions & 9 deletions Source/Csla/Reflection/LateBoundObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,8 @@ public async Task CallMethodTryAsync(string methodName, params object[] paramete
}

private ServiceProviderMethodCaller serviceProviderMethodCaller;
private ServiceProviderMethodCaller ServiceProviderMethodCaller
{
get
{
if (serviceProviderMethodCaller == null)
serviceProviderMethodCaller = (ServiceProviderMethodCaller)_applicationContext.CreateInstanceDI(typeof(ServiceProviderMethodCaller));
return serviceProviderMethodCaller;
}
}
private ServiceProviderMethodCaller ServiceProviderMethodCaller =>
serviceProviderMethodCaller ??= (ServiceProviderMethodCaller) _applicationContext.CreateInstanceDI(typeof(ServiceProviderMethodCaller));

/// <summary>
/// Invokes a method using the await keyword
Expand Down
18 changes: 3 additions & 15 deletions Source/Csla/Reflection/MethodCaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -653,11 +653,7 @@ private static object CallMethod(object obj, System.Reflection.MethodInfo info,
}
catch (Exception e)
{
Exception inner;
if (e.InnerException == null)
inner = e;
else
inner = e.InnerException;
var inner = e.InnerException ?? e;
throw new CallMethodException(obj.GetType().Name + "." + info.Name + " " + Resources.MethodCallFailed, inner);
}
return result;
Expand Down Expand Up @@ -1073,11 +1069,7 @@ public static object GetPropertyValue(object obj, PropertyInfo info)
}
catch (Exception e)
{
Exception inner;
if (e.InnerException == null)
inner = e;
else
inner = e.InnerException;
var inner = e.InnerException ?? e;
throw new CallMethodException(obj.GetType().Name + "." + info.Name + " " + Resources.MethodCallFailed, inner);
}
return result;
Expand All @@ -1098,11 +1090,7 @@ public static object CallMethod(object obj, System.Reflection.MethodInfo info)
}
catch (Exception e)
{
Exception inner;
if (e.InnerException == null)
inner = e;
else
inner = e.InnerException;
var inner = e.InnerException ?? e;
throw new CallMethodException(obj.GetType().Name + "." + info.Name + " " + Resources.MethodCallFailed, inner);
}
return result;
Expand Down
6 changes: 1 addition & 5 deletions Source/Csla/Reflection/ServiceProviderMethodCaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -526,11 +526,7 @@ public async Task<object> CallMethodTryAsync(object obj, ServiceProviderMethodIn
}
catch (Exception ex)
{
Exception inner = null;
if (ex.InnerException == null)
inner = ex;
else
inner = ex.InnerException;
var inner = ex.InnerException ?? ex;
throw new CallMethodException(obj.GetType().Name + "." + info.Name + " " + Resources.MethodCallFailed, inner);
}
}
Expand Down
22 changes: 4 additions & 18 deletions Source/Csla/Rules/BusinessRules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,8 @@ public BusinessRules(ApplicationContext applicationContext, IHostRules target)

// list of broken rules for this business object.
private BrokenRulesCollection _brokenRules;
private BrokenRulesCollection BrokenRules
{
get
{
if (_brokenRules == null)
_brokenRules = new BrokenRulesCollection(true);
return _brokenRules;
}
}
private BrokenRulesCollection BrokenRules =>
_brokenRules ??= new(true);

private bool _suppressRuleChecking;
/// <summary>
Expand Down Expand Up @@ -278,15 +271,8 @@ public bool RunningRules

[NonSerialized]
private AsyncManualResetEvent _busyChanged;
private AsyncManualResetEvent BusyChanged
{
get
{
if (_busyChanged == null)
_busyChanged = new AsyncManualResetEvent();
return _busyChanged;
}
}
private AsyncManualResetEvent BusyChanged =>
_busyChanged ??= new AsyncManualResetEvent();

/// <summary>
/// Gets a value indicating whether any async
Expand Down
12 changes: 2 additions & 10 deletions Source/Csla/Rules/RuleContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,8 @@ public Dictionary<IPropertyInfo, object> OutputPropertyValues
[EditorBrowsable(EditorBrowsableState.Never)]
public List<RuleResult> Results
{
get
{
if (_results == null)
_results = new List<RuleResult>();
return _results;
}
private set
{
_results = value;
}
get => _results ??= [];
private set => _results = value;
}

private readonly Action<IRuleContext> _completeHandler;
Expand Down
11 changes: 2 additions & 9 deletions Source/Csla/Server/DataPortal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,8 @@ private IDataPortalServer GetServicedComponentPortal(TransactionalAttribute tran
#endif

private Reflection.ServiceProviderMethodCaller serviceProviderMethodCaller;
private Reflection.ServiceProviderMethodCaller ServiceProviderMethodCaller
{
get
{
if (serviceProviderMethodCaller == null)
serviceProviderMethodCaller = (Reflection.ServiceProviderMethodCaller)_applicationContext.CreateInstanceDI(typeof(Reflection.ServiceProviderMethodCaller));
return serviceProviderMethodCaller;
}
}
private Reflection.ServiceProviderMethodCaller ServiceProviderMethodCaller =>
serviceProviderMethodCaller ??= (Reflection.ServiceProviderMethodCaller) _applicationContext.CreateInstanceDI(typeof(Reflection.ServiceProviderMethodCaller));

/// <summary>
/// Create a new business object.
Expand Down
12 changes: 2 additions & 10 deletions Source/Csla/SmartDate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -363,16 +363,8 @@ public static void SetDefaultFormatString(string formatString)
/// <value>A format string.</value>
public string FormatString
{
get
{
if (_format == null)
_format = _defaultFormat;
return _format;
}
set
{
_format = value;
}
get => _format ??= _defaultFormat;
set => _format = value;
}

/// <summary>
Expand Down
Loading