aloneguid / config

⚙ Config.Net - the easiest configuration framework for .NET developers. No BS.
MIT License
641 stars 85 forks source link

Aliases do not work with Collections #65

Open paul-barton opened 6 years ago

paul-barton commented 6 years ago

Config.Net does not find aliases when used on collections.

Should be able to reproduce by using following interfaces:

interface ICredentials
{
   [Option(Alias = "uname")]
   string Username { get; }
   [Option(Alias = "pw")]
   string Password { get; }
}

interface IMyConfig
{
   [Option(Alias = "creds")]
   IEnumerable<ICredentials> AllCredentials { get; }
}

and using json store:

IMyConfig config= new ConfigurationBuilder<IMyConfig>()
   .UseJsonFile(jsonPath)
   .Build();

and json:

{
    "creds": [
        {
            "uname": "janedoe",
            "pw": "1234"
        },
        {
            "uname": "johndoe",
            "pw": "5678"
        }
    ]
}

Above is a simple example of my config but should reproduce the issue I believe. If not I can update a more specific example. Workaround is just to not use the alias on the collection and just use the camel case method name for the collection.

{
    "AllCredentials": [
        {
            "uname": "janedoe",
            "pw": "1234"
        },
        {
            "uname": "johndoe",
            "pw": "5678"
        }
    ]
}
martin-braun commented 2 years ago

@aloneguid I can confirm this issue and it drove me crazy. Could you please look into it?

aloneguid commented 2 years ago

thanks @martin-braun looking into this