diff --git a/src/Spring/Spring.Core/Objects/Factory/Config/ManagedDictionary.cs b/src/Spring/Spring.Core/Objects/Factory/Config/ManagedDictionary.cs index ae46b4e0..18d9efea 100644 --- a/src/Spring/Spring.Core/Objects/Factory/Config/ManagedDictionary.cs +++ b/src/Spring/Spring.Core/Objects/Factory/Config/ManagedDictionary.cs @@ -1,7 +1,7 @@ #region License /* - * Copyright © 2002-2011 the original author or authors. + * Copyright � 2002-2011 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -203,31 +203,37 @@ namespace Spring.Objects.Factory.Config /// If merging is not enabled for this instance, /// (i.e. MergeEnabled equals false. public object Merge(object parent) - { - if (!this.mergeEnabled) - { - throw new InvalidOperationException( - "Not allowed to merge when the 'MergeEnabled' property is set to 'false'"); - } - if (parent == null) - { - return this; - } - IDictionary pDict = parent as IDictionary; - if (pDict == null) - { - throw new InvalidOperationException("Cannot merge with object of type [" + parent.GetType() + "]"); - } - IDictionary merged = new ManagedDictionary(); - foreach (DictionaryEntry dictionaryEntry in pDict) - { + { + if (!this.mergeEnabled) + { + throw new InvalidOperationException( + "Not allowed to merge when the 'MergeEnabled' property is set to 'false'"); + } + if (parent == null) + { + return this; + } + var pDict = parent as IDictionary; + if (pDict == null) + { + throw new InvalidOperationException("Cannot merge with object of type [" + parent.GetType() + "]"); + } + var merged = new ManagedDictionary(); + var pManagedDict = pDict as ManagedDictionary; + if (pManagedDict != null) + { + merged.KeyTypeName = pManagedDict.keyTypeName; + merged.valueTypeName = pManagedDict.valueTypeName; + } + foreach (DictionaryEntry dictionaryEntry in pDict) + { merged[dictionaryEntry.Key] = dictionaryEntry.Value; } foreach (DictionaryEntry entry in this) { merged[entry.Key] = entry.Value; } - return merged; + return merged; } } -} \ No newline at end of file +} diff --git a/test/Spring/Spring.Core.Tests/Objects/Factory/Support/ManagedDictionaryTests.cs b/test/Spring/Spring.Core.Tests/Objects/Factory/Support/ManagedDictionaryTests.cs index d0fdc81c..570d4155 100644 --- a/test/Spring/Spring.Core.Tests/Objects/Factory/Support/ManagedDictionaryTests.cs +++ b/test/Spring/Spring.Core.Tests/Objects/Factory/Support/ManagedDictionaryTests.cs @@ -1,19 +1,19 @@ #region License -/* - * Copyright 2002-2010 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. +/* + * Copyright 2002-2010 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #endregion @@ -146,5 +146,30 @@ namespace Spring.Objects.Factory.Support Assert.AreEqual(1, resolved.Count); Assert.AreEqual(typeof(List), resolved["key"].GetType()); } + + [Test] + public void ResolvesMergedGenericType() + { + ManagedDictionary parent = new ManagedDictionary(); + parent.Add("one", 1); + parent.Add("two", 2); + parent.KeyTypeName = "string"; + parent.ValueTypeName = "int"; + + ManagedDictionary child = new ManagedDictionary(); + child.MergeEnabled = true; + child.Add("one", -1); + child.Add("three", 3); + + ManagedDictionary merged = (ManagedDictionary) child.Merge(parent); + + IDictionary resolved = (IDictionary) merged.Resolve("somename", new RootObjectDefinition(typeof(object)), "prop", + (name, definition, argumentName, element) => element); + + Assert.IsInstanceOf>(resolved); + Assert.AreEqual(3, resolved.Count); + Assert.AreEqual(typeof(int), resolved["two"].GetType()); + Assert.AreEqual(-1, resolved["one"]); + } } }