* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / corlib / System.Resources / ResourceWriter.cs
index 15b03969eb5ba04392bf05b0fa96e085053aaabe..b693ca94546cdaefc04281649780bacb1c41d6a4 100644 (file)
@@ -8,6 +8,29 @@
 // (C) 2001, 2002 Ximian, Inc.         http://www.ximian.com
 //
 
+//
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
 using System.IO;
 using System.Collections;
 using System.Text;
@@ -29,7 +52,7 @@ namespace System.Resources
                                throw new ArgumentException ("stream is not writable.");
 
                        this.stream=stream;
-                       resources=new Hashtable(new CaseInsensitiveHashCodeProvider(), new CaseInsensitiveComparer());
+                       resources=new Hashtable(CaseInsensitiveHashCodeProvider.Default, CaseInsensitiveComparer.Default);
                }
                
                public ResourceWriter (String fileName)
@@ -38,7 +61,7 @@ namespace System.Resources
                                throw new ArgumentNullException ("fileName is null.");
 
                        stream=new FileStream(fileName, FileMode.Create, FileAccess.Write);
-                       resources=new Hashtable(new CaseInsensitiveHashCodeProvider(), new CaseInsensitiveComparer());
+                       resources=new Hashtable(CaseInsensitiveHashCodeProvider.Default, CaseInsensitiveComparer.Default);
                }
                
                public void AddResource (string name, byte[] value)
@@ -64,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");
                        }
@@ -183,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);
 
@@ -200,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
@@ -331,5 +357,11 @@ namespace System.Resources
                                value = high;
                        } while(value != 0);
                }
+
+               internal Stream Stream {
+                       get {
+                               return stream;
+                       }
+               }
        }
 }