diff --git a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/StaticRouteHandlerModel.Parser.cs b/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/StaticRouteHandlerModel.Parser.cs index 38e6924b5633..4a43e3aab0ff 100644 --- a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/StaticRouteHandlerModel.Parser.cs +++ b/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/StaticRouteHandlerModel.Parser.cs @@ -75,22 +75,15 @@ private static bool TryGetRouteHandlerPattern(IInvocationOperation invocation, o private static bool TryGetRouteHandlerMethod(IInvocationOperation invocation, out IMethodSymbol method) { - IArgumentOperation? argumentOperation = null; - method = null; foreach (var argument in invocation.Arguments) { if (argument.Parameter?.Ordinal == _routeHandlerArgumentOrdinal) { - argumentOperation = argument; + method = ResolveMethodFromOperation(argument); + return true; } } - - if (argumentOperation is not null) - { - method = ResolveMethodFromOperation(argumentOperation); - return true; - } - + method = null; return false; } diff --git a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/StaticRouteHandlerModel.cs b/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/StaticRouteHandlerModel.cs index 99e29d282065..8ea595f82635 100644 --- a/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/StaticRouteHandlerModel.cs +++ b/src/Http/Http.Extensions/gen/StaticRouteHandlerModel/StaticRouteHandlerModel.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System; using System.Collections.Generic; namespace Microsoft.AspNetCore.Http.Generators.StaticRouteHandlerModel; @@ -15,38 +16,92 @@ internal enum RequestParameterSource BodyOrService } -internal sealed class RequestParameter +internal sealed class RequestParameter : IEquatable { public string Name { get; } public string Type { get; } public RequestParameterSource Source { get; set; } public bool IsOptional { get; set; } public object? DefaultValue { get; set; } + + public override bool Equals(object? obj) + => obj is RequestParameter requestParameter && Equals(requestParameter); + + public bool Equals(RequestParameter other) + => Name.Equals(other.Name, StringComparison.Ordinal) && + Type.Equals(other.Type, StringComparison.Ordinal) && + Source == other.Source && + IsOptional == other.IsOptional && + DefaultValue.Equals(DefaultValue); + + public override int GetHashCode() + => (Name, Type, Source, IsOptional, DefaultValue).GetHashCode(); } -internal sealed class EndpointRoute +internal sealed class EndpointRoute : IEquatable { public string RoutePattern { get; set; } public List RouteParameters { get; set; } + + public override bool Equals(object? obj) + => obj is EndpointRoute route && Equals(route); + + public bool Equals(EndpointRoute other) + => RoutePattern.Equals(other.RoutePattern, StringComparison.Ordinal) && + RouteParameters.Equals(other.RouteParameters); + + public override int GetHashCode() + => (RoutePattern, RouteParameters).GetHashCode(); } -internal sealed class EndpointResponse +internal sealed class EndpointResponse : IEquatable { public string ResponseType { get; set; } public string ContentType { get; set; } + public override bool Equals(object? obj) + => obj is EndpointResponse endpointResponse && Equals(endpointResponse); + + public bool Equals(EndpointResponse other) + => ResponseType == other.ResponseType + && ContentType == other.ContentType; + + public override int GetHashCode() + => (ResponseType, ContentType).GetHashCode(); } -internal sealed class EndpointRequest +internal sealed class EndpointRequest : IEquatable { public List RequestParameters { get; set; } + + public override bool Equals(object? obj) + => obj is EndpointRequest endpointRequest && Equals(endpointRequest); + + public bool Equals(EndpointRequest other) + => RequestParameters == other.RequestParameters; + + public override int GetHashCode() + => RequestParameters.GetHashCode(); } -internal sealed class Endpoint +internal sealed class Endpoint : IEquatable { public string HttpMethod { get; set; } public EndpointRoute Route { get; set; } public EndpointRequest Request { get; set; } public EndpointResponse Response { get; set; } public (string, int) Location { get; set; } + + public override bool Equals(object? obj) + => obj is Endpoint endpoint && Equals(endpoint); + + public bool Equals(Endpoint other) + => HttpMethod == other.HttpMethod && + Route.Equals(other.Route) && + Request.Equals(other.Request) && + Response.Equals(other.Response) && + Location.Equals(other.Location); + + public override int GetHashCode() + => (HttpMethod, Route, Request, Response, Location).GetHashCode(); }