1
1
// Licensed to the .NET Foundation under one or more agreements.
2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
4
+ using System ;
4
5
using System . Collections . Generic ;
5
6
6
7
namespace Microsoft . AspNetCore . Http . Generators . StaticRouteHandlerModel ;
@@ -15,38 +16,92 @@ internal enum RequestParameterSource
15
16
BodyOrService
16
17
}
17
18
18
- internal sealed class RequestParameter
19
+ internal sealed class RequestParameter : IEquatable < RequestParameter >
19
20
{
20
21
public string Name { get ; }
21
22
public string Type { get ; }
22
23
public RequestParameterSource Source { get ; set ; }
23
24
public bool IsOptional { get ; set ; }
24
25
public object ? DefaultValue { get ; set ; }
26
+
27
+ public override bool Equals ( object ? obj )
28
+ => obj is RequestParameter requestParameter && Equals ( requestParameter ) ;
29
+
30
+ public bool Equals ( RequestParameter other )
31
+ => Name . Equals ( other . Name , StringComparison . Ordinal ) &&
32
+ Type . Equals ( other . Type , StringComparison . Ordinal ) &&
33
+ Source == other . Source &&
34
+ IsOptional == other . IsOptional &&
35
+ DefaultValue . Equals ( DefaultValue ) ;
36
+
37
+ public override int GetHashCode ( )
38
+ => ( Name , Type , Source , IsOptional , DefaultValue ) . GetHashCode ( ) ;
25
39
}
26
40
27
- internal sealed class EndpointRoute
41
+ internal sealed class EndpointRoute : IEquatable < EndpointRoute >
28
42
{
29
43
public string RoutePattern { get ; set ; }
30
44
31
45
public List < string > RouteParameters { get ; set ; }
46
+
47
+ public override bool Equals ( object ? obj )
48
+ => obj is EndpointRoute route && Equals ( route ) ;
49
+
50
+ public bool Equals ( EndpointRoute other )
51
+ => RoutePattern . Equals ( other . RoutePattern , StringComparison . Ordinal ) &&
52
+ RouteParameters . Equals ( other . RouteParameters ) ;
53
+
54
+ public override int GetHashCode ( )
55
+ => ( RoutePattern , RouteParameters ) . GetHashCode ( ) ;
32
56
}
33
57
34
- internal sealed class EndpointResponse
58
+ internal sealed class EndpointResponse : IEquatable < EndpointResponse >
35
59
{
36
60
public string ResponseType { get ; set ; }
37
61
public string ContentType { get ; set ; }
62
+ public override bool Equals ( object ? obj )
63
+ => obj is EndpointResponse endpointResponse && Equals ( endpointResponse ) ;
64
+
65
+ public bool Equals ( EndpointResponse other )
66
+ => ResponseType == other . ResponseType
67
+ && ContentType == other . ContentType ;
68
+
69
+ public override int GetHashCode ( )
70
+ => ( ResponseType , ContentType ) . GetHashCode ( ) ;
38
71
}
39
72
40
- internal sealed class EndpointRequest
73
+ internal sealed class EndpointRequest : IEquatable < EndpointRequest >
41
74
{
42
75
public List < RequestParameter > RequestParameters { get ; set ; }
76
+
77
+ public override bool Equals ( object ? obj )
78
+ => obj is EndpointRequest endpointRequest && Equals ( endpointRequest ) ;
79
+
80
+ public bool Equals ( EndpointRequest other )
81
+ => RequestParameters == other . RequestParameters ;
82
+
83
+ public override int GetHashCode ( )
84
+ => RequestParameters . GetHashCode ( ) ;
43
85
}
44
86
45
- internal sealed class Endpoint
87
+ internal sealed class Endpoint : IEquatable < Endpoint >
46
88
{
47
89
public string HttpMethod { get ; set ; }
48
90
public EndpointRoute Route { get ; set ; }
49
91
public EndpointRequest Request { get ; set ; }
50
92
public EndpointResponse Response { get ; set ; }
51
93
public ( string , int ) Location { get ; set ; }
94
+
95
+ public override bool Equals ( object ? obj )
96
+ => obj is Endpoint endpoint && Equals ( endpoint ) ;
97
+
98
+ public bool Equals ( Endpoint other )
99
+ => HttpMethod == other . HttpMethod &&
100
+ Route . Equals ( other . Route ) &&
101
+ Request . Equals ( other . Request ) &&
102
+ Response . Equals ( other . Response ) &&
103
+ Location . Equals ( other . Location ) ;
104
+
105
+ public override int GetHashCode ( )
106
+ => ( HttpMethod , Route , Request , Response , Location ) . GetHashCode ( ) ;
52
107
}
0 commit comments