diff --git a/src/Config.Net.Tests/Stores/JsonFileCOnfigStoreTest.cs b/src/Config.Net.Tests/Stores/JsonFileCOnfigStoreTest.cs index 21d25cb..5d5d8a5 100644 --- a/src/Config.Net.Tests/Stores/JsonFileCOnfigStoreTest.cs +++ b/src/Config.Net.Tests/Stores/JsonFileCOnfigStoreTest.cs @@ -51,6 +51,30 @@ public void Write_new_value_hierarchically() Assert.Equal("111", _store.Read(key)); } + [Fact] + public void AliasesOnCollections() + { + IMyConfigUsingAliases myConfig = new ConfigurationBuilder() + .UseConfigStore(_store) + .Build(); + + Assert.NotNull(myConfig.Credentials); + foreach (ICredsWithAlias c in myConfig.Credentials) + { + if (c.Name == "user1") + { + Assert.Equal("pass1", c.Pass); + } + else if (c.Name == "user2") + { + Assert.Equal("pass2", c.Pass); + } + else + { + Assert.Equal("user1", c.Name); + } + } + [Fact] public void TestCreatingFileInMissingFolder() { @@ -76,4 +100,17 @@ public void Dispose() _store.Dispose(); } } + public interface ICredsWithAlias + { + [Option(Alias = "Username")] + string Name { get; set; } + [Option(Alias = "Password")] + string Pass { get; set; } + } + + public interface IMyConfigUsingAliases + { + [Option(Alias = "Creds")] + IEnumerable Credentials { get; } + } } diff --git a/src/Config.Net/Core/Box/BoxFactory.cs b/src/Config.Net/Core/Box/BoxFactory.cs index e825cd0..6e99479 100644 --- a/src/Config.Net/Core/Box/BoxFactory.cs +++ b/src/Config.Net/Core/Box/BoxFactory.cs @@ -56,6 +56,7 @@ private static void DiscoverProperties(Type t, ValueHandler valueHandler, Dictio if(isCollection) { rbox = new CollectionResultBox(pi.Name, rbox); + AddAttributes(rbox, pi, valueHandler); } result[pi.Name] = rbox;