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 PostAsync(string operation) /// public HttpPortal Portal { - get - { - if (_portal == null) - _portal = _applicationContext.CreateInstanceDI(); - return _portal; - } - set { _portal = value; } + get => _portal ??= _applicationContext.CreateInstanceDI(); + 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 /// /// Ignored. /// This control only contains a "Default" view. - 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"); /// /// 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 /// /// This designer supports only a "Default" view. /// - 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"); /// /// 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 Children - { - get - { - if (_children == null) - _children = new List(); - - return _children; - } - } + internal List 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 DeletedList - { - get - { - if (_deletedList == null) - _deletedList = new MobileList(); - return _deletedList; - } - } + protected MobileList 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 DeletedList - { - get - { - if (_deletedList == null) - _deletedList = new MobileList(); - return _deletedList; - } - } + protected MobileList 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. /// - 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. /// - 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 : System.Collections.ObjectModel.Obse /// and checking user rights. /// [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 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. /// - 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)); /// /// 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 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; /// @@ -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(); /// /// 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 OutputPropertyValues [EditorBrowsable(EditorBrowsableState.Never)] public List Results { - get - { - if (_results == null) - _results = new List(); - return _results; - } - private set - { - _results = value; - } + get => _results ??= []; + private set => _results = value; } private readonly Action _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)); /// /// 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) /// A format string. public string FormatString { - get - { - if (_format == null) - _format = _defaultFormat; - return _format; - } - set - { - _format = value; - } + get => _format ??= _defaultFormat; + set => _format = value; } ///