Skip to content

Instantly share code, notes, and snippets.

@maryamariyan
Created November 19, 2020 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maryamariyan/206065b6dd81ef6f027cf0e8a92d0fb8 to your computer and use it in GitHub Desktop.
Save maryamariyan/206065b6dd81ef6f027cf0e8a92d0fb8 to your computer and use it in GitHub Desktop.
ambiguous match
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