Skip to content

Commit

Permalink
Use collection literals when invoking methods
Browse files Browse the repository at this point in the history
  • Loading branch information
mburumaxwell committed Jun 5, 2024
1 parent a55144d commit 09cdcf7
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ private async Task ReceiveAsync(EventRegistration reg, EventConsumerRegistration
using var scope = CreateScope(); // shared
foreach (var message in messages)
{
await ((Task)method.Invoke(this, new object[] { reg, ecr, queueUrl, message, cancellationToken, })!).ConfigureAwait(false);
await ((Task)method.Invoke(this, [reg, ecr, queueUrl, message, cancellationToken])!).ConfigureAwait(false);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected override async Task StartCoreAsync(CancellationToken cancellationToken
var flags = System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic;
var mt = GetType().GetMethod(nameof(OnEventReceivedAsync), flags) ?? throw new InvalidOperationException("Methods should be null");
var method = mt.MakeGenericMethod(reg.EventType, ecr.ConsumerType);
return (Task)method.Invoke(this, new object[] { reg, ecr, processor, args, })!;
return (Task)method.Invoke(this, [reg, ecr, processor, args])!;
};

// start processing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ private async Task ReceiveAsync(EventRegistration reg, EventConsumerRegistration
using var scope = CreateScope(); // shared
foreach (var message in messages)
{
await ((Task)method.Invoke(this, new object[] { reg, ecr, queueClient, message, scope, cancellationToken, })!).ConfigureAwait(false);
await ((Task)method.Invoke(this, [reg, ecr, queueClient, message, scope, cancellationToken])!).ConfigureAwait(false);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ protected override async Task StartCoreAsync(CancellationToken cancellationToken
var flags = System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic;
var mt = GetType().GetMethod(nameof(OnMessageReceivedAsync), flags) ?? throw new InvalidOperationException("Methods should be null");
var method = mt.MakeGenericMethod(reg.EventType, ecr.ConsumerType);
return (Task)method.Invoke(this, new object[] { reg, ecr, processor, args, })!;
return (Task)method.Invoke(this, [reg, ecr, processor, args])!;
};

// start processing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public async Task CancelScheduledMessageAsync(long sequenceNumber, CancellationT
?? throw new ArgumentException($"An item with the sequence number {sequenceNumber} does not exist.", nameof(sequenceNumber));

// make new items and replace
items = items.AsEnumerable().Except(new[] { matching }).ToList();
items = items.AsEnumerable().Except([matching]).ToList();
}
finally
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ protected override async Task StartCoreAsync(CancellationToken cancellationToken
var flags = System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic;
var mt = GetType().GetMethod(nameof(OnMessageReceivedAsync), flags) ?? throw new InvalidOperationException("Methods should be null");
var method = mt.MakeGenericMethod(reg.EventType, ecr.ConsumerType);
return (Task)method.Invoke(this, new object[] { reg, ecr, processor, args, })!;
return (Task)method.Invoke(this, [reg, ecr, processor, args])!;
};

// start processing
Expand Down
2 changes: 1 addition & 1 deletion src/Tingle.EventBus.Transports.Kafka/KafkaTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ private async Task ProcessAsync(CancellationToken cancellationToken)
// form the generic method
var ecr = reg.Consumers.Single(); // only one consumer per event
var method = mt.MakeGenericMethod(reg.EventType, ecr.ConsumerType);
await ((Task)method.Invoke(this, new object[] { reg, ecr, result, cancellationToken, })!).ConfigureAwait(false);
await ((Task)method.Invoke(this, [reg, ecr, result, cancellationToken])!).ConfigureAwait(false);
}
catch (TaskCanceledException)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ private async Task ConnectConsumersAsync(CancellationToken cancellationToken)
var flags = System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic;
var mt = GetType().GetMethod(nameof(OnMessageReceivedAsync), flags) ?? throw new InvalidOperationException("Methods should be null");
var method = mt.MakeGenericMethod(reg.EventType, ecr.ConsumerType);
return (Task)method.Invoke(this, new object[] { reg, ecr, channel, @event, CancellationToken.None, })!; // do not chain CancellationToken
return (Task)method.Invoke(this, [reg, ecr, channel, @event, CancellationToken.None])!; // do not chain CancellationToken
};
channel.BasicConsume(queue: queueName, autoAck: false, consumer);
}
Expand Down

0 comments on commit 09cdcf7

Please sign in to comment.