From: Atsushi Kanamori Date: Wed, 22 Mar 2017 22:28:14 +0000 (-0700) Subject: Move Type.IsSerializable and Type.DefaultBinder to shared file. (dotnet/coreclr#10395) X-Git-Tag: submit/tizen/20210909.063632~11030^2~7607 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=29eeac5ed0d1958dbf0a0196e4885b508413e55b;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Move Type.IsSerializable and Type.DefaultBinder to shared file. (dotnet/coreclr#10395) This will pave the way for the mirrorbot to fix https://github.com/dotnet/corert/issues/3061. Commit migrated from https://github.com/dotnet/coreclr/commit/f10955c88f0f82bb3eae7966390979f49dcb47ae --- diff --git a/src/coreclr/src/mscorlib/shared/System/Type.Helpers.cs b/src/coreclr/src/mscorlib/shared/System/Type.Helpers.cs index f2f3bf6..db8df23 100644 --- a/src/coreclr/src/mscorlib/shared/System/Type.Helpers.cs +++ b/src/coreclr/src/mscorlib/shared/System/Type.Helpers.cs @@ -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 diff --git a/src/coreclr/src/mscorlib/shared/System/Type.cs b/src/coreclr/src/mscorlib/shared/System/Type.cs index 09a72aa..fa0a7b9 100644 --- a/src/coreclr/src/mscorlib/shared/System/Type.cs +++ b/src/coreclr/src/mscorlib/shared/System/Type.cs @@ -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(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(); public static readonly object Missing = System.Reflection.Missing.Value; diff --git a/src/coreclr/src/mscorlib/src/System/RtType.cs b/src/coreclr/src/mscorlib/src/System/RtType.cs index f49aad5..826bbea 100644 --- a/src/coreclr/src/mscorlib/src/System/RtType.cs +++ b/src/coreclr/src/mscorlib/src/System/RtType.cs @@ -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(); diff --git a/src/coreclr/src/mscorlib/src/System/Type.CoreCLR.cs b/src/coreclr/src/mscorlib/src/System/Type.CoreCLR.cs index f06b633..9c443b4 100644 --- a/src/coreclr/src/mscorlib/src/System/Type.CoreCLR.cs +++ b/src/coreclr/src/mscorlib/src/System/Type.CoreCLR.cs @@ -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(ref defaultBinder, binder, null); - } - } - internal virtual RuntimeTypeHandle GetTypeHandleInternal() { return TypeHandle;