Skip to content

Commit 4892839

Browse files
authored
Minor code cleanup (#87)
This removes a few un-used using statements. It also leverages the CallerArgumentExpression for argument exceptions
1 parent a0b8141 commit 4892839

File tree

13 files changed

+53
-56
lines changed

13 files changed

+53
-56
lines changed

src/CommunityToolkit.Datasync.Client/Exceptions/EntityDoesNotExistException.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
using CommunityToolkit.Datasync.Client.Service;
6-
75
namespace CommunityToolkit.Datasync.Client;
86

97
/// <summary>

src/CommunityToolkit.Datasync.Client/Offline/DatasyncOfflineOptionsBuilder.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ internal DatasyncOfflineOptionsBuilder(IEnumerable<Type> entityTypes)
3333
/// <returns>The current builder for chaining.</returns>
3434
public DatasyncOfflineOptionsBuilder UseHttpClientFactory(IHttpClientFactory httpClientFactory)
3535
{
36-
ArgumentNullException.ThrowIfNull(httpClientFactory, nameof(httpClientFactory));
36+
ArgumentNullException.ThrowIfNull(httpClientFactory);
3737
this._httpClientFactory = httpClientFactory;
3838
return this;
3939
}
@@ -46,7 +46,7 @@ public DatasyncOfflineOptionsBuilder UseHttpClientFactory(IHttpClientFactory htt
4646
/// <returns>The current builder for chaining.</returns>
4747
public DatasyncOfflineOptionsBuilder UseHttpClient(HttpClient httpClient)
4848
{
49-
ArgumentNullException.ThrowIfNull(httpClient, nameof(httpClient));
49+
ArgumentNullException.ThrowIfNull(httpClient);
5050
this._httpClientFactory = new BasicHttpClientFactory(httpClient);
5151
return this;
5252
}
@@ -59,7 +59,7 @@ public DatasyncOfflineOptionsBuilder UseHttpClient(HttpClient httpClient)
5959
/// <returns>The current builder for chaining.</returns>
6060
public DatasyncOfflineOptionsBuilder UseEndpoint(Uri endpoint)
6161
{
62-
ArgumentNullException.ThrowIfNull(endpoint, nameof(endpoint));
62+
ArgumentNullException.ThrowIfNull(endpoint);
6363
ThrowIf.IsNotValidEndpoint(endpoint, nameof(endpoint));
6464
this._httpClientFactory = new HttpClientFactory(new HttpClientOptions { Endpoint = endpoint });
6565
return this;
@@ -73,7 +73,7 @@ public DatasyncOfflineOptionsBuilder UseEndpoint(Uri endpoint)
7373
/// <returns>The current builder for chaining.</returns>
7474
public DatasyncOfflineOptionsBuilder UseHttpClientOptions(HttpClientOptions clientOptions)
7575
{
76-
ArgumentNullException.ThrowIfNull(clientOptions, nameof(clientOptions));
76+
ArgumentNullException.ThrowIfNull(clientOptions);
7777
this._httpClientFactory = new HttpClientFactory(clientOptions);
7878
return this;
7979
}
@@ -86,7 +86,7 @@ public DatasyncOfflineOptionsBuilder UseHttpClientOptions(HttpClientOptions clie
8686
/// <returns>The current builder for chaining.</returns>
8787
public DatasyncOfflineOptionsBuilder Entity<TEntity>(Action<EntityOfflineOptions<TEntity>> configure) where TEntity : class
8888
{
89-
ArgumentNullException.ThrowIfNull(configure, nameof(configure));
89+
ArgumentNullException.ThrowIfNull(configure);
9090
if (!this._entities.TryGetValue(typeof(TEntity).FullName!, out EntityOfflineOptions? options))
9191
{
9292
throw new DatasyncException($"Entity is not synchronizable.");
@@ -108,8 +108,8 @@ public DatasyncOfflineOptionsBuilder Entity<TEntity>(Action<EntityOfflineOptions
108108
/// <returns>The current builder for chaining.</returns>
109109
public DatasyncOfflineOptionsBuilder Entity(Type entityType, Action<EntityOfflineOptions> configure)
110110
{
111-
ArgumentNullException.ThrowIfNull(entityType, nameof(entityType));
112-
ArgumentNullException.ThrowIfNull(configure, nameof(configure));
111+
ArgumentNullException.ThrowIfNull(entityType);
112+
ArgumentNullException.ThrowIfNull(configure);
113113
if (!this._entities.TryGetValue(entityType.FullName!, out EntityOfflineOptions? options))
114114
{
115115
throw new DatasyncException($"Entity is not synchronizable.");

src/CommunityToolkit.Datasync.Client/Offline/OfflineDbContext.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
240240
/// <returns>The results of the pull operation.</returns>
241241
public Task<PullResult> PullAsync(IEnumerable<Type> entityTypes, PullOptions pullOptions, CancellationToken cancellationToken = default)
242242
{
243-
ArgumentNullException.ThrowIfNull(entityTypes, nameof(entityTypes));
243+
ArgumentNullException.ThrowIfNull(entityTypes);
244244
ArgumentValidationException.ThrowIfNotValid(pullOptions, nameof(pullOptions));
245245

246246
OfflineOptions offlineOptions = BuildDatasyncOfflineOptions();
@@ -281,7 +281,7 @@ public Task<PullResult> PullAsync(Action<PullRequestBuilder> configureAction, Ca
281281
/// <returns>The results of the pull operation.</returns>
282282
internal async Task<PullResult> PullAsync(IEnumerable<PullRequest> pullRequests, PullOptions pullOptions, CancellationToken cancellationToken)
283283
{
284-
ArgumentNullException.ThrowIfNull(pullRequests, nameof(pullRequests));
284+
ArgumentNullException.ThrowIfNull(pullRequests);
285285
ArgumentValidationException.ThrowIfNotValid(pullOptions, nameof(pullOptions));
286286

287287
if (!pullRequests.Any())

src/CommunityToolkit.Datasync.Client/Offline/OperationsQueue/OperationsQueueManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ internal List<EntityEntry> GetChangedEntitiesInScope()
8181
/// </remarks>
8282
internal Dictionary<string, Type> GetEntityMap(OfflineDbContext context)
8383
{
84-
ArgumentNullException.ThrowIfNull(context, nameof(context));
84+
ArgumentNullException.ThrowIfNull(context);
8585

8686
Type[] modelEntities = context.Model.GetEntityTypes().Select(m => m.ClrType).ToArray();
8787
Type[] synchronizableEntities = context.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)
@@ -239,7 +239,7 @@ internal bool IsSynchronizationEntity(PropertyInfo property)
239239
/// <returns>The results of the push operation (asynchronously)</returns>
240240
internal async Task<PushResult> PushAsync(IEnumerable<Type> entityTypes, PushOptions pushOptions, CancellationToken cancellationToken = default)
241241
{
242-
ArgumentNullException.ThrowIfNull(entityTypes, nameof(entityTypes));
242+
ArgumentNullException.ThrowIfNull(entityTypes);
243243
ArgumentValidationException.ThrowIfNotValid(pushOptions, nameof(pushOptions));
244244
PushResult pushResult = new();
245245

src/CommunityToolkit.Datasync.Client/Paging/ConcurrentObservableCollection.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public ConcurrentObservableCollection(IEnumerable<T> list) : base(list)
4040
/// <param name="collection">The new collection.</param>
4141
public void ReplaceAll(IEnumerable<T> collection)
4242
{
43-
ArgumentNullException.ThrowIfNull(collection, nameof(collection));
43+
ArgumentNullException.ThrowIfNull(collection);
4444
try
4545
{
4646
this.suppressNotification = true;
@@ -65,7 +65,7 @@ public void ReplaceAll(IEnumerable<T> collection)
6565
/// <returns><c>true</c> if any records were added; <c>false</c> otherwise.</returns>
6666
public bool AddRange(IEnumerable<T> collection)
6767
{
68-
ArgumentNullException.ThrowIfNull(collection, nameof(collection));
68+
ArgumentNullException.ThrowIfNull(collection);
6969
bool changed = false;
7070
try
7171
{
@@ -97,8 +97,8 @@ public bool AddRange(IEnumerable<T> collection)
9797
/// <returns><c>true</c> if the item was added, <c>false</c> otherwise.</returns>
9898
public bool AddIfMissing(Func<T, bool> match, T item)
9999
{
100-
ArgumentNullException.ThrowIfNull(match, nameof(match));
101-
ArgumentNullException.ThrowIfNull(item, nameof(item));
100+
ArgumentNullException.ThrowIfNull(match);
101+
ArgumentNullException.ThrowIfNull(item);
102102
if (!this.Any(match))
103103
{
104104
Add(item);
@@ -115,7 +115,7 @@ public bool AddIfMissing(Func<T, bool> match, T item)
115115
/// <returns><c>true</c> if an item was removed, <c>false</c> otherwise.</returns>
116116
public bool RemoveIf(Func<T, bool> match)
117117
{
118-
ArgumentNullException.ThrowIfNull(match, nameof(match));
118+
ArgumentNullException.ThrowIfNull(match);
119119
T[] itemsToRemove = this.Where(match).ToArray();
120120
foreach (T? item in itemsToRemove)
121121
{
@@ -134,8 +134,8 @@ public bool RemoveIf(Func<T, bool> match)
134134
/// <returns><c>true</c> if an item was replaced, <c>false</c> otherwise.</returns>
135135
public bool ReplaceIf(Func<T, bool> match, T replacement)
136136
{
137-
ArgumentNullException.ThrowIfNull(match, nameof(match));
138-
ArgumentNullException.ThrowIfNull(replacement, nameof(replacement));
137+
ArgumentNullException.ThrowIfNull(match);
138+
ArgumentNullException.ThrowIfNull(replacement);
139139
T[] itemsToReplace = this.Where(match).ToArray();
140140
foreach (T? item in itemsToReplace)
141141
{

src/CommunityToolkit.Datasync.Client/Query/IAsyncEnumerableExtensions.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ internal static class IAsyncEnumerableExtensions
2525
/// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
2626
internal static async ValueTask<TSource[]> ToDatasyncArrayAsync<TSource>(this IAsyncEnumerable<TSource> source, CancellationToken cancellationToken = default)
2727
{
28-
ArgumentNullException.ThrowIfNull(source, nameof(source));
28+
ArgumentNullException.ThrowIfNull(source);
2929
List<TSource> list = await source.ToDatasyncListAsync(cancellationToken).ConfigureAwait(false);
3030
return [.. list];
3131
}
@@ -58,8 +58,8 @@ internal static ValueTask<Dictionary<TKey, TSource>> ToDatasyncDictionaryAsync<T
5858
/// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
5959
internal static async ValueTask<Dictionary<TKey, TSource>> ToDatasyncDictionaryAsync<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey>? comparer, CancellationToken cancellationToken = default) where TKey : notnull
6060
{
61-
ArgumentNullException.ThrowIfNull(source, nameof(source));
62-
ArgumentNullException.ThrowIfNull(keySelector, nameof(keySelector));
61+
ArgumentNullException.ThrowIfNull(source);
62+
ArgumentNullException.ThrowIfNull(keySelector);
6363
Dictionary<TKey, TSource> d = new(comparer);
6464
await foreach (TSource? item in source.WithCancellation(cancellationToken).ConfigureAwait(false))
6565
{
@@ -94,7 +94,7 @@ internal static ValueTask<HashSet<TSource>> ToDatasyncHashSetAsync<TSource>(this
9494
/// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
9595
internal static async ValueTask<HashSet<TSource>> ToDatasyncHashSetAsync<TSource>(this IAsyncEnumerable<TSource> source, IEqualityComparer<TSource>? comparer, CancellationToken cancellationToken = default)
9696
{
97-
ArgumentNullException.ThrowIfNull(source, nameof(source));
97+
ArgumentNullException.ThrowIfNull(source);
9898
HashSet<TSource> set = new(comparer);
9999
await foreach (TSource? item in source.WithCancellation(cancellationToken).ConfigureAwait(false))
100100
{
@@ -114,7 +114,7 @@ internal static async ValueTask<HashSet<TSource>> ToDatasyncHashSetAsync<TSource
114114
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
115115
internal static async ValueTask<List<TSource>> ToDatasyncListAsync<TSource>(this IAsyncEnumerable<TSource> source, CancellationToken cancellationToken = default)
116116
{
117-
ArgumentNullException.ThrowIfNull(source, nameof(source));
117+
ArgumentNullException.ThrowIfNull(source);
118118
List<TSource> list = [];
119119
await foreach (TSource? item in source.WithCancellation(cancellationToken).ConfigureAwait(false))
120120
{
@@ -146,7 +146,7 @@ internal static ValueTask<ConcurrentObservableCollection<TSource>> ToDatasyncObs
146146
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
147147
internal static async ValueTask<ConcurrentObservableCollection<TSource>> ToDatasyncObservableCollectionAsync<TSource>(this IAsyncEnumerable<TSource> source, ConcurrentObservableCollection<TSource> existingCollection, CancellationToken cancellationToken = default)
148148
{
149-
ArgumentNullException.ThrowIfNull(source, nameof(source));
149+
ArgumentNullException.ThrowIfNull(source);
150150
List<TSource> list = await source.ToDatasyncListAsync(cancellationToken).ConfigureAwait(false);
151151
existingCollection.ReplaceAll(list);
152152
return existingCollection;

src/CommunityToolkit.Datasync.Client/Query/Linq/FilterBuildingExpressionVisitor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ internal static QueryNode Compile(Expression filterExpression, JsonNamingPolicy
108108
/// <returns>the table member name</returns>
109109
internal static string GetTableMemberName(Expression expression, JsonNamingPolicy namingPolicy)
110110
{
111-
ArgumentNullException.ThrowIfNull(expression, nameof(expression));
111+
ArgumentNullException.ThrowIfNull(expression);
112112
if (expression is MemberExpression member)
113113
{
114114
if (member.Expression.NodeType == ExpressionType.Parameter)

src/CommunityToolkit.Datasync.Client/Query/Linq/QueryTranslator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ internal class QueryTranslator<T> where T : class
2929
/// <param name="query">The <see cref="IDatasyncQueryable{TEntity}"/> to translate.</param>
3030
internal QueryTranslator(IDatasyncQueryable<T> query)
3131
{
32-
ArgumentNullException.ThrowIfNull(query, nameof(query));
32+
ArgumentNullException.ThrowIfNull(query);
3333
Query = query.Queryable;
3434
QueryDescription = new() { QueryParameters = query.QueryParameters, RequestTotalCount = query.RequestTotalCount };
3535
NamingPolicy = ((DatasyncServiceClient<T>)query.ServiceClient).JsonSerializerOptions.PropertyNamingPolicy;
@@ -41,7 +41,7 @@ internal QueryTranslator(IDatasyncQueryable<T> query)
4141
/// <param name="query">The <see cref="IDatasyncPullQuery{TEntity}"/> to translate.</param>
4242
internal QueryTranslator(IDatasyncPullQuery<T> query)
4343
{
44-
ArgumentNullException.ThrowIfNull(query, nameof(query));
44+
ArgumentNullException.ThrowIfNull(query);
4545
Query = query.Queryable;
4646
QueryDescription = new() { QueryParameters = query.QueryParameters, RequestTotalCount = false };
4747
NamingPolicy = DatasyncSerializer.JsonSerializerOptions.PropertyNamingPolicy;

src/CommunityToolkit.Datasync.Client/Query/Linq/VisitorHelper.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ private VisitorHelper()
5555
/// </returns>
5656
public static Expression VisitAll(Expression expression, Func<Expression, Func<Expression, Expression>, Expression> visitor)
5757
{
58-
ArgumentNullException.ThrowIfNull(expression, nameof(expression));
59-
ArgumentNullException.ThrowIfNull(visitor, nameof(visitor));
58+
ArgumentNullException.ThrowIfNull(expression);
59+
ArgumentNullException.ThrowIfNull(visitor);
6060
return new VisitorHelper() { visitor = visitor }.Visit(expression);
6161
}
6262

@@ -73,8 +73,8 @@ public static Expression VisitAll(Expression expression, Func<Expression, Func<E
7373
/// </returns>
7474
public static Expression VisitMembers(Expression expression, Func<MemberExpression, Func<MemberExpression, Expression>, Expression> visitor)
7575
{
76-
ArgumentNullException.ThrowIfNull(expression, nameof(expression));
77-
ArgumentNullException.ThrowIfNull(visitor, nameof(visitor));
76+
ArgumentNullException.ThrowIfNull(expression);
77+
ArgumentNullException.ThrowIfNull(visitor);
7878
return new VisitorHelper() { memberVisitor = visitor }.Visit(expression);
7979
}
8080

src/CommunityToolkit.Datasync.Client/Query/OData/ODataExpressionVisitor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public override QueryNode Visit(UnaryOperatorNode node)
187187
/// <param name="node">The node to visit</param>
188188
protected void Accept(QueryNode parent, QueryNode node)
189189
{
190-
ArgumentNullException.ThrowIfNull(node, nameof(node));
190+
ArgumentNullException.ThrowIfNull(node);
191191
node.Accept(this);
192192
}
193193
}

0 commit comments

Comments
 (0)