Move Type.IsSerializable and Type.DefaultBinder to shared file. (#10395)
authorAtsushi Kanamori <AtsushiKan@users.noreply.github.com>
Wed, 22 Mar 2017 22:28:14 +0000 (15:28 -0700)
committerGitHub <noreply@github.com>
Wed, 22 Mar 2017 22:28:14 +0000 (15:28 -0700)
This will pave the way for the mirrorbot to fix
https://github.com/dotnet/corert/issues/3061.

src/mscorlib/shared/System/Type.Helpers.cs
src/mscorlib/shared/System/Type.cs
src/mscorlib/src/System/RtType.cs
src/mscorlib/src/System/Type.CoreCLR.cs

index f2f3bf6..db8df23 100644 (file)
@@ -9,6 +9,34 @@ namespace System
     // This file collects the longer methods of Type to make the main Type class more readable.
     public abstract partial class Type : MemberInfo, IReflect
     {
+        public virtual bool IsSerializable
+        {
+            get
+            {
+                if ((GetAttributeFlagsImpl() & TypeAttributes.Serializable) != 0)
+                    return true;
+
+                Type underlyingType = UnderlyingSystemType;
+                if (underlyingType.IsRuntimeImplemented())
+                {
+                    do
+                    {
+                        // In all sane cases we only need to compare the direct level base type with
+                        // System.Enum and System.MulticastDelegate. However, a generic parameter can
+                        // have a base type constraint that is Delegate or even a real delegate type.
+                        // Let's maintain compatibility and return true for them.
+                        if (underlyingType == typeof(Delegate) || underlyingType == typeof(Enum))
+                            return true;
+
+                        underlyingType = underlyingType.BaseType;
+                    }
+                    while (underlyingType != null);
+                }
+
+                return false;
+            }
+        }
+
         public virtual bool ContainsGenericParameters
         {
             get
index 09a72aa..fa0a7b9 100644 (file)
@@ -2,6 +2,7 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
 
+using System.Threading;
 using System.Reflection;
 using System.Diagnostics;
 using System.Globalization;
@@ -328,6 +329,21 @@ namespace System
 
         public static Type ReflectionOnlyGetType(string typeName, bool throwIfNotFound, bool ignoreCase) { throw new PlatformNotSupportedException(SR.PlatformNotSupported_ReflectionOnly); }
 
+        public static Binder DefaultBinder
+        {
+            get
+            {
+                if (s_defaultBinder == null)
+                {
+                    DefaultBinder binder = new DefaultBinder();
+                    Interlocked.CompareExchange<Binder>(ref s_defaultBinder, binder, null);
+                }
+                return s_defaultBinder;
+            }
+        }
+
+        private static volatile Binder s_defaultBinder;
+
         public static readonly char Delimiter = '.';
         public static readonly Type[] EmptyTypes = Array.Empty<Type>();
         public static readonly object Missing = System.Reflection.Missing.Value;
index f49aad5..826bbea 100644 (file)
@@ -2481,24 +2481,6 @@ namespace System
             }
         }
 
-        internal bool IsSpecialSerializableType()
-        {
-            RuntimeType rt = this;
-            do
-            {
-                // In all sane cases we only need to compare the direct level base type with
-                // System.Enum and System.MulticastDelegate. However, a generic argument can
-                // have a base type constraint that is Delegate or even a real delegate type.
-                // Let's maintain compatibility and return true for them.
-                if (rt == RuntimeType.DelegateType || rt == RuntimeType.EnumType)
-                    return true;
-
-                rt = rt.GetBaseType();
-            } while (rt != null);
-
-            return false;
-        }
-
         private string GetDefaultMemberName()
         {
             return Cache.GetDefaultMemberName();
index f06b633..9c443b4 100644 (file)
@@ -3,7 +3,6 @@
 // See the LICENSE file in the project root for more information.
 
 using System.Reflection;
-using System.Threading;
 using System.Runtime.CompilerServices;
 using System.Diagnostics.Contracts;
 using StackCrawlMark = System.Threading.StackCrawlMark;
@@ -12,9 +11,6 @@ namespace System
 {
     public abstract partial class Type : MemberInfo, IReflect
     {
-        // The Default binder.  We create a single one and expose that.
-        private static Binder defaultBinder;
-
         public bool IsInterface
         {
             get
@@ -26,21 +22,6 @@ namespace System
             }
         }
 
-        public virtual bool IsSerializable
-        {
-            get
-            {
-                if ((GetAttributeFlagsImpl() & TypeAttributes.Serializable) != 0)
-                    return true;
-
-                RuntimeType rt = this.UnderlyingSystemType as RuntimeType;
-                if (rt != null)
-                    return rt.IsSpecialSerializableType();
-
-                return false;
-            }
-        }
-
         [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
         public static Type GetType(String typeName, bool throwOnError, bool ignoreCase)
         {
@@ -121,27 +102,6 @@ namespace System
             return RuntimeType.GetTypeFromCLSIDImpl(clsid, server, throwOnError);
         }
 
-        // Return the Default binder used by the system.
-        static public Binder DefaultBinder
-        {
-            get
-            {
-                // Allocate the default binder if it hasn't been allocated yet.
-                if (defaultBinder == null)
-                    CreateBinder();
-                return defaultBinder;
-            }
-        }
-
-        static private void CreateBinder()
-        {
-            if (defaultBinder == null)
-            {
-                DefaultBinder binder = new DefaultBinder();
-                Interlocked.CompareExchange<Binder>(ref defaultBinder, binder, null);
-            }
-        }
-
         internal virtual RuntimeTypeHandle GetTypeHandleInternal()
         {
             return TypeHandle;