From 21cac017c311c3362f20787b029915b9cd7397da Mon Sep 17 00:00:00 2001 From: henry Date: Mon, 14 Apr 2008 16:57:08 +0000 Subject: [PATCH] Fixed the ReflectionBasedDictionaryAdapter Enumerator git-svn-id: https://svn.castleproject.org/svn/castle/trunk@5000 73e77b4c-caa6-f847-a29a-24ab75ae54b6 --- .../ReflectionBasedDictionaryAdapterTestCase.cs | 20 ++++++++++++++++++++ Core/Castle.Core/Castle.Core-vs2008.csproj | 2 +- Core/Castle.Core/ReflectionBasedDictionaryAdapter.cs | 16 +++++++++------- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/Core/Castle.Core.Tests/ReflectionBasedDictionaryAdapterTestCase.cs b/Core/Castle.Core.Tests/ReflectionBasedDictionaryAdapterTestCase.cs index 1b5bf14f2..f0e927022 100644 --- a/Core/Castle.Core.Tests/ReflectionBasedDictionaryAdapterTestCase.cs +++ b/Core/Castle.Core.Tests/ReflectionBasedDictionaryAdapterTestCase.cs @@ -15,6 +15,7 @@ namespace Castle.Core.Tests { using System; + using System.Collections; using Castle.Core; using NUnit.Framework; @@ -66,6 +67,25 @@ namespace Castle.Core.Tests Assert.IsNull(dict["age"]); } +#if DOTNET35 + [Test] + public void EnumeratorIteration() + { + ReflectionBasedDictionaryAdapter dict = new ReflectionBasedDictionaryAdapter(new {id = 1, name = "jonh", age = 25}); + + Assert.AreEqual(3, dict.Count); + + IDictionaryEnumerator enumerator = (IDictionaryEnumerator) dict.GetEnumerator(); + + while (enumerator.MoveNext()) + { + Assert.IsNotNull(enumerator.Key); + Assert.IsNotNull(enumerator.Value); + } + } +#endif + + public class Customer { private int id; diff --git a/Core/Castle.Core/Castle.Core-vs2008.csproj b/Core/Castle.Core/Castle.Core-vs2008.csproj index 292699fc4..4d30dadd3 100644 --- a/Core/Castle.Core/Castle.Core-vs2008.csproj +++ b/Core/Castle.Core/Castle.Core-vs2008.csproj @@ -23,7 +23,7 @@ full false bin\Debug\ - TRACE;DEBUG + TRACE;DEBUG;DOTNET35 prompt 4 true diff --git a/Core/Castle.Core/ReflectionBasedDictionaryAdapter.cs b/Core/Castle.Core/ReflectionBasedDictionaryAdapter.cs index 9738db993..8317b0b64 100644 --- a/Core/Castle.Core/ReflectionBasedDictionaryAdapter.cs +++ b/Core/Castle.Core/ReflectionBasedDictionaryAdapter.cs @@ -246,7 +246,14 @@ namespace Castle.Core public bool MoveNext() { - return enumerator.MoveNext(); + bool moved = enumerator.MoveNext(); + + if (moved) + { + current = (KeyValuePair)enumerator.Current; + } + + return moved; } public void Reset() @@ -256,12 +263,7 @@ namespace Castle.Core public object Current { - get - { - - current = (KeyValuePair) enumerator.Current; - return new DictionaryEntry(Key, Value); - } + get { return new DictionaryEntry(Key, Value); } } } } -- 2.11.4.GIT