Preserve the value of Name Attribute in XmlConfigurationProvider

This commit is contained in:
Bill.B.Jia 2016-11-15 15:14:47 +08:00
Родитель 09bc782255
Коммит 7bc4aece14
2 изменённых файлов: 5 добавлений и 5 удалений

Просмотреть файл

@ -187,11 +187,6 @@ namespace Microsoft.Extensions.Configuration.Xml
private static void AddAttributePair(XmlReader reader, Stack<string> prefixStack, private static void AddAttributePair(XmlReader reader, Stack<string> prefixStack,
IDictionary<string, string> data, XmlWriter writer) IDictionary<string, string> data, XmlWriter writer)
{ {
if (string.Equals(reader.LocalName, NameAttributeKey, StringComparison.OrdinalIgnoreCase))
{
return;
}
prefixStack.Push(reader.LocalName); prefixStack.Push(reader.LocalName);
var key = ConfigurationPath.Combine(prefixStack.Reverse()); var key = ConfigurationPath.Combine(prefixStack.Reverse());
if (data.ContainsKey(key)) if (data.ContainsKey(key))

Просмотреть файл

@ -123,8 +123,10 @@ namespace Microsoft.Extensions.Configuration.Xml.Test
xmlConfigSrc.Load(TestStreamHelpers.StringToStream(xml)); xmlConfigSrc.Load(TestStreamHelpers.StringToStream(xml));
Assert.Equal("DefaultConnection", xmlConfigSrc.Get("Data:DefaultConnection:Name"));
Assert.Equal("TestConnectionString", xmlConfigSrc.Get("Data:DefaultConnection:ConnectionString")); Assert.Equal("TestConnectionString", xmlConfigSrc.Get("Data:DefaultConnection:ConnectionString"));
Assert.Equal("SqlClient", xmlConfigSrc.Get("Data:DefaultConnection:Provider")); Assert.Equal("SqlClient", xmlConfigSrc.Get("Data:DefaultConnection:Provider"));
Assert.Equal("Inventory", xmlConfigSrc.Get("Data:Inventory:Name"));
Assert.Equal("AnotherTestConnectionString", xmlConfigSrc.Get("Data:Inventory:ConnectionString")); Assert.Equal("AnotherTestConnectionString", xmlConfigSrc.Get("Data:Inventory:ConnectionString"));
Assert.Equal("MySql", xmlConfigSrc.Get("Data:Inventory:Provider")); Assert.Equal("MySql", xmlConfigSrc.Get("Data:Inventory:Provider"));
} }
@ -147,6 +149,7 @@ namespace Microsoft.Extensions.Configuration.Xml.Test
xmlConfigSrc.Load(TestStreamHelpers.StringToStream(xml)); xmlConfigSrc.Load(TestStreamHelpers.StringToStream(xml));
Assert.Equal("Data", xmlConfigSrc.Get("Data:Name"));
Assert.Equal("TestConnectionString", xmlConfigSrc.Get("Data:DefaultConnection:ConnectionString")); Assert.Equal("TestConnectionString", xmlConfigSrc.Get("Data:DefaultConnection:ConnectionString"));
Assert.Equal("SqlClient", xmlConfigSrc.Get("Data:DefaultConnection:Provider")); Assert.Equal("SqlClient", xmlConfigSrc.Get("Data:DefaultConnection:Provider"));
Assert.Equal("AnotherTestConnectionString", xmlConfigSrc.Get("Data:Inventory:ConnectionString")); Assert.Equal("AnotherTestConnectionString", xmlConfigSrc.Get("Data:Inventory:ConnectionString"));
@ -169,8 +172,10 @@ namespace Microsoft.Extensions.Configuration.Xml.Test
xmlConfigSrc.Load(TestStreamHelpers.StringToStream(xml)); xmlConfigSrc.Load(TestStreamHelpers.StringToStream(xml));
Assert.Equal("DefaultConnection", xmlConfigSrc.Get("Data:DefaultConnection:Name"));
Assert.Equal("TestConnectionString", xmlConfigSrc.Get("Data:DefaultConnection:ConnectionString")); Assert.Equal("TestConnectionString", xmlConfigSrc.Get("Data:DefaultConnection:ConnectionString"));
Assert.Equal("SqlClient", xmlConfigSrc.Get("Data:DefaultConnection:Provider")); Assert.Equal("SqlClient", xmlConfigSrc.Get("Data:DefaultConnection:Provider"));
Assert.Equal("Inventory", xmlConfigSrc.Get("Data:Inventory:Name"));
Assert.Equal("AnotherTestConnectionString", xmlConfigSrc.Get("Data:Inventory:ConnectionString")); Assert.Equal("AnotherTestConnectionString", xmlConfigSrc.Get("Data:Inventory:ConnectionString"));
Assert.Equal("MySql", xmlConfigSrc.Get("Data:Inventory:Provider")); Assert.Equal("MySql", xmlConfigSrc.Get("Data:Inventory:Provider"));
} }