From d87b2aa5a389a9f582ebbafe6b41e230c87f64c1 Mon Sep 17 00:00:00 2001 From: eeichinger Date: Tue, 22 Jul 2008 10:49:47 +0000 Subject: [PATCH] fixed CaseInsensitiveHashtable serialization issue w/ net 1.0 & 1.1 --- .../Collections/CaseInsensitiveHashtable.cs | 35 ++++++------------- 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/src/Spring/Spring.Core/Collections/CaseInsensitiveHashtable.cs b/src/Spring/Spring.Core/Collections/CaseInsensitiveHashtable.cs index 1282cd64..eed1a23f 100644 --- a/src/Spring/Spring.Core/Collections/CaseInsensitiveHashtable.cs +++ b/src/Spring/Spring.Core/Collections/CaseInsensitiveHashtable.cs @@ -13,8 +13,7 @@ namespace Spring.Collections [Serializable] public class CaseInsensitiveHashtable : Hashtable { - private readonly TextInfo _textInfo; - private readonly CompareInfo _compareInfo; + private readonly CultureInfo _culture; /// /// Creates a case-insensitive hashtable using . @@ -38,18 +37,9 @@ namespace Spring.Collections /// the dictionary to copy entries from /// the to calculate the hashcode public CaseInsensitiveHashtable(IDictionary d, CultureInfo culture) - :this(d, culture.TextInfo, culture.CompareInfo) - {} - - /// - /// Creates a case-insensitive hashtable using the given , initially - /// populated with entries from another dictionary. - /// - protected CaseInsensitiveHashtable(IDictionary d, TextInfo textInfo, CompareInfo compareInfo) { - AssertUtils.ArgumentNotNull(textInfo, "textInfo"); - _textInfo = textInfo; - _compareInfo = compareInfo; + AssertUtils.ArgumentNotNull(culture, "culture"); + _culture = culture; if (d != null) { @@ -58,7 +48,7 @@ namespace Spring.Collections { this.Add(enumerator.Key, enumerator.Value); } - } + } } /// @@ -69,11 +59,9 @@ namespace Spring.Collections /// info is null. protected CaseInsensitiveHashtable(SerializationInfo info, StreamingContext context) : base(info, context) { - _textInfo = (TextInfo) info.GetValue("_textInfo", typeof(TextInfo)); - _compareInfo = (CompareInfo) info.GetValue("_compareInfo", typeof(CompareInfo)); - - AssertUtils.ArgumentNotNull(_textInfo, "TextInfo"); - AssertUtils.ArgumentNotNull(_compareInfo, "CompareInfo"); + string cultureName = info.GetString("_cultureName"); + _culture = new CultureInfo(cultureName); + AssertUtils.ArgumentNotNull(_culture, "Culture"); } /// @@ -86,8 +74,7 @@ namespace Spring.Collections public override void GetObjectData(SerializationInfo info, StreamingContext context) { base.GetObjectData(info, context); - info.AddValue("_textInfo", _textInfo); - info.AddValue("_compareInfo", _compareInfo); + info.AddValue("_cultureName", _culture.Name); } /// @@ -97,7 +84,7 @@ namespace Spring.Collections /// protected override int GetHash(object key) { - return _textInfo.ToLower((string) key).GetHashCode(); + return _culture.TextInfo.ToLower((string) key).GetHashCode(); } /// @@ -105,7 +92,7 @@ namespace Spring.Collections /// protected override bool KeyEquals(object item, object key) { - return 0==_compareInfo.Compare((string) item, (string) key, CompareOptions.IgnoreCase); + return 0==_culture.CompareInfo.Compare((string) item, (string) key, CompareOptions.IgnoreCase); } /// @@ -113,7 +100,7 @@ namespace Spring.Collections /// public override object Clone() { - return new CaseInsensitiveHashtable(this, _textInfo, _compareInfo ); + return new CaseInsensitiveHashtable(this, _culture ); } } }