ambiguous match
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
using System; | |
using System.Collections.Generic; | |
using Microsoft.Extensions.Configuration; | |
using Microsoft.Extensions.FileSystemGlobbing; | |
using CustomOptionsConfigurationExensionsNamespace; | |
class Program | |
{ | |
static void Main() | |
{ | |
Console.WriteLine("Hello World"); | |
var configuration = new ConfigurationBuilder().AddInMemoryCollection(new Dictionary<string, string>() | |
{ | |
{"CustomOptions", "value1"}, | |
}).Build(); | |
var co = new CustomOptions(); | |
configuration.Bind<CustomOptions>(co, o => { }); | |
} | |
} | |
namespace Microsoft.Extensions.Configuration | |
{ | |
public static class ConfigurationBinder | |
{ | |
// one of the API additions proposed in this issue that would become part of framework. Aim is for this API to be picked if source gen is not enabled and make binding linker friendly | |
public static void Bind<T>(this IConfiguration configuration, T instance, Action<BinderOptions> configureOptions) | |
=> configuration.Bind((object)instance, configureOptions); | |
} | |
} | |
namespace CustomOptionsConfigurationExensionsNamespace | |
{ | |
public static class CustomOptionsConfigurationExensions | |
{ | |
// this could be source generated for the concrete type, and the compiler ideally picking this overload when source gen is enabled. | |
public static void Bind<T>(this IConfiguration configuration, T instance, Action<BinderOptions> configureOptions) | |
where T : CustomOptions | |
=> configuration.Bind((object)instance, configureOptions); | |
} | |
} | |
public class CustomOptions | |
{ | |
public string CustomProperty { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment