From: <dav...@us...> - 2009-08-02 16:47:19
|
Revision: 4672 http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4672&view=rev Author: davybrion Date: 2009-08-02 16:46:25 +0000 (Sun, 02 Aug 2009) Log Message: ----------- applied patch from Jimmy Bogard for NH-1903 Modified Paths: -------------- trunk/nhibernate/src/NHibernate/Collection/Generic/PersistentGenericMap.cs trunk/nhibernate/src/NHibernate.Test/GenericTest/MapGeneric/MapGenericFixture.cs Property Changed: ---------------- trunk/nhibernate/src/ Property changes on: trunk/nhibernate/src ___________________________________________________________________ Modified: svn:mergeinfo - /branches/2.1.x/nhibernate/src:4659 + /branches/2.1.x/nhibernate/src:4659,4671 Modified: trunk/nhibernate/src/NHibernate/Collection/Generic/PersistentGenericMap.cs =================================================================== --- trunk/nhibernate/src/NHibernate/Collection/Generic/PersistentGenericMap.cs 2009-08-02 16:26:52 UTC (rev 4671) +++ trunk/nhibernate/src/NHibernate/Collection/Generic/PersistentGenericMap.cs 2009-08-02 16:46:25 UTC (rev 4672) @@ -16,13 +16,13 @@ /// <typeparam name="TKey">The type of the keys in the IDictionary.</typeparam> /// <typeparam name="TValue">The type of the elements in the IDictionary.</typeparam> [Serializable] - [DebuggerTypeProxy(typeof (DictionaryProxy<,>))] + [DebuggerTypeProxy(typeof(DictionaryProxy<,>))] public class PersistentGenericMap<TKey, TValue> : PersistentMap, IDictionary<TKey, TValue> { // TODO NH: find a way to writeonce (no duplicated code from PersistentMap) protected IDictionary<TKey, TValue> gmap; - public PersistentGenericMap() {} - public PersistentGenericMap(ISessionImplementor session) : base(session) {} + public PersistentGenericMap() { } + public PersistentGenericMap(ISessionImplementor session) : base(session) { } public PersistentGenericMap(ISessionImplementor session, IDictionary<TKey, TValue> map) : base(session, map as IDictionary) @@ -37,15 +37,15 @@ foreach (KeyValuePair<TKey, TValue> e in gmap) { object copy = persister.ElementType.DeepCopy(e.Value, entityMode, persister.Factory); - clonedMap[e.Key] = (TValue) copy; + clonedMap[e.Key] = (TValue)copy; } return clonedMap; } public override void BeforeInitialize(ICollectionPersister persister, int anticipatedSize) { - gmap = (IDictionary<TKey, TValue>) persister.CollectionType.Instantiate(anticipatedSize); - map = (IDictionary) gmap; + gmap = (IDictionary<TKey, TValue>)persister.CollectionType.Instantiate(anticipatedSize); + map = (IDictionary)gmap; } public override IEnumerable GetDeletes(ICollectionPersister persister, bool indexIsFormula) @@ -156,7 +156,7 @@ } else { - value = (TValue) result; + value = (TValue)result; return true; } } @@ -166,7 +166,7 @@ get { object result = ReadElementByIndex(key); - return result == Unknown ? gmap[key] : (TValue) result; + return result == Unknown ? gmap[key] : (TValue)result; } set { @@ -234,7 +234,7 @@ { if (exists.Value) { - TValue x = ((IDictionary<TKey, TValue>) this)[item.Key]; + TValue x = ((IDictionary<TKey, TValue>)this)[item.Key]; TValue y = item.Value; return EqualityComparer<TValue>.Default.Equals(x, y); } @@ -269,7 +269,7 @@ bool ICollection<KeyValuePair<TKey, TValue>>.Remove(KeyValuePair<TKey, TValue> item) { - if (((ICollection<KeyValuePair<TKey, TValue>>) this).Contains(item)) + if (((ICollection<KeyValuePair<TKey, TValue>>)this).Contains(item)) { Remove(item.Key); return true; @@ -291,5 +291,15 @@ } #endregion + + #region IEnumerable Members + + IEnumerator IEnumerable.GetEnumerator() + { + Read(); + return gmap.GetEnumerator(); + } + + #endregion } } \ No newline at end of file Modified: trunk/nhibernate/src/NHibernate.Test/GenericTest/MapGeneric/MapGenericFixture.cs =================================================================== --- trunk/nhibernate/src/NHibernate.Test/GenericTest/MapGeneric/MapGenericFixture.cs 2009-08-02 16:26:52 UTC (rev 4671) +++ trunk/nhibernate/src/NHibernate.Test/GenericTest/MapGeneric/MapGenericFixture.cs 2009-08-02 16:46:25 UTC (rev 4672) @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Collections.Generic; using System.Text; using NHibernate.Engine; @@ -78,6 +79,51 @@ } } + [Test] + public void SimpleTypes() + { + A a = new A(); + a.Name = "first generic type"; + a.Items = new Dictionary<string, B>(); + B firstB = new B(); + firstB.Name = "first b"; + B secondB = new B(); + secondB.Name = "second b"; + B thirdB = new B(); + thirdB.Name = "third b"; + + a.Items.Add("first", firstB); + a.Items.Add("second", secondB); + a.Items.Add("third", thirdB); + + using (ISession s = OpenSession()) + { + s.SaveOrUpdate(a); + s.Flush(); + } + + using (ISession s = OpenSession()) + { + a = s.Load<A>(a.Id); + IDictionary<string, B> genericDict = a.Items; + IEnumerable<KeyValuePair<string, B>> genericEnum = a.Items; + IEnumerable nonGenericEnum = a.Items; + + foreach (var enumerable in genericDict) + { + Assert.That(enumerable, Is.InstanceOf<KeyValuePair<string, B>>()); + } + foreach (var enumerable in genericEnum) + { + Assert.That(enumerable, Is.InstanceOf<KeyValuePair<string, B>>()); + } + foreach (var enumerable in nonGenericEnum) + { + Assert.That(enumerable, Is.InstanceOf<KeyValuePair<string, B>>()); + } + } + } + // NH-669 [Test] public void UpdatesToSimpleMap() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |