Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ private protected HttpDomainClientFactory(Uri serverBaseUri, HttpMessageHandler
private protected HttpDomainClientFactory(Uri serverBaseUri, Func<HttpClient> httpClientFactory)
{
base.ServerBaseUri = serverBaseUri;
if (httpClientFactory is null)
throw new ArgumentNullException(nameof(httpClientFactory));
ArgumentNullException.ThrowIfNull(httpClientFactory);

this._httpClientFactory = (Uri uri) =>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFrameworks>net472;netstandard2.0;net8.0</TargetFrameworks>
<TargetFrameworks>net472;net8.0</TargetFrameworks>
Comment thread
Daniel-Svensson marked this conversation as resolved.
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<RootNamespace>OpenRiaServices.Client.DomainClients</RootNamespace>
<NeutralLanguage>en</NeutralLanguage>
Expand All @@ -22,6 +22,7 @@
<ProjectReference Include="..\..\OpenRiaServices.Client\Framework\OpenRiaServices.Client.csproj" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\OpenRiaServices.Client\Framework\Polyfills.cs" Link="Polyfills.cs" />
<Compile Update="Http\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,8 @@ public ServiceQueryPart()
/// <param name="expression">The query expression</param>
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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,9 @@ internal WebDomainClient(Uri serviceUri, bool usesHttps)
/// </exception>
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
</ItemGroup>

<ItemGroup>
<Compile Include="..\..\OpenRiaServices.Client\Framework\Polyfills.cs" Link="Polyfills.cs" />
<Compile Include="..\..\OpenRiaServices.Client\Framework\BinaryTypeUtility.cs">
<Link>Utilities\BinaryTypeUtility.cs</Link>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ public abstract class WcfDomainClientFactory : DomainClientFactory
/// E.g "binary", "soap"</param>
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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ public sealed class AuthenticationEventArgs : EventArgs
/// </exception>
internal AuthenticationEventArgs(IPrincipal user)
{
if (user == null)
{
throw new ArgumentNullException(nameof(user));
}
ArgumentNullException.ThrowIfNull(user);
this.User = user;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,10 +457,7 @@ private static string GetBusyPropertyName(AuthenticationOperation operation)
/// </exception>
protected void RaisePropertyChanged(string propertyName)
{
if (string.IsNullOrEmpty(propertyName))
{
throw new ArgumentNullException(nameof(propertyName));
}
ArgumentException.ThrowIfNullOrEmpty(propertyName);

this._propertyChangedEventHandler?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,7 @@ protected internal override Task<LoginResult> LoginAsync(LoginParameters paramet
{
this.Initialize();

if (parameters == null)
{
throw new ArgumentNullException(nameof(parameters));
}
ArgumentNullException.ThrowIfNull(parameters);

EntityQuery query;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
private static WebContextBase s_current;

private PropertyChangedEventHandler _propertyChangedEventHandler;
private bool _started;

Check warning on line 26 in src/OpenRiaServices.Client/Framework/Authentication/WebContextBase.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Field 'WebContextBase._started' is never assigned to, and will always have its default value false
private AuthenticationService _authentication;

/// <summary>
Expand Down Expand Up @@ -101,10 +101,7 @@
}
set
{
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
ArgumentNullException.ThrowIfNull(value);
if (this._started)
{
throw new InvalidOperationException(Resources.WebContext_CannotModifyAuthentication);
Expand All @@ -130,10 +127,7 @@
/// </exception>
protected void RaisePropertyChanged(string propertyName)
{
if (string.IsNullOrEmpty(propertyName))
{
throw new ArgumentNullException(nameof(propertyName));
}
ArgumentException.ThrowIfNullOrEmpty(propertyName);
this._propertyChangedEventHandler?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
50 changes: 10 additions & 40 deletions src/OpenRiaServices.Client/Framework/ComplexObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,26 +167,11 @@ internal ValidationResultCollection ValidationResultCollection
/// <param name="onMemberValidationChanged">The callback to call when validation has changed for a property.</param>
internal void Attach(object parent, string propertyName, Action onDataMemberChanging, Action onDataMemberChanged, Action<string, IEnumerable<ValidationResult>> 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);
Expand Down Expand Up @@ -227,10 +212,7 @@ event PropertyChangedEventHandler? INotifyPropertyChanged.PropertyChanged
/// <param name="propertyName">The name of the property that has changed</param>
protected void RaisePropertyChanged(string propertyName)
{
if (string.IsNullOrEmpty(propertyName))
{
throw new ArgumentNullException(nameof(propertyName));
}
ArgumentException.ThrowIfNullOrEmpty(propertyName);

OnPropertyChanged(propertyName);
}
Expand All @@ -252,10 +234,7 @@ protected virtual void OnPropertyChanged(string propertyName)
/// <param name="propertyName">The name of the property that has changed</param>
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.
Expand Down Expand Up @@ -321,10 +300,7 @@ private void AttachComplexObjectInstance(MetaMember metaMember)
/// <param name="propertyName">The name of the property that is changing</param>
protected void RaiseDataMemberChanging(string propertyName)
{
if (string.IsNullOrEmpty(propertyName))
{
throw new ArgumentNullException(nameof(propertyName));
}
ArgumentException.ThrowIfNullOrEmpty(propertyName);

this.OnDataMemberChanging();
}
Expand Down Expand Up @@ -405,10 +381,7 @@ private void NotifyParentMemberValidationChanged(string? propertyName, IEnumerab
/// configured to prevent editing.</exception>
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
Expand Down Expand Up @@ -480,10 +453,7 @@ protected void ValidateProperty(string propertyName, object value)
/// <exception cref="ArgumentNullException"> is thrown if <paramref name="validationContext"/> is <c>null</c>.</exception>
protected virtual void ValidateProperty(ValidationContext validationContext, object value)
{
if (validationContext == null)
{
throw new ArgumentNullException(nameof(validationContext));
}
ArgumentNullException.ThrowIfNull(validationContext);

List<ValidationResult> validationResults = new List<ValidationResult>();
Validator.TryValidateProperty(value, validationContext, validationResults);
Expand Down
5 changes: 1 addition & 4 deletions src/OpenRiaServices.Client/Framework/DomainClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,7 @@ public virtual bool SupportsCancellation
/// <returns>The results returned by the submit request.</returns>
public Task<SubmitCompletedResult> SubmitAsync(EntityChangeSet changeSet, CancellationToken cancellationToken)
{
if (changeSet == null)
{
throw new ArgumentNullException(nameof(changeSet));
}
ArgumentNullException.ThrowIfNull(changeSet);

if (changeSet.IsEmpty)
{
Expand Down
9 changes: 3 additions & 6 deletions src/OpenRiaServices.Client/Framework/DomainClientFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand All @@ -63,10 +62,8 @@ public Uri ServerBaseUri
/// <returns>A <see cref="DomainClient"/> to use when communicating with the service</returns>
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));

Expand Down
Loading
Loading