[corlib] Fixed StringBuilder construction bugs in marshalling caused by changes to...
[mono.git] / mcs / class / corlib / System.Runtime.Serialization / FormatterServices.cs
index 22ac5110c94c2e6e33aa6298356512b0b912a5f4..e2a8702befaeddde56684502e24e96878c699031 100644 (file)
@@ -33,24 +33,21 @@ using System;
 using System.Collections;
 using System.Reflection;
 using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
 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
+       static
+       public class FormatterServices
        {
                private const BindingFlags fieldFlags = BindingFlags.Public |
                                                        BindingFlags.Instance |
                                                        BindingFlags.NonPublic |
                                                        BindingFlags.DeclaredOnly;
 
-               private FormatterServices ()
-               {
-               }
 
                public static object [] GetObjectData (object obj, MemberInfo [] members)
                {
@@ -116,8 +113,8 @@ namespace System.Runtime.Serialization
                        foreach (FieldInfo field in fs)
                                if (!(field.IsNotSerialized)) {
                                        MonoField mf = field as MonoField;
-                                       if (mf != null) {
-                                               string fname = (reflectedType != type && !mf.IsPublic) ? type.Name + "+" + mf.Name : mf.Name;
+                                       if (mf != null && reflectedType != type && !mf.IsPublic) {
+                                               string fname = type.Name + "+" + mf.Name;
                                                fields.Add (mf.Clone (fname));
                                        }
                                        else
@@ -178,7 +175,6 @@ namespace System.Runtime.Serialization
                        return obj;
                }
                
-#if NET_1_1
 
                public static void CheckTypeSecurity (Type t, TypeFilterLevel securityLevel)
                {
@@ -209,6 +205,14 @@ namespace System.Runtime.Serialization
                        
                        return GetUninitializedObject (type);
                }
-#endif
+
+               // This method was introduced in .Net due to a bug serializing objects with circular references
+               // which we don't appear to have, so we just return the same object.
+               // See http://support.microsoft.com/kb/927495/en-us/ in case of doubt.
+               [ComVisible (false)]
+               public static ISerializationSurrogate GetSurrogateForCyclicalReference (ISerializationSurrogate innerSurrogate)
+               {
+                       return innerSurrogate;
+               }
        }
 }