Skip to content

Commit

Permalink
fixes method selector to support reverse proxy rename
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyredondo committed Jun 23, 2020
1 parent 93add75 commit 23a3564
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
15 changes: 9 additions & 6 deletions src/Wanhjor.ObjectInspector/DuckType.Methods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,20 +225,23 @@ private static void CreateMethods(Type baseType, Type instanceType, FieldInfo in

allMethods ??= instanceType.GetMethods(duckAttr.Flags);

// Trying to select the one with the same name
// Trying to select the one with the same name (used by reverse proxy)
var iMethodString = iMethod.ToString();
var remaining = allMethods.Where(m =>
{
if (m.Name == duckAttr.Name) return true;
return m.ToString() == duckAttr.Name;
foreach (var duckAttribute in m.GetCustomAttributes<DuckAttribute>(true))
{
if (duckAttribute.Name == iMethodString)
return true;
}
return false;
}).ToList();

if (remaining.Count == 0)
continue;
if (remaining.Count == 1)
return remaining[0];

// Trying to select the ones with the same parameters count
remaining = remaining.Where(m =>
remaining = allMethods.Where(m =>
{
if (m.Name != duckAttr.Name) return false;
Expand Down
2 changes: 1 addition & 1 deletion src/Wanhjor.ObjectInspector/Wanhjor.ObjectInspector.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Description>An efficient .NET object inspector/accesor to avoid reflection usage with duck typing support.</Description>
<LangVersion>8</LangVersion>
<Nullable>enable</Nullable>
<Version>0.4.0-beta.6</Version>
<Version>0.4.0-beta.7</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Title>ObjectInspector</Title>
<Authors>Daniel Redondo</Authors>
Expand Down
1 change: 1 addition & 0 deletions test/Wanhjor.ObjectInspector.Tests/TestObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public TestEnum ShowEnum(TestEnum val)

//
public void Add(TestObject obj) {}
[Duck(Name = "Void Add(System.String, System.Object)")]
public void Add(string name, TestObject obj) { }
public void Add(string name, int obj) { }
public void Add(string name, string obj = "none") { }
Expand Down

0 comments on commit 23a3564

Please sign in to comment.