-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added interception for missing extension method event
- Loading branch information
1 parent
2f70acd
commit cc2bbe3
Showing
10 changed files
with
213 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/ConfigurationProcessor.Core/ConfigurationReaderOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// ------------------------------------------------------------------------------------------------- | ||
// Copyright (c) almostchristian. All rights reserved. | ||
// ------------------------------------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using ConfigurationProcessor.Core.Implementation; | ||
|
||
namespace ConfigurationProcessor.Core | ||
{ | ||
/// <summary> | ||
/// Configuration reader options. | ||
/// </summary> | ||
public class ConfigurationReaderOptions | ||
{ | ||
/// <summary> | ||
/// Gets the config section. | ||
/// </summary> | ||
public string ConfigSection { get; set; } = "Services"; | ||
|
||
/// <summary> | ||
/// Gets the context paths. | ||
/// </summary> | ||
public IEnumerable<string>? ContextPaths { get; set; } | ||
|
||
/// <summary> | ||
/// Gets ths method filter factory. | ||
/// </summary> | ||
public MethodFilterFactory? MethodFilterFactory { get; set; } | ||
|
||
/// <summary> | ||
/// Additional methods. | ||
/// </summary> | ||
public IEnumerable<MethodInfo> AdditionalMethods { get; set; } = Enumerable.Empty<MethodInfo>(); | ||
|
||
/// <summary> | ||
/// Gets or sets the method to invoke when a method is not found. The default method throws a <see cref="MissingMethodException"/>. | ||
/// </summary> | ||
public Action<ExtensionMethodNotFoundEventArgs> OnExtensionMethodNotFound { get; set; } = x => { }; | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/ConfigurationProcessor.Core/ExtensionMethodNotFoundEventArgs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// ------------------------------------------------------------------------------------------------- | ||
// Copyright (c) almostchristian. All rights reserved. | ||
// ------------------------------------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
using Microsoft.Extensions.Configuration; | ||
|
||
namespace ConfigurationProcessor.Core | ||
{ | ||
/// <summary> | ||
/// Represents event data when an extension method was not found. | ||
/// </summary> | ||
public class ExtensionMethodNotFoundEventArgs : EventArgs | ||
{ | ||
internal ExtensionMethodNotFoundEventArgs( | ||
IEnumerable<MethodInfo> candidateMethods, | ||
IEnumerable<string> candidateNames, | ||
Type extensionMethodType, | ||
IReadOnlyDictionary<string, IConfigurationSection> suppliedArguments) | ||
{ | ||
CandidateMethods = candidateMethods; | ||
CandidateNames = candidateNames; | ||
ExtensionMethodType = extensionMethodType; | ||
SuppliedArguments = suppliedArguments; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the candidate methods. | ||
/// </summary> | ||
public IEnumerable<MethodInfo> CandidateMethods { get; } | ||
|
||
/// <summary> | ||
/// Gets the candidate method names. | ||
/// </summary> | ||
public IEnumerable<string> CandidateNames { get; } | ||
|
||
/// <summary> | ||
/// Gets the extension method type that was searched. | ||
/// </summary> | ||
public Type ExtensionMethodType { get; } | ||
|
||
/// <summary> | ||
/// Gets the supplied argument names. | ||
/// </summary> | ||
public IReadOnlyDictionary<string, IConfigurationSection> SuppliedArguments { get; } | ||
|
||
/// <summary> | ||
/// Gets or sets if the event is handled. If true, an exception will not be thrown. | ||
/// </summary> | ||
public bool Handled { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.