From fdf6b279407f1194bbab77efc4461953d04603b9 Mon Sep 17 00:00:00 2001
From: Simon Cropp <simon.cropp@gmail.com>
Date: Thu, 20 Feb 2025 22:24:42 +1100
Subject: [PATCH] use some null coalescing

---
 .../Server/Hosts/HttpPortalController.cs      |  9 ++------
 Source/Csla.Web/CslaDataSource.cs             |  8 ++-----
 .../Csla.Web/Design/CslaDataSourceDesigner.cs | 10 ++-------
 Source/Csla.Windows/BindingSourceNode.cs      | 12 ++--------
 Source/Csla/BusinessBindingListBase.cs        | 10 +--------
 Source/Csla/BusinessListBase.cs               | 10 +--------
 .../Core/FieldManager/PropertyInfoFactory.cs  | 11 ++--------
 Source/Csla/Core/ManagedObjectBase.cs         | 11 ++--------
 .../Csla/Core/MobileObservableCollection.cs   | 12 +++-------
 Source/Csla/DataPortalT.cs                    | 11 ++--------
 Source/Csla/ReadOnlyBase.cs                   | 13 ++---------
 Source/Csla/Reflection/LateBoundObject.cs     | 11 ++--------
 Source/Csla/Reflection/MethodCaller.cs        | 18 +++------------
 .../Reflection/ServiceProviderMethodCaller.cs |  6 +----
 Source/Csla/Rules/BusinessRules.cs            | 22 ++++---------------
 Source/Csla/Rules/RuleContext.cs              | 12 ++--------
 Source/Csla/Server/DataPortal.cs              | 11 ++--------
 Source/Csla/SmartDate.cs                      | 12 ++--------
 18 files changed, 37 insertions(+), 172 deletions(-)

diff --git a/Source/Csla.Web.Mvc.Shared/Server/Hosts/HttpPortalController.cs b/Source/Csla.Web.Mvc.Shared/Server/Hosts/HttpPortalController.cs
index 50f42b92ae..14ac47ee07 100644
--- a/Source/Csla.Web.Mvc.Shared/Server/Hosts/HttpPortalController.cs
+++ b/Source/Csla.Web.Mvc.Shared/Server/Hosts/HttpPortalController.cs
@@ -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 
diff --git a/Source/Csla.Web/CslaDataSource.cs b/Source/Csla.Web/CslaDataSource.cs
index 33459782b3..3eb7a8124d 100644
--- a/Source/Csla.Web/CslaDataSource.cs
+++ b/Source/Csla.Web/CslaDataSource.cs
@@ -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).
diff --git a/Source/Csla.Web/Design/CslaDataSourceDesigner.cs b/Source/Csla.Web/Design/CslaDataSourceDesigner.cs
index 4d5c7ae584..a02c60011e 100644
--- a/Source/Csla.Web/Design/CslaDataSourceDesigner.cs
+++ b/Source/Csla.Web/Design/CslaDataSourceDesigner.cs
@@ -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.
diff --git a/Source/Csla.Windows/BindingSourceNode.cs b/Source/Csla.Windows/BindingSourceNode.cs
index 5204ed2dd7..5464e680f5 100644
--- a/Source/Csla.Windows/BindingSourceNode.cs
+++ b/Source/Csla.Windows/BindingSourceNode.cs
@@ -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; }
 
diff --git a/Source/Csla/BusinessBindingListBase.cs b/Source/Csla/BusinessBindingListBase.cs
index 6b6f2dcde9..991b026e09 100644
--- a/Source/Csla/BusinessBindingListBase.cs
+++ b/Source/Csla/BusinessBindingListBase.cs
@@ -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")]
diff --git a/Source/Csla/BusinessListBase.cs b/Source/Csla/BusinessListBase.cs
index 0bb715c958..e0c5283f00 100644
--- a/Source/Csla/BusinessListBase.cs
+++ b/Source/Csla/BusinessListBase.cs
@@ -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")]
diff --git a/Source/Csla/Core/FieldManager/PropertyInfoFactory.cs b/Source/Csla/Core/FieldManager/PropertyInfoFactory.cs
index 73df302d2d..18bccfd6d3 100644
--- a/Source/Csla/Core/FieldManager/PropertyInfoFactory.cs
+++ b/Source/Csla/Core/FieldManager/PropertyInfoFactory.cs
@@ -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);
   }
 }
\ No newline at end of file
diff --git a/Source/Csla/Core/ManagedObjectBase.cs b/Source/Csla/Core/ManagedObjectBase.cs
index a153fffd1d..39d4a91321 100644
--- a/Source/Csla/Core/ManagedObjectBase.cs
+++ b/Source/Csla/Core/ManagedObjectBase.cs
@@ -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;
 
diff --git a/Source/Csla/Core/MobileObservableCollection.cs b/Source/Csla/Core/MobileObservableCollection.cs
index 3582074837..fe47ebd487 100644
--- a/Source/Csla/Core/MobileObservableCollection.cs
+++ b/Source/Csla/Core/MobileObservableCollection.cs
@@ -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;
diff --git a/Source/Csla/DataPortalT.cs b/Source/Csla/DataPortalT.cs
index dfbc2c068d..59317ca327 100644
--- a/Source/Csla/DataPortalT.cs
+++ b/Source/Csla/DataPortalT.cs
@@ -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
diff --git a/Source/Csla/ReadOnlyBase.cs b/Source/Csla/ReadOnlyBase.cs
index 88369a4d6d..530f4c8042 100644
--- a/Source/Csla/ReadOnlyBase.cs
+++ b/Source/Csla/ReadOnlyBase.cs
@@ -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;
 
diff --git a/Source/Csla/Reflection/LateBoundObject.cs b/Source/Csla/Reflection/LateBoundObject.cs
index 118ed51fb7..fb4b9c1ed7 100644
--- a/Source/Csla/Reflection/LateBoundObject.cs
+++ b/Source/Csla/Reflection/LateBoundObject.cs
@@ -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
diff --git a/Source/Csla/Reflection/MethodCaller.cs b/Source/Csla/Reflection/MethodCaller.cs
index d828c8f5e9..faad0cab00 100644
--- a/Source/Csla/Reflection/MethodCaller.cs
+++ b/Source/Csla/Reflection/MethodCaller.cs
@@ -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;
@@ -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;
@@ -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;
diff --git a/Source/Csla/Reflection/ServiceProviderMethodCaller.cs b/Source/Csla/Reflection/ServiceProviderMethodCaller.cs
index f26d4bb936..d69e223304 100644
--- a/Source/Csla/Reflection/ServiceProviderMethodCaller.cs
+++ b/Source/Csla/Reflection/ServiceProviderMethodCaller.cs
@@ -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);
       }
     }
diff --git a/Source/Csla/Rules/BusinessRules.cs b/Source/Csla/Rules/BusinessRules.cs
index 290c51d73d..20900331a5 100644
--- a/Source/Csla/Rules/BusinessRules.cs
+++ b/Source/Csla/Rules/BusinessRules.cs
@@ -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>
@@ -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
diff --git a/Source/Csla/Rules/RuleContext.cs b/Source/Csla/Rules/RuleContext.cs
index e857ab15a5..ff7e34e0f6 100644
--- a/Source/Csla/Rules/RuleContext.cs
+++ b/Source/Csla/Rules/RuleContext.cs
@@ -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;
diff --git a/Source/Csla/Server/DataPortal.cs b/Source/Csla/Server/DataPortal.cs
index e19b0ff141..1a3b202236 100644
--- a/Source/Csla/Server/DataPortal.cs
+++ b/Source/Csla/Server/DataPortal.cs
@@ -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.
diff --git a/Source/Csla/SmartDate.cs b/Source/Csla/SmartDate.cs
index c129072cf8..cfcfe0389d 100644
--- a/Source/Csla/SmartDate.cs
+++ b/Source/Csla/SmartDate.cs
@@ -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>