Skip to content

Commit 32536d6

Browse files
Improve discovery of executable methods to include implemented interfaces
1 parent 2a383a7 commit 32536d6

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

src/ConfigurationProcessor.Core/Implementation/Extensions.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public static void CallConfigurationMethods(
113113
IEnumerable? GetCollection(MethodInfo method)
114114
{
115115
var argValue = new ObjectArgumentValue(configSection!);
116-
var collectionType = method.GetParameters().ElementAt(1).ParameterType;
116+
var collectionType = method.GetParameters().ElementAt(method.IsStatic ? 1 : 0).ParameterType;
117117
return argValue.ConvertTo(method, collectionType, resolutionContext) as ICollection;
118118
}
119119

@@ -185,15 +185,16 @@ private static List<MethodInfo> FindConfigurationExtensionMethods(
185185
MethodFilter? filter)
186186
{
187187
IReadOnlyCollection<Assembly> configurationAssemblies = resolutionContext.ConfigurationAssemblies;
188-
188+
var interfaces = configType.GetInterfaces();
189189
var candidateMethods = configurationAssemblies
190190
.SelectMany(a => SafeGetExportedTypes(a)
191191
.Select(t => t.GetTypeInfo())
192192
.Where(t => t.IsSealed && t.IsAbstract && !t.IsNested))
193193
.Union(new[] { configType.GetTypeInfo() })
194+
.Concat(interfaces.Select(t => t.GetTypeInfo()))
194195
.SelectMany(t => candidateNames != null ? candidateNames.SelectMany(n => t.GetDeclaredMethods(n)) : t.DeclaredMethods)
195196
.Where(m => filter == null || filter(m, key))
196-
.Where(m => !m.IsDefined(typeof(CompilerGeneratedAttribute), false) && m.IsPublic && ((m.IsStatic && m.IsDefined(typeof(ExtensionAttribute), false)) || m.DeclaringType == configType))
197+
.Where(m => !m.IsDefined(typeof(CompilerGeneratedAttribute), false) && m.IsPublic && ((m.IsStatic && m.IsDefined(typeof(ExtensionAttribute), false)) || m.DeclaringType == configType || interfaces.Contains(m.DeclaringType)))
197198
.Where(m => !m.IsStatic || SafeGetParameters(m).ElementAtOrDefault(0)?.ParameterType.IsAssignableFrom(configType) == true) // If static method, checks that the first parameter is same as the extension type
198199
.ToList();
199200

src/Directory.Build.props

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
</PropertyGroup>
66

77
<PropertyGroup>
8-
<Version>1.3.0</Version>
8+
<Version>1.4.0</Version>
99
<FileVersion>$(Version).$([System.DateTime]::Now.ToString(yy))$([System.DateTime]::Now.DayOfYear.ToString(000))</FileVersion>
1010
<PackageVersion>$(Version)</PackageVersion>
1111
<InformationalVersion>$(FileVersion)-$(GIT_VERSION)</InformationalVersion>
@@ -23,6 +23,8 @@
2323
<PackageTags>dependencyinjection;configuration;ioc;di;</PackageTags>
2424
<PackageReadmeFile>README.md</PackageReadmeFile>
2525
<PackageReleaseNotes>
26+
v1.4.0
27+
- Improve discovery of executable methods to include implemented interfaces
2628
v1.3.0
2729
- Add support for disambiguating overloads with different array types.
2830
- Prefer overloads with the most matching parameters

tests/TestDummies/IChildValue.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,11 @@
66

77
namespace TestDummies
88
{
9-
public interface IChildValue
9+
public interface IChildValue : IRootChildValue
1010
{
11-
string Child { get; set; }
1211
Type ContextType { get; set; }
1312
Uri Location { get; set; }
1413
Delegate OnError { get; set; }
1514
TimeSpan? Time { get; set; }
16-
17-
void Reset();
1815
}
1916
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// -------------------------------------------------------------------------------------------------
2+
// Copyright (c) Integrated Health Information Systems Pte Ltd. All rights reserved.
3+
// -------------------------------------------------------------------------------------------------
4+
5+
namespace TestDummies
6+
{
7+
public interface IRootChildValue
8+
{
9+
string Child { get; set; }
10+
11+
void Reset();
12+
}
13+
}

0 commit comments

Comments
 (0)