2009-06-25 Miguel de Icaza <miguel@novell.com>
[mono.git] / mcs / class / corlib / System.Runtime.Serialization / FormatterServices.cs
index 1a03f703682323d190bc3dd8657ce4e1dc2d3874..2876b294e61cb85946b0b245abf1691fbfa40e90 100644 (file)
@@ -6,14 +6,41 @@
 //
 // (C) 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;
 using System.Collections;
 using System.Reflection;
 using System.Runtime.CompilerServices;
 using System.Runtime.Serialization.Formatters;
+using System.Globalization;
 
 namespace System.Runtime.Serialization
 {
+#if NET_2_0
+       [System.Runtime.InteropServices.ComVisibleAttribute (true)]
+#endif
        public sealed class FormatterServices
        {
                private const BindingFlags fieldFlags = BindingFlags.Public |
@@ -74,7 +101,7 @@ namespace System.Runtime.Serialization
                                        throw new SerializationException (msg);
                                }
 
-                               GetFields (t, fields);
+                               GetFields (type, t, fields);
                                t = t.BaseType;
                        }
 
@@ -83,12 +110,19 @@ namespace System.Runtime.Serialization
                        return result;
                }
 
-               private static void GetFields (Type type, ArrayList fields)
+               private static void GetFields (Type reflectedType, Type type, ArrayList fields)
                {
                        FieldInfo [] fs = type.GetFields (fieldFlags);
                        foreach (FieldInfo field in fs)
-                               if (!(field.IsNotSerialized))
-                                       fields.Add (field);
+                               if (!(field.IsNotSerialized)) {
+                                       MonoField mf = field as MonoField;
+                                       if (mf != null && reflectedType != type && !mf.IsPublic) {
+                                               string fname = type.Name + "+" + mf.Name;
+                                               fields.Add (mf.Clone (fname));
+                                       }
+                                       else
+                                               fields.Add (field);
+                               }
                }
 
                public static Type GetTypeFromAssembly (Assembly assem, string name)