Skip to content

Commit

Permalink
Merge pull request #801 from sunero4/feat/static-lambdas
Browse files Browse the repository at this point in the history
Added static modifier for lambdas where applicable in Mediatr project.
  • Loading branch information
jbogard authored Nov 20, 2022
2 parents d2f166e + 205172d commit 054ccc1
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/MediatR/Internal/HandlersOrderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ public static IList<object> Prioritize<TRequest>(IList<object> handlers, TReques
}

var requestObjectDetails = new ObjectDetails(request);
var handlerObjectsDetails = handlers.Select(s => new ObjectDetails(s)).ToList();
var handlerObjectsDetails = handlers.Select(static s => new ObjectDetails(s)).ToList();

var uniqueHandlers = RemoveOverridden(handlerObjectsDetails).ToArray();
Array.Sort(uniqueHandlers, requestObjectDetails);

return uniqueHandlers.Select(s => s.Value).ToList();
return uniqueHandlers.Select(static s => s.Value).ToList();
}

private static IEnumerable<ObjectDetails> RemoveOverridden(IList<ObjectDetails> handlersData)
Expand All @@ -45,6 +45,6 @@ private static IEnumerable<ObjectDetails> RemoveOverridden(IList<ObjectDetails>
}
}

return handlersData.Where(w => !w.IsOverridden);
return handlersData.Where(static w => !w.IsOverridden);
}
}
2 changes: 1 addition & 1 deletion src/MediatR/Mediator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public IAsyncEnumerable<TResponse> CreateStream<TResponse>(IStreamRequest<TRespo
{
var requestInterfaceType = requestTypeKey
.GetInterfaces()
.FirstOrDefault(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IStreamRequest<>));
.FirstOrDefault(static i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IStreamRequest<>));
var isValidRequest = requestInterfaceType != null;

if (!isValidRequest)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public async Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TRe

var actionsForException = exceptionTypes
.SelectMany(exceptionType => GetActionsForException(exceptionType, request))
.GroupBy(actionForException => actionForException.Action.GetType())
.Select(actionForException => actionForException.First())
.Select(actionForException => (MethodInfo: GetMethodInfoForAction(actionForException.ExceptionType), actionForException.Action))
.GroupBy(static actionForException => actionForException.Action.GetType())
.Select(static actionForException => actionForException.First())
.Select(static actionForException => (MethodInfo: GetMethodInfoForAction(actionForException.ExceptionType), actionForException.Action))
.ToList();

foreach (var actionForException in actionsForException)
Expand Down
6 changes: 3 additions & 3 deletions src/MediatR/Pipeline/RequestExceptionProcessorBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public async Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TRe

var handlersForException = exceptionTypes
.SelectMany(exceptionType => GetHandlersForException(exceptionType, request))
.GroupBy(handlerForException => handlerForException.Handler.GetType())
.Select(handlerForException => handlerForException.First())
.Select(handlerForException => (MethodInfo: GetMethodInfoForHandler(handlerForException.ExceptionType), handlerForException.Handler))
.GroupBy(static handlerForException => handlerForException.Handler.GetType())
.Select(static handlerForException => handlerForException.First())
.Select(static handlerForException => (MethodInfo: GetMethodInfoForHandler(handlerForException.ExceptionType), handlerForException.Handler))
.ToList();

foreach (var handlerForException in handlersForException)
Expand Down
2 changes: 1 addition & 1 deletion src/MediatR/Wrappers/NotificationHandlerWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public override Task Handle(INotification notification, ServiceFactory serviceFa
{
var handlers = serviceFactory
.GetInstances<INotificationHandler<TNotification>>()
.Select(x => new Func<INotification, CancellationToken, Task>((theNotification, theToken) => x.Handle((TNotification)theNotification, theToken)));
.Select(static x => new Func<INotification, CancellationToken, Task>((theNotification, theToken) => x.Handle((TNotification)theNotification, theToken)));

return publish(handlers, notification, cancellationToken);
}
Expand Down

0 comments on commit 054ccc1

Please sign in to comment.