Merge pull request #1304 from slluis/mac-proxy-autoconfig
[mono.git] / mcs / class / corlib / System.Runtime.Serialization / FormatterServices.cs
index f0a1ecfa4f1b0d2f0c9dca15cb865aece8abeef4..f8171915a41777a68a75bd7027d496b839a12894 100644 (file)
@@ -33,21 +33,30 @@ 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
 {
-       public sealed class FormatterServices
+       [System.Runtime.InteropServices.ComVisibleAttribute (true)]
+#if NET_4_5
+       static
+#else
+       sealed
+#endif
+       public class FormatterServices
        {
                private const BindingFlags fieldFlags = BindingFlags.Public |
                                                        BindingFlags.Instance |
                                                        BindingFlags.NonPublic |
                                                        BindingFlags.DeclaredOnly;
 
+#if !NET_4_5
                private FormatterServices ()
                {
                }
+#endif
 
                public static object [] GetObjectData (object obj, MemberInfo [] members)
                {
@@ -113,8 +122,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
@@ -175,7 +184,6 @@ namespace System.Runtime.Serialization
                        return obj;
                }
                
-#if NET_1_1
 
                public static void CheckTypeSecurity (Type t, TypeFilterLevel securityLevel)
                {
@@ -206,6 +214,16 @@ namespace System.Runtime.Serialization
                        
                        return GetUninitializedObject (type);
                }
+
+#if NET_4_0
+               // 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;
+               }
 #endif
        }
 }