-
-
Notifications
You must be signed in to change notification settings - Fork 784
Expand file tree
/
Copy pathMethodTableKey.cs
More file actions
79 lines (66 loc) · 2.51 KB
/
Copy pathMethodTableKey.cs
File metadata and controls
79 lines (66 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright (c) 2019-2026 ReactiveUI and Contributors. All rights reserved.
// ReactiveUI and Contributors licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.
namespace Refit;
/// <summary>Represents a method composed of its name, generic arguments and parameters.</summary>
internal readonly struct MethodTableKey : IEquatable<MethodTableKey>
{
/// <summary>Initializes a new instance of the <see cref="MethodTableKey"/> struct.</summary>
/// <param name="methodName">Represents the methods name.</param>
/// <param name="parameters">Array containing the methods parameters.</param>
/// <param name="genericArguments">Array containing the methods generic arguments.</param>
internal MethodTableKey(string methodName, Type[] parameters, Type[] genericArguments)
{
MethodName = methodName;
Parameters = parameters;
GenericArguments = genericArguments;
}
/// <summary>Gets the methods name.</summary>
internal string MethodName { get; }
/// <summary>Gets the Array containing the methods parameters.</summary>
internal Type[] Parameters { get; }
/// <summary>Gets the Array containing the methods generic arguments.</summary>
internal Type[] GenericArguments { get; }
/// <inheritdoc/>
public override int GetHashCode()
{
HashCode hashCode = default;
hashCode.Add(MethodName);
for (var i = 0; i < Parameters.Length; i++)
{
hashCode.Add(Parameters[i]);
}
for (var i = 0; i < GenericArguments.Length; i++)
{
hashCode.Add(GenericArguments[i]);
}
return hashCode.ToHashCode();
}
/// <inheritdoc/>
public bool Equals(MethodTableKey other)
{
if (Parameters.Length != other.Parameters.Length
|| GenericArguments.Length != other.GenericArguments.Length
|| MethodName != other.MethodName)
{
return false;
}
for (var i = 0; i < Parameters.Length; i++)
{
if (Parameters[i] != other.Parameters[i])
{
return false;
}
}
for (var i = 0; i < GenericArguments.Length; i++)
{
if (GenericArguments[i] != other.GenericArguments[i])
{
return false;
}
}
return true;
}
/// <inheritdoc/>
public override bool Equals(object? obj) => obj is MethodTableKey other && Equals(other);
}