File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed
src/Serilog.Settings.Configuration/Settings/Configuration Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change 2
2
using System . Collections . Generic ;
3
3
using System . Linq ;
4
4
using System . Reflection ;
5
+ using System . Runtime . CompilerServices ;
5
6
using System . Text . RegularExpressions ;
6
7
7
8
using Microsoft . Extensions . Configuration ;
@@ -548,15 +549,24 @@ static IReadOnlyCollection<MethodInfo> FindEventEnricherConfigurationMethods(IRe
548
549
static List < MethodInfo > FindConfigurationExtensionMethods ( IReadOnlyCollection < Assembly > configurationAssemblies , Type configType )
549
550
{
550
551
// ExtensionAttribute can be polyfilled to support extension methods
551
- bool HasExtensionAttribute ( MethodInfo m ) =>
552
- m . CustomAttributes . Any ( a => a . AttributeType . FullName == "System.Runtime.CompilerServices.ExtensionAttribute" ) ;
552
+ static bool HasCustomExtensionAttribute ( MethodInfo m )
553
+ {
554
+ try
555
+ {
556
+ return m . CustomAttributes . Any ( a => a . AttributeType . FullName == "System.Runtime.CompilerServices.ExtensionAttribute" ) ;
557
+ }
558
+ catch ( CustomAttributeFormatException )
559
+ {
560
+ return false ;
561
+ }
562
+ }
553
563
554
564
return configurationAssemblies
555
565
. SelectMany ( a => a . ExportedTypes
556
566
. Select ( t => t . GetTypeInfo ( ) )
557
567
. Where ( t => t . IsSealed && t . IsAbstract && ! t . IsNested ) )
558
568
. SelectMany ( t => t . DeclaredMethods )
559
- . Where ( m => m . IsStatic && m . IsPublic && HasExtensionAttribute ( m ) )
569
+ . Where ( m => m . IsStatic && m . IsPublic && ( m . IsDefined ( typeof ( ExtensionAttribute ) , false ) || HasCustomExtensionAttribute ( m ) ) )
560
570
. Where ( m => m . GetParameters ( ) [ 0 ] . ParameterType == configType )
561
571
. ToList ( ) ;
562
572
}
You can’t perform that action at this time.
0 commit comments