// 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
// 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;
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;
}
}
- 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();
// 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;
{
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
}
}
- 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)
{
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;