Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small, targeted refactor: Address CA1517 (use nameof) #8516

Merged
merged 1 commit into from Jul 5, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/AWS/Orleans.Streaming.SQS/Streams/SQSAdapter.cs
Expand Up @@ -25,7 +25,7 @@ internal class SQSAdapter : IQueueAdapter

public SQSAdapter(Serializer<SQSBatchContainer> serializer, IConsistentRingStreamQueueMapper streamQueueMapper, ILoggerFactory loggerFactory, string dataConnectionString, string serviceId, string providerName)
{
if (string.IsNullOrEmpty(dataConnectionString)) throw new ArgumentNullException("dataConnectionString");
if (string.IsNullOrEmpty(dataConnectionString)) throw new ArgumentNullException(nameof(dataConnectionString));
if (string.IsNullOrEmpty(serviceId)) throw new ArgumentNullException(nameof(serviceId));
this.loggerFactory = loggerFactory;
this.serializer = serializer;
Expand All @@ -44,7 +44,7 @@ public async Task QueueMessageBatchAsync<T>(StreamId streamId, IEnumerable<T> ev
{
if (token != null)
{
throw new ArgumentException("SQSStream stream provider currently does not support non-null StreamSequenceToken.", "token");
throw new ArgumentException("SQSStream stream provider currently does not support non-null StreamSequenceToken.", nameof(token));
}
var queueId = streamQueueMapper.GetQueueForStream(streamId);
SQSStorage queue;
Expand Down
8 changes: 4 additions & 4 deletions src/AWS/Orleans.Streaming.SQS/Streams/SQSAdapterReceiver.cs
Expand Up @@ -27,8 +27,8 @@ internal class SQSAdapterReceiver : IQueueAdapterReceiver

public static IQueueAdapterReceiver Create(Serializer<SQSBatchContainer> serializer, ILoggerFactory loggerFactory, QueueId queueId, string dataConnectionString, string serviceId)
{
if (queueId.IsDefault) throw new ArgumentNullException("queueId");
if (string.IsNullOrEmpty(dataConnectionString)) throw new ArgumentNullException("dataConnectionString");
if (queueId.IsDefault) throw new ArgumentNullException(nameof(queueId));
if (string.IsNullOrEmpty(dataConnectionString)) throw new ArgumentNullException(nameof(dataConnectionString));
if (string.IsNullOrEmpty(serviceId)) throw new ArgumentNullException(nameof(serviceId));

var queue = new SQSStorage(loggerFactory, queueId.ToString(), dataConnectionString, serviceId);
Expand All @@ -37,8 +37,8 @@ public static IQueueAdapterReceiver Create(Serializer<SQSBatchContainer> seriali

private SQSAdapterReceiver(Serializer<SQSBatchContainer> serializer, ILoggerFactory loggerFactory, QueueId queueId, SQSStorage queue)
{
if (queueId.IsDefault) throw new ArgumentNullException("queueId");
if (queue == null) throw new ArgumentNullException("queue");
if (queueId.IsDefault) throw new ArgumentNullException(nameof(queueId));
if (queue == null) throw new ArgumentNullException(nameof(queue));

Id = queueId;
this.queue = queue;
Expand Down
2 changes: 1 addition & 1 deletion src/AWS/Orleans.Streaming.SQS/Streams/SQSBatchContainer.cs
Expand Up @@ -54,7 +54,7 @@ public StreamSequenceToken SequenceToken

private SQSBatchContainer(StreamId streamId, List<object> events, Dictionary<string, object> requestContext)
{
if (events == null) throw new ArgumentNullException("events", "Message contains no events");
if (events == null) throw new ArgumentNullException(nameof(events), "Message contains no events");

StreamId = streamId;
this.events = events;
Expand Down
Expand Up @@ -99,12 +99,12 @@ public async Task<bool> InsertRow(MembershipEntry entry, TableVersion tableVersi
if (entry == null)
{
if (logger.IsEnabled(LogLevel.Debug)) logger.LogDebug("AdoNetClusteringTable.InsertRow aborted due to null check. MembershipEntry is null.");
throw new ArgumentNullException("entry");
throw new ArgumentNullException(nameof(entry));
}
if (tableVersion == null)
{
if (logger.IsEnabled(LogLevel.Debug)) logger.LogDebug("AdoNetClusteringTable.InsertRow aborted due to null check. TableVersion is null ");
throw new ArgumentNullException("tableVersion");
throw new ArgumentNullException(nameof(tableVersion));
}

try
Expand All @@ -131,12 +131,12 @@ public async Task<bool> UpdateRow(MembershipEntry entry, string etag, TableVersi
if (entry == null)
{
if (logger.IsEnabled(LogLevel.Debug)) logger.LogDebug("AdoNetClusteringTable.UpdateRow aborted due to null check. MembershipEntry is null.");
throw new ArgumentNullException("entry");
throw new ArgumentNullException(nameof(entry));
}
if (tableVersion == null)
{
if (logger.IsEnabled(LogLevel.Debug)) logger.LogDebug("AdoNetClusteringTable.UpdateRow aborted due to null check. TableVersion is null");
throw new ArgumentNullException("tableVersion");
throw new ArgumentNullException(nameof(tableVersion));
}

try
Expand All @@ -158,7 +158,7 @@ public async Task UpdateIAmAlive(MembershipEntry entry)
if (entry == null)
{
if (logger.IsEnabled(LogLevel.Debug)) logger.LogDebug("AdoNetClusteringTable.UpdateIAmAlive aborted due to null check. MembershipEntry is null.");
throw new ArgumentNullException("entry");
throw new ArgumentNullException(nameof(entry));
}
try
{
Expand Down
32 changes: 16 additions & 16 deletions src/AdoNet/Shared/Storage/OrleansRelationalDownloadStream.cs
Expand Up @@ -62,10 +62,10 @@ public class OrleansRelationalDownloadStream : Stream
/// <param name="reader">The reader to use to read from the database.</param>
/// <param name="ordinal">The column ordinal to read from.</param>
public OrleansRelationalDownloadStream(DbDataReader reader, int ordinal)
{
{
this.reader = reader;
this.ordinal = ordinal;

//This return the total length of the column pointed by the ordinal.
totalBytes = reader.GetBytes(ordinal, 0, null, 0, 0);
}
Expand Down Expand Up @@ -112,7 +112,7 @@ public override bool CanWrite

/// <summary>
/// The length of the stream.
/// </summary>
/// </summary>
public override long Length
{
get { return totalBytes; }
Expand All @@ -128,10 +128,10 @@ public override long Position
set { throw new NotSupportedException(); }
}


/// <summary>
/// Throws <exception cref="NotSupportedException"/>.
/// </summary>
/// </summary>
/// <exception cref="NotSupportedException" />.
public override void Flush()
{
Expand All @@ -152,7 +152,7 @@ public override int Read(byte[] buffer, int offset, int count)
ValidateReadParameters(buffer, offset, count);

try
{
{
int length = Math.Min(count, (int)(totalBytes - position));
long bytesRead = 0;
if(length > 0)
Expand All @@ -176,7 +176,7 @@ public override int Read(byte[] buffer, int offset, int count)
/// </summary>
/// <param name="buffer">The buffer to read to.</param>
/// <param name="offset">The offset to the buffer to stat reading.</param>
/// <param name="count">The count of bytes to read to.</param>
/// <param name="count">The count of bytes to read to.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>The number of actual bytes read from the stream.</returns>
public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
Expand Down Expand Up @@ -236,7 +236,7 @@ public override async Task CopyToAsync(Stream destination, int bufferSize, Cance
}
}


/// <summary>
/// Throws <exception cref="NotSupportedException"/>.
/// </summary>
Expand All @@ -251,7 +251,7 @@ public override long Seek(long offset, SeekOrigin origin)


/// <summary>
/// Throws <exception cref="NotSupportedException"/>.
/// Throws <exception cref="NotSupportedException"/>.
/// </summary>
/// <returns>Throws <exception cref="NotSupportedException"/>.</returns>
/// <exception cref="NotSupportedException" />.
Expand All @@ -262,7 +262,7 @@ public override void SetLength(long value)


/// <summary>
/// Throws <exception cref="NotSupportedException"/>.
/// Throws <exception cref="NotSupportedException"/>.
/// </summary>
/// <param name="buffer">The buffer.</param>
/// <param name="offset">The offset to the buffer.</param>
Expand Down Expand Up @@ -290,23 +290,23 @@ protected override void Dispose(bool disposing)

/// <summary>
/// Checks the parameters passed into a ReadAsync() or Read() are valid.
/// </summary>
/// </summary>
/// <param name="buffer"></param>
/// <param name="offset"></param>
/// <param name="count"></param>
private static void ValidateReadParameters(byte[] buffer, int offset, int count)
{
{
if(buffer == null)
{
throw new ArgumentNullException("buffer");
throw new ArgumentNullException(nameof(buffer));
}
if(offset < 0)
{
throw new ArgumentOutOfRangeException("offset");
throw new ArgumentOutOfRangeException(nameof(offset));
}
if(count < 0)
{
throw new ArgumentOutOfRangeException("count");
throw new ArgumentOutOfRangeException(nameof(count));
}
try
{
Expand All @@ -316,7 +316,7 @@ private static void ValidateReadParameters(byte[] buffer, int offset, int count)
}
}
catch(OverflowException)
{
{
throw new ArgumentException("Invalid offset length");
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/AdoNet/Shared/Storage/RelationalStorage.cs
Expand Up @@ -87,12 +87,12 @@ public static IRelationalStorage CreateInstance(string invariantName, string con
{
if(string.IsNullOrWhiteSpace(invariantName))
{
throw new ArgumentException("The name of invariant must contain characters", "invariantName");
throw new ArgumentException("The name of invariant must contain characters", nameof(invariantName));
}

if(string.IsNullOrWhiteSpace(connectionString))
{
throw new ArgumentException("Connection string must contain characters", "connectionString");
throw new ArgumentException("Connection string must contain characters", nameof(connectionString));
}

return new RelationalStorage(invariantName, connectionString);
Expand Down Expand Up @@ -153,12 +153,12 @@ public async Task<IEnumerable<TResult>> ReadAsync<TResult>(string query, Action<
//If the query is something else that is not acceptable (e.g. an empty string), there will an appropriate database exception.
if(query == null)
{
throw new ArgumentNullException("query");
throw new ArgumentNullException(nameof(query));
}

if(selector == null)
{
throw new ArgumentNullException("selector");
throw new ArgumentNullException(nameof(selector));
}

return (await ExecuteAsync(query, parameterProvider, ExecuteReaderAsync, selector, cancellationToken, commandBehavior).ConfigureAwait(false)).Item1;
Expand Down Expand Up @@ -191,7 +191,7 @@ public async Task<int> ExecuteAsync(string query, Action<IDbCommand> parameterPr
//If the query is something else that is not acceptable (e.g. an empty string), there will an appropriate database exception.
if(query == null)
{
throw new ArgumentNullException("query");
throw new ArgumentNullException(nameof(query));
}

return (await ExecuteAsync(query, parameterProvider, ExecuteReaderAsync, (unit, id, c) => Task.FromResult(unit), cancellationToken, commandBehavior).ConfigureAwait(false)).Item2;
Expand Down
4 changes: 2 additions & 2 deletions src/AdoNet/Shared/Storage/RelationalStorageExtensions.cs
Expand Up @@ -50,12 +50,12 @@ public static Task<int> ExecuteMultipleInsertIntoAsync<T>(this IRelationalStorag
{
if(string.IsNullOrWhiteSpace(tableName))
{
throw new ArgumentException("The name must be a legal SQL table name", "tableName");
throw new ArgumentException("The name must be a legal SQL table name", nameof(tableName));
}

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

var storageConsts = DbConstantsStore.GetDbConstants(storage.InvariantName);
Expand Down
Expand Up @@ -50,7 +50,7 @@ internal EventSequenceToken RealSequenceToken

public AzureQueueBatchContainer(StreamId streamId, List<object> events, Dictionary<string, object> requestContext)
{
if (events == null) throw new ArgumentNullException("events", "Message contains no events");
if (events == null) throw new ArgumentNullException(nameof(events), "Message contains no events");

StreamId = streamId;
this.events = events;
Expand Down
Expand Up @@ -96,11 +96,11 @@ public Task InitAsync()
{
if (subscriptionId == null)
{
throw new ArgumentNullException("subscriptionId");
throw new ArgumentNullException(nameof(subscriptionId));
}
if (string.IsNullOrWhiteSpace(streamProviderName))
{
throw new ArgumentNullException("streamProviderName");
throw new ArgumentNullException(nameof(streamProviderName));
}

var failureEntity = createEntity();
Expand Down
8 changes: 4 additions & 4 deletions src/Azure/Shared/Storage/AzureTableDataManager.cs
Expand Up @@ -455,11 +455,11 @@ public async Task DeleteTableEntriesAsync(List<(T Entity, string ETag)> collecti
var startTime = DateTime.UtcNow;
if (Logger.IsEnabled(LogLevel.Trace)) Logger.LogTrace("{Operation} entries: {Data} table {TableName}", operation, Utils.EnumerableToString(collection), TableName);

if (collection == null) throw new ArgumentNullException("collection");
if (collection == null) throw new ArgumentNullException(nameof(collection));

if (collection.Count > this.StoragePolicyOptions.MaxBulkUpdateRows)
{
throw new ArgumentOutOfRangeException("collection", collection.Count,
throw new ArgumentOutOfRangeException(nameof(collection), collection.Count,
"Too many rows for bulk delete - max " + this.StoragePolicyOptions.MaxBulkUpdateRows);
}

Expand Down Expand Up @@ -564,10 +564,10 @@ await foreach (var value in results)
public async Task BulkInsertTableEntries(IReadOnlyCollection<T> collection)
{
const string operation = "BulkInsertTableEntries";
if (collection == null) throw new ArgumentNullException("collection");
if (collection == null) throw new ArgumentNullException(nameof(collection));
if (collection.Count > this.StoragePolicyOptions.MaxBulkUpdateRows)
{
throw new ArgumentOutOfRangeException("collection", collection.Count,
throw new ArgumentOutOfRangeException(nameof(collection), collection.Count,
"Too many rows for bulk update - max " + this.StoragePolicyOptions.MaxBulkUpdateRows);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Orleans.Core.Abstractions/IDs/Legacy/UniqueKey.cs
Expand Up @@ -133,7 +133,7 @@ private static UniqueKey NewKey(ulong typeCodeData, string keyExt)
if (IsKeyExt(GetCategory(typeCodeData)))
{
if (string.IsNullOrWhiteSpace(keyExt))
throw keyExt is null ? new ArgumentNullException("keyExt") : throw new ArgumentException("Extended key is empty or white space.", "keyExt");
throw keyExt is null ? new ArgumentNullException(nameof(keyExt)) : throw new ArgumentException("Extended key is empty or white space.", nameof(keyExt));
}
else if (keyExt != null) throw new ArgumentException("Only key extended grains can specify a non-null key extension.");
return new UniqueKey { TypeCodeData = typeCodeData, KeyExt = keyExt };
Expand Down
8 changes: 4 additions & 4 deletions src/Orleans.Core/Async/AsyncExecutorWithRetries.cs
Expand Up @@ -346,10 +346,10 @@ internal class ExponentialBackoff : IBackoffProvider
/// </exception>
public ExponentialBackoff(TimeSpan minDelay, TimeSpan maxDelay, TimeSpan step)
{
if (minDelay <= TimeSpan.Zero) throw new ArgumentOutOfRangeException("minDelay", minDelay, "ExponentialBackoff min delay must be a positive number.");
if (maxDelay <= TimeSpan.Zero) throw new ArgumentOutOfRangeException("maxDelay", maxDelay, "ExponentialBackoff max delay must be a positive number.");
if (step <= TimeSpan.Zero) throw new ArgumentOutOfRangeException("step", step, "ExponentialBackoff step must be a positive number.");
if (minDelay >= maxDelay) throw new ArgumentOutOfRangeException("minDelay", minDelay, "ExponentialBackoff min delay must be greater than max delay.");
if (minDelay <= TimeSpan.Zero) throw new ArgumentOutOfRangeException(nameof(minDelay), minDelay, "ExponentialBackoff min delay must be a positive number.");
if (maxDelay <= TimeSpan.Zero) throw new ArgumentOutOfRangeException(nameof(maxDelay), maxDelay, "ExponentialBackoff max delay must be a positive number.");
if (step <= TimeSpan.Zero) throw new ArgumentOutOfRangeException(nameof(step), step, "ExponentialBackoff step must be a positive number.");
if (minDelay >= maxDelay) throw new ArgumentOutOfRangeException(nameof(minDelay), minDelay, "ExponentialBackoff min delay must be greater than max delay.");

this.minDelay = minDelay;
this.maxDelay = maxDelay;
Expand Down
2 changes: 1 addition & 1 deletion src/Orleans.Core/Async/MultiTaskCompletionSource.cs
Expand Up @@ -25,7 +25,7 @@ public MultiTaskCompletionSource(int count)
{
if (count <= 0)
{
throw new ArgumentOutOfRangeException("count", "count has to be positive.");
throw new ArgumentOutOfRangeException(nameof(count), "count has to be positive.");
}
tcs = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
this.count = count;
Expand Down