From fd7d7eaae5e04dd8fce31d396e75c05c45b8d59b Mon Sep 17 00:00:00 2001 From: Geoff Norton Date: Sat, 12 Feb 2005 23:23:20 +0000 Subject: [PATCH] 2005-02-12 Geoff Norton * ResourceReader.cs: If a resource type index is -1 return null instead of throwing an exception * ResourceWriter.cs: If an object is null; encode it with type index -1 instead of throwing an exception. svn path=/trunk/mcs/; revision=40569 --- mcs/class/corlib/System.Resources/ChangeLog | 7 +++++++ .../corlib/System.Resources/ResourceReader.cs | 2 ++ .../corlib/System.Resources/ResourceWriter.cs | 23 ++++++++++++---------- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/mcs/class/corlib/System.Resources/ChangeLog b/mcs/class/corlib/System.Resources/ChangeLog index 5081b6c926d..112f8ee9e2a 100644 --- a/mcs/class/corlib/System.Resources/ChangeLog +++ b/mcs/class/corlib/System.Resources/ChangeLog @@ -1,3 +1,10 @@ +2005-02-12 Geoff Norton + + * ResourceReader.cs: If a resource type index is -1 return null + instead of throwing an exception + * ResourceWriter.cs: If an object is null; encode it with type index + -1 instead of throwing an exception. + 2005-02-11 Zoltan Varga * Win32Resources.cs: Fix warning. diff --git a/mcs/class/corlib/System.Resources/ResourceReader.cs b/mcs/class/corlib/System.Resources/ResourceReader.cs index 3f5d3046ae3..159a330b1b9 100644 --- a/mcs/class/corlib/System.Resources/ResourceReader.cs +++ b/mcs/class/corlib/System.Resources/ResourceReader.cs @@ -241,6 +241,8 @@ namespace System.Resources long data_offset=reader.ReadInt32(); reader.BaseStream.Seek(data_offset+dataSectionOffset, SeekOrigin.Begin); int type_index=Read7BitEncodedInt(); + if (type_index == -1) + return null; Type type=types[type_index]; if (type==typeof(Byte)) { diff --git a/mcs/class/corlib/System.Resources/ResourceWriter.cs b/mcs/class/corlib/System.Resources/ResourceWriter.cs index a8751c7dcc5..b693ca94546 100644 --- a/mcs/class/corlib/System.Resources/ResourceWriter.cs +++ b/mcs/class/corlib/System.Resources/ResourceWriter.cs @@ -87,9 +87,6 @@ namespace System.Resources if (name == null) { throw new ArgumentNullException ("name is null"); } - if (value == null) { - throw new ArgumentNullException ("value is null"); - } if(resources==null) { throw new InvalidOperationException ("ResourceWriter has been closed"); } @@ -206,13 +203,6 @@ namespace System.Resources IDictionaryEnumerator res_enum=resources.GetEnumerator(); while(res_enum.MoveNext()) { - Type type=res_enum.Value.GetType(); - - /* Keep a list of unique types */ - if(!types.Contains(type)) { - types.Add(type); - } - /* Hash the name */ hashes[count]=GetHash((string)res_enum.Key); @@ -223,6 +213,19 @@ namespace System.Resources res_name.Write((string)res_enum.Key); res_name.Write((int)res_data.BaseStream.Position); + if (res_enum.Value == null) { + Write7BitEncodedInt (res_data, -1); + count++; + continue; + } + + Type type=res_enum.Value.GetType(); + + /* Keep a list of unique types */ + if(!types.Contains(type)) { + types.Add(type); + } + /* Write the data section */ Write7BitEncodedInt(res_data, types.IndexOf(type)); /* Strangely, Char is serialized -- 2.11.4.GIT