Skip to content

Commit b7c5c84

Browse files
committed
fixes method selector
1 parent e930dd2 commit b7c5c84

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/Wanhjor.ObjectInspector/DuckType.Methods.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ private static void CreateMethods(Type baseType, Type instanceType, FieldInfo in
208208
if (y.Version is null) return -1;
209209
return x.Version.CompareTo(y.Version);
210210
});
211-
211+
var iMethodString = iMethod.ToString();
212212
MethodAttributesSelector[] allMethods = null!;
213213
foreach (var duckAttr in duckAttrs)
214214
{
@@ -219,9 +219,18 @@ private static void CreateMethods(Type baseType, Type instanceType, FieldInfo in
219219

220220
// We select the method to call
221221
var method = instanceType.GetMethod(duckAttr.Name, duckAttr.Flags, null, parametersTypes, null);
222-
222+
223223
if (!(method is null))
224-
return method;
224+
{
225+
var attrs = method.GetCustomAttributes<DuckAttribute>().ToList();
226+
if (attrs.Count == 0)
227+
return method;
228+
foreach (var attribute in attrs)
229+
{
230+
if (attribute.Name == iMethodString)
231+
return method;
232+
}
233+
}
225234

226235
if (allMethods is null)
227236
{
@@ -232,7 +241,6 @@ private static void CreateMethods(Type baseType, Type instanceType, FieldInfo in
232241
new List<DuckAttribute>(methods[i].GetCustomAttributes<DuckAttribute>(true)));
233242
}
234243

235-
var iMethodString = iMethod.ToString();
236244
var remaining = allMethods.Where(ma =>
237245
{
238246
if (ma.Attributes.Count == 0)

src/Wanhjor.ObjectInspector/Wanhjor.ObjectInspector.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<Description>An efficient .NET object inspector/accesor to avoid reflection usage with duck typing support.</Description>
77
<LangVersion>8</LangVersion>
88
<Nullable>enable</Nullable>
9-
<Version>0.4.0-beta.8</Version>
9+
<Version>0.4.0-beta.9</Version>
1010
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
1111
<Title>ObjectInspector</Title>
1212
<Authors>Daniel Redondo</Authors>

0 commit comments

Comments
 (0)