diff --git a/Changelog.md b/Changelog.md index 9606ade2e..3f35aafc2 100644 --- a/Changelog.md +++ b/Changelog.md @@ -23,6 +23,8 @@ This release gives some ❤️ to AvaloniaUI and other frameworks which use ILis ### Other +* Changed parameter validation to use `ArgumentNullException.ThrowIfNull` for better performance and more consistent exception messages + * **IMPORTANT**: This is a breaking change if you expect `ArgumentNullException` thrown by OpenRiaServices for empty strings * Fixed build pipeline problems after updating to VS 2026 * Improved polyfills to allow modernization of the codebase * Analyzer fixes diff --git a/src/.editorconfig b/src/.editorconfig index 3a356d506..3bd96b957 100644 --- a/src/.editorconfig +++ b/src/.editorconfig @@ -112,8 +112,6 @@ tab_width = 4 dotnet_diagnostic.VSTHRD010.severity = suggestion ## These suggestions does not make sense as long as we multitarget with old frameworks -# CA1510: Use 'ArgumentNullException.ThrowIfNull' instead of explicitly throwing a new exception instance -dotnet_diagnostic.CA1510.severity = none # CA1863: Cache a 'CompositeFormat' for repeated use in this formatting operation dotnet_diagnostic.CA1863.severity = none dotnet_diagnostic.CA1826.severity = warning diff --git a/src/OpenRiaServices.Client.DomainClients.Http/Framework/Http/DataContractHttpDomainClient.cs b/src/OpenRiaServices.Client.DomainClients.Http/Framework/Http/DataContractHttpDomainClient.cs index 037ddb3a4..4d8e05306 100644 --- a/src/OpenRiaServices.Client.DomainClients.Http/Framework/Http/DataContractHttpDomainClient.cs +++ b/src/OpenRiaServices.Client.DomainClients.Http/Framework/Http/DataContractHttpDomainClient.cs @@ -46,8 +46,7 @@ abstract class DataContractHttpDomainClient : DomainClient private protected DataContractHttpDomainClient(HttpClient httpClient, Type serviceInterface) { - if (serviceInterface is null) - throw new ArgumentNullException(nameof(serviceInterface)); + ArgumentNullException.ThrowIfNull(serviceInterface); HttpClient = httpClient; lock (s_globalCacheHelpers) diff --git a/src/OpenRiaServices.Client.DomainClients.Http/Framework/HttpDomainClientFactory.cs b/src/OpenRiaServices.Client.DomainClients.Http/Framework/HttpDomainClientFactory.cs index a4fb2395a..f85235b0b 100644 --- a/src/OpenRiaServices.Client.DomainClients.Http/Framework/HttpDomainClientFactory.cs +++ b/src/OpenRiaServices.Client.DomainClients.Http/Framework/HttpDomainClientFactory.cs @@ -31,8 +31,7 @@ private protected HttpDomainClientFactory(Uri serverBaseUri, HttpMessageHandler private protected HttpDomainClientFactory(Uri serverBaseUri, Func httpClientFactory) { base.ServerBaseUri = serverBaseUri; - if (httpClientFactory is null) - throw new ArgumentNullException(nameof(httpClientFactory)); + ArgumentNullException.ThrowIfNull(httpClientFactory); this._httpClientFactory = (Uri uri) => { diff --git a/src/OpenRiaServices.Client.DomainClients.Http/Framework/OpenRiaServices.Client.DomainClients.Http.csproj b/src/OpenRiaServices.Client.DomainClients.Http/Framework/OpenRiaServices.Client.DomainClients.Http.csproj index cfdf963ac..18c1305ba 100644 --- a/src/OpenRiaServices.Client.DomainClients.Http/Framework/OpenRiaServices.Client.DomainClients.Http.csproj +++ b/src/OpenRiaServices.Client.DomainClients.Http/Framework/OpenRiaServices.Client.DomainClients.Http.csproj @@ -1,7 +1,7 @@  Library - net472;netstandard2.0;net8.0 + net472;net8.0 False OpenRiaServices.Client.DomainClients en @@ -22,6 +22,7 @@ + True True diff --git a/src/OpenRiaServices.Client.DomainClients.Http/Framework/SystemServiceModel.Dispatcher/QueryStringConverter.cs b/src/OpenRiaServices.Client.DomainClients.Http/Framework/SystemServiceModel.Dispatcher/QueryStringConverter.cs index 47064b1b8..4325635c4 100644 --- a/src/OpenRiaServices.Client.DomainClients.Http/Framework/SystemServiceModel.Dispatcher/QueryStringConverter.cs +++ b/src/OpenRiaServices.Client.DomainClients.Http/Framework/SystemServiceModel.Dispatcher/QueryStringConverter.cs @@ -70,10 +70,7 @@ public virtual bool CanConvert(Type type) public virtual string ConvertValueToString(object parameter, Type parameterType) { - if (parameterType == null) - { - throw new ArgumentNullException(nameof(parameterType)); - } + ArgumentNullException.ThrowIfNull(parameterType); if (parameterType.IsValueType && parameter == null) { throw new ArgumentNullException(nameof(parameter)); diff --git a/src/OpenRiaServices.Client.Web/Framework/Data/ServiceQueryPart.cs b/src/OpenRiaServices.Client.Web/Framework/Data/ServiceQueryPart.cs index 397ae4c75..755476780 100644 --- a/src/OpenRiaServices.Client.Web/Framework/Data/ServiceQueryPart.cs +++ b/src/OpenRiaServices.Client.Web/Framework/Data/ServiceQueryPart.cs @@ -35,14 +35,8 @@ public ServiceQueryPart() /// The query expression public ServiceQueryPart(string queryOperator, string expression) { - if (queryOperator == null) - { - throw new ArgumentNullException(nameof(queryOperator)); - } - if (expression == null) - { - throw new ArgumentNullException(nameof(expression)); - } + ArgumentNullException.ThrowIfNull(queryOperator); + ArgumentNullException.ThrowIfNull(expression); if (queryOperator != "where" && queryOperator != "orderby" && queryOperator != "skip" && queryOperator != "take") diff --git a/src/OpenRiaServices.Client.Web/Framework/Data/WebDomainClient.cs b/src/OpenRiaServices.Client.Web/Framework/Data/WebDomainClient.cs index 585b2f37d..f1fda87e3 100644 --- a/src/OpenRiaServices.Client.Web/Framework/Data/WebDomainClient.cs +++ b/src/OpenRiaServices.Client.Web/Framework/Data/WebDomainClient.cs @@ -77,13 +77,9 @@ internal WebDomainClient(Uri serviceUri, bool usesHttps) /// public WebDomainClient(Uri serviceUri, bool usesHttps, WcfDomainClientFactory domainClientFactory) { - if (serviceUri == null) - { - throw new ArgumentNullException(nameof(serviceUri)); - } + ArgumentNullException.ThrowIfNull(serviceUri); - if (domainClientFactory == null) - throw new ArgumentNullException(nameof(domainClientFactory)); + ArgumentNullException.ThrowIfNull(domainClientFactory); #if !SILVERLIGHT if (!serviceUri.IsAbsoluteUri) diff --git a/src/OpenRiaServices.Client.Web/Framework/OpenRiaServices.Client.Web.csproj b/src/OpenRiaServices.Client.Web/Framework/OpenRiaServices.Client.Web.csproj index 199eccba2..f199fc81b 100644 --- a/src/OpenRiaServices.Client.Web/Framework/OpenRiaServices.Client.Web.csproj +++ b/src/OpenRiaServices.Client.Web/Framework/OpenRiaServices.Client.Web.csproj @@ -20,6 +20,7 @@ + Utilities\BinaryTypeUtility.cs diff --git a/src/OpenRiaServices.Client.Web/Framework/Web/WcfDomainClientFactory.cs b/src/OpenRiaServices.Client.Web/Framework/Web/WcfDomainClientFactory.cs index 8e517fc41..bf6b0ff80 100644 --- a/src/OpenRiaServices.Client.Web/Framework/Web/WcfDomainClientFactory.cs +++ b/src/OpenRiaServices.Client.Web/Framework/Web/WcfDomainClientFactory.cs @@ -40,8 +40,7 @@ public abstract class WcfDomainClientFactory : DomainClientFactory /// E.g "binary", "soap" protected WcfDomainClientFactory(string endpointSuffix) { - if (endpointSuffix == null) - throw new ArgumentNullException(nameof(endpointSuffix)); + ArgumentNullException.ThrowIfNull(endpointSuffix); _createInstanceMethod = typeof(WcfDomainClientFactory).GetMethod(nameof(CreateInstance), BindingFlags.NonPublic | BindingFlags.Instance); diff --git a/src/OpenRiaServices.Client/Framework/Authentication/AuthenticationEventArgs.cs b/src/OpenRiaServices.Client/Framework/Authentication/AuthenticationEventArgs.cs index 5bfb8a7d6..c57bdfdfa 100644 --- a/src/OpenRiaServices.Client/Framework/Authentication/AuthenticationEventArgs.cs +++ b/src/OpenRiaServices.Client/Framework/Authentication/AuthenticationEventArgs.cs @@ -16,10 +16,7 @@ public sealed class AuthenticationEventArgs : EventArgs /// internal AuthenticationEventArgs(IPrincipal user) { - if (user == null) - { - throw new ArgumentNullException(nameof(user)); - } + ArgumentNullException.ThrowIfNull(user); this.User = user; } diff --git a/src/OpenRiaServices.Client/Framework/Authentication/AuthenticationService.cs b/src/OpenRiaServices.Client/Framework/Authentication/AuthenticationService.cs index 62018d70d..c06a50cc0 100644 --- a/src/OpenRiaServices.Client/Framework/Authentication/AuthenticationService.cs +++ b/src/OpenRiaServices.Client/Framework/Authentication/AuthenticationService.cs @@ -457,10 +457,7 @@ private static string GetBusyPropertyName(AuthenticationOperation operation) /// protected void RaisePropertyChanged(string propertyName) { - if (string.IsNullOrEmpty(propertyName)) - { - throw new ArgumentNullException(nameof(propertyName)); - } + ArgumentException.ThrowIfNullOrEmpty(propertyName); this._propertyChangedEventHandler?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } diff --git a/src/OpenRiaServices.Client/Framework/Authentication/WebAuthenticationService.cs b/src/OpenRiaServices.Client/Framework/Authentication/WebAuthenticationService.cs index cf41f75f9..349200413 100644 --- a/src/OpenRiaServices.Client/Framework/Authentication/WebAuthenticationService.cs +++ b/src/OpenRiaServices.Client/Framework/Authentication/WebAuthenticationService.cs @@ -150,10 +150,7 @@ protected internal override Task LoginAsync(LoginParameters paramet { this.Initialize(); - if (parameters == null) - { - throw new ArgumentNullException(nameof(parameters)); - } + ArgumentNullException.ThrowIfNull(parameters); EntityQuery query; diff --git a/src/OpenRiaServices.Client/Framework/Authentication/WebContextBase.cs b/src/OpenRiaServices.Client/Framework/Authentication/WebContextBase.cs index d6eb4383d..018f24155 100644 --- a/src/OpenRiaServices.Client/Framework/Authentication/WebContextBase.cs +++ b/src/OpenRiaServices.Client/Framework/Authentication/WebContextBase.cs @@ -101,10 +101,7 @@ public AuthenticationService Authentication } set { - if (value == null) - { - throw new ArgumentNullException(nameof(value)); - } + ArgumentNullException.ThrowIfNull(value); if (this._started) { throw new InvalidOperationException(Resources.WebContext_CannotModifyAuthentication); @@ -130,10 +127,7 @@ public AuthenticationService Authentication /// protected void RaisePropertyChanged(string propertyName) { - if (string.IsNullOrEmpty(propertyName)) - { - throw new ArgumentNullException(nameof(propertyName)); - } + ArgumentException.ThrowIfNullOrEmpty(propertyName); this._propertyChangedEventHandler?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } diff --git a/src/OpenRiaServices.Client/Framework/ComplexObject.INotifyDataErrorInfo.cs b/src/OpenRiaServices.Client/Framework/ComplexObject.INotifyDataErrorInfo.cs index 06d05ff81..66579e268 100644 --- a/src/OpenRiaServices.Client/Framework/ComplexObject.INotifyDataErrorInfo.cs +++ b/src/OpenRiaServices.Client/Framework/ComplexObject.INotifyDataErrorInfo.cs @@ -52,7 +52,7 @@ IEnumerable INotifyDataErrorInfo.GetErrors(string? propertyName) // If the property name is null or empty, then we want to include errors // where the member names array is empty, or where the member names array // contains a null or empty string. - results = this.ValidationResultCollection.Where(e => !e.MemberNames.Any() || e.MemberNames.Contains(propertyName)); + results = this.ValidationResultCollection.Where(e => !e.MemberNames.Any() || e.MemberNames.Any(string.IsNullOrEmpty)); } else { diff --git a/src/OpenRiaServices.Client/Framework/ComplexObject.cs b/src/OpenRiaServices.Client/Framework/ComplexObject.cs index b812758a0..0fc6e689c 100644 --- a/src/OpenRiaServices.Client/Framework/ComplexObject.cs +++ b/src/OpenRiaServices.Client/Framework/ComplexObject.cs @@ -167,26 +167,11 @@ internal ValidationResultCollection ValidationResultCollection /// The callback to call when validation has changed for a property. internal void Attach(object parent, string propertyName, Action onDataMemberChanging, Action onDataMemberChanged, Action> onMemberValidationChanged) { - if (parent == null) - { - throw new ArgumentNullException(nameof(parent)); - } - if (string.IsNullOrEmpty(propertyName)) - { - throw new ArgumentNullException(nameof(propertyName)); - } - if (onDataMemberChanging == null) - { - throw new ArgumentNullException(nameof(onDataMemberChanging)); - } - if (onDataMemberChanged == null) - { - throw new ArgumentNullException(nameof(onDataMemberChanged)); - } - if (onMemberValidationChanged == null) - { - throw new ArgumentNullException(nameof(onMemberValidationChanged)); - } + ArgumentNullException.ThrowIfNull(parent); + ArgumentException.ThrowIfNullOrEmpty(propertyName); + ArgumentNullException.ThrowIfNull(onDataMemberChanging); + ArgumentNullException.ThrowIfNull(onDataMemberChanged); + ArgumentNullException.ThrowIfNull(onMemberValidationChanged); Debug.Assert(typeof(Entity).IsAssignableFrom(parent.GetType()) || typeof(ComplexObject).IsAssignableFrom(parent.GetType()), "Parent must be an Entity or ComplexObject."); this.CheckForCycles(parent); @@ -227,10 +212,7 @@ event PropertyChangedEventHandler? INotifyPropertyChanged.PropertyChanged /// The name of the property that has changed protected void RaisePropertyChanged(string propertyName) { - if (string.IsNullOrEmpty(propertyName)) - { - throw new ArgumentNullException(nameof(propertyName)); - } + ArgumentException.ThrowIfNullOrEmpty(propertyName); OnPropertyChanged(propertyName); } @@ -252,10 +234,7 @@ protected virtual void OnPropertyChanged(string propertyName) /// The name of the property that has changed protected void RaiseDataMemberChanged(string propertyName) { - if (string.IsNullOrEmpty(propertyName)) - { - throw new ArgumentNullException(nameof(propertyName)); - } + ArgumentException.ThrowIfNullOrEmpty(propertyName); // Note, RaiseDataMemberChanged is called on every property update. We need to avoid as // much overhead as possible. @@ -321,10 +300,7 @@ private void AttachComplexObjectInstance(MetaMember metaMember) /// The name of the property that is changing protected void RaiseDataMemberChanging(string propertyName) { - if (string.IsNullOrEmpty(propertyName)) - { - throw new ArgumentNullException(nameof(propertyName)); - } + ArgumentException.ThrowIfNullOrEmpty(propertyName); this.OnDataMemberChanging(); } @@ -405,10 +381,7 @@ private void NotifyParentMemberValidationChanged(string? propertyName, IEnumerab /// configured to prevent editing. protected void ValidateProperty(string propertyName, object value) { - if (string.IsNullOrEmpty(propertyName)) - { - throw new ArgumentNullException(nameof(propertyName)); - } + ArgumentException.ThrowIfNullOrEmpty(propertyName); // if this instance is currently being deserialized, or if it is hosted by an // entity that is being deserialized or is having state applied to it, skip @@ -480,10 +453,7 @@ protected void ValidateProperty(string propertyName, object value) /// is thrown if is null. protected virtual void ValidateProperty(ValidationContext validationContext, object value) { - if (validationContext == null) - { - throw new ArgumentNullException(nameof(validationContext)); - } + ArgumentNullException.ThrowIfNull(validationContext); List validationResults = new List(); Validator.TryValidateProperty(value, validationContext, validationResults); diff --git a/src/OpenRiaServices.Client/Framework/DomainClient.cs b/src/OpenRiaServices.Client/Framework/DomainClient.cs index 28c66be69..58b429e5c 100644 --- a/src/OpenRiaServices.Client/Framework/DomainClient.cs +++ b/src/OpenRiaServices.Client/Framework/DomainClient.cs @@ -78,10 +78,7 @@ public virtual bool SupportsCancellation /// The results returned by the submit request. public Task SubmitAsync(EntityChangeSet changeSet, CancellationToken cancellationToken) { - if (changeSet == null) - { - throw new ArgumentNullException(nameof(changeSet)); - } + ArgumentNullException.ThrowIfNull(changeSet); if (changeSet.IsEmpty) { diff --git a/src/OpenRiaServices.Client/Framework/DomainClientFactory.cs b/src/OpenRiaServices.Client/Framework/DomainClientFactory.cs index af8922fed..2a6b5a464 100644 --- a/src/OpenRiaServices.Client/Framework/DomainClientFactory.cs +++ b/src/OpenRiaServices.Client/Framework/DomainClientFactory.cs @@ -40,8 +40,7 @@ public Uri ServerBaseUri } set { - if (value == null) - throw new ArgumentNullException(nameof(value)); + ArgumentNullException.ThrowIfNull(value); if (!value.IsAbsoluteUri) throw new ArgumentException("ServiceBaseUri must be absolute", nameof(value)); @@ -63,10 +62,8 @@ public Uri ServerBaseUri /// A to use when communicating with the service public DomainClient CreateDomainClient([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] Type serviceContract, Uri serviceUri, bool requiresSecureEndpoint) { - if (serviceContract == null) - throw new ArgumentNullException(nameof(serviceContract)); - if (serviceUri == null) - throw new ArgumentNullException(nameof(serviceUri)); + ArgumentNullException.ThrowIfNull(serviceContract); + ArgumentNullException.ThrowIfNull(serviceUri); if (!serviceContract.IsInterface) throw new ArgumentException(Resource.DomainClientFactory_ServiceContractMustBeAnInterface, nameof(serviceContract)); diff --git a/src/OpenRiaServices.Client/Framework/DomainContext.cs b/src/OpenRiaServices.Client/Framework/DomainContext.cs index 1fced39f9..dd1295697 100644 --- a/src/OpenRiaServices.Client/Framework/DomainContext.cs +++ b/src/OpenRiaServices.Client/Framework/DomainContext.cs @@ -50,10 +50,7 @@ public abstract class DomainContext : INotifyPropertyChanged /// The instance this should use protected DomainContext(DomainClient domainClient) { - if (domainClient == null) - { - throw new ArgumentNullException(nameof(domainClient)); - } + ArgumentNullException.ThrowIfNull(domainClient); this._domainClient = domainClient; } @@ -91,8 +88,7 @@ public static IDomainClientFactory DomainClientFactory } set { - if (value == null) - throw new ArgumentNullException(nameof(value)); + ArgumentNullException.ThrowIfNull(value); s_domainClientFactory = value; } } @@ -221,15 +217,9 @@ public ValidationContext? ValidationContext /// A to register as an external reference. public void AddReference(Type entityType, DomainContext domainContext) { - if (entityType == null) - { - throw new ArgumentNullException(nameof(entityType)); - } + ArgumentNullException.ThrowIfNull(entityType); - if (domainContext == null) - { - throw new ArgumentNullException(nameof(domainContext)); - } + ArgumentNullException.ThrowIfNull(domainContext); EntitySet entitySet = domainContext.EntityContainer.GetEntitySet(entityType); this.EntityContainer.AddReference(entitySet); @@ -562,10 +552,7 @@ public Task> LoadAsync(EntityQuery query, public virtual Task> LoadAsync(EntityQuery query, LoadBehavior loadBehavior, CancellationToken cancellationToken) where TEntity : Entity { - if (query == null) - { - throw new ArgumentNullException(nameof(query)); - } + ArgumentNullException.ThrowIfNull(query); // verify the specified query was created by this DomainContext if (this.DomainClient != query.DomainClient) @@ -874,10 +861,7 @@ protected virtual Task> InvokeOperationAsync(string throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resource.Parameter_NullOrEmpty, "operationName")); } - if (returnType is null) - { - throw new ArgumentNullException(nameof(returnType)); - } + ArgumentNullException.ThrowIfNull(returnType); InvokeArgs invokeArgs = new InvokeArgs(operationName, returnType, parameters, hasSideEffects); return this.DomainClient.InvokeAsync(invokeArgs, cancellationToken) @@ -920,10 +904,7 @@ protected virtual Task> InvokeOperationAsync(string /// The property to raise the event for protected void RaisePropertyChanged(string propertyName) { - if (string.IsNullOrEmpty(propertyName)) - { - throw new ArgumentNullException(nameof(propertyName)); - } + ArgumentException.ThrowIfNullOrEmpty(propertyName); this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } @@ -954,10 +935,7 @@ private void DecrementLoadCount() /// The parameters to the method. protected void ValidateMethod(string methodName, IDictionary? parameters) { - if (string.IsNullOrEmpty(methodName)) - { - throw new ArgumentNullException(nameof(methodName)); - } + ArgumentException.ThrowIfNullOrEmpty(methodName); object?[] paramValues = parameters != null ? parameters.Values.ToArray() : Array.Empty(); if (!this.MethodRequiresValidation(methodName, paramValues)) diff --git a/src/OpenRiaServices.Client/Framework/Entity.cs b/src/OpenRiaServices.Client/Framework/Entity.cs index f0efd10de..9d2a5515a 100644 --- a/src/OpenRiaServices.Client/Framework/Entity.cs +++ b/src/OpenRiaServices.Client/Framework/Entity.cs @@ -1088,10 +1088,7 @@ protected virtual void OnPropertyChanged(string propertyName) /// The name of the property that has changed protected void RaiseDataMemberChanged(string propertyName) { - if (string.IsNullOrEmpty(propertyName)) - { - throw new ArgumentNullException(nameof(propertyName)); - } + ArgumentException.ThrowIfNullOrEmpty(propertyName); this.OnDataMemberChanged(); @@ -1183,10 +1180,7 @@ protected internal void RaisePropertyChanged(string propertyName) /// The name of the property that is changing protected void RaiseDataMemberChanging(string propertyName) { - if (string.IsNullOrEmpty(propertyName)) - { - throw new ArgumentNullException(nameof(propertyName)); - } + ArgumentException.ThrowIfNullOrEmpty(propertyName); this.OnDataMemberChanging(); @@ -1238,10 +1232,7 @@ private void OnDataMemberChanging() /// configured to prevent editing. protected void ValidateProperty(string propertyName, object? value) { - if (string.IsNullOrEmpty(propertyName)) - { - throw new ArgumentNullException(nameof(propertyName)); - } + ArgumentException.ThrowIfNullOrEmpty(propertyName); if (this.IsDeserializing || this.IsApplyingState) { @@ -1311,10 +1302,7 @@ protected void ValidateProperty(string propertyName, object? value) /// is thrown if is null. protected virtual void ValidateProperty(ValidationContext validationContext, object? value) { - if (validationContext == null) - { - throw new ArgumentNullException(nameof(validationContext)); - } + ArgumentNullException.ThrowIfNull(validationContext); List validationResults = new List(); Validator.TryValidateProperty(value, validationContext, validationResults); @@ -1532,8 +1520,7 @@ internal protected void UndoAction(EntityAction action) /// If the action does not belong to this Entity's private void UndoAction(EntityAction action, bool throwIfSubmitting) { - if (action == null) - throw new ArgumentNullException(nameof(action)); + ArgumentNullException.ThrowIfNull(action); // verify that the action can currently be invoked if (throwIfSubmitting && this.IsSubmitting) diff --git a/src/OpenRiaServices.Client/Framework/EntityChangeSet.cs b/src/OpenRiaServices.Client/Framework/EntityChangeSet.cs index 316f9641e..dc710f0ba 100644 --- a/src/OpenRiaServices.Client/Framework/EntityChangeSet.cs +++ b/src/OpenRiaServices.Client/Framework/EntityChangeSet.cs @@ -21,18 +21,9 @@ internal EntityChangeSet( ReadOnlyCollection modifiedEntities, ReadOnlyCollection removedEntities) { - if (addedEntities == null) - { - throw new ArgumentNullException(nameof(addedEntities)); - } - if (modifiedEntities == null) - { - throw new ArgumentNullException(nameof(modifiedEntities)); - } - if (removedEntities == null) - { - throw new ArgumentNullException(nameof(removedEntities)); - } + ArgumentNullException.ThrowIfNull(addedEntities); + ArgumentNullException.ThrowIfNull(modifiedEntities); + ArgumentNullException.ThrowIfNull(removedEntities); this._addedEntities = addedEntities; this._removedEntities = removedEntities; diff --git a/src/OpenRiaServices.Client/Framework/EntityCollection.cs b/src/OpenRiaServices.Client/Framework/EntityCollection.cs index 4c8d2edde..e1bc4e254 100644 --- a/src/OpenRiaServices.Client/Framework/EntityCollection.cs +++ b/src/OpenRiaServices.Client/Framework/EntityCollection.cs @@ -58,18 +58,9 @@ public sealed class EntityCollection : IEntityCollection, IEntityCollec /// which are members of this collection. public EntityCollection(Entity parent, string memberName, Func entityPredicate) { - if (parent == null) - { - throw new ArgumentNullException(nameof(parent)); - } - if (string.IsNullOrEmpty(memberName)) - { - throw new ArgumentNullException(nameof(memberName)); - } - if (entityPredicate == null) - { - throw new ArgumentNullException(nameof(entityPredicate)); - } + ArgumentNullException.ThrowIfNull(parent); + ArgumentException.ThrowIfNullOrEmpty(memberName); + ArgumentNullException.ThrowIfNull(entityPredicate); this._parent = parent; this._entityPredicate = entityPredicate; @@ -105,14 +96,8 @@ public EntityCollection(Entity parent, string memberName, Func en public EntityCollection(Entity parent, string memberName, Func entityPredicate, Action attachAction, Action detachAction) : this(parent, memberName, entityPredicate) { - if (attachAction == null) - { - throw new ArgumentNullException(nameof(attachAction)); - } - if (detachAction == null) - { - throw new ArgumentNullException(nameof(detachAction)); - } + ArgumentNullException.ThrowIfNull(attachAction); + ArgumentNullException.ThrowIfNull(detachAction); this._attachAction = attachAction; this._detachAction = detachAction; @@ -217,10 +202,7 @@ private EntitySet? SourceSet /// The entity to add public void Add(TEntity entity) { - if (entity == null) - { - throw new ArgumentNullException(nameof(entity)); - } + ArgumentNullException.ThrowIfNull(entity); if (this.IsSourceExternal) { @@ -288,10 +270,7 @@ public void Add(TEntity entity) /// The entity to remove public void Remove(TEntity entity) { - if (entity == null) - { - throw new ArgumentNullException(nameof(entity)); - } + ArgumentNullException.ThrowIfNull(entity); if (entity == this._detachingEntity) { diff --git a/src/OpenRiaServices.Client/Framework/EntityCollectionChangedEventArgs.cs b/src/OpenRiaServices.Client/Framework/EntityCollectionChangedEventArgs.cs index b2acd3b03..fba8e5c18 100644 --- a/src/OpenRiaServices.Client/Framework/EntityCollectionChangedEventArgs.cs +++ b/src/OpenRiaServices.Client/Framework/EntityCollectionChangedEventArgs.cs @@ -19,10 +19,7 @@ public class EntityCollectionChangedEventArgs : EventArgs /// The affected public EntityCollectionChangedEventArgs(TEntity entity) { - if (entity == null) - { - throw new ArgumentNullException(nameof(entity)); - } + ArgumentNullException.ThrowIfNull(entity); this._entity = entity; } diff --git a/src/OpenRiaServices.Client/Framework/EntityConflict.cs b/src/OpenRiaServices.Client/Framework/EntityConflict.cs index cfc15be04..1e19c097d 100644 --- a/src/OpenRiaServices.Client/Framework/EntityConflict.cs +++ b/src/OpenRiaServices.Client/Framework/EntityConflict.cs @@ -30,25 +30,15 @@ public sealed class EntityConflict /// is null. internal EntityConflict(Entity currentEntity, Entity storeEntity, IEnumerable propertyNames, bool isDeleted) { - if (currentEntity == null) - { - throw new ArgumentNullException(nameof(currentEntity)); - } + ArgumentNullException.ThrowIfNull(currentEntity); this._currentEntity = currentEntity; this._isDeleted = isDeleted; if (!isDeleted) { - if (storeEntity == null) - { - throw new ArgumentNullException(nameof(storeEntity)); - } + ArgumentNullException.ThrowIfNull(storeEntity); + ArgumentNullException.ThrowIfNull(propertyNames); - if (propertyNames == null) - { - throw new ArgumentNullException(nameof(propertyNames)); - } - this._storeEntity = storeEntity; this._propertyNames = new ReadOnlyCollection(propertyNames.ToList()); } diff --git a/src/OpenRiaServices.Client/Framework/EntityContainer.cs b/src/OpenRiaServices.Client/Framework/EntityContainer.cs index fa682d3ba..71973ddf9 100644 --- a/src/OpenRiaServices.Client/Framework/EntityContainer.cs +++ b/src/OpenRiaServices.Client/Framework/EntityContainer.cs @@ -88,10 +88,7 @@ internal void CheckCrossContainer(Entity entity) /// A to register as an external reference. public void AddReference(EntitySet entitySet) { - if (entitySet == null) - { - throw new ArgumentNullException(nameof(entitySet)); - } + ArgumentNullException.ThrowIfNull(entitySet); Type entityType = entitySet.EntityType; if (this._entitySets.ContainsKey(entityType) @@ -376,10 +373,7 @@ public IReadOnlyCollection LoadEntities(IEnumerable entities) /// are already cached locally, the return set will contain the cached instances. public IReadOnlyCollection LoadEntities(IEnumerable entities, LoadBehavior loadBehavior) { - if (entities == null) - { - throw new ArgumentNullException(nameof(entities)); - } + ArgumentNullException.ThrowIfNull(entities); // group the entities by type, and load each group into it's entity // list (ensuring we don't modify the relative ordering of each sequence diff --git a/src/OpenRiaServices.Client/Framework/EntityKey.cs b/src/OpenRiaServices.Client/Framework/EntityKey.cs index 84e086ed9..1cd87f52d 100644 --- a/src/OpenRiaServices.Client/Framework/EntityKey.cs +++ b/src/OpenRiaServices.Client/Framework/EntityKey.cs @@ -45,10 +45,7 @@ public static EntityKey Create(T1 v1, T2 v2, T3 v3) /// The entity key public static EntityKey Create(params object[] keyValues) { - if (keyValues == null) - { - throw new ArgumentNullException(nameof(keyValues)); - } + ArgumentNullException.ThrowIfNull(keyValues); int keyLength = keyValues.Length; if (keyLength == 0) @@ -120,10 +117,7 @@ public override string ToString() /// The key value to format internal static void FormatKeyValue(StringBuilder sb, T value) { - if (sb == null) - { - throw new ArgumentNullException(nameof(sb)); - } + ArgumentNullException.ThrowIfNull(sb); if (value == null) { throw new ArgumentNullException(Resource.EntityKey_CannotBeNull); @@ -202,10 +196,7 @@ internal override void FormatKey(StringBuilder sb) /// True if the keys are equal public bool Equals(EntityKey other) { - if (other == null) - { - throw new ArgumentNullException(nameof(other)); - } + ArgumentNullException.ThrowIfNull(other); return EqualityComparer.Default.Equals(this._v, other._v); } @@ -277,10 +268,7 @@ internal override void FormatKey(StringBuilder sb) /// True if the keys are equal public bool Equals(EntityKey other) { - if (other == null) - { - throw new ArgumentNullException(nameof(other)); - } + ArgumentNullException.ThrowIfNull(other); return EqualityComparer.Default.Equals(this._v1, other._v1) && EqualityComparer.Default.Equals(this._v2, other._v2); } diff --git a/src/OpenRiaServices.Client/Framework/EntityList.cs b/src/OpenRiaServices.Client/Framework/EntityList.cs index cd57a651e..795d67995 100644 --- a/src/OpenRiaServices.Client/Framework/EntityList.cs +++ b/src/OpenRiaServices.Client/Framework/EntityList.cs @@ -55,10 +55,7 @@ public EntityList(EntitySet entitySet) /// The source collection used to populate this list public EntityList(EntitySet entitySet, IEnumerable source) { - if (entitySet == null) - { - throw new ArgumentNullException(nameof(entitySet)); - } + ArgumentNullException.ThrowIfNull(entitySet); _entitySet = entitySet; _weakCollectionChangedLister = diff --git a/src/OpenRiaServices.Client/Framework/EntityQuery.cs b/src/OpenRiaServices.Client/Framework/EntityQuery.cs index 10406dde2..fad0abc5f 100644 --- a/src/OpenRiaServices.Client/Framework/EntityQuery.cs +++ b/src/OpenRiaServices.Client/Framework/EntityQuery.cs @@ -33,18 +33,9 @@ public abstract class EntityQuery /// True if the query supports composition, false otherwise. private protected EntityQuery(DomainClient domainClient, string queryName, Type entityType, IDictionary? parameters, bool hasSideEffects, bool isComposable) { - if (domainClient == null) - { - throw new ArgumentNullException(nameof(domainClient)); - } - if (string.IsNullOrEmpty(queryName)) - { - throw new ArgumentNullException(nameof(queryName)); - } - if (entityType == null) - { - throw new ArgumentNullException(nameof(entityType)); - } + ArgumentNullException.ThrowIfNull(domainClient); + ArgumentException.ThrowIfNullOrEmpty(queryName); + ArgumentNullException.ThrowIfNull(entityType); this._domainClient = domainClient; this._queryName = queryName; this._entityType = entityType; @@ -62,14 +53,8 @@ private protected EntityQuery(DomainClient domainClient, string queryName, Type /// The new query. internal EntityQuery(EntityQuery baseQuery, IQueryable query) { - if (baseQuery == null) - { - throw new ArgumentNullException(nameof(baseQuery)); - } - if (query == null) - { - throw new ArgumentNullException(nameof(query)); - } + ArgumentNullException.ThrowIfNull(baseQuery); + ArgumentNullException.ThrowIfNull(query); this._domainClient = baseQuery._domainClient; this._queryName = baseQuery._queryName; this._entityType = baseQuery._entityType; @@ -195,7 +180,6 @@ internal EntityQuery(EntityQuery eq, IQueryable query) { } - /// /// internal new IQueryable? Query { diff --git a/src/OpenRiaServices.Client/Framework/EntityQueryable.cs b/src/OpenRiaServices.Client/Framework/EntityQueryable.cs index 0d3b2d64e..9b283081b 100644 --- a/src/OpenRiaServices.Client/Framework/EntityQueryable.cs +++ b/src/OpenRiaServices.Client/Framework/EntityQueryable.cs @@ -21,14 +21,8 @@ public static class EntityQueryable /// The composed query. public static EntityQuery OrderBy(this EntityQuery source, Expression> keySelector) where TEntity : Entity { - if (source == null) - { - throw new ArgumentNullException(nameof(source)); - } - if (keySelector == null) - { - throw new ArgumentNullException(nameof(keySelector)); - } + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(keySelector); if (!source.IsComposable) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resource.EntityQuery_NotComposable, typeof(TEntity).Name, source.QueryName)); @@ -46,14 +40,8 @@ public static EntityQuery OrderBy(this EntityQueryThe composed query. public static EntityQuery OrderByDescending(this EntityQuery source, Expression> keySelector) where TEntity : Entity { - if (source == null) - { - throw new ArgumentNullException(nameof(source)); - } - if (keySelector == null) - { - throw new ArgumentNullException(nameof(keySelector)); - } + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(keySelector); if (!source.IsComposable) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resource.EntityQuery_NotComposable, typeof(TEntity).Name, source.QueryName)); @@ -70,10 +58,7 @@ public static EntityQuery OrderByDescending(this EntityQ /// The composed query. public static EntityQuery Skip(this EntityQuery source, int count) where TEntity : Entity { - if (source == null) - { - throw new ArgumentNullException(nameof(source)); - } + ArgumentNullException.ThrowIfNull(source); if (!source.IsComposable) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resource.EntityQuery_NotComposable, typeof(TEntity).Name, source.QueryName)); @@ -90,10 +75,7 @@ public static EntityQuery Skip(this EntityQuery sourc /// The composed query. public static EntityQuery Take(this EntityQuery source, int count) where TEntity : Entity { - if (source == null) - { - throw new ArgumentNullException(nameof(source)); - } + ArgumentNullException.ThrowIfNull(source); if (!source.IsComposable) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resource.EntityQuery_NotComposable, typeof(TEntity).Name, source.QueryName)); @@ -111,14 +93,8 @@ public static EntityQuery Take(this EntityQuery sourc /// The composed query. public static EntityQuery ThenBy(this EntityQuery source, Expression> keySelector) where TEntity : Entity { - if (source == null) - { - throw new ArgumentNullException(nameof(source)); - } - if (keySelector == null) - { - throw new ArgumentNullException(nameof(keySelector)); - } + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(keySelector); if (!source.IsComposable) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resource.EntityQuery_NotComposable, typeof(TEntity).Name, source.QueryName)); @@ -136,14 +112,8 @@ public static EntityQuery ThenBy(this EntityQueryThe composed query. public static EntityQuery ThenByDescending(this EntityQuery source, Expression> keySelector) where TEntity : Entity { - if (source == null) - { - throw new ArgumentNullException(nameof(source)); - } - if (keySelector == null) - { - throw new ArgumentNullException(nameof(keySelector)); - } + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(keySelector); if (!source.IsComposable) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resource.EntityQuery_NotComposable, typeof(TEntity).Name, source.QueryName)); @@ -160,14 +130,8 @@ public static EntityQuery ThenByDescending(this EntityQu /// The composed query. public static EntityQuery Where(this EntityQuery source, Expression> predicate) where TEntity : Entity { - if (source == null) - { - throw new ArgumentNullException(nameof(source)); - } - if (predicate == null) - { - throw new ArgumentNullException(nameof(predicate)); - } + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(predicate); if (!source.IsComposable) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resource.EntityQuery_NotComposable, typeof(TEntity).Name, source.QueryName)); @@ -185,14 +149,8 @@ public static EntityQuery Where(this EntityQuery sour /// The composed query. public static EntityQuery Select(this EntityQuery source, Expression> selector) where TEntity : Entity { - if (source == null) - { - throw new ArgumentNullException(nameof(source)); - } - if (selector == null) - { - throw new ArgumentNullException(nameof(selector)); - } + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(selector); return new EntityQuery(source, Queryable.Select(source.QueryRoot, selector)); } } diff --git a/src/OpenRiaServices.Client/Framework/EntityRef.cs b/src/OpenRiaServices.Client/Framework/EntityRef.cs index 048da2dbc..2e8afa182 100644 --- a/src/OpenRiaServices.Client/Framework/EntityRef.cs +++ b/src/OpenRiaServices.Client/Framework/EntityRef.cs @@ -39,18 +39,9 @@ public sealed class EntityRef : IEntityRef where TEntity : Entity /// The function used to filter the associated entity. public EntityRef(Entity parent, string memberName, Func entityPredicate) { - if (parent == null) - { - throw new ArgumentNullException(nameof(parent)); - } - if (string.IsNullOrEmpty(memberName)) - { - throw new ArgumentNullException(nameof(memberName)); - } - if (entityPredicate == null) - { - throw new ArgumentNullException(nameof(entityPredicate)); - } + ArgumentNullException.ThrowIfNull(parent); + ArgumentException.ThrowIfNullOrEmpty(memberName); + ArgumentNullException.ThrowIfNull(entityPredicate); this._parent = parent; this._entityPredicate = entityPredicate; diff --git a/src/OpenRiaServices.Client/Framework/EntitySet.cs b/src/OpenRiaServices.Client/Framework/EntitySet.cs index 6694f0744..bc8d713c0 100644 --- a/src/OpenRiaServices.Client/Framework/EntitySet.cs +++ b/src/OpenRiaServices.Client/Framework/EntitySet.cs @@ -41,10 +41,7 @@ public abstract class EntitySet : IList, INotifyCollectionChanged, IRevertibleCh /// The type of the set will contain private protected EntitySet(Type entityType) { - if (entityType == null) - { - throw new ArgumentNullException(nameof(entityType)); - } + ArgumentNullException.ThrowIfNull(entityType); if (!typeof(Entity).IsAssignableFrom(entityType)) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resource.Type_Not_Entity, entityType), nameof(entityType)); @@ -243,10 +240,7 @@ internal void EnsureEditable(EntitySetOperations operation) private void EnsureEntityType(object entity) { - if (entity == null) - { - throw new ArgumentNullException(nameof(entity)); - } + ArgumentNullException.ThrowIfNull(entity); if (!this._entityType.IsAssignableFrom(entity.GetType())) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resource.EntitySet_Wrong_Type, this._entityType, entity.GetType()), nameof(entity)); @@ -666,10 +660,7 @@ internal void AttachInternal(Entity entity) /// The entity to detach public void Detach(Entity entity) { - if (entity == null) - { - throw new ArgumentNullException(nameof(entity)); - } + ArgumentNullException.ThrowIfNull(entity); this.EnsureEntityType(entity); @@ -1085,18 +1076,9 @@ private class AddAttachInferrer : EntityVisitor public static void Infer(EntityContainer container, Entity entity, Action action) { - if (container == null) - { - throw new ArgumentNullException(nameof(container)); - } - if (entity == null) - { - throw new ArgumentNullException(nameof(entity)); - } - if (action == null) - { - throw new ArgumentNullException(nameof(action)); - } + ArgumentNullException.ThrowIfNull(container); + ArgumentNullException.ThrowIfNull(entity); + ArgumentNullException.ThrowIfNull(action); new AddAttachInferrer(container, action).Visit(entity); } diff --git a/src/OpenRiaServices.Client/Framework/EntityVisitor.cs b/src/OpenRiaServices.Client/Framework/EntityVisitor.cs index 6a2c6bf7b..dadf4fbac 100644 --- a/src/OpenRiaServices.Client/Framework/EntityVisitor.cs +++ b/src/OpenRiaServices.Client/Framework/EntityVisitor.cs @@ -17,10 +17,7 @@ internal class EntityVisitor /// The entity to visit public virtual void Visit(Entity entity) { - if (entity == null) - { - throw new ArgumentNullException(nameof(entity)); - } + ArgumentNullException.ThrowIfNull(entity); foreach (MetaMember association in entity.MetaType.AssociationMembers) { diff --git a/src/OpenRiaServices.Client/Framework/InvokeArgs.cs b/src/OpenRiaServices.Client/Framework/InvokeArgs.cs index b5e80afdf..ad8f832ed 100644 --- a/src/OpenRiaServices.Client/Framework/InvokeArgs.cs +++ b/src/OpenRiaServices.Client/Framework/InvokeArgs.cs @@ -20,14 +20,8 @@ public sealed class InvokeArgs /// True if the operation has side-effects, false otherwise. public InvokeArgs(string operationName, Type returnType, IDictionary? parameters, bool hasSideEffects) { - if (string.IsNullOrEmpty(operationName)) - { - throw new ArgumentNullException(nameof(operationName)); - } - if (returnType == null) - { - throw new ArgumentNullException(nameof(returnType)); - } + ArgumentException.ThrowIfNullOrEmpty(operationName); + ArgumentNullException.ThrowIfNull(returnType); OperationName = operationName; ReturnType = returnType; diff --git a/src/OpenRiaServices.Client/Framework/InvokeCompletedResult.cs b/src/OpenRiaServices.Client/Framework/InvokeCompletedResult.cs index 52c3fbb6d..da8ebce34 100644 --- a/src/OpenRiaServices.Client/Framework/InvokeCompletedResult.cs +++ b/src/OpenRiaServices.Client/Framework/InvokeCompletedResult.cs @@ -30,10 +30,7 @@ public InvokeCompletedResult(object? returnValue) /// A collection of validation errors. public InvokeCompletedResult(object? returnValue, IEnumerable validationErrors) { - if (validationErrors == null) - { - throw new ArgumentNullException(nameof(validationErrors)); - } + ArgumentNullException.ThrowIfNull(validationErrors); ReturnValue = returnValue; ValidationErrors = validationErrors.ToList().AsReadOnly(); diff --git a/src/OpenRiaServices.Client/Framework/InvokeOperation.cs b/src/OpenRiaServices.Client/Framework/InvokeOperation.cs index c0991443d..0874d1a7f 100644 --- a/src/OpenRiaServices.Client/Framework/InvokeOperation.cs +++ b/src/OpenRiaServices.Client/Framework/InvokeOperation.cs @@ -32,10 +32,7 @@ internal InvokeOperation(string operationName, IDictionary? par CancellationTokenSource? cancellationTokenSource) : base(userState, cancellationTokenSource) { - if (string.IsNullOrEmpty(operationName)) - { - throw new ArgumentNullException(nameof(operationName)); - } + ArgumentException.ThrowIfNullOrEmpty(operationName); this.OperationName = operationName; this._parameters = parameters; this._completeAction = completeAction; diff --git a/src/OpenRiaServices.Client/Framework/LoadOperation.cs b/src/OpenRiaServices.Client/Framework/LoadOperation.cs index 894ef0cce..d7d9b17e6 100644 --- a/src/OpenRiaServices.Client/Framework/LoadOperation.cs +++ b/src/OpenRiaServices.Client/Framework/LoadOperation.cs @@ -35,10 +35,7 @@ public abstract class LoadOperation : OperationBase, ILoadResult private protected LoadOperation(EntityQuery query, LoadBehavior loadBehavior, object? userState, CancellationTokenSource? cancellationTokenSource) : base(userState, cancellationTokenSource) { - if (query == null) - { - throw new ArgumentNullException(nameof(query)); - } + ArgumentNullException.ThrowIfNull(query); this._query = query; this._loadBehavior = loadBehavior; } @@ -139,10 +136,7 @@ public IReadOnlyCollection ValidationErrors /// The results of the completed load operation. private protected virtual void UpdateResults(ILoadResult result) { - if (result == null) - { - throw new ArgumentNullException(nameof(result)); - } + ArgumentNullException.ThrowIfNull(result); // if the Entities property has been examined, update the backing // observable collection @@ -202,10 +196,7 @@ public LoadOperation(EntityQuery query, CancellationTokenSource? cancellationTokenSource) : base(query, loadBehavior, userState, cancellationTokenSource) { - if (loadResultTask == null) - { - throw new ArgumentNullException(nameof(loadResultTask)); - } + ArgumentNullException.ThrowIfNull(loadResultTask); this._completeAction = completeAction; @@ -280,10 +271,7 @@ protected override void InvokeCompleteAction() /// The result. private void SetResult(LoadResult result) { - if (result == null) - { - throw new ArgumentNullException(nameof(result)); - } + ArgumentNullException.ThrowIfNull(result); // before calling base, we need to update any cached // observable collection results so the correct data diff --git a/src/OpenRiaServices.Client/Framework/OpenRiaServices.Client.csproj b/src/OpenRiaServices.Client/Framework/OpenRiaServices.Client.csproj index 287d424d4..83f76fab3 100644 --- a/src/OpenRiaServices.Client/Framework/OpenRiaServices.Client.csproj +++ b/src/OpenRiaServices.Client/Framework/OpenRiaServices.Client.csproj @@ -1,7 +1,7 @@  - net472;netstandard2.0;net8.0;net8.0-windows + net472;net8.0;net8.0-windows $(DefineConstants);HAS_COLLECTIONVIEW true diff --git a/src/OpenRiaServices.Client/Framework/OperationBase.cs b/src/OpenRiaServices.Client/Framework/OperationBase.cs index ae7e559cc..abb768bfc 100644 --- a/src/OpenRiaServices.Client/Framework/OperationBase.cs +++ b/src/OpenRiaServices.Client/Framework/OperationBase.cs @@ -300,10 +300,7 @@ private void InvokeCompletedEvent() /// The error. protected void SetError(Exception error) { - if (error == null) - { - throw new ArgumentNullException(nameof(error)); - } + ArgumentNullException.ThrowIfNull(error); this.EnsureNotCompleted(); diff --git a/src/OpenRiaServices.Client/Framework/Polyfills.cs b/src/OpenRiaServices.Client/Framework/Polyfills.cs index 5826383ac..91b67631a 100644 --- a/src/OpenRiaServices.Client/Framework/Polyfills.cs +++ b/src/OpenRiaServices.Client/Framework/Polyfills.cs @@ -28,7 +28,9 @@ public static void ThrowIfNull([NotNull] object? argument, [CallerArgumentExpres public static void ThrowIfNullOrEmpty([NotNull] string? argument, [CallerArgumentExpression(nameof(argument))] string? paramName = null) { if (argument is null || argument.Length == 0) - ThrowArgumentNullException(paramName); + { + ThrowStringNullOrEmptyException(argument, paramName); + } } } @@ -37,6 +39,13 @@ private static void ThrowArgumentNullException(string? paramName) { throw new ArgumentNullException(paramName); } + + [DoesNotReturn] + private static void ThrowStringNullOrEmptyException(string? argument, string? paramName) + { + ArgumentNullException.ThrowIfNull(argument, paramName); + throw new ArgumentException("The value cannot be an empty string.", paramName: paramName); + } } } diff --git a/src/OpenRiaServices.Client/Framework/QueryBuilder.cs b/src/OpenRiaServices.Client/Framework/QueryBuilder.cs index 9fa80d831..a3cfbeb53 100644 --- a/src/OpenRiaServices.Client/Framework/QueryBuilder.cs +++ b/src/OpenRiaServices.Client/Framework/QueryBuilder.cs @@ -66,10 +66,7 @@ public QueryBuilder(bool requestTotalItemCount) /// public QueryBuilder OrderBy(Expression> keySelector) { - if (keySelector == null) - { - throw new ArgumentNullException(nameof(keySelector)); - } + ArgumentNullException.ThrowIfNull(keySelector); Func, EntityQuery> entityQueryReplay = _entityQueryReplay; Func, IQueryable> queryableReplay = _queryableReplay; @@ -102,10 +99,7 @@ public QueryBuilder OrderBy(Expression> keySelector) /// public QueryBuilder OrderByDescending(Expression> keySelector) { - if (keySelector == null) - { - throw new ArgumentNullException(nameof(keySelector)); - } + ArgumentNullException.ThrowIfNull(keySelector); Func, EntityQuery> entityQueryReplay = _entityQueryReplay; Func, IQueryable> queryableReplay = _queryableReplay; @@ -138,10 +132,7 @@ public QueryBuilder OrderByDescending(Expression> keySele /// public QueryBuilder Select(Expression> selector) { - if (selector == null) - { - throw new ArgumentNullException(nameof(selector)); - } + ArgumentNullException.ThrowIfNull(selector); Func, EntityQuery> entityQueryReplay = _entityQueryReplay; Func, IQueryable> queryableReplay = _queryableReplay; @@ -228,10 +219,7 @@ public QueryBuilder Take(int count) /// public QueryBuilder ThenBy(Expression> keySelector) { - if (keySelector == null) - { - throw new ArgumentNullException(nameof(keySelector)); - } + ArgumentNullException.ThrowIfNull(keySelector); Func, EntityQuery> entityQueryReplay = _entityQueryReplay; Func, IQueryable> queryableReplay = _queryableReplay; @@ -264,10 +252,7 @@ public QueryBuilder ThenBy(Expression> keySelector) /// public QueryBuilder ThenByDescending(Expression> keySelector) { - if (keySelector == null) - { - throw new ArgumentNullException(nameof(keySelector)); - } + ArgumentNullException.ThrowIfNull(keySelector); Func, EntityQuery> entityQueryReplay = _entityQueryReplay; Func, IQueryable> queryableReplay = _queryableReplay; @@ -299,10 +284,7 @@ public QueryBuilder ThenByDescending(Expression> keySelec /// public QueryBuilder Where(Expression> predicate) { - if (predicate == null) - { - throw new ArgumentNullException(nameof(predicate)); - } + ArgumentNullException.ThrowIfNull(predicate); Func, EntityQuery> entityQueryReplay = _entityQueryReplay; Func, IQueryable> queryableReplay = _queryableReplay; @@ -338,10 +320,7 @@ public QueryBuilder Where(Expression> predicate) /// public EntityQuery ApplyTo(EntityQuery entityQuery) { - if (entityQuery == null) - { - throw new ArgumentNullException(nameof(entityQuery)); - } + ArgumentNullException.ThrowIfNull(entityQuery); entityQuery.IncludeTotalCount = RequestTotalItemCount; if (_entityQueryReplay != null) @@ -361,10 +340,7 @@ public EntityQuery ApplyTo(EntityQuery entityQuery) /// public IEnumerable ApplyTo(IEnumerable enumerable) { - if (enumerable == null) - { - throw new ArgumentNullException(nameof(enumerable)); - } + ArgumentNullException.ThrowIfNull(enumerable); return ApplyTo(enumerable.AsQueryable()); } @@ -379,10 +355,7 @@ public IEnumerable ApplyTo(IEnumerable enumerable) /// public IQueryable ApplyTo(IQueryable queryable) { - if (queryable == null) - { - throw new ArgumentNullException(nameof(queryable)); - } + ArgumentNullException.ThrowIfNull(queryable); if (_queryableReplay != null) { @@ -401,10 +374,7 @@ public IQueryable ApplyTo(IQueryable queryable) /// public ObservableCollection ApplyTo(ObservableCollection collection) { - if (collection == null) - { - throw new ArgumentNullException(nameof(collection)); - } + ArgumentNullException.ThrowIfNull(collection); return new ObservableCollection(ApplyTo((IEnumerable)collection)); } diff --git a/src/OpenRiaServices.Client/Framework/QueryCompletedResult.cs b/src/OpenRiaServices.Client/Framework/QueryCompletedResult.cs index 7995b1b0f..7915eeb4a 100644 --- a/src/OpenRiaServices.Client/Framework/QueryCompletedResult.cs +++ b/src/OpenRiaServices.Client/Framework/QueryCompletedResult.cs @@ -25,18 +25,9 @@ public class QueryCompletedResult /// A collection of validation errors. public QueryCompletedResult(IEnumerable entities, IEnumerable includedEntities, int totalCount, IEnumerable validationErrors) { - if (entities == null) - { - throw new ArgumentNullException(nameof(entities)); - } - if (includedEntities == null) - { - throw new ArgumentNullException(nameof(includedEntities)); - } - if (validationErrors == null) - { - throw new ArgumentNullException(nameof(validationErrors)); - } + ArgumentNullException.ThrowIfNull(entities); + ArgumentNullException.ThrowIfNull(includedEntities); + ArgumentNullException.ThrowIfNull(validationErrors); this._entities = entities.ToList().AsReadOnly(); this._includedEntities = includedEntities.ToList().AsReadOnly(); diff --git a/src/OpenRiaServices.Client/Framework/SubmitCompletedResult.cs b/src/OpenRiaServices.Client/Framework/SubmitCompletedResult.cs index 04e6e33f5..491471b5f 100644 --- a/src/OpenRiaServices.Client/Framework/SubmitCompletedResult.cs +++ b/src/OpenRiaServices.Client/Framework/SubmitCompletedResult.cs @@ -21,14 +21,8 @@ public class SubmitCompletedResult /// DomainService for the submit operation. public SubmitCompletedResult(EntityChangeSet changeSet, IEnumerable operationResults) { - if (changeSet == null) - { - throw new ArgumentNullException(nameof(changeSet)); - } - if (operationResults == null) - { - throw new ArgumentNullException(nameof(operationResults)); - } + ArgumentNullException.ThrowIfNull(changeSet); + ArgumentNullException.ThrowIfNull(operationResults); this._changeSet = changeSet; this._operationResults =new ReadOnlyCollection(operationResults.ToList()); diff --git a/src/OpenRiaServices.Client/Framework/SubmitOperation.cs b/src/OpenRiaServices.Client/Framework/SubmitOperation.cs index aa777737e..0755b5be9 100644 --- a/src/OpenRiaServices.Client/Framework/SubmitOperation.cs +++ b/src/OpenRiaServices.Client/Framework/SubmitOperation.cs @@ -29,10 +29,7 @@ public SubmitOperation(EntityChangeSet changeSet, Task sumitResultTask, CancellationTokenSource? cancellationTokenSource) : base(userState, cancellationTokenSource) { - if (changeSet == null) - { - throw new ArgumentNullException(nameof(changeSet)); - } + ArgumentNullException.ThrowIfNull(changeSet); this._completeAction = completeAction; this._changeSet = changeSet; diff --git a/src/OpenRiaServices.Client/Framework/ValidationResultCollection.cs b/src/OpenRiaServices.Client/Framework/ValidationResultCollection.cs index 0fef1fdbb..8b99778a4 100644 --- a/src/OpenRiaServices.Client/Framework/ValidationResultCollection.cs +++ b/src/OpenRiaServices.Client/Framework/ValidationResultCollection.cs @@ -197,10 +197,7 @@ protected virtual void OnPropertyErrorsChanged(string? propertyName) /// The item to be added. public void Add(ValidationResult item) { - if (item == null) - { - throw new ArgumentNullException(nameof(item)); - } + ArgumentNullException.ThrowIfNull(item); IEnumerable propertiesAffected = item.MemberNames; @@ -319,10 +316,7 @@ public bool IsReadOnly /// true if the removal was successful, otherwise false. public bool Remove(ValidationResult item) { - if (item == null) - { - throw new ArgumentNullException(nameof(item)); - } + ArgumentNullException.ThrowIfNull(item); IEnumerable propertiesAffected = item.MemberNames; diff --git a/src/OpenRiaServices.Client/Framework/ValidationResultInfo.cs b/src/OpenRiaServices.Client/Framework/ValidationResultInfo.cs index 6a9eb37d4..f39450fe8 100644 --- a/src/OpenRiaServices.Client/Framework/ValidationResultInfo.cs +++ b/src/OpenRiaServices.Client/Framework/ValidationResultInfo.cs @@ -38,15 +38,9 @@ public ValidationResultInfo() /// A collection of the names of the members the error originated from. public ValidationResultInfo(string message, IEnumerable sourceMemberNames) { - if (message == null) - { - throw new ArgumentNullException(nameof(message)); - } + ArgumentNullException.ThrowIfNull(message); - if (sourceMemberNames == null) - { - throw new ArgumentNullException(nameof(sourceMemberNames)); - } + ArgumentNullException.ThrowIfNull(sourceMemberNames); this._message = message; this._sourceMemberNames = sourceMemberNames; @@ -62,15 +56,9 @@ public ValidationResultInfo(string message, IEnumerable sourceMemberName /// A collection of the names of the members the error originated from. public ValidationResultInfo(string message, int errorCode, string stackTrace, IEnumerable sourceMemberNames) { - if (message == null) - { - throw new ArgumentNullException(nameof(message)); - } + ArgumentNullException.ThrowIfNull(message); - if (sourceMemberNames == null) - { - throw new ArgumentNullException(nameof(sourceMemberNames)); - } + ArgumentNullException.ThrowIfNull(sourceMemberNames); this._message = message; this._errorCode = errorCode; diff --git a/src/OpenRiaServices.Client/Framework/ValidationUtilities.cs b/src/OpenRiaServices.Client/Framework/ValidationUtilities.cs index 0053e0979..265b8a635 100644 --- a/src/OpenRiaServices.Client/Framework/ValidationUtilities.cs +++ b/src/OpenRiaServices.Client/Framework/ValidationUtilities.cs @@ -32,10 +32,7 @@ internal static class ValidationUtilities /// A new validation context. internal static ValidationContext CreateValidationContext(object instance, ValidationContext? parentContext) { - if (instance == null) - { - throw new ArgumentNullException(nameof(instance)); - } + ArgumentNullException.ThrowIfNull(instance); ValidationContext context = new ValidationContext(instance, parentContext, parentContext != null ? parentContext.Items : null); return context; @@ -604,15 +601,9 @@ internal static bool ValidateMethodCall(string methodName, ValidationContext validationContext, object[] parameters, List validationResults, bool performTypeValidation) { - if (string.IsNullOrEmpty(methodName)) - { - throw new ArgumentNullException(nameof(methodName)); - } + ArgumentException.ThrowIfNullOrEmpty(methodName); - if (validationContext == null) - { - throw new ArgumentNullException(nameof(validationContext)); - } + ArgumentNullException.ThrowIfNull(validationContext); if (validationContext.ObjectInstance == null) { diff --git a/src/OpenRiaServices.Client/Test/Client.Test/Authentication/WebContextBaseTest.cs b/src/OpenRiaServices.Client/Test/Client.Test/Authentication/WebContextBaseTest.cs index bbec640c2..868fc05e5 100644 --- a/src/OpenRiaServices.Client/Test/Client.Test/Authentication/WebContextBaseTest.cs +++ b/src/OpenRiaServices.Client/Test/Client.Test/Authentication/WebContextBaseTest.cs @@ -238,7 +238,7 @@ public void RaisePropertyChanged() ExceptionHelper.ExpectArgumentNullException( () => context.RaisePropertyChangedMock(null), "propertyName"); - ExceptionHelper.ExpectArgumentNullException( + ExceptionHelper.ExpectEmptyStringArgumentException( () => context.RaisePropertyChangedMock(string.Empty), "propertyName"); propertyName = "Property 1"; diff --git a/src/OpenRiaServices.EntityFramework/Framework/DbContextExtensions.cs b/src/OpenRiaServices.EntityFramework/Framework/DbContextExtensions.cs index 70a9cb730..588285ee2 100644 --- a/src/OpenRiaServices.EntityFramework/Framework/DbContextExtensions.cs +++ b/src/OpenRiaServices.EntityFramework/Framework/DbContextExtensions.cs @@ -23,22 +23,10 @@ public static class DbContextExtensions /// The corresponding public static void AttachAsModified(this IDbSet dbSet, T current, T original, DbContext dbContext) where T : class { - if (dbSet == null) - { - throw new ArgumentNullException(nameof(dbSet)); - } - if (current == null) - { - throw new ArgumentNullException(nameof(current)); - } - if (original == null) - { - throw new ArgumentNullException(nameof(original)); - } - if (dbContext == null) - { - throw new ArgumentNullException(nameof(dbContext)); - } + ArgumentNullException.ThrowIfNull(dbSet); + ArgumentNullException.ThrowIfNull(current); + ArgumentNullException.ThrowIfNull(original); + ArgumentNullException.ThrowIfNull(dbContext); DbEntityEntry entityEntry = dbContext.Entry(current); if (entityEntry.State == EntityState.Detached) @@ -72,18 +60,9 @@ public static void AttachAsModified(this IDbSet dbSet, T current, T origin /// The coresponding public static void AttachAsModified(this IDbSet dbSet, T entity, DbContext dbContext) where T : class { - if (dbSet == null) - { - throw new ArgumentNullException(nameof(dbSet)); - } - if (entity == null) - { - throw new ArgumentNullException(nameof(entity)); - } - if (dbContext == null) - { - throw new ArgumentNullException(nameof(dbContext)); - } + ArgumentNullException.ThrowIfNull(dbSet); + ArgumentNullException.ThrowIfNull(entity); + ArgumentNullException.ThrowIfNull(dbContext); DbEntityEntry entityEntry = dbContext.Entry(entity); if (entityEntry.State == EntityState.Detached) diff --git a/src/OpenRiaServices.EntityFramework/Framework/DbDomainServiceDescriptionProviderAttribute.cs b/src/OpenRiaServices.EntityFramework/Framework/DbDomainServiceDescriptionProviderAttribute.cs index 5e8b4563c..39afbbd12 100644 --- a/src/OpenRiaServices.EntityFramework/Framework/DbDomainServiceDescriptionProviderAttribute.cs +++ b/src/OpenRiaServices.EntityFramework/Framework/DbDomainServiceDescriptionProviderAttribute.cs @@ -72,10 +72,7 @@ public Type DbContextType /// The description provider. public override DomainServiceDescriptionProvider CreateProvider(Type domainServiceType, DomainServiceDescriptionProvider parent) { - if (domainServiceType == null) - { - throw new ArgumentNullException(nameof(domainServiceType)); - } + ArgumentNullException.ThrowIfNull(domainServiceType); if (_dbContextType == null) { diff --git a/src/OpenRiaServices.EntityFramework/Framework/LinqToEntitiesDomainServiceDescriptionProviderAttribute.cs b/src/OpenRiaServices.EntityFramework/Framework/LinqToEntitiesDomainServiceDescriptionProviderAttribute.cs index 04202c832..e6f61ae23 100644 --- a/src/OpenRiaServices.EntityFramework/Framework/LinqToEntitiesDomainServiceDescriptionProviderAttribute.cs +++ b/src/OpenRiaServices.EntityFramework/Framework/LinqToEntitiesDomainServiceDescriptionProviderAttribute.cs @@ -59,10 +59,7 @@ public Type ObjectContextType /// The description provider. public override DomainServiceDescriptionProvider CreateProvider(Type domainServiceType, DomainServiceDescriptionProvider parent) { - if (domainServiceType == null) - { - throw new ArgumentNullException(nameof(domainServiceType)); - } + ArgumentNullException.ThrowIfNull(domainServiceType); if (this._objectContextType == null) { diff --git a/src/OpenRiaServices.EntityFramework/Framework/LinqToEntitiesTypeDescriptionContext.cs b/src/OpenRiaServices.EntityFramework/Framework/LinqToEntitiesTypeDescriptionContext.cs index 533ff4a23..1bf6a4ff9 100644 --- a/src/OpenRiaServices.EntityFramework/Framework/LinqToEntitiesTypeDescriptionContext.cs +++ b/src/OpenRiaServices.EntityFramework/Framework/LinqToEntitiesTypeDescriptionContext.cs @@ -29,10 +29,7 @@ internal class LinqToEntitiesTypeDescriptionContext : TypeDescriptionContextBase /// The ObjectContext Type public LinqToEntitiesTypeDescriptionContext(Type contextType) { - if (contextType == null) - { - throw new ArgumentNullException(nameof(contextType)); - } + ArgumentNullException.ThrowIfNull(contextType); this._contextType = contextType; } diff --git a/src/OpenRiaServices.EntityFramework/Framework/MetadataWorkspaceUtilities.cs b/src/OpenRiaServices.EntityFramework/Framework/MetadataWorkspaceUtilities.cs index 175e17295..994983af3 100644 --- a/src/OpenRiaServices.EntityFramework/Framework/MetadataWorkspaceUtilities.cs +++ b/src/OpenRiaServices.EntityFramework/Framework/MetadataWorkspaceUtilities.cs @@ -217,20 +217,11 @@ public static bool IsMetadata(string path) public MetadataWorkspaceInfo(string csdlPath, string mslPath, string ssdlPath) { - if (csdlPath == null) - { - throw new ArgumentNullException(nameof(csdlPath)); - } + ArgumentNullException.ThrowIfNull(csdlPath); - if (mslPath == null) - { - throw new ArgumentNullException(nameof(mslPath)); - } + ArgumentNullException.ThrowIfNull(mslPath); - if (ssdlPath == null) - { - throw new ArgumentNullException(nameof(ssdlPath)); - } + ArgumentNullException.ThrowIfNull(ssdlPath); this.Csdl = csdlPath; this.Msl = mslPath; diff --git a/src/OpenRiaServices.EntityFramework/Framework/ObjectContextExtensions.cs b/src/OpenRiaServices.EntityFramework/Framework/ObjectContextExtensions.cs index e9ac41077..dae81196c 100644 --- a/src/OpenRiaServices.EntityFramework/Framework/ObjectContextExtensions.cs +++ b/src/OpenRiaServices.EntityFramework/Framework/ObjectContextExtensions.cs @@ -22,18 +22,9 @@ public static class ObjectContextExtensions /// The original entity state public static void AttachAsModified(this ObjectSet objectSet, T current, T original) where T : class { - if (objectSet == null) - { - throw new ArgumentNullException(nameof(objectSet)); - } - if (current == null) - { - throw new ArgumentNullException(nameof(current)); - } - if (original == null) - { - throw new ArgumentNullException(nameof(original)); - } + ArgumentNullException.ThrowIfNull(objectSet); + ArgumentNullException.ThrowIfNull(current); + ArgumentNullException.ThrowIfNull(original); // Attach the entity if it is not already attached, or if it is already // attached, transition to Modified @@ -67,14 +58,8 @@ public static void AttachAsModified(this ObjectSet objectSet, T current, T /// The current entity state public static void AttachAsModified(this ObjectSet objectSet, T entity) where T : class { - if (objectSet == null) - { - throw new ArgumentNullException(nameof(objectSet)); - } - if (entity == null) - { - throw new ArgumentNullException(nameof(entity)); - } + ArgumentNullException.ThrowIfNull(objectSet); + ArgumentNullException.ThrowIfNull(entity); ObjectContext context = objectSet.Context; EntityState currState = ObjectContextUtilities.GetEntityState(context, entity); diff --git a/src/OpenRiaServices.EntityFramework/Framework/ObjectContextUtilities.cs b/src/OpenRiaServices.EntityFramework/Framework/ObjectContextUtilities.cs index f14fc45d8..a8fe05528 100644 --- a/src/OpenRiaServices.EntityFramework/Framework/ObjectContextUtilities.cs +++ b/src/OpenRiaServices.EntityFramework/Framework/ObjectContextUtilities.cs @@ -46,14 +46,8 @@ internal static class ObjectContextUtilities /// is not mapped. public static StructuralType GetEdmType(MetadataWorkspace workspace, Type clrType) { - if (workspace == null) - { - throw new ArgumentNullException(nameof(workspace)); - } - if (clrType == null) - { - throw new ArgumentNullException(nameof(clrType)); - } + ArgumentNullException.ThrowIfNull(workspace); + ArgumentNullException.ThrowIfNull(clrType); if (clrType.IsPrimitive || clrType == typeof(object)) { @@ -100,14 +94,8 @@ public static StructuralType GetEdmType(MetadataWorkspace workspace, Type clrTyp /// The current of the specified entity public static EntityState GetEntityState(ObjectContext context, object entity) { - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } - if (entity == null) - { - throw new ArgumentNullException(nameof(entity)); - } + ArgumentNullException.ThrowIfNull(context); + ArgumentNullException.ThrowIfNull(entity); ObjectStateEntry stateEntry = null; if (!context.ObjectStateManager.TryGetObjectStateEntry(entity, out stateEntry)) diff --git a/src/OpenRiaServices.EntityFramework/Framework/OpenRiaServices.EntityFramework.csproj b/src/OpenRiaServices.EntityFramework/Framework/OpenRiaServices.EntityFramework.csproj index 1ccbb1187..f36fbb78f 100644 --- a/src/OpenRiaServices.EntityFramework/Framework/OpenRiaServices.EntityFramework.csproj +++ b/src/OpenRiaServices.EntityFramework/Framework/OpenRiaServices.EntityFramework.csproj @@ -12,6 +12,7 @@ + True diff --git a/src/OpenRiaServices.Hosting.Local/Framework/DomainServiceProxy.cs b/src/OpenRiaServices.Hosting.Local/Framework/DomainServiceProxy.cs index 6036f118c..667ede3c2 100644 --- a/src/OpenRiaServices.Hosting.Local/Framework/DomainServiceProxy.cs +++ b/src/OpenRiaServices.Hosting.Local/Framework/DomainServiceProxy.cs @@ -123,10 +123,7 @@ public static TDomainServiceContract Create(); @@ -245,20 +242,11 @@ private static void InitializeStaticDelegates(Type proxyType, Delegate queryDele public static void AssociateOriginal(object domainServiceProxy, TEntity current, TEntity original) where TEntity : new() { - if (domainServiceProxy == null) - { - throw new ArgumentNullException(nameof(domainServiceProxy)); - } + ArgumentNullException.ThrowIfNull(domainServiceProxy); - if (current == null) - { - throw new ArgumentNullException(nameof(current)); - } + ArgumentNullException.ThrowIfNull(current); - if (original == null) - { - throw new ArgumentNullException(nameof(original)); - } + ArgumentNullException.ThrowIfNull(original); PropertyInfo currentOriginalProp = domainServiceProxy.GetType().GetProperty("CurrentOriginalEntityMap", BindingFlags.Public | BindingFlags.Instance); @@ -296,10 +284,7 @@ private sealed class HttpContextBaseServiceProvider : IServiceProvider /// The . public HttpContextBaseServiceProvider(HttpContextBase httpContextBase) { - if (httpContextBase == null) - { - throw new ArgumentNullException(nameof(httpContextBase)); - } + ArgumentNullException.ThrowIfNull(httpContextBase); this._httpContextBase = httpContextBase; } @@ -312,10 +297,7 @@ public HttpContextBaseServiceProvider(HttpContextBase httpContextBase) /// service object of type serviceType. public object GetService(Type serviceType) { - if (serviceType == null) - { - throw new ArgumentNullException(nameof(serviceType)); - } + ArgumentNullException.ThrowIfNull(serviceType); if (serviceType == typeof(IPrincipal)) { diff --git a/src/OpenRiaServices.Hosting.Local/Framework/Internal/DomainServiceProxyGenerator.cs b/src/OpenRiaServices.Hosting.Local/Framework/Internal/DomainServiceProxyGenerator.cs index 71e65d698..5b6c17760 100644 --- a/src/OpenRiaServices.Hosting.Local/Framework/Internal/DomainServiceProxyGenerator.cs +++ b/src/OpenRiaServices.Hosting.Local/Framework/Internal/DomainServiceProxyGenerator.cs @@ -66,15 +66,9 @@ static DomainServiceProxyGenerator() /// Returns a proxy type. public static Type Generate(Type domainServiceContract, Type domainService) { - if (domainServiceContract == null) - { - throw new ArgumentNullException(nameof(domainServiceContract)); - } + ArgumentNullException.ThrowIfNull(domainServiceContract); - if (domainService == null) - { - throw new ArgumentNullException(nameof(domainService)); - } + ArgumentNullException.ThrowIfNull(domainService); // Verify 'domainServiceContract' is actually a public interface. if (!domainServiceContract.IsInterface || (!domainServiceContract.IsPublic && !domainServiceContract.IsNestedPublic)) diff --git a/src/OpenRiaServices.Hosting.Local/Framework/OpenRiaServices.Hosting.Local.csproj b/src/OpenRiaServices.Hosting.Local/Framework/OpenRiaServices.Hosting.Local.csproj index 4754c8b41..d215bca48 100644 --- a/src/OpenRiaServices.Hosting.Local/Framework/OpenRiaServices.Hosting.Local.csproj +++ b/src/OpenRiaServices.Hosting.Local/Framework/OpenRiaServices.Hosting.Local.csproj @@ -15,6 +15,7 @@ + True diff --git a/src/OpenRiaServices.Hosting.Wcf.Endpoint/Framework/WCF/Tracing/InMemoryTraceListener.cs b/src/OpenRiaServices.Hosting.Wcf.Endpoint/Framework/WCF/Tracing/InMemoryTraceListener.cs index efa9f6ba3..2beb5f42f 100644 --- a/src/OpenRiaServices.Hosting.Wcf.Endpoint/Framework/WCF/Tracing/InMemoryTraceListener.cs +++ b/src/OpenRiaServices.Hosting.Wcf.Endpoint/Framework/WCF/Tracing/InMemoryTraceListener.cs @@ -57,10 +57,7 @@ public InMemoryTraceListener(string name) : base(name) /// Message to trace. public override void Write(string message) { - if (message == null) - { - throw new ArgumentNullException(nameof(message)); - } + ArgumentNullException.ThrowIfNull(message); currentEntry = currentEntry == null ? message : currentEntry + message; } diff --git a/src/OpenRiaServices.Hosting.Wcf.Endpoint/Framework/WCF/Tracing/TracingDomainServiceEndpointFactory.cs b/src/OpenRiaServices.Hosting.Wcf.Endpoint/Framework/WCF/Tracing/TracingDomainServiceEndpointFactory.cs index ef7b6272a..dd1dcb7f9 100644 --- a/src/OpenRiaServices.Hosting.Wcf.Endpoint/Framework/WCF/Tracing/TracingDomainServiceEndpointFactory.cs +++ b/src/OpenRiaServices.Hosting.Wcf.Endpoint/Framework/WCF/Tracing/TracingDomainServiceEndpointFactory.cs @@ -36,10 +36,7 @@ public TracingDomainServiceEndpointFactory() : base(string.Empty) { } /// The collection of endpoints. public override IEnumerable CreateEndpoints(DomainServiceDescription description, DomainServiceHost serviceHost, ContractDescription contractDescription) { - if (serviceHost == null) - { - throw new ArgumentNullException(nameof(serviceHost)); - } + ArgumentNullException.ThrowIfNull(serviceHost); if (this.Parameters["maxEntries"] != null) { @@ -96,10 +93,7 @@ public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRu public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher) { - if (endpointDispatcher == null) - { - throw new ArgumentNullException(nameof(endpointDispatcher)); - } + ArgumentNullException.ThrowIfNull(endpointDispatcher); endpointDispatcher.DispatchRuntime.SynchronizationContext = null; endpointDispatcher.DispatchRuntime.ConcurrencyMode = ConcurrencyMode.Single; diff --git a/src/OpenRiaServices.Hosting.Wcf/Framework/Linq/DynamicQueryable.cs b/src/OpenRiaServices.Hosting.Wcf/Framework/Linq/DynamicQueryable.cs index dfdbf7982..b401ed593 100644 --- a/src/OpenRiaServices.Hosting.Wcf/Framework/Linq/DynamicQueryable.cs +++ b/src/OpenRiaServices.Hosting.Wcf/Framework/Linq/DynamicQueryable.cs @@ -23,10 +23,8 @@ internal static class DynamicQueryable { public static IQueryable Where(this IQueryable source, string predicate, QueryResolver queryResolver) { - if (source == null) - throw new ArgumentNullException(nameof(source)); - if (predicate == null) - throw new ArgumentNullException(nameof(predicate)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(predicate); LambdaExpression lambda = DynamicExpression.ParseLambda(source.ElementType, typeof(bool), predicate, queryResolver); return source.Provider.CreateQuery( Expression.Call( @@ -37,10 +35,8 @@ public static IQueryable Where(this IQueryable source, string predicate, QueryRe public static IQueryable OrderBy(this IQueryable source, string ordering, QueryResolver queryResolver) { - if (source == null) - throw new ArgumentNullException(nameof(source)); - if (ordering == null) - throw new ArgumentNullException(nameof(ordering)); + ArgumentNullException.ThrowIfNull(source); + ArgumentNullException.ThrowIfNull(ordering); ParameterExpression[] parameters = new ParameterExpression[] { Expression.Parameter(source.ElementType, "") }; ExpressionParser parser = new ExpressionParser(parameters, ordering, queryResolver); @@ -62,8 +58,7 @@ public static IQueryable OrderBy(this IQueryable source, string ordering, QueryR public static IQueryable Take(this IQueryable source, int count) { - if (source == null) - throw new ArgumentNullException(nameof(source)); + ArgumentNullException.ThrowIfNull(source); return source.Provider.CreateQuery( Expression.Call( typeof(Queryable), "Take", @@ -73,8 +68,7 @@ public static IQueryable Take(this IQueryable source, int count) public static IQueryable Skip(this IQueryable source, int count) { - if (source == null) - throw new ArgumentNullException(nameof(source)); + ArgumentNullException.ThrowIfNull(source); return source.Provider.CreateQuery( Expression.Call( typeof(Queryable), "Skip", @@ -377,8 +371,7 @@ string GetString(Token token) public ExpressionParser(ParameterExpression[] parameters, string expression, QueryResolver queryResolver) { - if (expression == null) - throw new ArgumentNullException(nameof(expression)); + ArgumentNullException.ThrowIfNull(expression); this._queryResolver = queryResolver; if (parameters != null) diff --git a/src/OpenRiaServices.Hosting.Wcf/Framework/Linq/QueryDeserializer.cs b/src/OpenRiaServices.Hosting.Wcf/Framework/Linq/QueryDeserializer.cs index 444ee8265..ae2fe9ce1 100644 --- a/src/OpenRiaServices.Hosting.Wcf/Framework/Linq/QueryDeserializer.cs +++ b/src/OpenRiaServices.Hosting.Wcf/Framework/Linq/QueryDeserializer.cs @@ -62,10 +62,7 @@ private class PostProcessor : ExpressionVisitor private PostProcessor(DomainServiceDescription domainServiceDescription) { - if (domainServiceDescription == null) - { - throw new ArgumentNullException(nameof(domainServiceDescription)); - } + ArgumentNullException.ThrowIfNull(domainServiceDescription); this.domainServiceDescription = domainServiceDescription; } diff --git a/src/OpenRiaServices.Hosting.Wcf/Framework/Wcf/DomainServiceEndpointFactory.cs b/src/OpenRiaServices.Hosting.Wcf/Framework/Wcf/DomainServiceEndpointFactory.cs index 5597a324d..2a7338056 100644 --- a/src/OpenRiaServices.Hosting.Wcf/Framework/Wcf/DomainServiceEndpointFactory.cs +++ b/src/OpenRiaServices.Hosting.Wcf/Framework/Wcf/DomainServiceEndpointFactory.cs @@ -43,10 +43,7 @@ public string Name } set { - if (value == null) - { - throw new ArgumentNullException(nameof(value)); - } + ArgumentNullException.ThrowIfNull(value); this._name = value; } diff --git a/src/OpenRiaServices.Hosting.Wcf/Framework/Wcf/DomainServiceHost.cs b/src/OpenRiaServices.Hosting.Wcf/Framework/Wcf/DomainServiceHost.cs index 63f15f0a6..5b3ca2b75 100644 --- a/src/OpenRiaServices.Hosting.Wcf/Framework/Wcf/DomainServiceHost.cs +++ b/src/OpenRiaServices.Hosting.Wcf/Framework/Wcf/DomainServiceHost.cs @@ -35,15 +35,8 @@ public class DomainServiceHost : ServiceHost, IServiceProvider /// public DomainServiceHost(Type domainServiceType, params Uri[] baseAddresses) { - if (domainServiceType == null) - { - throw new ArgumentNullException(nameof(domainServiceType)); - } - - if (baseAddresses == null) - { - throw new ArgumentNullException(nameof(baseAddresses)); - } + ArgumentNullException.ThrowIfNull(domainServiceType); + ArgumentNullException.ThrowIfNull(baseAddresses); EnableClientAccessAttribute att = (EnableClientAccessAttribute)TypeDescriptor.GetAttributes(domainServiceType)[typeof(EnableClientAccessAttribute)]; @@ -71,10 +64,7 @@ public DomainServiceHost(Type domainServiceType, params Uri[] baseAddresses) [Obsolete("Resolve services from DomainService.ServiceContext instead")] public object GetService(Type serviceType) { - if (serviceType == null) - { - throw new ArgumentNullException(nameof(serviceType)); - } + ArgumentNullException.ThrowIfNull(serviceType); if (serviceType == typeof(IPrincipal)) { diff --git a/src/OpenRiaServices.Hosting.Wcf/Framework/Wcf/MessageEncoders/PoxBinaryMessageEncodingBindingElement.cs b/src/OpenRiaServices.Hosting.Wcf/Framework/Wcf/MessageEncoders/PoxBinaryMessageEncodingBindingElement.cs index 423870f62..6abb750a7 100644 --- a/src/OpenRiaServices.Hosting.Wcf/Framework/Wcf/MessageEncoders/PoxBinaryMessageEncodingBindingElement.cs +++ b/src/OpenRiaServices.Hosting.Wcf/Framework/Wcf/MessageEncoders/PoxBinaryMessageEncodingBindingElement.cs @@ -53,14 +53,8 @@ public XmlDictionaryReaderQuotas ReaderQuotas } set { - if (value == null) - { - throw new ArgumentNullException(nameof(value)); - } - else - { - value.CopyTo(this._readerQuotas); - } + ArgumentNullException.ThrowIfNull(value); + value.CopyTo(this._readerQuotas); } } #endif @@ -77,10 +71,7 @@ public override BindingElement Clone() public override IChannelFactory BuildChannelFactory(BindingContext context) { - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } + ArgumentNullException.ThrowIfNull(context); context.BindingParameters.Add(this); return context.BuildInnerChannelFactory(); @@ -88,10 +79,7 @@ public override IChannelFactory BuildChannelFactory(BindingC public override bool CanBuildChannelFactory(BindingContext context) { - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } + ArgumentNullException.ThrowIfNull(context); return context.CanBuildInnerChannelFactory(); } @@ -99,20 +87,14 @@ public override bool CanBuildChannelFactory(BindingContext context) #if NETFRAMEWORK public override IChannelListener BuildChannelListener(BindingContext context) { - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } + ArgumentNullException.ThrowIfNull(context); context.BindingParameters.Add(this); return context.BuildInnerChannelListener(); } public override bool CanBuildChannelListener(BindingContext context) { - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } + ArgumentNullException.ThrowIfNull(context); return context.CanBuildInnerChannelListener(); } @@ -126,10 +108,7 @@ private class PoxBinaryMessageEncoderFactory : MessageEncoderFactory public PoxBinaryMessageEncoderFactory(XmlDictionaryReaderQuotas readerQuotas) { - if (readerQuotas == null) - { - throw new ArgumentNullException(nameof(readerQuotas)); - } + ArgumentNullException.ThrowIfNull(readerQuotas); this._readerQuotas = readerQuotas; } @@ -165,14 +144,8 @@ private class PoxBinaryMessageEncoder : MessageEncoder public PoxBinaryMessageEncoder(MessageVersion messageVersion, XmlDictionaryReaderQuotas readerQuotas) { - if (messageVersion == null) - { - throw new ArgumentNullException(nameof(messageVersion)); - } - if (readerQuotas == null) - { - throw new ArgumentNullException(nameof(readerQuotas)); - } + ArgumentNullException.ThrowIfNull(messageVersion); + ArgumentNullException.ThrowIfNull(readerQuotas); this._readerQuotas = readerQuotas; this._messageVersion = messageVersion; } @@ -203,10 +176,7 @@ public override MessageVersion MessageVersion public override Message ReadMessage(ArraySegment buffer, BufferManager bufferManager, string contentType) { - if (bufferManager == null) - { - throw new ArgumentNullException(nameof(bufferManager)); - } + ArgumentNullException.ThrowIfNull(bufferManager); ThrowIfIncorrectContentType(contentType); #if !SILVERLIGHT @@ -219,10 +189,7 @@ public override Message ReadMessage(ArraySegment buffer, BufferManager buf public override Message ReadMessage(Stream stream, int maxSizeOfHeaders, string contentType) { - if (stream == null) - { - throw new ArgumentNullException(nameof(stream)); - } + ArgumentNullException.ThrowIfNull(stream); ThrowIfIncorrectContentType(contentType); @@ -235,11 +202,9 @@ public override Message ReadMessage(Stream stream, int maxSizeOfHeaders, string public override ArraySegment WriteMessage(Message message, int maxMessageSize, BufferManager bufferManager, int messageOffset) { - if (message == null) - throw new ArgumentNullException(nameof(message)); + ArgumentNullException.ThrowIfNull(message); - if (bufferManager == null) - throw new ArgumentNullException(nameof(bufferManager)); + ArgumentNullException.ThrowIfNull(bufferManager); if (maxMessageSize < 0) throw new ArgumentOutOfRangeException(nameof(maxMessageSize)); @@ -251,15 +216,9 @@ public override ArraySegment WriteMessage(Message message, int maxMessageS public override void WriteMessage(Message message, Stream stream) { - if (message == null) - { - throw new ArgumentNullException(nameof(message)); - } + ArgumentNullException.ThrowIfNull(message); - if (stream == null) - { - throw new ArgumentNullException(nameof(stream)); - } + ArgumentNullException.ThrowIfNull(stream); this.ThrowIfInvalidMessageVersion(message); @@ -650,10 +609,7 @@ public override Message CreateMessage() /// public override void WriteMessage(Stream stream) { - if (stream == null) - { - throw new ArgumentNullException(nameof(stream)); - } + ArgumentNullException.ThrowIfNull(stream); lock (this.ThisLock) { diff --git a/src/OpenRiaServices.LinqToSql/Framework/DataContextExtensions.cs b/src/OpenRiaServices.LinqToSql/Framework/DataContextExtensions.cs index 13af29d0e..709c3f026 100644 --- a/src/OpenRiaServices.LinqToSql/Framework/DataContextExtensions.cs +++ b/src/OpenRiaServices.LinqToSql/Framework/DataContextExtensions.cs @@ -16,10 +16,7 @@ public static class DataContextExtensions /// True if the entity is currently attached, false otherwise public static bool IsAttached(this ITable table, object entity) { - if (entity == null) - { - throw new ArgumentNullException(nameof(entity)); - } + ArgumentNullException.ThrowIfNull(entity); // Only way currently to determine if an entity is attached // is to see if original state is null diff --git a/src/OpenRiaServices.LinqToSql/Framework/LinqToSqlDomainServiceDescriptionProviderAttribute.cs b/src/OpenRiaServices.LinqToSql/Framework/LinqToSqlDomainServiceDescriptionProviderAttribute.cs index 63882b619..73a612b4d 100644 --- a/src/OpenRiaServices.LinqToSql/Framework/LinqToSqlDomainServiceDescriptionProviderAttribute.cs +++ b/src/OpenRiaServices.LinqToSql/Framework/LinqToSqlDomainServiceDescriptionProviderAttribute.cs @@ -54,10 +54,7 @@ public Type DataContextType /// The description provider. public override DomainServiceDescriptionProvider CreateProvider(Type domainServiceType, DomainServiceDescriptionProvider parent) { - if (domainServiceType == null) - { - throw new ArgumentNullException(nameof(domainServiceType)); - } + ArgumentNullException.ThrowIfNull(domainServiceType); if (this._dataContextType == null) { diff --git a/src/OpenRiaServices.LinqToSql/Framework/LinqToSqlTypeDescriptionContext.cs b/src/OpenRiaServices.LinqToSql/Framework/LinqToSqlTypeDescriptionContext.cs index 594e61b1d..d20c34ce0 100644 --- a/src/OpenRiaServices.LinqToSql/Framework/LinqToSqlTypeDescriptionContext.cs +++ b/src/OpenRiaServices.LinqToSql/Framework/LinqToSqlTypeDescriptionContext.cs @@ -23,10 +23,7 @@ internal class LinqToSqlTypeDescriptionContext : TypeDescriptionContextBase /// The DataContext type public LinqToSqlTypeDescriptionContext(Type dataContextType) { - if (dataContextType == null) - { - throw new ArgumentNullException(nameof(dataContextType)); - } + ArgumentNullException.ThrowIfNull(dataContextType); System.Data.Linq.DataContext dataContext = null; try diff --git a/src/OpenRiaServices.LinqToSql/Framework/OpenRiaServices.LinqToSql.csproj b/src/OpenRiaServices.LinqToSql/Framework/OpenRiaServices.LinqToSql.csproj index 91bbe6545..a5a05c283 100644 --- a/src/OpenRiaServices.LinqToSql/Framework/OpenRiaServices.LinqToSql.csproj +++ b/src/OpenRiaServices.LinqToSql/Framework/OpenRiaServices.LinqToSql.csproj @@ -10,6 +10,7 @@ + diff --git a/src/OpenRiaServices.Server.EntityFrameworkCore/Framework/DbContextEFCoreExtensions.cs b/src/OpenRiaServices.Server.EntityFrameworkCore/Framework/DbContextEFCoreExtensions.cs index 401938f24..dd8b24446 100644 --- a/src/OpenRiaServices.Server.EntityFrameworkCore/Framework/DbContextEFCoreExtensions.cs +++ b/src/OpenRiaServices.Server.EntityFrameworkCore/Framework/DbContextEFCoreExtensions.cs @@ -23,22 +23,10 @@ public static class DbContextEFCoreExtensions /// The corresponding public static void AttachAsModified(this DbSet dbSet, T current, T original, DbContext dbContext) where T : class { - if (dbSet == null) - { - throw new ArgumentNullException(nameof(dbSet)); - } - if (current == null) - { - throw new ArgumentNullException(nameof(current)); - } - if (original == null) - { - throw new ArgumentNullException(nameof(original)); - } - if (dbContext == null) - { - throw new ArgumentNullException(nameof(dbContext)); - } + ArgumentNullException.ThrowIfNull(dbSet); + ArgumentNullException.ThrowIfNull(current); + ArgumentNullException.ThrowIfNull(original); + ArgumentNullException.ThrowIfNull(dbContext); EntityEntry entityEntry = dbContext.Entry(current); if (entityEntry.State == EntityState.Detached) @@ -72,18 +60,9 @@ public static void AttachAsModified(this DbSet dbSet, T current, T origina /// The coresponding public static void AttachAsModified(this DbSet dbSet, T entity, DbContext dbContext) where T : class { - if (dbSet == null) - { - throw new ArgumentNullException(nameof(dbSet)); - } - if (entity == null) - { - throw new ArgumentNullException(nameof(entity)); - } - if (dbContext == null) - { - throw new ArgumentNullException(nameof(dbContext)); - } + ArgumentNullException.ThrowIfNull(dbSet); + ArgumentNullException.ThrowIfNull(entity); + ArgumentNullException.ThrowIfNull(dbContext); EntityEntry entityEntry = dbContext.Entry(entity); if (entityEntry.State == EntityState.Detached) diff --git a/src/OpenRiaServices.Server.EntityFrameworkCore/Framework/EFCoreTypeDescriptionContext.cs b/src/OpenRiaServices.Server.EntityFrameworkCore/Framework/EFCoreTypeDescriptionContext.cs index 53fc3e01e..5e806c567 100644 --- a/src/OpenRiaServices.Server.EntityFrameworkCore/Framework/EFCoreTypeDescriptionContext.cs +++ b/src/OpenRiaServices.Server.EntityFrameworkCore/Framework/EFCoreTypeDescriptionContext.cs @@ -29,10 +29,7 @@ internal class EFCoreTypeDescriptionContext /// The ObjectContext Type public EFCoreTypeDescriptionContext(Type contextType) { - if (contextType == null) - { - throw new ArgumentNullException(nameof(contextType)); - } + ArgumentNullException.ThrowIfNull(contextType); _contextType = contextType; } diff --git a/src/OpenRiaServices.Server.EntityFrameworkCore/Framework/OpenRiaServices.Server.EntityFrameworkCore.csproj b/src/OpenRiaServices.Server.EntityFrameworkCore/Framework/OpenRiaServices.Server.EntityFrameworkCore.csproj index 71224b6f7..847792f98 100644 --- a/src/OpenRiaServices.Server.EntityFrameworkCore/Framework/OpenRiaServices.Server.EntityFrameworkCore.csproj +++ b/src/OpenRiaServices.Server.EntityFrameworkCore/Framework/OpenRiaServices.Server.EntityFrameworkCore.csproj @@ -24,6 +24,7 @@ + diff --git a/src/OpenRiaServices.Server.EntityFrameworkCore/Test/DbContextModel/EFCoreModels.csproj b/src/OpenRiaServices.Server.EntityFrameworkCore/Test/DbContextModel/EFCoreModels.csproj index d0f08b923..96a7dda5d 100644 --- a/src/OpenRiaServices.Server.EntityFrameworkCore/Test/DbContextModel/EFCoreModels.csproj +++ b/src/OpenRiaServices.Server.EntityFrameworkCore/Test/DbContextModel/EFCoreModels.csproj @@ -18,4 +18,4 @@ - \ No newline at end of file + diff --git a/src/OpenRiaServices.Server.UnitTesting/Framework/DomainServiceTestHost.cs b/src/OpenRiaServices.Server.UnitTesting/Framework/DomainServiceTestHost.cs index 4daf38c17..54a189814 100644 --- a/src/OpenRiaServices.Server.UnitTesting/Framework/DomainServiceTestHost.cs +++ b/src/OpenRiaServices.Server.UnitTesting/Framework/DomainServiceTestHost.cs @@ -107,14 +107,8 @@ private DomainServiceTestHost(IServiceProvider serviceProvider, IPrincipal user) /// is thrown when is null private DomainServiceTestHost(IDomainServiceFactory factory, IServiceProvider serviceProvider, IPrincipal user) { - if (serviceProvider == null) - { - throw new ArgumentNullException(nameof(serviceProvider)); - } - if (user == null) - { - throw new ArgumentNullException(nameof(user)); - } + ArgumentNullException.ThrowIfNull(serviceProvider); + ArgumentNullException.ThrowIfNull(user); this._factory = factory; this._serviceProvider = serviceProvider; @@ -139,10 +133,7 @@ public IDomainServiceFactory Factory set { - if (value == null) - { - throw new ArgumentNullException(nameof(value)); - } + ArgumentNullException.ThrowIfNull(value); this._factory = value; } } @@ -165,10 +156,7 @@ public IServiceProvider ServiceProvider set { - if (value == null) - { - throw new ArgumentNullException(nameof(value)); - } + ArgumentNullException.ThrowIfNull(value); this._serviceProvider = value; } } @@ -182,10 +170,7 @@ public IPrincipal User get => _user; set { - if (value == null) - { - throw new ArgumentNullException(nameof(value)); - } + ArgumentNullException.ThrowIfNull(value); this._user = value; } } @@ -1171,10 +1156,7 @@ private class DomainServiceFactory : IDomainServiceFactory public DomainServiceFactory(Func createDomainService) { - if (createDomainService == null) - { - throw new ArgumentNullException(nameof(createDomainService)); - } + ArgumentNullException.ThrowIfNull(createDomainService); this._createDomainService = createDomainService; } diff --git a/src/OpenRiaServices.Server.UnitTesting/Framework/OpenRiaServices.Server.UnitTesting.csproj b/src/OpenRiaServices.Server.UnitTesting/Framework/OpenRiaServices.Server.UnitTesting.csproj index 012dea6b3..de036d8c4 100644 --- a/src/OpenRiaServices.Server.UnitTesting/Framework/OpenRiaServices.Server.UnitTesting.csproj +++ b/src/OpenRiaServices.Server.UnitTesting/Framework/OpenRiaServices.Server.UnitTesting.csproj @@ -12,6 +12,7 @@ + True True diff --git a/src/OpenRiaServices.Server.UnitTesting/Framework/OperationContext.cs b/src/OpenRiaServices.Server.UnitTesting/Framework/OperationContext.cs index 0a29015dc..106109123 100644 --- a/src/OpenRiaServices.Server.UnitTesting/Framework/OperationContext.cs +++ b/src/OpenRiaServices.Server.UnitTesting/Framework/OperationContext.cs @@ -10,18 +10,9 @@ internal class OperationContext public OperationContext(DomainServiceContext domainServiceContext, DomainService domainService, DomainServiceDescription domainServiceDescription) { - if (domainServiceContext == null) - { - throw new ArgumentNullException(nameof(domainServiceContext)); - } - if (domainService == null) - { - throw new ArgumentNullException(nameof(domainService)); - } - if (domainServiceDescription == null) - { - throw new ArgumentNullException(nameof(domainServiceDescription)); - } + ArgumentNullException.ThrowIfNull(domainServiceContext); + ArgumentNullException.ThrowIfNull(domainService); + ArgumentNullException.ThrowIfNull(domainServiceDescription); this._domainServiceContext = domainServiceContext; this._domainService = domainService; diff --git a/src/OpenRiaServices.Server/Framework/Authentication/AuthenticationCodeProcessor.cs b/src/OpenRiaServices.Server/Framework/Authentication/AuthenticationCodeProcessor.cs index 89e6861ce..382663772 100644 --- a/src/OpenRiaServices.Server/Framework/Authentication/AuthenticationCodeProcessor.cs +++ b/src/OpenRiaServices.Server/Framework/Authentication/AuthenticationCodeProcessor.cs @@ -249,10 +249,7 @@ public override void ProcessGeneratedCode(DomainServiceDescription domainService /// A collection of comment statements that matches the input resource internal static CodeCommentStatementCollection GetDocComments(string resourceComment) { - if (resourceComment == null) - { - throw new ArgumentNullException(nameof(resourceComment)); - } + ArgumentNullException.ThrowIfNull(resourceComment); var commentCollection = new CodeCommentStatementCollection(); foreach (string comment in resourceComment.Split(new string[] { Environment.NewLine }, StringSplitOptions.None)) diff --git a/src/OpenRiaServices.Server/Framework/Data/AuthorizationAttribute.cs b/src/OpenRiaServices.Server/Framework/Data/AuthorizationAttribute.cs index 632c98521..c9eaf377e 100644 --- a/src/OpenRiaServices.Server/Framework/Data/AuthorizationAttribute.cs +++ b/src/OpenRiaServices.Server/Framework/Data/AuthorizationAttribute.cs @@ -42,14 +42,8 @@ public abstract class AuthorizationAttribute : Attribute /// public AuthorizationResult Authorize(IPrincipal principal, AuthorizationContext authorizationContext) { - if (principal == null) - { - throw new ArgumentNullException(nameof(principal)); - } - if (authorizationContext == null) - { - throw new ArgumentNullException(nameof(authorizationContext)); - } + ArgumentNullException.ThrowIfNull(principal); + ArgumentNullException.ThrowIfNull(authorizationContext); return this.IsAuthorized(principal, authorizationContext); } diff --git a/src/OpenRiaServices.Server/Framework/Data/AuthorizationContext.cs b/src/OpenRiaServices.Server/Framework/Data/AuthorizationContext.cs index 26b514e35..bd01eb9f6 100644 --- a/src/OpenRiaServices.Server/Framework/Data/AuthorizationContext.cs +++ b/src/OpenRiaServices.Server/Framework/Data/AuthorizationContext.cs @@ -103,10 +103,7 @@ public AuthorizationContext(object? instance, string operation, string operation public AuthorizationContext(object? instance, string operation, string operationType, AuthorizationContext authorizationContext) : this((IServiceProvider) authorizationContext) { - if (authorizationContext == null) - { - throw new ArgumentNullException(nameof(authorizationContext)); - } + ArgumentNullException.ThrowIfNull(authorizationContext); // We use the _items field rather than the property to preserve the lazy instantiation semantics if it's null this.Setup(instance, operation, operationType, authorizationContext._items); @@ -234,17 +231,11 @@ private void Setup(object? instance, string operation, string operationType, IDi this._instance = instance; // Operation is required - if (string.IsNullOrEmpty(operation)) - { - throw new ArgumentNullException(nameof(operation)); - } + ArgumentException.ThrowIfNullOrEmpty(operation); this._operation = operation; // OperationType is required - if (string.IsNullOrEmpty(operationType)) - { - throw new ArgumentNullException(nameof(operationType)); - } + ArgumentException.ThrowIfNullOrEmpty(operationType); this._operationType = operationType; // Snapshot the dictionary if provided, else create lazily on demand diff --git a/src/OpenRiaServices.Server/Framework/Data/ChangeSet.cs b/src/OpenRiaServices.Server/Framework/Data/ChangeSet.cs index 9442676ef..d2b718391 100644 --- a/src/OpenRiaServices.Server/Framework/Data/ChangeSet.cs +++ b/src/OpenRiaServices.Server/Framework/Data/ChangeSet.cs @@ -29,10 +29,7 @@ public sealed class ChangeSet /// if is null. public ChangeSet(IEnumerable changeSetEntries) { - if (changeSetEntries == null) - { - throw new ArgumentNullException(nameof(changeSetEntries)); - } + ArgumentNullException.ThrowIfNull(changeSetEntries); // ensure the changeset is valid ValidateChangeSetEntries(changeSetEntries); @@ -245,15 +242,9 @@ private Dictionary> AssociatedStoreEntities /// the 's items. public void Replace(TEntity clientEntity, TEntity returnedEntity) where TEntity : class { - if (clientEntity == null) - { - throw new ArgumentNullException(nameof(clientEntity)); - } + ArgumentNullException.ThrowIfNull(clientEntity); - if (returnedEntity == null) - { - throw new ArgumentNullException(nameof(returnedEntity)); - } + ArgumentNullException.ThrowIfNull(returnedEntity); Type clientEntityType = clientEntity.GetType(); Type returnedEntityType = returnedEntity.GetType(); @@ -289,10 +280,7 @@ public void Replace(TEntity clientEntity, TEntity returnedEntity) where /// if is not in the change set. public TEntity GetOriginal(TEntity clientEntity) where TEntity : class { - if (clientEntity == null) - { - throw new ArgumentNullException(nameof(clientEntity)); - } + ArgumentNullException.ThrowIfNull(clientEntity); ChangeSetEntry entry = this._changeSetEntries.FirstOrDefault(p => object.ReferenceEquals(p.Entity, clientEntity)); if (entry == null) @@ -317,10 +305,7 @@ public TEntity GetOriginal(TEntity clientEntity) where TEntity : class /// The for the specified object. public ChangeOperation GetChangeOperation(object entity) { - if (entity == null) - { - throw new ArgumentNullException(nameof(entity)); - } + ArgumentNullException.ThrowIfNull(entity); // Rather than error for objects not in the changeset, // we need to return 'None', since this method can be @@ -368,14 +353,8 @@ public IEnumerable GetAssociatedChanges(TEntity entity, Expres private IEnumerable GetAssociatedChangesInternal(object entity, LambdaExpression expression, ChangeOperation? operationType) { - if (entity == null) - { - throw new ArgumentNullException(nameof(entity)); - } - if (expression == null) - { - throw new ArgumentNullException(nameof(expression)); - } + ArgumentNullException.ThrowIfNull(entity); + ArgumentNullException.ThrowIfNull(expression); this.VerifyExistsInChangeset(entity); @@ -628,20 +607,11 @@ public void Associate(TEntity clientEntity, TStoreEntity where TEntity : class where TStoreEntity : class { - if (clientEntity == null) - { - throw new ArgumentNullException(nameof(clientEntity)); - } + ArgumentNullException.ThrowIfNull(clientEntity); - if (storeEntity == null) - { - throw new ArgumentNullException(nameof(storeEntity)); - } + ArgumentNullException.ThrowIfNull(storeEntity); - if (storeToClientTransform == null) - { - throw new ArgumentNullException(nameof(storeToClientTransform)); - } + ArgumentNullException.ThrowIfNull(storeToClientTransform); // Verify the provided client entity exists in our changeset this.VerifyExistsInChangeset(clientEntity); @@ -671,10 +641,7 @@ public void Associate(TEntity clientEntity, TStoreEntity public IEnumerable GetAssociatedEntities(TStoreEntity storeEntity) where TEntity : class { - if (storeEntity == null) - { - throw new ArgumentNullException(nameof(storeEntity)); - } + ArgumentNullException.ThrowIfNull(storeEntity); List associatedModels = null; if (this.AssociatedStoreEntities.TryGetValue(storeEntity, out associatedModels)) @@ -732,15 +699,9 @@ private class AssociatedEntityInfo /// The entity transform. public AssociatedEntityInfo(object clientEntity, Action entityTransform) { - if (clientEntity == null) - { - throw new ArgumentNullException(nameof(clientEntity)); - } + ArgumentNullException.ThrowIfNull(clientEntity); - if (entityTransform == null) - { - throw new ArgumentNullException(nameof(entityTransform)); - } + ArgumentNullException.ThrowIfNull(entityTransform); this._clientEntity = clientEntity; this._entityTransform = entityTransform; diff --git a/src/OpenRiaServices.Server/Framework/Data/ChangeSetEntry.cs b/src/OpenRiaServices.Server/Framework/Data/ChangeSetEntry.cs index 779638bf8..0ab1b7139 100644 --- a/src/OpenRiaServices.Server/Framework/Data/ChangeSetEntry.cs +++ b/src/OpenRiaServices.Server/Framework/Data/ChangeSetEntry.cs @@ -39,10 +39,7 @@ public ChangeSetEntry() /// The operation to be performed public ChangeSetEntry(int id, object entity, object originalEntity, DomainOperation operation) { - if (entity == null) - { - throw new ArgumentNullException(nameof(entity)); - } + ArgumentNullException.ThrowIfNull(entity); this._id = id; this._entity = entity; diff --git a/src/OpenRiaServices.Server/Framework/Data/CodeProcessor.cs b/src/OpenRiaServices.Server/Framework/Data/CodeProcessor.cs index 8c1c61624..9d6ebd1eb 100644 --- a/src/OpenRiaServices.Server/Framework/Data/CodeProcessor.cs +++ b/src/OpenRiaServices.Server/Framework/Data/CodeProcessor.cs @@ -23,10 +23,7 @@ public abstract class CodeProcessor /// The used during code generation. protected CodeProcessor(CodeDomProvider codeDomProvider) { - if (codeDomProvider == null) - { - throw new ArgumentNullException(nameof(codeDomProvider)); - } + ArgumentNullException.ThrowIfNull(codeDomProvider); this._codeDomProvider = codeDomProvider; } diff --git a/src/OpenRiaServices.Server/Framework/Data/DomainOperationEntry.cs b/src/OpenRiaServices.Server/Framework/Data/DomainOperationEntry.cs index cb8567df1..b2968f7db 100644 --- a/src/OpenRiaServices.Server/Framework/Data/DomainOperationEntry.cs +++ b/src/OpenRiaServices.Server/Framework/Data/DomainOperationEntry.cs @@ -38,26 +38,11 @@ public abstract class DomainOperationEntry /// The method level attributes for the operation protected DomainOperationEntry(Type domainServiceType, string name, DomainOperation operation, Type returnType, IEnumerable parameters, AttributeCollection attributes) { - if (string.IsNullOrEmpty(name)) - { - throw new ArgumentNullException(nameof(name)); - } - if (returnType == null) - { - throw new ArgumentNullException(nameof(returnType)); - } - if (parameters == null) - { - throw new ArgumentNullException(nameof(parameters)); - } - if (attributes == null) - { - throw new ArgumentNullException(nameof(attributes)); - } - if (domainServiceType == null) - { - throw new ArgumentNullException(nameof(domainServiceType)); - } + ArgumentNullException.ThrowIfNull(domainServiceType); + ArgumentException.ThrowIfNullOrEmpty(name); + ArgumentNullException.ThrowIfNull(returnType); + ArgumentNullException.ThrowIfNull(parameters); + ArgumentNullException.ThrowIfNull(attributes); if (operation == DomainOperation.None) { diff --git a/src/OpenRiaServices.Server/Framework/Data/DomainOperationParameter.cs b/src/OpenRiaServices.Server/Framework/Data/DomainOperationParameter.cs index 4734611d4..0dba67598 100644 --- a/src/OpenRiaServices.Server/Framework/Data/DomainOperationParameter.cs +++ b/src/OpenRiaServices.Server/Framework/Data/DomainOperationParameter.cs @@ -21,20 +21,11 @@ public sealed class DomainOperationParameter /// The set of attributes for the parameter public DomainOperationParameter(string name, Type parameterType, AttributeCollection attributes) { - if (string.IsNullOrEmpty(name)) - { - throw new ArgumentNullException(nameof(name)); - } + ArgumentException.ThrowIfNullOrEmpty(name); - if (parameterType == null) - { - throw new ArgumentNullException(nameof(parameterType)); - } + ArgumentNullException.ThrowIfNull(parameterType); - if (attributes == null) - { - throw new ArgumentNullException(nameof(attributes)); - } + ArgumentNullException.ThrowIfNull(attributes); Name = name; ParameterType = parameterType; diff --git a/src/OpenRiaServices.Server/Framework/Data/DomainService.cs b/src/OpenRiaServices.Server/Framework/Data/DomainService.cs index 41f289a24..dac892e2d 100644 --- a/src/OpenRiaServices.Server/Framework/Data/DomainService.cs +++ b/src/OpenRiaServices.Server/Framework/Data/DomainService.cs @@ -146,10 +146,7 @@ protected ValidationContext? ValidationContext /// public AuthorizationResult IsAuthorized(DomainOperationEntry domainOperationEntry, object? entity) { - if (domainOperationEntry == null) - { - throw new ArgumentNullException(nameof(domainOperationEntry)); - } + ArgumentNullException.ThrowIfNull(domainOperationEntry); // A null entity is not permitted in a Submit. // Queries are always null. @@ -239,10 +236,7 @@ protected ChangeSet? ChangeSet /// instance. Overrides must call the base method. public virtual void Initialize(DomainServiceContext context) { - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } + ArgumentNullException.ThrowIfNull(context); if (this._serviceContext != null) { @@ -270,10 +264,7 @@ public async virtual ValueTask> QueryAsync(QueryDescrip try { - if (queryDescription == null) - { - throw new ArgumentNullException(nameof(queryDescription)); - } + ArgumentNullException.ThrowIfNull(queryDescription); this.EnsureInitialized(); this.CheckOperationType(DomainOperationType.Query); @@ -421,10 +412,7 @@ public virtual async ValueTask InvokeAsync(InvokeDescriptio { try { - if (invokeDescription == null) - { - throw new ArgumentNullException(nameof(invokeDescription)); - } + ArgumentNullException.ThrowIfNull(invokeDescription); this.EnsureInitialized(); this.CheckOperationType(DomainOperationType.Invoke); @@ -499,10 +487,7 @@ public virtual async ValueTask SubmitAsync(ChangeSet changeSet, Cancellati { try { - if (changeSet == null) - { - throw new ArgumentNullException(nameof(changeSet)); - } + ArgumentNullException.ThrowIfNull(changeSet); this._changeSet = changeSet; this.EnsureInitialized(); @@ -582,7 +567,7 @@ private static AuthorizationResult EvaluateAuthorization(IEnumerableA instance to release. public void ReleaseDomainService(DomainService domainService) { - if (domainService == null) - { - throw new ArgumentNullException(nameof(domainService)); - } + ArgumentNullException.ThrowIfNull(domainService); domainService.Dispose(); } } diff --git a/src/OpenRiaServices.Server/Framework/Data/DomainServiceDescription.cs b/src/OpenRiaServices.Server/Framework/Data/DomainServiceDescription.cs index 06f638581..923daa623 100644 --- a/src/OpenRiaServices.Server/Framework/Data/DomainServiceDescription.cs +++ b/src/OpenRiaServices.Server/Framework/Data/DomainServiceDescription.cs @@ -48,10 +48,7 @@ public sealed class DomainServiceDescription /// The Type of the DomainService internal DomainServiceDescription(Type domainServiceType) { - if (domainServiceType == null) - { - throw new ArgumentNullException(nameof(domainServiceType)); - } + ArgumentNullException.ThrowIfNull(domainServiceType); this._domainServiceType = domainServiceType; this._createSerializationType = (Type type) => this.CreateSerializationType(type); @@ -63,10 +60,7 @@ internal DomainServiceDescription(Type domainServiceType) /// The base internal DomainServiceDescription(DomainServiceDescription baseDescription) { - if (baseDescription == null) - { - throw new ArgumentNullException(nameof(baseDescription)); - } + ArgumentNullException.ThrowIfNull(baseDescription); this._domainServiceType = baseDescription._domainServiceType; this._attributes = baseDescription._attributes; @@ -201,10 +195,7 @@ public void AddOperation(DomainOperationEntry operation) { this.CheckInvalidUpdate(); - if (operation == null) - { - throw new ArgumentNullException(nameof(operation)); - } + ArgumentNullException.ThrowIfNull(operation); if (operation.DomainServiceType != this.DomainServiceType) { @@ -267,10 +258,7 @@ public DomainOperationEntry GetCustomMethod(Type entityType, string methodName) { this.EnsureInitialized(); - if (entityType == null) - { - throw new ArgumentNullException(nameof(entityType)); - } + ArgumentNullException.ThrowIfNull(entityType); if (string.IsNullOrEmpty(methodName)) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resource.DomainOperationEntry_ArgumentCannotBeNullOrEmpty, "methodName")); @@ -304,10 +292,7 @@ public IEnumerable GetCustomMethods(Type entityType) { this.EnsureInitialized(); - if (entityType == null) - { - throw new ArgumentNullException(nameof(entityType)); - } + ArgumentNullException.ThrowIfNull(entityType); Dictionary entityCustomMethods = null; if (this._customMethods.TryGetValue(entityType, out entityCustomMethods)) @@ -329,10 +314,7 @@ public DomainOperationEntry GetSubmitMethod(Type entityType, DomainOperation ope { this.EnsureInitialized(); - if (entityType == null) - { - throw new ArgumentNullException(nameof(entityType)); - } + ArgumentNullException.ThrowIfNull(entityType); if ((operation != DomainOperation.Insert) && (operation != DomainOperation.Update) && (operation != DomainOperation.Delete)) @@ -367,10 +349,7 @@ public IEnumerable GetParentAssociations(Type entityType) { this.EnsureInitialized(); - if (entityType == null) - { - throw new ArgumentNullException(nameof(entityType)); - } + ArgumentNullException.ThrowIfNull(entityType); List assocList = null; if (this._compositionMap.TryGetValue(entityType, out assocList)) @@ -431,10 +410,7 @@ private Type CreateSerializationType(Type t) /// has no base types. public Type GetRootEntityType(Type entityType) { - if (entityType == null) - { - throw new ArgumentNullException(nameof(entityType)); - } + ArgumentNullException.ThrowIfNull(entityType); EnsureInitialized(); Type rootType = null; @@ -464,10 +440,7 @@ public Type GetRootEntityType(Type entityType) /// had no visible base types. public Type GetEntityBaseType(Type entityType) { - if (entityType == null) - { - throw new ArgumentNullException(nameof(entityType)); - } + ArgumentNullException.ThrowIfNull(entityType); EnsureInitialized(); Type baseType = entityType.BaseType; @@ -489,10 +462,7 @@ public Type GetEntityBaseType(Type entityType) /// The description for the specified type public static DomainServiceDescription GetDescription(Type domainServiceType) { - if (domainServiceType == null) - { - throw new ArgumentNullException(nameof(domainServiceType)); - } + ArgumentNullException.ThrowIfNull(domainServiceType); if (domainServiceType.IsAbstract || domainServiceType.IsGenericType @@ -1929,10 +1899,7 @@ private void ValidateDerivedDomainOperations() /// True if the operation is supported, false otherwise. public bool IsOperationSupported(Type entityType, DomainOperation operationType) { - if (entityType == null) - { - throw new ArgumentNullException(nameof(entityType)); - } + ArgumentNullException.ThrowIfNull(entityType); if (operationType != DomainOperation.Insert && operationType != DomainOperation.Update && diff --git a/src/OpenRiaServices.Server/Framework/Data/DomainServiceDescriptionProvider.cs b/src/OpenRiaServices.Server/Framework/Data/DomainServiceDescriptionProvider.cs index b1606495c..2663870d0 100644 --- a/src/OpenRiaServices.Server/Framework/Data/DomainServiceDescriptionProvider.cs +++ b/src/OpenRiaServices.Server/Framework/Data/DomainServiceDescriptionProvider.cs @@ -26,10 +26,7 @@ public abstract class DomainServiceDescriptionProvider /// The existing parent description provider. May be null. protected DomainServiceDescriptionProvider(Type domainServiceType, DomainServiceDescriptionProvider parent) { - if (domainServiceType == null) - { - throw new ArgumentNullException(nameof(domainServiceType)); - } + ArgumentNullException.ThrowIfNull(domainServiceType); this._domainServiceType = domainServiceType; this._parentDescriptionProvider = parent; @@ -77,14 +74,8 @@ public virtual DomainServiceDescription GetDescription() /// The for the specified Type. public virtual ICustomTypeDescriptor GetTypeDescriptor(Type type, ICustomTypeDescriptor parent) { - if (type == null) - { - throw new ArgumentNullException(nameof(type)); - } - if (parent == null) - { - throw new ArgumentNullException(nameof(parent)); - } + ArgumentNullException.ThrowIfNull(type); + ArgumentNullException.ThrowIfNull(parent); if (this._parentDescriptionProvider != null) { @@ -106,10 +97,7 @@ public virtual ICustomTypeDescriptor GetTypeDescriptor(Type type, ICustomTypeDes /// false otherwise. public virtual bool LookupIsEntityType(Type type) { - if (type == null) - { - throw new ArgumentNullException(nameof(type)); - } + ArgumentNullException.ThrowIfNull(type); return false; } @@ -123,10 +111,7 @@ public virtual bool LookupIsEntityType(Type type) /// The operation attributes. public virtual AttributeCollection GetOperationAttributes(DomainOperationEntry operation) { - if (operation == null) - { - throw new ArgumentNullException(nameof(operation)); - } + ArgumentNullException.ThrowIfNull(operation); if (this._parentDescriptionProvider != null) { @@ -145,10 +130,7 @@ public virtual AttributeCollection GetOperationAttributes(DomainOperationEntry o /// Returns true if the is an entity, false otherwise. protected internal bool IsEntityType(Type type) { - if (type == null) - { - throw new ArgumentNullException(nameof(type)); - } + ArgumentNullException.ThrowIfNull(type); if (this._isEntityTypeFunc != null) { @@ -184,10 +166,7 @@ protected DomainServiceDescription CreateDescription() /// A new description based on the base description. protected DomainServiceDescription CreateDescription(DomainServiceDescription baseDescription) { - if (baseDescription == null) - { - throw new ArgumentNullException(nameof(baseDescription)); - } + ArgumentNullException.ThrowIfNull(baseDescription); return new DomainServiceDescription(baseDescription); } } diff --git a/src/OpenRiaServices.Server/Framework/Data/DomainServiceDescriptionProviderAttribute.cs b/src/OpenRiaServices.Server/Framework/Data/DomainServiceDescriptionProviderAttribute.cs index 1375a8ea9..eeae2c2ad 100644 --- a/src/OpenRiaServices.Server/Framework/Data/DomainServiceDescriptionProviderAttribute.cs +++ b/src/OpenRiaServices.Server/Framework/Data/DomainServiceDescriptionProviderAttribute.cs @@ -18,10 +18,7 @@ public class DomainServiceDescriptionProviderAttribute : Attribute /// The type public DomainServiceDescriptionProviderAttribute(Type domainServiceDescriptionProviderType) { - if (domainServiceDescriptionProviderType == null) - { - throw new ArgumentNullException(nameof(domainServiceDescriptionProviderType)); - } + ArgumentNullException.ThrowIfNull(domainServiceDescriptionProviderType); this._domainServiceDescriptionProviderType = domainServiceDescriptionProviderType; } @@ -57,10 +54,7 @@ public override object TypeId /// The description provider public virtual DomainServiceDescriptionProvider CreateProvider(Type domainServiceType, DomainServiceDescriptionProvider parent) { - if (domainServiceType == null) - { - throw new ArgumentNullException(nameof(domainServiceType)); - } + ArgumentNullException.ThrowIfNull(domainServiceType); if (!typeof(DomainService).IsAssignableFrom(domainServiceType)) { diff --git a/src/OpenRiaServices.Server/Framework/Data/DomainTypeDescriptionProvider.cs b/src/OpenRiaServices.Server/Framework/Data/DomainTypeDescriptionProvider.cs index e04b00678..e741fa045 100644 --- a/src/OpenRiaServices.Server/Framework/Data/DomainTypeDescriptionProvider.cs +++ b/src/OpenRiaServices.Server/Framework/Data/DomainTypeDescriptionProvider.cs @@ -18,10 +18,7 @@ internal class DomainTypeDescriptionProvider : TypeDescriptionProvider public DomainTypeDescriptionProvider(Type type, DomainServiceDescriptionProvider descriptionProvider) : base(TypeDescriptor.GetProvider(type)) { - if (descriptionProvider == null) - { - throw new ArgumentNullException(nameof(descriptionProvider)); - } + ArgumentNullException.ThrowIfNull(descriptionProvider); this._type = type; this._descriptionProvider = descriptionProvider; diff --git a/src/OpenRiaServices.Server/Framework/Data/InvokeDescription.cs b/src/OpenRiaServices.Server/Framework/Data/InvokeDescription.cs index 68ab849ed..77dc97dd6 100644 --- a/src/OpenRiaServices.Server/Framework/Data/InvokeDescription.cs +++ b/src/OpenRiaServices.Server/Framework/Data/InvokeDescription.cs @@ -18,10 +18,7 @@ public sealed class InvokeDescription /// The parameter values for the method if it requires any. public InvokeDescription(DomainOperationEntry domainOperationEntry, object[] parameterValues) { - if (domainOperationEntry == null) - { - throw new ArgumentNullException(nameof(domainOperationEntry)); - } + ArgumentNullException.ThrowIfNull(domainOperationEntry); this._domainOperationEntry = domainOperationEntry; this._parameterValues = parameterValues; diff --git a/src/OpenRiaServices.Server/Framework/Data/QueryDescription.cs b/src/OpenRiaServices.Server/Framework/Data/QueryDescription.cs index 7fc3db88a..159c3fef8 100644 --- a/src/OpenRiaServices.Server/Framework/Data/QueryDescription.cs +++ b/src/OpenRiaServices.Server/Framework/Data/QueryDescription.cs @@ -22,10 +22,7 @@ public sealed class QueryDescription /// The query operation to be processed public QueryDescription(DomainOperationEntry domainOperationEntry) { - if (domainOperationEntry == null) - { - throw new ArgumentNullException(nameof(domainOperationEntry)); - } + ArgumentNullException.ThrowIfNull(domainOperationEntry); if (domainOperationEntry.Operation != DomainOperation.Query) { throw new ArgumentOutOfRangeException(nameof(domainOperationEntry)); @@ -42,10 +39,7 @@ public QueryDescription(DomainOperationEntry domainOperationEntry) /// Parameter values for the method if it requires any public QueryDescription(DomainOperationEntry domainOperationEntry, object[] parameterValues) : this(domainOperationEntry) { - if (parameterValues == null) - { - throw new ArgumentNullException(nameof(parameterValues)); - } + ArgumentNullException.ThrowIfNull(parameterValues); this._parameterValues = parameterValues; } diff --git a/src/OpenRiaServices.Server/Framework/Data/ReflectionDomainServiceDescriptionProvider.cs b/src/OpenRiaServices.Server/Framework/Data/ReflectionDomainServiceDescriptionProvider.cs index 9bc741731..d9b926960 100644 --- a/src/OpenRiaServices.Server/Framework/Data/ReflectionDomainServiceDescriptionProvider.cs +++ b/src/OpenRiaServices.Server/Framework/Data/ReflectionDomainServiceDescriptionProvider.cs @@ -400,10 +400,7 @@ internal class ReflectionDomainOperationEntry : DomainOperationEntry public ReflectionDomainOperationEntry(Type domainServiceType, MethodInfo methodInfo, DomainOperation operation) : base(domainServiceType, methodInfo.Name, operation, methodInfo.ReturnType, GetMethodParameters(methodInfo), GetAttributeCollection(methodInfo)) { - if (methodInfo == null) - { - throw new ArgumentNullException(nameof(methodInfo)); - } + ArgumentNullException.ThrowIfNull(methodInfo); // Generic methods aren’t supported, and will be caught during DomainServiceDescription validation. if (!methodInfo.IsGenericMethodDefinition) diff --git a/src/OpenRiaServices.Server/Framework/Data/ServiceInvokeResult.cs b/src/OpenRiaServices.Server/Framework/Data/ServiceInvokeResult.cs index 8d4ec40fb..b8a33596d 100644 --- a/src/OpenRiaServices.Server/Framework/Data/ServiceInvokeResult.cs +++ b/src/OpenRiaServices.Server/Framework/Data/ServiceInvokeResult.cs @@ -29,8 +29,7 @@ public ServiceInvokeResult(object? result) /// the validation errors, should never be modified after beeing passed in public ServiceInvokeResult(IReadOnlyCollection validationErrors) { - if (validationErrors == null) - throw new ArgumentNullException(nameof(validationErrors)); + ArgumentNullException.ThrowIfNull(validationErrors); if (validationErrors.Count == 0) throw new ArgumentException(Resource.ValidationErrorsCannotBeEmpty, nameof(validationErrors)); diff --git a/src/OpenRiaServices.Server/Framework/Data/ServiceQueryResult.cs b/src/OpenRiaServices.Server/Framework/Data/ServiceQueryResult.cs index 46d2955dd..a0f24770b 100644 --- a/src/OpenRiaServices.Server/Framework/Data/ServiceQueryResult.cs +++ b/src/OpenRiaServices.Server/Framework/Data/ServiceQueryResult.cs @@ -29,8 +29,7 @@ public ServiceQueryResult(IEnumerable result, int? totalResult) /// the validation errors, should never be modified after beeing passed in public ServiceQueryResult(IReadOnlyCollection validationErrors) { - if (validationErrors == null) - throw new ArgumentNullException(nameof(validationErrors)); + ArgumentNullException.ThrowIfNull(validationErrors); if (validationErrors.Count == 0) throw new ArgumentException(Resource.ValidationErrorsCannotBeEmpty, nameof(validationErrors)); diff --git a/src/OpenRiaServices.Server/Test/AuthorizationContextTests.cs b/src/OpenRiaServices.Server/Test/AuthorizationContextTests.cs index 3d7923f07..e1bf0c5de 100644 --- a/src/OpenRiaServices.Server/Test/AuthorizationContextTests.cs +++ b/src/OpenRiaServices.Server/Test/AuthorizationContextTests.cs @@ -53,11 +53,11 @@ public void AuthorizationContext_Ctor_And_Properties() { // Operation param cannot be null or empty ExceptionHelper.ExpectArgumentNullExceptionStandard(() => new AuthorizationContext(/*instance*/ null, /*operation*/ null, "operationType", /*serviceProvider*/ null, items: null), "operation"); - ExceptionHelper.ExpectArgumentNullExceptionStandard(() => new AuthorizationContext(/*instance*/ null, /*operation*/ string.Empty, "operationType", /*serviceProvider*/ null, items: null), "operation"); + ExceptionHelper.ExpectEmptyStringArgumentException(() => new AuthorizationContext(/*instance*/ null, /*operation*/ string.Empty, "operationType", /*serviceProvider*/ null, items: null), "operation"); // Operation param cannot be null or empty ExceptionHelper.ExpectArgumentNullExceptionStandard(() => new AuthorizationContext(/*instance*/ null, "operation", /*operationType*/ null, /*serviceProvider*/ null, items: null), "operationType"); - ExceptionHelper.ExpectArgumentNullExceptionStandard(() => new AuthorizationContext(/*instance*/ null, "operation", /*operationType*/ string.Empty, /*serviceProvider*/ null, items: null), "operationType"); + ExceptionHelper.ExpectEmptyStringArgumentException(() => new AuthorizationContext(/*instance*/ null, "operation", /*operationType*/ string.Empty, /*serviceProvider*/ null, items: null), "operationType"); string instance = "mockEntity"; // type is only required to be object string operation = "testOp"; diff --git a/src/OpenRiaServices.Tools.CodeGenTask/OpenRiaServices.Tools.CodeGenTask.csproj b/src/OpenRiaServices.Tools.CodeGenTask/OpenRiaServices.Tools.CodeGenTask.csproj index 1b4da2730..f326c61a7 100644 --- a/src/OpenRiaServices.Tools.CodeGenTask/OpenRiaServices.Tools.CodeGenTask.csproj +++ b/src/OpenRiaServices.Tools.CodeGenTask/OpenRiaServices.Tools.CodeGenTask.csproj @@ -18,7 +18,7 @@ - + diff --git a/src/OpenRiaServices.Tools.TextTemplate/Framework/CSharpGenerators/AttributeGenerationHelpers/AttributeGeneratorHelper.cs b/src/OpenRiaServices.Tools.TextTemplate/Framework/CSharpGenerators/AttributeGenerationHelpers/AttributeGeneratorHelper.cs index cfd494296..addcfc341 100644 --- a/src/OpenRiaServices.Tools.TextTemplate/Framework/CSharpGenerators/AttributeGenerationHelpers/AttributeGeneratorHelper.cs +++ b/src/OpenRiaServices.Tools.TextTemplate/Framework/CSharpGenerators/AttributeGenerationHelpers/AttributeGeneratorHelper.cs @@ -195,10 +195,7 @@ private static void ValidateAttributeDeclarationRequirements(AttributeDeclaratio private static ICustomAttributeBuilder GetCustomAttributeBuilder(Type attributeType) { - if (attributeType == null) - { - throw new ArgumentNullException(nameof(attributeType)); - } + ArgumentNullException.ThrowIfNull(attributeType); ICustomAttributeBuilder cab = null; diff --git a/src/OpenRiaServices.Tools.TextTemplate/Framework/OpenRiaServices.Tools.TextTemplate.csproj b/src/OpenRiaServices.Tools.TextTemplate/Framework/OpenRiaServices.Tools.TextTemplate.csproj index 274fd506a..cec2fce5e 100644 --- a/src/OpenRiaServices.Tools.TextTemplate/Framework/OpenRiaServices.Tools.TextTemplate.csproj +++ b/src/OpenRiaServices.Tools.TextTemplate/Framework/OpenRiaServices.Tools.TextTemplate.csproj @@ -10,6 +10,7 @@ $(NoWarn);CS0618 + diff --git a/src/OpenRiaServices.Tools/Framework/ClientCodeGenerationOptions.cs b/src/OpenRiaServices.Tools/Framework/ClientCodeGenerationOptions.cs index c67ab8b0e..af7ca11e0 100644 --- a/src/OpenRiaServices.Tools/Framework/ClientCodeGenerationOptions.cs +++ b/src/OpenRiaServices.Tools/Framework/ClientCodeGenerationOptions.cs @@ -27,10 +27,7 @@ public string Language } set { - if (string.IsNullOrEmpty(value)) - { - throw new ArgumentNullException(nameof(value), Resource.Null_Language_Property); - } + ArgumentException.ThrowIfNullOrEmpty(value); this._language = value; } } diff --git a/src/OpenRiaServices.Tools/Framework/ClientProxyFixupCodeDomVisitor.cs b/src/OpenRiaServices.Tools/Framework/ClientProxyFixupCodeDomVisitor.cs index 231cf6a6e..07a4e9648 100644 --- a/src/OpenRiaServices.Tools/Framework/ClientProxyFixupCodeDomVisitor.cs +++ b/src/OpenRiaServices.Tools/Framework/ClientProxyFixupCodeDomVisitor.cs @@ -20,10 +20,7 @@ internal sealed class ClientProxyFixupCodeDomVisitor : CodeDomVisitor /// The current options. public ClientProxyFixupCodeDomVisitor(ClientCodeGenerationOptions options) { - if (options == null) - { - throw new ArgumentNullException(nameof(options)); - } + ArgumentNullException.ThrowIfNull(options); this._options = options; this._isCSharp = (this._options.Language == "C#"); diff --git a/src/OpenRiaServices.Tools/Framework/CodeDomClientCodeGenerator.cs b/src/OpenRiaServices.Tools/Framework/CodeDomClientCodeGenerator.cs index ec563bc35..3c688970b 100644 --- a/src/OpenRiaServices.Tools/Framework/CodeDomClientCodeGenerator.cs +++ b/src/OpenRiaServices.Tools/Framework/CodeDomClientCodeGenerator.cs @@ -71,20 +71,11 @@ public string GenerateCode(ICodeGenerationHost host, IEnumerable descriptions, ClientCodeGenerationOptions options) { - if (host == null) - { - throw new ArgumentNullException(nameof(host)); - } + ArgumentNullException.ThrowIfNull(host); - if (options == null) - { - throw new ArgumentNullException(nameof(options)); - } + ArgumentNullException.ThrowIfNull(options); - if (descriptions == null) - { - throw new ArgumentNullException(nameof(descriptions)); - } + ArgumentNullException.ThrowIfNull(descriptions); // Initialize all the instance variables this._host = host; @@ -551,10 +542,7 @@ private void GenerateDataContractTypes(IEnumerable typesToGenerate, ListThe to visit. public void Visit(CodeCompileUnit codeCompileUnit) { - if (codeCompileUnit == null) - { - throw new ArgumentNullException(nameof(codeCompileUnit)); - } + ArgumentNullException.ThrowIfNull(codeCompileUnit); this.VisitBase(codeCompileUnit); } diff --git a/src/OpenRiaServices.Tools/Framework/CodeGenUtilities.cs b/src/OpenRiaServices.Tools/Framework/CodeGenUtilities.cs index 030b27f26..fdba81d88 100644 --- a/src/OpenRiaServices.Tools/Framework/CodeGenUtilities.cs +++ b/src/OpenRiaServices.Tools/Framework/CodeGenUtilities.cs @@ -476,10 +476,7 @@ internal static CodeTypeReference GetTypeReference(string typeFullName, string c /// A string representing the safe type name. private static string GetSafeTypeName(string typeFullName, string containingNamespace, bool userType) { - if (string.IsNullOrEmpty(typeFullName)) - { - throw new ArgumentNullException(nameof(typeFullName)); - } + ArgumentException.ThrowIfNullOrEmpty(typeFullName); string typeName = typeFullName; string typeNamespace = string.Empty; @@ -803,10 +800,7 @@ internal static CodeCommentStatementCollection GenerateReturnsCodeComment(string /// A collection of comment statements that matches the input resource internal static CodeCommentStatementCollection GetDocComments(string resourceComment, bool isCSharp) { - if (resourceComment == null) - { - throw new ArgumentNullException(nameof(resourceComment)); - } + ArgumentNullException.ThrowIfNull(resourceComment); CodeCommentStatementCollection commentCollection = new CodeCommentStatementCollection(); foreach (string comment in resourceComment.Split(new string[] { Environment.NewLine }, StringSplitOptions.None)) @@ -828,10 +822,7 @@ internal static CodeCommentStatementCollection GetDocComments(string resourceCom /// reference error. private static bool RegisterTypeName(string typeNamespace, string typeName, string containingNamespace) { - if (string.IsNullOrEmpty(typeName)) - { - throw new ArgumentNullException(nameof(typeName)); - } + ArgumentException.ThrowIfNullOrEmpty(typeName); if (isVisualBasic || (containingNamespace == null)) { diff --git a/src/OpenRiaServices.Tools/Framework/DomainServiceCatalog.cs b/src/OpenRiaServices.Tools/Framework/DomainServiceCatalog.cs index 1a057b528..c7762d3ad 100644 --- a/src/OpenRiaServices.Tools/Framework/DomainServiceCatalog.cs +++ b/src/OpenRiaServices.Tools/Framework/DomainServiceCatalog.cs @@ -27,15 +27,9 @@ internal class DomainServiceCatalog /// is thrown if or is null. public DomainServiceCatalog(IEnumerable assembliesToLoad, ILogger logger) { - if (assembliesToLoad == null) - { - throw new ArgumentNullException(nameof(assembliesToLoad)); - } + ArgumentNullException.ThrowIfNull(assembliesToLoad); - if (logger == null) - { - throw new ArgumentNullException(nameof(logger)); - } + ArgumentNullException.ThrowIfNull(logger); this._logger = logger; @@ -54,15 +48,9 @@ public DomainServiceCatalog(IEnumerable assembliesToLoad, ILogger logger /// is thrown if or is null. public DomainServiceCatalog(Type domainServiceType, ILogger logger) { - if (domainServiceType == null) - { - throw new ArgumentNullException(nameof(domainServiceType)); - } + ArgumentNullException.ThrowIfNull(domainServiceType); - if (logger == null) - { - throw new ArgumentNullException(nameof(logger)); - } + ArgumentNullException.ThrowIfNull(logger); this._logger = logger; @@ -77,15 +65,9 @@ public DomainServiceCatalog(Type domainServiceType, ILogger logger) /// is thrown if or is null. public DomainServiceCatalog(IEnumerable domainServiceTypes, ILogger logger) { - if (domainServiceTypes == null) - { - throw new ArgumentNullException(nameof(domainServiceTypes)); - } + ArgumentNullException.ThrowIfNull(domainServiceTypes); - if (logger == null) - { - throw new ArgumentNullException(nameof(logger)); - } + ArgumentNullException.ThrowIfNull(logger); this._logger = logger; diff --git a/src/OpenRiaServices.Tools/Framework/EndpointRoutePattern.cs b/src/OpenRiaServices.Tools/Framework/EndpointRoutePattern.cs index 7b2fd491c..db061a0f1 100644 --- a/src/OpenRiaServices.Tools/Framework/EndpointRoutePattern.cs +++ b/src/OpenRiaServices.Tools/Framework/EndpointRoutePattern.cs @@ -5,7 +5,7 @@ namespace OpenRiaServices.Tools { /// - /// IMPORTANT: THIS IS AN EXACT copy of where all values are identical. + /// IMPORTANT: THIS IS AN EXACT copy of Server.EndpointRoutePattern where all values are identical. /// We don't use the server version in the options because we don't want to load in the Server assembly until a bit later /// after the options are created. /// diff --git a/src/OpenRiaServices.Tools/Framework/LinkedServerProjectCache.cs b/src/OpenRiaServices.Tools/Framework/LinkedServerProjectCache.cs index f25b2fb55..38da71a6b 100644 --- a/src/OpenRiaServices.Tools/Framework/LinkedServerProjectCache.cs +++ b/src/OpenRiaServices.Tools/Framework/LinkedServerProjectCache.cs @@ -33,25 +33,13 @@ internal class LinkedServerProjectCache /// Instance to use to read the project files. internal LinkedServerProjectCache(string rootProjectPath, string historyFilePath, ILogger logger, ProjectFileReader projectFileReader) { - if (string.IsNullOrEmpty(rootProjectPath)) - { - throw new ArgumentNullException(nameof(rootProjectPath)); - } + ArgumentException.ThrowIfNullOrEmpty(rootProjectPath); - if (string.IsNullOrEmpty(historyFilePath)) - { - throw new ArgumentNullException(nameof(historyFilePath)); - } + ArgumentException.ThrowIfNullOrEmpty(historyFilePath); - if (logger == null) - { - throw new ArgumentNullException(nameof(logger)); - } + ArgumentNullException.ThrowIfNull(logger); - if (projectFileReader == null) - { - throw new ArgumentNullException(nameof(projectFileReader)); - } + ArgumentNullException.ThrowIfNull(projectFileReader); this._rootProjectPath = rootProjectPath; this._historyFilePath = historyFilePath; @@ -118,20 +106,14 @@ internal string this[string projectPath] { get { - if (string.IsNullOrEmpty(projectPath)) - { - throw new ArgumentNullException(nameof(projectPath)); - } + ArgumentException.ThrowIfNullOrEmpty(projectPath); string result = null; this.LinkedServerProjectsByProject.TryGetValue(projectPath, out result); return result; } set { - if (string.IsNullOrEmpty(projectPath)) - { - throw new ArgumentNullException(nameof(projectPath)); - } + ArgumentException.ThrowIfNullOrEmpty(projectPath); this.LinkedServerProjectsByProject[projectPath] = value; this.IsFileCacheCurrent = false; } diff --git a/src/OpenRiaServices.Tools/Framework/MetadataPipeline/AttributeDeclaration.cs b/src/OpenRiaServices.Tools/Framework/MetadataPipeline/AttributeDeclaration.cs index 7478dc13f..c21634489 100644 --- a/src/OpenRiaServices.Tools/Framework/MetadataPipeline/AttributeDeclaration.cs +++ b/src/OpenRiaServices.Tools/Framework/MetadataPipeline/AttributeDeclaration.cs @@ -23,10 +23,7 @@ internal sealed class AttributeDeclaration /// The to represent. Cannot be null. public AttributeDeclaration(Type attributeType) { - if (attributeType == null) - { - throw new ArgumentNullException(nameof(attributeType)); - } + ArgumentNullException.ThrowIfNull(attributeType); this._attributeType = attributeType; this._errors = new List(); diff --git a/src/OpenRiaServices.Tools/Framework/MetadataPipeline/CustomAttributeGenerator.cs b/src/OpenRiaServices.Tools/Framework/MetadataPipeline/CustomAttributeGenerator.cs index e0156005a..c05191a4d 100644 --- a/src/OpenRiaServices.Tools/Framework/MetadataPipeline/CustomAttributeGenerator.cs +++ b/src/OpenRiaServices.Tools/Framework/MetadataPipeline/CustomAttributeGenerator.cs @@ -313,10 +313,7 @@ private static void GenerateCustomAttributesErrorCommentHeader(CodeCommentStatem /// The custom attribute builder for it. private static ICustomAttributeBuilder GetCustomAttributeBuilder(Type attributeType) { - if (attributeType == null) - { - throw new ArgumentNullException(nameof(attributeType)); - } + ArgumentNullException.ThrowIfNull(attributeType); ICustomAttributeBuilder cab = null; diff --git a/src/OpenRiaServices.Tools/Framework/MetadataPipeline/StandardCustomAttributeBuilder.cs b/src/OpenRiaServices.Tools/Framework/MetadataPipeline/StandardCustomAttributeBuilder.cs index c93cf7519..f6f7ac570 100644 --- a/src/OpenRiaServices.Tools/Framework/MetadataPipeline/StandardCustomAttributeBuilder.cs +++ b/src/OpenRiaServices.Tools/Framework/MetadataPipeline/StandardCustomAttributeBuilder.cs @@ -23,10 +23,7 @@ internal class StandardCustomAttributeBuilder : ICustomAttributeBuilder /// A representing the . public virtual AttributeDeclaration GetAttributeDeclaration(Attribute attribute) { - if (attribute == null) - { - throw new ArgumentNullException(nameof(attribute)); - } + ArgumentNullException.ThrowIfNull(attribute); Type attributeType = attribute.GetType(); AttributeDeclaration attributeDeclaration = new AttributeDeclaration(attributeType); diff --git a/src/OpenRiaServices.Tools/Framework/OpenRiaServices.Tools.csproj b/src/OpenRiaServices.Tools/Framework/OpenRiaServices.Tools.csproj index d3fbfd438..6cad60410 100644 --- a/src/OpenRiaServices.Tools/Framework/OpenRiaServices.Tools.csproj +++ b/src/OpenRiaServices.Tools/Framework/OpenRiaServices.Tools.csproj @@ -65,6 +65,7 @@ + diff --git a/src/OpenRiaServices.Tools/Framework/ProjectFileReader.cs b/src/OpenRiaServices.Tools/Framework/ProjectFileReader.cs index e377a6f57..f9ad38b7a 100644 --- a/src/OpenRiaServices.Tools/Framework/ProjectFileReader.cs +++ b/src/OpenRiaServices.Tools/Framework/ProjectFileReader.cs @@ -24,10 +24,7 @@ internal class ProjectFileReader : IDisposable /// The to use for warnings and errors. internal ProjectFileReader(ILogger logger) { - if (logger == null) - { - throw new ArgumentNullException(nameof(logger)); - } + ArgumentNullException.ThrowIfNull(logger); this._logger = logger; } @@ -79,10 +76,7 @@ internal static string ConvertToFullPath(string path, string projectPath) /// The project instance or null if it does not exist internal Project LoadProject(string projectPath) { - if (string.IsNullOrEmpty(projectPath)) - { - throw new ArgumentNullException(nameof(projectPath)); - } + ArgumentException.ThrowIfNullOrEmpty(projectPath); if (!File.Exists(projectPath)) { diff --git a/src/OpenRiaServices.Tools/Framework/ProjectSourceFileCache.cs b/src/OpenRiaServices.Tools/Framework/ProjectSourceFileCache.cs index e24c8a7be..a0bdf1a20 100644 --- a/src/OpenRiaServices.Tools/Framework/ProjectSourceFileCache.cs +++ b/src/OpenRiaServices.Tools/Framework/ProjectSourceFileCache.cs @@ -39,25 +39,13 @@ internal class ProjectSourceFileCache /// Instance to use to read the project files. internal ProjectSourceFileCache(string rootProjectPath, string historyFilePath, ILogger logger, ProjectFileReader projectFileReader) { - if (string.IsNullOrEmpty(rootProjectPath)) - { - throw new ArgumentNullException(nameof(rootProjectPath)); - } + ArgumentException.ThrowIfNullOrEmpty(rootProjectPath); - if (string.IsNullOrEmpty(historyFilePath)) - { - throw new ArgumentNullException(nameof(historyFilePath)); - } + ArgumentException.ThrowIfNullOrEmpty(historyFilePath); - if (logger == null) - { - throw new ArgumentNullException(nameof(logger)); - } + ArgumentNullException.ThrowIfNull(logger); - if (projectFileReader == null) - { - throw new ArgumentNullException(nameof(projectFileReader)); - } + ArgumentNullException.ThrowIfNull(projectFileReader); this._rootProjectPath = rootProjectPath; this._historyFilePath = historyFilePath; @@ -121,20 +109,14 @@ internal IEnumerable this[string projectPath] { get { - if (string.IsNullOrEmpty(projectPath)) - { - throw new ArgumentNullException(nameof(projectPath)); - } + ArgumentException.ThrowIfNullOrEmpty(projectPath); IEnumerable result = null; this.SourceFilesByProject.TryGetValue(projectPath, out result); return result; } set { - if (string.IsNullOrEmpty(projectPath)) - { - throw new ArgumentNullException(nameof(projectPath)); - } + ArgumentException.ThrowIfNullOrEmpty(projectPath); this.IsFileCacheCurrent = false; this.SourceFilesByProject[projectPath] = value; } @@ -168,10 +150,7 @@ internal IEnumerable GetAllKnownProjects() /// internal IEnumerable GetSourceFilesInProject(string projectPath) { - if (string.IsNullOrEmpty(projectPath)) - { - throw new ArgumentNullException(nameof(projectPath)); - } + ArgumentException.ThrowIfNullOrEmpty(projectPath); IEnumerable files = null; this.GetOrLoadSourceFilesByProject().TryGetValue(projectPath, out files); return files; diff --git a/src/OpenRiaServices.Tools/Framework/RiaClientFilesTask.cs b/src/OpenRiaServices.Tools/Framework/RiaClientFilesTask.cs index 60dd71ca3..68e9f2505 100644 --- a/src/OpenRiaServices.Tools/Framework/RiaClientFilesTask.cs +++ b/src/OpenRiaServices.Tools/Framework/RiaClientFilesTask.cs @@ -695,10 +695,7 @@ protected void DeleteFolderIfEmpty(string folderPath) /// The input without any trailing slashes internal static string NormalizeFolderPath(string path) { - if (path == null) - { - throw new ArgumentNullException(nameof(path)); - } + ArgumentNullException.ThrowIfNull(path); // Empty paths are not accepted by Path.GetFullPath if (path.Length > 0) diff --git a/src/OpenRiaServices.Tools/Framework/SharedTypes/SharedAssemblies.cs b/src/OpenRiaServices.Tools/Framework/SharedTypes/SharedAssemblies.cs index ccc925617..4ce6096c7 100644 --- a/src/OpenRiaServices.Tools/Framework/SharedTypes/SharedAssemblies.cs +++ b/src/OpenRiaServices.Tools/Framework/SharedTypes/SharedAssemblies.cs @@ -27,10 +27,7 @@ internal sealed class SharedAssemblies : IDisposable /// Optional logger to use to report errors or warnings public SharedAssemblies(IEnumerable assemblyFileNames, IEnumerable assemblySearchPaths, ILogger logger) { - if (assemblyFileNames == null) - { - throw new ArgumentNullException(nameof(assemblyFileNames)); - } + ArgumentNullException.ThrowIfNull(assemblyFileNames); _logger = logger; _sharedTypeByName = new Dictionary(StringComparer.Ordinal); _resolver = new CustomAssemblyResolver(assemblySearchPaths ?? Enumerable.Empty()); diff --git a/src/OpenRiaServices.Tools/Framework/SharedTypes/SourceFileLocationService.cs b/src/OpenRiaServices.Tools/Framework/SharedTypes/SourceFileLocationService.cs index fa83f8a57..7d441d018 100644 --- a/src/OpenRiaServices.Tools/Framework/SharedTypes/SourceFileLocationService.cs +++ b/src/OpenRiaServices.Tools/Framework/SharedTypes/SourceFileLocationService.cs @@ -60,10 +60,7 @@ internal SourceFileLocationService(IEnumerable provi /// public IEnumerable GetFilesForType(Type type) { - if (type == null) - { - throw new ArgumentNullException(nameof(type)); - } + ArgumentNullException.ThrowIfNull(type); // Get the list of members for this type IEnumerable memberInfos = this.GetMembersForType(type); @@ -84,10 +81,7 @@ public IEnumerable GetFilesForType(Type type) /// The full path of the source file or null if it cannot be determined. public string GetFileForMember(MemberInfo memberInfo) { - if (memberInfo == null) - { - throw new ArgumentNullException(nameof(memberInfo)); - } + ArgumentNullException.ThrowIfNull(memberInfo); // Either load the members or retrieve them from the cache. // In either case, this memberInfo should be in the cache after the call. diff --git a/src/OpenRiaServices.Tools/Framework/ValidateDomainServicesTask.cs b/src/OpenRiaServices.Tools/Framework/ValidateDomainServicesTask.cs index 5b2a4147d..d12e4d3a8 100644 --- a/src/OpenRiaServices.Tools/Framework/ValidateDomainServicesTask.cs +++ b/src/OpenRiaServices.Tools/Framework/ValidateDomainServicesTask.cs @@ -183,10 +183,7 @@ private class TaskLoggingHelperLoggingService : MarshalByRefObject, ILoggingServ public TaskLoggingHelperLoggingService(TaskLoggingHelper log) { - if (log == null) - { - throw new ArgumentNullException(nameof(log)); - } + ArgumentNullException.ThrowIfNull(log); this._log = log; } diff --git a/src/OpenRiaServices.Tools/Framework/Validation/DomainServiceValidator.cs b/src/OpenRiaServices.Tools/Framework/Validation/DomainServiceValidator.cs index a06eaaa38..fae3b2419 100644 --- a/src/OpenRiaServices.Tools/Framework/Validation/DomainServiceValidator.cs +++ b/src/OpenRiaServices.Tools/Framework/Validation/DomainServiceValidator.cs @@ -17,14 +17,8 @@ internal sealed class DomainServiceValidator : MarshalByRefObject, IDisposable { public void Validate(string[] assemblies, ILoggingService logger) { - if (assemblies == null) - { - throw new ArgumentNullException(nameof(assemblies)); - } - if (logger == null) - { - throw new ArgumentNullException(nameof(logger)); - } + ArgumentNullException.ThrowIfNull(assemblies); + ArgumentNullException.ThrowIfNull(logger); // Just creating an instance of the DomainServiceCatalog will locate all the DomainServices in the specified // assemblies and use their corresponding DomainServiceDescriptions to identify and report errors. These diff --git a/src/OpenRiaServices.Tools/Test/ClientCodeGenerationOptionsTests.cs b/src/OpenRiaServices.Tools/Test/ClientCodeGenerationOptionsTests.cs index 25c932a1f..eff8fa8b5 100644 --- a/src/OpenRiaServices.Tools/Test/ClientCodeGenerationOptionsTests.cs +++ b/src/OpenRiaServices.Tools/Test/ClientCodeGenerationOptionsTests.cs @@ -33,8 +33,8 @@ public void ClientCodeGenerationOptionTests_Properties() Assert.IsFalse(options.UseFullTypeNames); // Null languge throws - ExceptionHelper.ExpectArgumentNullException(() => options.Language = null, Resource.Null_Language_Property, "value"); - ExceptionHelper.ExpectArgumentNullException(() => options.Language = string.Empty, Resource.Null_Language_Property, "value"); + ExceptionHelper.ExpectArgumentNullException(() => options.Language = null, "value"); + ExceptionHelper.ExpectEmptyStringArgumentException(() => options.Language = string.Empty, "value"); // Now test a range of values for each property foreach (string language in new string[] { "C#", "VB", "notALanguage" }) diff --git a/src/OpenRiaServices.Tools/Test/LinkedServerProjectCacheTests.cs b/src/OpenRiaServices.Tools/Test/LinkedServerProjectCacheTests.cs index 454a443a4..16c4b3031 100644 --- a/src/OpenRiaServices.Tools/Test/LinkedServerProjectCacheTests.cs +++ b/src/OpenRiaServices.Tools/Test/LinkedServerProjectCacheTests.cs @@ -29,11 +29,11 @@ public void LinkedServerProjectCache_Ctor() { // Null project file throws ExceptionHelper.ExpectArgumentNullExceptionStandard(() => cache = new LinkedServerProjectCache(null, "breadCrumb", logger, projectFileReader), "rootProjectPath"); - ExceptionHelper.ExpectArgumentNullExceptionStandard(() => cache = new LinkedServerProjectCache(String.Empty, "breadCrumb", logger, projectFileReader), "rootProjectPath"); + ExceptionHelper.ExpectEmptyStringArgumentException(() => cache = new LinkedServerProjectCache(string.Empty, "breadCrumb", logger, projectFileReader), "rootProjectPath"); // Null logger throws ExceptionHelper.ExpectArgumentNullExceptionStandard(() => cache = new LinkedServerProjectCache("proj", null, logger, projectFileReader), "historyFilePath"); - ExceptionHelper.ExpectArgumentNullExceptionStandard(() => cache = new LinkedServerProjectCache("proj", String.Empty, logger, projectFileReader), "historyFilePath"); + ExceptionHelper.ExpectEmptyStringArgumentException(() => cache = new LinkedServerProjectCache("proj", string.Empty, logger, projectFileReader), "historyFilePath"); // Null logger throws ExceptionHelper.ExpectArgumentNullExceptionStandard(() => cache = new LinkedServerProjectCache("proj", "breadCrumb", null, projectFileReader), "logger"); @@ -65,12 +65,12 @@ public void LinkedServerProjectCache_Indexer() // Null indexer parameter throws on sets ExceptionHelper.ExpectArgumentNullExceptionStandard((() => cache[null] = "x"), "projectPath"); - ExceptionHelper.ExpectArgumentNullExceptionStandard((() => cache[string.Empty] = "x"), "projectPath"); + ExceptionHelper.ExpectEmptyStringArgumentException((() => cache[string.Empty] = "x"), "projectPath"); // Null indexer parameter throws on gets string unused; ExceptionHelper.ExpectArgumentNullExceptionStandard((() => unused = cache[null]), "projectPath"); - ExceptionHelper.ExpectArgumentNullExceptionStandard((() => unused = cache[string.Empty]), "projectPath"); + ExceptionHelper.ExpectEmptyStringArgumentException((() => unused = cache[string.Empty]), "projectPath"); // Indexer setter can be called with valid values cache["proj1"] = "proj1.Web"; diff --git a/src/OpenRiaServices.Tools/Test/ProjectSourceFileCacheTests.cs b/src/OpenRiaServices.Tools/Test/ProjectSourceFileCacheTests.cs index d68ea5d8e..0dbb10c52 100644 --- a/src/OpenRiaServices.Tools/Test/ProjectSourceFileCacheTests.cs +++ b/src/OpenRiaServices.Tools/Test/ProjectSourceFileCacheTests.cs @@ -30,11 +30,11 @@ public void ProjectSourceFileCache_Ctor() { // Null/empty server project throws ExceptionHelper.ExpectArgumentNullExceptionStandard(() => cache = new ProjectSourceFileCache(null, "breadCrumb", logger, projectFileReader), "rootProjectPath"); - ExceptionHelper.ExpectArgumentNullExceptionStandard(() => cache = new ProjectSourceFileCache(string.Empty, "breadCrumb", logger, projectFileReader), "rootProjectPath"); + ExceptionHelper.ExpectEmptyStringArgumentException(() => cache = new ProjectSourceFileCache(string.Empty, "breadCrumb", logger, projectFileReader), "rootProjectPath"); // Null/empty bread crumb file throws ExceptionHelper.ExpectArgumentNullExceptionStandard(() => cache = new ProjectSourceFileCache("proj", null, logger, projectFileReader), "historyFilePath"); - ExceptionHelper.ExpectArgumentNullExceptionStandard(() => cache = new ProjectSourceFileCache("proj", string.Empty, logger, projectFileReader), "historyFilePath"); + ExceptionHelper.ExpectEmptyStringArgumentException(() => cache = new ProjectSourceFileCache("proj", string.Empty, logger, projectFileReader), "historyFilePath"); // Null logger throws ExceptionHelper.ExpectArgumentNullExceptionStandard(() => cache = new ProjectSourceFileCache("proj", "breadCrumb", null, projectFileReader), "logger"); @@ -92,11 +92,11 @@ public void ProjectSourceFileCache_Indexer() // ArgNull exception on null/empty index setter ExceptionHelper.ExpectArgumentNullExceptionStandard(() => cache[null] = new string[] { "a" }, "projectPath"); - ExceptionHelper.ExpectArgumentNullExceptionStandard(() => cache[string.Empty] = new string[] { "a" }, "projectPath"); + ExceptionHelper.ExpectEmptyStringArgumentException(() => cache[string.Empty] = new string[] { "a" }, "projectPath"); // ArgNull exception on null/empty index getter ExceptionHelper.ExpectArgumentNullExceptionStandard(() => files = cache[null], "projectPath"); - ExceptionHelper.ExpectArgumentNullExceptionStandard(() => files = cache[string.Empty], "projectPath"); + ExceptionHelper.ExpectEmptyStringArgumentException(() => files = cache[string.Empty], "projectPath"); } } diff --git a/src/Test/Desktop/OpenRiaServices.Common.Test/ExceptionHelper.cs b/src/Test/Desktop/OpenRiaServices.Common.Test/ExceptionHelper.cs index 9111ae386..29a45ed61 100644 --- a/src/Test/Desktop/OpenRiaServices.Common.Test/ExceptionHelper.cs +++ b/src/Test/Desktop/OpenRiaServices.Common.Test/ExceptionHelper.cs @@ -253,10 +253,7 @@ public static WebException ExpectWebException(GenericDelegate del, string messag { WebException e = ExpectExceptionHelper(del); -#if !SILVERLIGHT // Message is set to "" in Silverlight in some cases Assert.AreEqual(message, e.Message); -#endif - Assert.AreEqual(webExceptionStatus, e.Status); return e; } @@ -267,5 +264,12 @@ public static InvalidCastException ExpectInvalidCastException(GenericDelegate de Assert.AreEqual(message, e.Message); return e; } + + public static void ExpectEmptyStringArgumentException(Action value, string paramName) + { + var ex = Assert.ThrowsExactly(value); + Assert.AreEqual(paramName, ex.ParamName); + Assert.Contains("The value cannot be an empty string.", ex.Message); + } } } diff --git a/src/Test/OpenRiaservices.EndToEnd.Wcf.Test/Data/CrossDomainServiceQueryTests.cs b/src/Test/OpenRiaservices.EndToEnd.Wcf.Test/Data/CrossDomainServiceQueryTests.cs index f7f4af6c3..33eba17e6 100644 --- a/src/Test/OpenRiaservices.EndToEnd.Wcf.Test/Data/CrossDomainServiceQueryTests.cs +++ b/src/Test/OpenRiaservices.EndToEnd.Wcf.Test/Data/CrossDomainServiceQueryTests.cs @@ -6,6 +6,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using TestDomainServices.LTS; using OpenRiaServices.Silverlight.Testing; +using System.Threading.Tasks; namespace OpenRiaServices.Client.Test { @@ -15,9 +16,7 @@ namespace OpenRiaServices.Client.Test /// Note: we're using the same generated client for both EF and LTS tests, varying only the /// provider string that the tests use. /// -#if !SILVERLIGHT [TestClass] -#endif public abstract class CrossDomainServiceQueryTests : DomainContextTestBase { public CrossDomainServiceQueryTests(Uri serviceUri, ProviderType providerType) @@ -436,38 +435,17 @@ orderby p.Weight ascending } [TestMethod] - [Asynchronous] - public void TestLoad_CustomTotalCount() + public async Task TestLoad_CustomTotalCount() { Catalog catalog = CreateDomainContext(); - int totalCountWithoutPaging = 0; var query = catalog.GetProductsWithCustomTotalCountQuery(); - Load(query); + var loadResult = await catalog.LoadAsync(query); + catalog.Products.Clear(); - EnqueueConditional(delegate - { - return IsLoadComplete; - }); - EnqueueCallback(delegate - { - totalCountWithoutPaging = LoadOperation.TotalEntityCount; - catalog.Products.Clear(); - }); - EnqueueCallback(delegate - { - Load(query.OrderBy(p => p.ProductID).Skip(2).Take(4)); - }); - EnqueueConditional(delegate - { - return IsLoadComplete; - }); - EnqueueCallback(delegate - { - Assert.AreEqual(totalCountWithoutPaging, LoadOperation.TotalEntityCount); - Assert.HasCount(4, LoadOperation.Entities); - }); - EnqueueTestComplete(); + var loadWithPagingResult = await catalog.LoadAsync(query.OrderBy(p => p.ProductID).Skip(2).Take(3)); + Assert.AreEqual(loadResult.TotalEntityCount, loadWithPagingResult.TotalEntityCount); + Assert.HasCount(3, loadWithPagingResult.Entities); } [TestMethod] diff --git a/src/Test/OpenRiaservices.EndToEnd.Wcf.Test/Data/EntityQueryTests.cs b/src/Test/OpenRiaservices.EndToEnd.Wcf.Test/Data/EntityQueryTests.cs index 2d139aa25..83a8333bb 100644 --- a/src/Test/OpenRiaservices.EndToEnd.Wcf.Test/Data/EntityQueryTests.cs +++ b/src/Test/OpenRiaservices.EndToEnd.Wcf.Test/Data/EntityQueryTests.cs @@ -195,7 +195,7 @@ public void ParameterChecking() EntityQuery citiesQuery = new EntityQuery(_testClient, null, parameters, false, true); }, "queryName"); - ExceptionHelper.ExpectArgumentNullException(delegate + ExceptionHelper.ExpectEmptyStringArgumentException(delegate { EntityQuery citiesQuery = new EntityQuery(_testClient, string.Empty, parameters, false, true); }, "queryName"); diff --git a/src/VisualStudio/Tools/Framework/DomainServiceWizard/BusinessLogicContext.cs b/src/VisualStudio/Tools/Framework/DomainServiceWizard/BusinessLogicContext.cs index ccfd81fb5..fe0eddd81 100644 --- a/src/VisualStudio/Tools/Framework/DomainServiceWizard/BusinessLogicContext.cs +++ b/src/VisualStudio/Tools/Framework/DomainServiceWizard/BusinessLogicContext.cs @@ -332,18 +332,9 @@ public GeneratedCode GenerateMetadataClasses(string language, string rootNamespa /// The namespace to use for the generated code. It cannot be empty. protected void GenerateBusinessLogicClass(CodeGenContext codeGenContext, string className, string namespaceName) { - if (codeGenContext == null) - { - throw new ArgumentNullException("codeGenContext"); - } - if (string.IsNullOrEmpty(className)) - { - throw new ArgumentNullException("className"); - } - if (string.IsNullOrEmpty(namespaceName)) - { - throw new ArgumentNullException("namespaceName"); - } + ArgumentNullException.ThrowIfNull(codeGenContext); + ArgumentException.ThrowIfNullOrEmpty(className); + ArgumentException.ThrowIfNullOrEmpty(namespaceName); // namespace XXX { } CodeNamespace ns = codeGenContext.GetOrGenNamespace(namespaceName); diff --git a/src/VisualStudio/Tools/Framework/DomainServiceWizard/BusinessLogicModel.cs b/src/VisualStudio/Tools/Framework/DomainServiceWizard/BusinessLogicModel.cs index 0a19e32f4..72cb03052 100644 --- a/src/VisualStudio/Tools/Framework/DomainServiceWizard/BusinessLogicModel.cs +++ b/src/VisualStudio/Tools/Framework/DomainServiceWizard/BusinessLogicModel.cs @@ -42,10 +42,7 @@ public BusinessLogicModel() : this(s => System.Diagnostics.Debug.WriteLine(s)) /// Callback to invoke to report errors during processing. public BusinessLogicModel(Action logger) { - if (logger == null) - { - throw new ArgumentNullException("logger"); - } + ArgumentNullException.ThrowIfNull(logger); this._logger = logger; } diff --git a/src/VisualStudio/Tools/Framework/DomainServiceWizard/BusinessLogicViewModel.cs b/src/VisualStudio/Tools/Framework/DomainServiceWizard/BusinessLogicViewModel.cs index a210ea501..a3eb64755 100644 --- a/src/VisualStudio/Tools/Framework/DomainServiceWizard/BusinessLogicViewModel.cs +++ b/src/VisualStudio/Tools/Framework/DomainServiceWizard/BusinessLogicViewModel.cs @@ -47,30 +47,11 @@ public class BusinessLogicViewModel : INotifyPropertyChanged, IDisposable /// The help object used to display help on pressing F1. public BusinessLogicViewModel(string projectDirectory, string className, string language, string rootNamespace, string assemblyName, IEnumerable contextTypes, IVsHelp help) { - if (string.IsNullOrEmpty(projectDirectory)) - { - throw new ArgumentNullException("projectDirectory"); - } - - if (string.IsNullOrEmpty(className)) - { - throw new ArgumentNullException("className"); - } - - if (string.IsNullOrEmpty(language)) - { - throw new ArgumentNullException("language"); - } - - if (contextTypes == null) - { - throw new ArgumentNullException("contextTypes"); - } - - if (string.IsNullOrEmpty(assemblyName)) - { - throw new ArgumentNullException("assemblyName"); - } + ArgumentException.ThrowIfNullOrEmpty(projectDirectory); + ArgumentException.ThrowIfNullOrEmpty(className); + ArgumentException.ThrowIfNullOrEmpty(language); + ArgumentException.ThrowIfNullOrEmpty(assemblyName); + ArgumentNullException.ThrowIfNull(contextTypes); this._projectDirectory = projectDirectory; this._className = className; diff --git a/src/VisualStudio/Tools/Framework/DomainServiceWizard/DomainServiceFixupCodeDomVisitor.cs b/src/VisualStudio/Tools/Framework/DomainServiceWizard/DomainServiceFixupCodeDomVisitor.cs index 2902b837a..052d18826 100644 --- a/src/VisualStudio/Tools/Framework/DomainServiceWizard/DomainServiceFixupCodeDomVisitor.cs +++ b/src/VisualStudio/Tools/Framework/DomainServiceWizard/DomainServiceFixupCodeDomVisitor.cs @@ -21,10 +21,7 @@ internal sealed class DomainServiceFixupCodeDomVisitor : CodeDomVisitor /// The current context. public DomainServiceFixupCodeDomVisitor(CodeGenContext context) { - if (context == null) - { - throw new ArgumentNullException("context"); - } + ArgumentNullException.ThrowIfNull(context); this._context = context; } diff --git a/src/VisualStudio/Tools/Framework/DomainServiceWizard/GeneratedCode.cs b/src/VisualStudio/Tools/Framework/DomainServiceWizard/GeneratedCode.cs index 413e3c40a..d4922a2b6 100644 --- a/src/VisualStudio/Tools/Framework/DomainServiceWizard/GeneratedCode.cs +++ b/src/VisualStudio/Tools/Framework/DomainServiceWizard/GeneratedCode.cs @@ -29,14 +29,8 @@ public GeneratedCode() public GeneratedCode(string sourceCode, IEnumerable references) { // Empty is allowed, null is not - if (sourceCode == null) - { - throw new ArgumentNullException("sourceCode"); - } - if (references == null) - { - throw new ArgumentNullException("references"); - } + ArgumentNullException.ThrowIfNull(sourceCode); + ArgumentNullException.ThrowIfNull(references); this._sourceCode = sourceCode; this._references = references; } diff --git a/src/VisualStudio/Tools/Framework/OpenRiaServices.VisualStudio.DomainServices.Tools.csproj b/src/VisualStudio/Tools/Framework/OpenRiaServices.VisualStudio.DomainServices.Tools.csproj index 9e3873083..4eaf36fa7 100644 --- a/src/VisualStudio/Tools/Framework/OpenRiaServices.VisualStudio.DomainServices.Tools.csproj +++ b/src/VisualStudio/Tools/Framework/OpenRiaServices.VisualStudio.DomainServices.Tools.csproj @@ -61,6 +61,7 @@ + diff --git a/src/VisualStudio/Tools/Framework/WebConfigUtil.cs b/src/VisualStudio/Tools/Framework/WebConfigUtil.cs index 65b403d2b..9f1f807da 100644 --- a/src/VisualStudio/Tools/Framework/WebConfigUtil.cs +++ b/src/VisualStudio/Tools/Framework/WebConfigUtil.cs @@ -42,10 +42,7 @@ public class WebConfigUtil /// The configuration to use. public WebConfigUtil(System.Configuration.Configuration configuration) { - if (configuration == null) - { - throw new ArgumentNullException("configuration"); - } + ArgumentNullException.ThrowIfNull(configuration); this._configuration = configuration; } diff --git a/src/VisualStudio/Tools/Test/DomainServiceWizard/BusinessLogicClassViewModelTests.cs b/src/VisualStudio/Tools/Test/DomainServiceWizard/BusinessLogicClassViewModelTests.cs index 762128bc9..6fb6daa6f 100644 --- a/src/VisualStudio/Tools/Test/DomainServiceWizard/BusinessLogicClassViewModelTests.cs +++ b/src/VisualStudio/Tools/Test/DomainServiceWizard/BusinessLogicClassViewModelTests.cs @@ -183,7 +183,7 @@ public void BusinessLogicViewModel_Ctor_Throw_Bad_Args() BusinessLogicViewModel model = new BusinessLogicViewModel(null, "FooClass", "C#", "ARootNamespace", "AnAssemblyName", Array.Empty(), /* IVsHelp object */ null); }, "projectDirectory"); - ExceptionHelper.ExpectArgumentNullExceptionStandard(delegate + ExceptionHelper.ExpectEmptyStringArgumentException(delegate { BusinessLogicViewModel model = new BusinessLogicViewModel(string.Empty, "FooClass", "C#", "ARootNamespace", "AnAssemblyName", Array.Empty(), /* IVsHelp object */ null); }, "projectDirectory"); @@ -194,7 +194,7 @@ public void BusinessLogicViewModel_Ctor_Throw_Bad_Args() BusinessLogicViewModel model = new BusinessLogicViewModel("FooFolder", null, "C#", "ARootNamespace", "AnAssemblyName", Array.Empty(), /* IVsHelp object */ null); }, "className"); - ExceptionHelper.ExpectArgumentNullExceptionStandard(delegate + ExceptionHelper.ExpectEmptyStringArgumentException(delegate { BusinessLogicViewModel model = new BusinessLogicViewModel("FooFolder", string.Empty, "C#", "ARootNamespace", "AnAssemblyName", Array.Empty(), /* IVsHelp object */ null); }, "className"); @@ -205,7 +205,7 @@ public void BusinessLogicViewModel_Ctor_Throw_Bad_Args() BusinessLogicViewModel model = new BusinessLogicViewModel("FooFolder", "AClassName", null, "ARootNamespace", "AnAssemblyName", Array.Empty(), /* IVsHelp object */ null); }, "language"); - ExceptionHelper.ExpectArgumentNullExceptionStandard(delegate + ExceptionHelper.ExpectEmptyStringArgumentException(delegate { BusinessLogicViewModel model = new BusinessLogicViewModel("FooFolder", "AClassName", string.Empty, "ARootNamespace", "AnAssemblyName", Array.Empty(), /* IVsHelp object */ null); }, "language"); @@ -216,7 +216,7 @@ public void BusinessLogicViewModel_Ctor_Throw_Bad_Args() BusinessLogicViewModel model = new BusinessLogicViewModel("FooFolder", "AClassName", "C#", "ARootNamespace", null, Array.Empty(), /* IVsHelp object */ null); }, "assemblyName"); - ExceptionHelper.ExpectArgumentNullExceptionStandard(delegate + ExceptionHelper.ExpectEmptyStringArgumentException(delegate { BusinessLogicViewModel model = new BusinessLogicViewModel("FooFolder", "AClassName", "C#", "ARootNamespace", "", Array.Empty(), /* IVsHelp object */ null); }, "assemblyName");