// Lluis Sanchez Gual (lluis@ideary.com)\r
//\r
// (C) 2003 Lluis Sanchez Gual\r
+
+//
+// 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.
+//
\r
using System;\r
using System.IO;\r
return;\r
}\r
\r
+ Hashtable typesTable;\r
+ bool isNew = false;\r
+ lock (_cachedTypes) {\r
+ typesTable = (Hashtable) _cachedTypes [_context.State];\r
+ if (typesTable == null) {\r
+ typesTable = new Hashtable ();\r
+ _cachedTypes [_context.State] = typesTable;\r
+ isNew = true;\r
+ }\r
+ }\r
+\r
metadata = null;\r
- lock (_cachedTypes)\r
- {\r
- Hashtable typesTable = (Hashtable) _cachedTypes [_context.State];\r
- if (typesTable != null)\r
- {\r
+ lock (typesTable) {\r
+ if (!isNew) {\r
metadata = (TypeMetadata) typesTable [instanceType];\r
- if (metadata == null) \r
- {\r
- metadata = CreateMemberTypeMetadata (instanceType);\r
- typesTable [instanceType] = metadata;\r
- }\r
}\r
- else\r
- {\r
+\r
+ if (metadata == null) {\r
metadata = CreateMemberTypeMetadata (instanceType);\r
- typesTable = new Hashtable ();\r
- typesTable [instanceType] = metadata;\r
- _cachedTypes [_context.State] = typesTable;\r
}\r
+\r
+ typesTable [instanceType] = metadata;\r
}\r
}\r
}\r
}\r
else\r
{\r
- int[] indices = new int[array.Rank];\r
-\r
- // Initialize indexes\r
- for (int dim = array.Rank-1; dim >= 0; dim--)\r
- indices[dim] = array.GetLowerBound (dim);\r
-\r
- bool end = false;\r
- while (!end)\r
- {\r
- WriteValue (writer, elementType, array.GetValue (indices));\r
-\r
- for (int dim = array.Rank-1; dim >= 0; dim--)\r
- {\r
- indices[dim]++;\r
- if (indices[dim] > array.GetUpperBound (dim))\r
- {\r
- if (dim > 0) {\r
- indices[dim] = array.GetLowerBound (dim);\r
- continue; // Increment the next dimension's index\r
- }\r
- end = true; // That was the last dimension. Finished.\r
- }\r
- break;\r
- }\r
- }\r
+ foreach (object item in array)\r
+ WriteValue (writer, elementType, item);\r
}\r
}\r
\r
private void WriteSingleDimensionArrayElements (BinaryWriter writer, Array array, Type elementType)\r
{\r
int numNulls = 0;\r
- for (int n = array.GetLowerBound (0); n<=array.GetUpperBound(0); n++)\r
+ foreach (object val in array)\r
{\r
- object val = array.GetValue (n);\r
if (val != null && numNulls > 0)\r
{\r
WriteNullFiller (writer, numNulls);\r