Merge pull request #347 from JamesB7/master
[mono.git] / mcs / class / corlib / System.Runtime.Serialization.Formatters.Binary / ObjectReader.cs
index 3393930dae5bc2b79a883f0bcf5fc84c5ba43350..e3962a3b7157a19bab06b7a1a89c3ddf9315fd61 100644 (file)
@@ -46,9 +46,7 @@ namespace System.Runtime.Serialization.Formatters.Binary
                StreamingContext _context;
                SerializationBinder _binder;
                
-#if NET_1_1
                TypeFilterLevel _filterLevel;
-#endif
 
                ObjectManager _manager;
                Hashtable _registeredAssemblies = new Hashtable();
@@ -84,9 +82,7 @@ namespace System.Runtime.Serialization.Formatters.Binary
                        _binder = formatter.Binder;
                        _manager = new ObjectManager (_surrogateSelector, _context);
                        
-#if NET_1_1
                        _filterLevel = formatter.FilterLevel;
-#endif
                }
 
                public void ReadObjectGraph (BinaryReader reader, bool readHeaders, out object result, out Header[] headers)
@@ -294,13 +290,22 @@ namespace System.Runtime.Serialization.Formatters.Binary
                                
                        info = metadata.NeedsSerializationInfo ? new SerializationInfo(metadata.Type, new FormatterConverter()) : null;
 
-                       if (metadata.MemberNames != null)
+                       if (metadata.MemberNames != null) {
                                for (int n=0; n<metadata.FieldCount; n++)
                                        ReadValue (reader, objectInstance, objectId, info, metadata.MemberTypes[n], metadata.MemberNames[n], null, null);
-                       else
-                               for (int n=0; n<metadata.FieldCount; n++)
+                       else
+                               for (int n=0; n<metadata.FieldCount; n++) {
                                        if (metadata.MemberInfos [n] != null)
-                                       ReadValue (reader, objectInstance, objectId, info, metadata.MemberTypes[n], metadata.MemberInfos[n].Name, metadata.MemberInfos[n], null);
+                                               ReadValue (reader, objectInstance, objectId, info, metadata.MemberTypes[n], metadata.MemberInfos[n].Name, metadata.MemberInfos[n], null);
+                                       else if (BinaryCommon.IsPrimitive(metadata.MemberTypes[n])) {
+                                               // Since the member info is null, the type in this
+                                               // domain does not have this type. Even though we
+                                               // are not going to store the value, we will read
+                                               // it from the stream so that we can advance to the
+                                               // next block.
+                                               ReadPrimitiveTypeValue (reader, metadata.MemberTypes[n]);
+                                       }
+                               }
                }
 
                private void RegisterObject (long objectId, object objectInstance, SerializationInfo info, long parentObjectId, MemberInfo parentObjectMemeber, int[] indices)
@@ -692,10 +697,6 @@ namespace System.Runtime.Serialization.Formatters.Binary
                                                        
                                                if (field != null)
                                                        metadata.MemberInfos [n] = field;
-#if ONLY_1_1
-                                               else
-                                                       throw new SerializationException ("Field \"" + names[n] + "\" not found in class " + metadata.Type.FullName);
-#endif
                                                
                                                if (!hasTypeInfo) {
                                                        types [n] = field.FieldType;
@@ -714,6 +715,22 @@ namespace System.Runtime.Serialization.Formatters.Binary
                        return metadata;
                }
 
+               // Called for primitive types
+               static bool IsGeneric (MemberInfo minfo)
+               {
+                       if (minfo == null)
+                               return false;
+
+                       Type mtype = null;
+                       switch (minfo.MemberType) {
+                       case MemberTypes.Field:
+                               mtype = ((FieldInfo) minfo).FieldType;
+                               break;
+                       default:
+                               throw new NotSupportedException ("Not supported: " + minfo.MemberType);
+                       }
+                       return (mtype != null && mtype.IsGenericType);
+               }
 
                private void ReadValue (BinaryReader reader, object parentObject, long parentObjectId, SerializationInfo info, Type valueType, string fieldName, MemberInfo memberInfo, int[] indices)
                {
@@ -721,7 +738,7 @@ namespace System.Runtime.Serialization.Formatters.Binary
 
                        object val;
 
-                       if (BinaryCommon.IsPrimitive (valueType))
+                       if (BinaryCommon.IsPrimitive (valueType) && !IsGeneric (memberInfo))
                        {
                                val = ReadPrimitiveTypeValue (reader, valueType);
                                SetObjectValue (parentObject, fieldName, memberInfo, info, val, valueType, indices);