|
2 | 2 | using System.Collections.Generic; |
3 | 3 | using System.Linq; |
4 | 4 | using System.Reflection; |
| 5 | +using System.Runtime.InteropServices; |
5 | 6 |
|
6 | 7 | namespace DllManipulator.Internal |
7 | 8 | { |
@@ -52,115 +53,47 @@ public NativeFunction(NativeFunctionIdentity identity, NativeDll containingDll) |
52 | 53 |
|
53 | 54 | internal class NativeFunctionSignature |
54 | 55 | { |
55 | | - public readonly Type returnParameterType; |
56 | | - public readonly Type[] returnParameterRequiredModifiers; |
57 | | - public readonly Type[] retunrParameterOptionalModifiers; |
| 56 | + public readonly Type returnParameterType; |
58 | 57 | public readonly Type[] parameterTypes; |
59 | | - public readonly Type[][] parameterRequiredModifiers; |
60 | | - public readonly Type[][] parameterOptionalModifiers; |
61 | | - public readonly System.Runtime.InteropServices.CallingConvention callingConvention; |
| 58 | + public readonly CallingConvention callingConvention; |
| 59 | + public readonly bool bestFitMapping; |
| 60 | + public readonly CharSet charSet; |
| 61 | + public readonly bool setLastError; |
| 62 | + public readonly bool throwOnUnmappableChar; |
62 | 63 |
|
63 | | - public NativeFunctionSignature(MethodInfo methodInfo, System.Runtime.InteropServices.CallingConvention callingConvention) |
| 64 | + public NativeFunctionSignature(MethodInfo methodInfo, CallingConvention callingConvention, bool bestFitMapping, CharSet charSet, bool setLastError, bool throwOnUnmappableChar) |
64 | 65 | { |
65 | | - var returnParameter = methodInfo.ReturnParameter; |
66 | | - returnParameterType = returnParameter.ParameterType; |
67 | | - returnParameterRequiredModifiers = returnParameter.GetRequiredCustomModifiers(); |
68 | | - retunrParameterOptionalModifiers = returnParameter.GetOptionalCustomModifiers(); |
69 | | - var parameters = methodInfo.GetParameters(); |
70 | | - parameterTypes = parameters.Select(p => p.ParameterType).ToArray(); |
71 | | - parameterRequiredModifiers = new Type[parameters.Length][]; |
72 | | - parameterOptionalModifiers = new Type[parameters.Length][]; |
73 | | - for (int i = 0; i < parameters.Length; i++) |
74 | | - { |
75 | | - parameterRequiredModifiers[i] = parameters[i].GetRequiredCustomModifiers(); |
76 | | - parameterOptionalModifiers[i] = parameters[i].GetOptionalCustomModifiers(); |
77 | | - } |
78 | | - |
| 66 | + this.returnParameterType = methodInfo.ReturnType; |
| 67 | + this.parameterTypes = methodInfo.GetParameters().Select(p => p.ParameterType).ToArray(); |
79 | 68 | this.callingConvention = callingConvention; |
| 69 | + this.bestFitMapping = bestFitMapping; |
| 70 | + this.charSet = charSet; |
| 71 | + this.setLastError = setLastError; |
| 72 | + this.throwOnUnmappableChar = throwOnUnmappableChar; |
80 | 73 | } |
81 | 74 |
|
82 | 75 | public override bool Equals(object obj) |
83 | 76 | { |
84 | | - if (obj == null) |
85 | | - { |
86 | | - return false; |
87 | | - } |
88 | | - |
89 | | - if (obj is NativeFunctionSignature other) |
90 | | - { |
91 | | - return Equals(other); |
92 | | - } |
93 | | - |
94 | | - return false; |
95 | | - } |
96 | | - |
97 | | - public bool Equals(NativeFunctionSignature other) |
98 | | - { |
99 | | - //Ordered by probability in being different |
100 | | - if (returnParameterType != other.returnParameterType) |
101 | | - { |
102 | | - return false; |
103 | | - } |
104 | | - |
105 | | - if (!parameterTypes.SequenceEqual(other.parameterTypes)) |
106 | | - { |
107 | | - return false; |
108 | | - } |
109 | | - |
110 | | - if (parameterRequiredModifiers.Length != other.parameterRequiredModifiers.Length) |
111 | | - { |
112 | | - return false; |
113 | | - } |
114 | | - |
115 | | - for (int i = 0; i < parameterRequiredModifiers.Length; i++) |
116 | | - { |
117 | | - if (!parameterRequiredModifiers[i].SequenceEqual(other.parameterRequiredModifiers[i])) |
118 | | - { |
119 | | - return false; |
120 | | - } |
121 | | - } |
122 | | - |
123 | | - if (!returnParameterRequiredModifiers.SequenceEqual(other.returnParameterRequiredModifiers)) |
124 | | - { |
125 | | - return false; |
126 | | - } |
127 | | - |
128 | | - if (callingConvention != other.callingConvention) |
129 | | - { |
130 | | - return false; |
131 | | - } |
132 | | - |
133 | | - if (parameterOptionalModifiers.Length != other.parameterOptionalModifiers.Length) |
134 | | - { |
135 | | - return false; |
136 | | - } |
137 | | - |
138 | | - for (int i = 0; i < parameterOptionalModifiers.Length; i++) |
139 | | - { |
140 | | - if (!parameterOptionalModifiers[i].SequenceEqual(other.parameterOptionalModifiers[i])) |
141 | | - { |
142 | | - return false; |
143 | | - } |
144 | | - } |
145 | | - |
146 | | - if (!retunrParameterOptionalModifiers.SequenceEqual(other.retunrParameterOptionalModifiers)) |
147 | | - { |
148 | | - return false; |
149 | | - } |
150 | | - |
151 | | - return true; |
| 77 | + return obj is NativeFunctionSignature other && |
| 78 | + EqualityComparer<Type>.Default.Equals(returnParameterType, other.returnParameterType) && |
| 79 | + EqualityComparer<Type[]>.Default.Equals(parameterTypes, other.parameterTypes) && |
| 80 | + callingConvention == other.callingConvention && |
| 81 | + bestFitMapping == other.bestFitMapping && |
| 82 | + charSet == other.charSet && |
| 83 | + setLastError == other.setLastError && |
| 84 | + throwOnUnmappableChar == other.throwOnUnmappableChar; |
152 | 85 | } |
153 | 86 |
|
154 | 87 | public override int GetHashCode() |
155 | 88 | { |
156 | | - var hashCode = 1660825957; |
| 89 | + var hashCode = 763644728; |
157 | 90 | hashCode = hashCode * -1521134295 + EqualityComparer<Type>.Default.GetHashCode(returnParameterType); |
158 | | - hashCode = hashCode * -1521134295 + EqualityComparer<Type[]>.Default.GetHashCode(returnParameterRequiredModifiers); |
159 | | - hashCode = hashCode * -1521134295 + EqualityComparer<Type[]>.Default.GetHashCode(retunrParameterOptionalModifiers); |
160 | 91 | hashCode = hashCode * -1521134295 + EqualityComparer<Type[]>.Default.GetHashCode(parameterTypes); |
161 | | - hashCode = hashCode * -1521134295 + EqualityComparer<Type[][]>.Default.GetHashCode(parameterRequiredModifiers); |
162 | | - hashCode = hashCode * -1521134295 + EqualityComparer<Type[][]>.Default.GetHashCode(parameterOptionalModifiers); |
163 | 92 | hashCode = hashCode * -1521134295 + callingConvention.GetHashCode(); |
| 93 | + hashCode = hashCode * -1521134295 + bestFitMapping.GetHashCode(); |
| 94 | + hashCode = hashCode * -1521134295 + charSet.GetHashCode(); |
| 95 | + hashCode = hashCode * -1521134295 + setLastError.GetHashCode(); |
| 96 | + hashCode = hashCode * -1521134295 + throwOnUnmappableChar.GetHashCode(); |
164 | 97 | return hashCode; |
165 | 98 | } |
166 | 99 | } |
|
0 commit comments