From 04f6e9f9435d7174785fde363ec9e4d8b5bddba8 Mon Sep 17 00:00:00 2001 From: Atsushi Kanamori Date: Thu, 9 Mar 2017 19:20:12 -0800 Subject: [PATCH] Move more types into the shared partition. (dotnet/coreclr#10068) * Split/Move files verbatim into shared partition. * Style cleanup. - Delete unused usings - Use autoprops when possible - Lambda syntax for TypeDelegator (yes, it's a lot of code review noise but if there was ever a canonical use-case for that syntax, this is it.) Commit migrated from https://github.com/dotnet/coreclr/commit/b7fe3e070f31e4101a13408790ac2c1ad81a0d92 --- .../src/mscorlib/System.Private.CoreLib.csproj | 5 - .../shared/System.Private.CoreLib.Shared.projitems | 8 + .../Reflection/ObfuscateAssemblyAttribute.cs | 19 ++ .../System/Reflection/ObfuscationAttribute.cs | 21 ++ .../shared/System/Reflection/TypeDelegator.cs | 122 ++++++++++ .../System/Runtime/ConstrainedExecution/Cer.cs | 14 ++ .../Runtime/ConstrainedExecution/Consistency.cs | 15 ++ .../ReliabilityContractAttribute.cs | 38 +-- .../Serialization/ISafeSerializationData.cs} | 34 --- .../Serialization/SafeSerializationEventArgs.cs | 31 +++ src/coreclr/src/mscorlib/src/SR.cs | 5 + .../src/mscorlib/src/System.Private.CoreLib.txt | 4 + .../Reflection/ObfuscateAssemblyAttribute.cs | 45 ---- .../src/System/Reflection/ObfuscationAttribute.cs | 74 ------ .../src/System/Reflection/TypeDelegator.cs | 269 --------------------- 15 files changed, 243 insertions(+), 461 deletions(-) create mode 100644 src/coreclr/src/mscorlib/shared/System/Reflection/ObfuscateAssemblyAttribute.cs create mode 100644 src/coreclr/src/mscorlib/shared/System/Reflection/ObfuscationAttribute.cs create mode 100644 src/coreclr/src/mscorlib/shared/System/Reflection/TypeDelegator.cs create mode 100644 src/coreclr/src/mscorlib/shared/System/Runtime/ConstrainedExecution/Cer.cs create mode 100644 src/coreclr/src/mscorlib/shared/System/Runtime/ConstrainedExecution/Consistency.cs rename src/coreclr/src/mscorlib/{src/System/Runtime/Reliability => shared/System/Runtime/ConstrainedExecution}/ReliabilityContractAttribute.cs (59%) rename src/coreclr/src/mscorlib/{src/System/Runtime/Serialization/SafeSerializationManager.cs => shared/System/Runtime/Serialization/ISafeSerializationData.cs} (90%) create mode 100644 src/coreclr/src/mscorlib/shared/System/Runtime/Serialization/SafeSerializationEventArgs.cs delete mode 100644 src/coreclr/src/mscorlib/src/System/Reflection/ObfuscateAssemblyAttribute.cs delete mode 100644 src/coreclr/src/mscorlib/src/System/Reflection/ObfuscationAttribute.cs delete mode 100644 src/coreclr/src/mscorlib/src/System/Reflection/TypeDelegator.cs diff --git a/src/coreclr/src/mscorlib/System.Private.CoreLib.csproj b/src/coreclr/src/mscorlib/System.Private.CoreLib.csproj index 55be676..8789ca8 100644 --- a/src/coreclr/src/mscorlib/System.Private.CoreLib.csproj +++ b/src/coreclr/src/mscorlib/System.Private.CoreLib.csproj @@ -171,7 +171,6 @@ - @@ -489,8 +488,6 @@ - - @@ -506,7 +503,6 @@ - @@ -850,7 +846,6 @@ - diff --git a/src/coreclr/src/mscorlib/shared/System.Private.CoreLib.Shared.projitems b/src/coreclr/src/mscorlib/shared/System.Private.CoreLib.Shared.projitems index cf9a5f0..8e211d4 100644 --- a/src/coreclr/src/mscorlib/shared/System.Private.CoreLib.Shared.projitems +++ b/src/coreclr/src/mscorlib/shared/System.Private.CoreLib.Shared.projitems @@ -153,12 +153,20 @@ + + + + + + + + diff --git a/src/coreclr/src/mscorlib/shared/System/Reflection/ObfuscateAssemblyAttribute.cs b/src/coreclr/src/mscorlib/shared/System/Reflection/ObfuscateAssemblyAttribute.cs new file mode 100644 index 0000000..f8f765c --- /dev/null +++ b/src/coreclr/src/mscorlib/shared/System/Reflection/ObfuscateAssemblyAttribute.cs @@ -0,0 +1,19 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace System.Reflection +{ + [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] + public sealed class ObfuscateAssemblyAttribute : Attribute + { + public ObfuscateAssemblyAttribute(bool assemblyIsPrivate) + { + AssemblyIsPrivate = assemblyIsPrivate; + } + + public bool AssemblyIsPrivate { get; } + public bool StripAfterObfuscation { get; set; } = true; + } +} + diff --git a/src/coreclr/src/mscorlib/shared/System/Reflection/ObfuscationAttribute.cs b/src/coreclr/src/mscorlib/shared/System/Reflection/ObfuscationAttribute.cs new file mode 100644 index 0000000..11d93b6 --- /dev/null +++ b/src/coreclr/src/mscorlib/shared/System/Reflection/ObfuscationAttribute.cs @@ -0,0 +1,21 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace System.Reflection +{ + [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Parameter | AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Event | AttributeTargets.Interface | AttributeTargets.Enum | AttributeTargets.Delegate, + AllowMultiple = true, Inherited = false)] + public sealed class ObfuscationAttribute : Attribute + { + public ObfuscationAttribute() + { + } + + public bool StripAfterObfuscation { get; set; } = true; + public bool Exclude { get; set; } = true; + public bool ApplyToMembers { get; set; } = true; + public string Feature { get; set; } = "all"; + } +} + diff --git a/src/coreclr/src/mscorlib/shared/System/Reflection/TypeDelegator.cs b/src/coreclr/src/mscorlib/shared/System/Reflection/TypeDelegator.cs new file mode 100644 index 0000000..7044126 --- /dev/null +++ b/src/coreclr/src/mscorlib/shared/System/Reflection/TypeDelegator.cs @@ -0,0 +1,122 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +// TypeDelegator +// +// This class wraps a Type object and delegates all methods to that Type. + +using CultureInfo = System.Globalization.CultureInfo; + +namespace System.Reflection +{ + [Serializable] + public class TypeDelegator : TypeInfo + { + public override bool IsAssignableFrom(TypeInfo typeInfo) + { + if (typeInfo == null) + return false; + return IsAssignableFrom(typeInfo.AsType()); + } + + protected Type typeImpl; + + protected TypeDelegator() { } + + public TypeDelegator(Type delegatingType) + { + if (delegatingType == null) + throw new ArgumentNullException(nameof(delegatingType)); + + typeImpl = delegatingType; + } + + public override Guid GUID => typeImpl.GUID; + public override int MetadataToken => typeImpl.MetadataToken; + + public override object InvokeMember(string name, BindingFlags invokeAttr, Binder binder, object target, + object[] args, ParameterModifier[] modifiers, CultureInfo culture, string[] namedParameters) + { + return typeImpl.InvokeMember(name, invokeAttr, binder, target, args, modifiers, culture, namedParameters); + } + + public override Module Module => typeImpl.Module; + public override Assembly Assembly => typeImpl.Assembly; + public override RuntimeTypeHandle TypeHandle => typeImpl.TypeHandle; + public override string Name => typeImpl.Name; + public override string FullName => typeImpl.FullName; + public override string Namespace => typeImpl.Namespace; + public override string AssemblyQualifiedName => typeImpl.AssemblyQualifiedName; + public override Type BaseType => typeImpl.BaseType; + + protected override ConstructorInfo GetConstructorImpl(BindingFlags bindingAttr, Binder binder, + CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers) + { + return typeImpl.GetConstructor(bindingAttr, binder, callConvention, types, modifiers); + } + + public override ConstructorInfo[] GetConstructors(BindingFlags bindingAttr) => typeImpl.GetConstructors(bindingAttr); + + protected override MethodInfo GetMethodImpl(string name, BindingFlags bindingAttr, Binder binder, + CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers) + { + // This is interesting there are two paths into the impl. One that validates + // type as non-null and one where type may be null. + if (types == null) + return typeImpl.GetMethod(name, bindingAttr); + else + return typeImpl.GetMethod(name, bindingAttr, binder, callConvention, types, modifiers); + } + + public override MethodInfo[] GetMethods(BindingFlags bindingAttr) => typeImpl.GetMethods(bindingAttr); + + public override FieldInfo GetField(string name, BindingFlags bindingAttr) => typeImpl.GetField(name, bindingAttr); + public override FieldInfo[] GetFields(BindingFlags bindingAttr) => typeImpl.GetFields(bindingAttr); + + public override Type GetInterface(string name, bool ignoreCase) => typeImpl.GetInterface(name, ignoreCase); + + public override Type[] GetInterfaces() => typeImpl.GetInterfaces(); + + public override EventInfo GetEvent(string name, BindingFlags bindingAttr) => typeImpl.GetEvent(name, bindingAttr); + + public override EventInfo[] GetEvents() => typeImpl.GetEvents(); + + protected override PropertyInfo GetPropertyImpl(string name, BindingFlags bindingAttr, Binder binder, + Type returnType, Type[] types, ParameterModifier[] modifiers) + { + if (returnType == null && types == null) + return typeImpl.GetProperty(name, bindingAttr); + else + return typeImpl.GetProperty(name, bindingAttr, binder, returnType, types, modifiers); + } + + public override PropertyInfo[] GetProperties(BindingFlags bindingAttr) => typeImpl.GetProperties(bindingAttr); + public override EventInfo[] GetEvents(BindingFlags bindingAttr) => typeImpl.GetEvents(bindingAttr); + public override Type[] GetNestedTypes(BindingFlags bindingAttr) => typeImpl.GetNestedTypes(bindingAttr); + public override Type GetNestedType(string name, BindingFlags bindingAttr) => typeImpl.GetNestedType(name, bindingAttr); + public override MemberInfo[] GetMember(string name, MemberTypes type, BindingFlags bindingAttr) => typeImpl.GetMember(name, type, bindingAttr); + public override MemberInfo[] GetMembers(BindingFlags bindingAttr) => typeImpl.GetMembers(bindingAttr); + + protected override TypeAttributes GetAttributeFlagsImpl() => typeImpl.Attributes; + + protected override bool IsArrayImpl() => typeImpl.IsArray; + protected override bool IsPrimitiveImpl() => typeImpl.IsPrimitive; + protected override bool IsByRefImpl() => typeImpl.IsByRef; + protected override bool IsPointerImpl() => typeImpl.IsPointer; + protected override bool IsValueTypeImpl() => typeImpl.IsValueType; + protected override bool IsCOMObjectImpl() => typeImpl.IsCOMObject; + public override bool IsConstructedGenericType => typeImpl.IsConstructedGenericType; + public override Type GetElementType() => typeImpl.GetElementType(); + protected override bool HasElementTypeImpl() => typeImpl.HasElementType; + + public override Type UnderlyingSystemType => typeImpl.UnderlyingSystemType; + + // ICustomAttributeProvider + public override object[] GetCustomAttributes(bool inherit) => typeImpl.GetCustomAttributes(inherit); + public override object[] GetCustomAttributes(Type attributeType, bool inherit) => typeImpl.GetCustomAttributes(attributeType, inherit); + + public override bool IsDefined(Type attributeType, bool inherit) => typeImpl.IsDefined(attributeType, inherit); + public override InterfaceMapping GetInterfaceMap(Type interfaceType) => typeImpl.GetInterfaceMap(interfaceType); + } +} diff --git a/src/coreclr/src/mscorlib/shared/System/Runtime/ConstrainedExecution/Cer.cs b/src/coreclr/src/mscorlib/shared/System/Runtime/ConstrainedExecution/Cer.cs new file mode 100644 index 0000000..c142ec9 --- /dev/null +++ b/src/coreclr/src/mscorlib/shared/System/Runtime/ConstrainedExecution/Cer.cs @@ -0,0 +1,14 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace System.Runtime.ConstrainedExecution +{ + [Serializable] + public enum Cer : int + { + None = 0, + MayFail = 1, // Might fail, but the method will say it failed + Success = 2, + } +} diff --git a/src/coreclr/src/mscorlib/shared/System/Runtime/ConstrainedExecution/Consistency.cs b/src/coreclr/src/mscorlib/shared/System/Runtime/ConstrainedExecution/Consistency.cs new file mode 100644 index 0000000..7ee8480 --- /dev/null +++ b/src/coreclr/src/mscorlib/shared/System/Runtime/ConstrainedExecution/Consistency.cs @@ -0,0 +1,15 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace System.Runtime.ConstrainedExecution +{ + [Serializable] + public enum Consistency : int + { + MayCorruptProcess = 0, + MayCorruptAppDomain = 1, + MayCorruptInstance = 2, + WillNotCorruptState = 3, + } +} diff --git a/src/coreclr/src/mscorlib/src/System/Runtime/Reliability/ReliabilityContractAttribute.cs b/src/coreclr/src/mscorlib/shared/System/Runtime/ConstrainedExecution/ReliabilityContractAttribute.cs similarity index 59% rename from src/coreclr/src/mscorlib/src/System/Runtime/Reliability/ReliabilityContractAttribute.cs rename to src/coreclr/src/mscorlib/shared/System/Runtime/ConstrainedExecution/ReliabilityContractAttribute.cs index 7781d3a..b3cb014 100644 --- a/src/coreclr/src/mscorlib/src/System/Runtime/Reliability/ReliabilityContractAttribute.cs +++ b/src/coreclr/src/mscorlib/shared/System/Runtime/ConstrainedExecution/ReliabilityContractAttribute.cs @@ -16,48 +16,18 @@ ** ===========================================================*/ -using System.Runtime.InteropServices; -using System; - namespace System.Runtime.ConstrainedExecution { - [Serializable] - public enum Consistency : int - { - MayCorruptProcess = 0, - MayCorruptAppDomain = 1, - MayCorruptInstance = 2, - WillNotCorruptState = 3, - } - - [Serializable] - public enum Cer : int - { - None = 0, - MayFail = 1, // Might fail, but the method will say it failed - Success = 2, - } - [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Interface /* | AttributeTargets.Delegate*/, Inherited = false)] public sealed class ReliabilityContractAttribute : Attribute { - private Consistency _consistency; - private Cer _cer; - public ReliabilityContractAttribute(Consistency consistencyGuarantee, Cer cer) { - _consistency = consistencyGuarantee; - _cer = cer; - } - - public Consistency ConsistencyGuarantee - { - get { return _consistency; } + ConsistencyGuarantee = consistencyGuarantee; + Cer = cer; } - public Cer Cer - { - get { return _cer; } - } + public Consistency ConsistencyGuarantee { get; } + public Cer Cer { get; } } } diff --git a/src/coreclr/src/mscorlib/src/System/Runtime/Serialization/SafeSerializationManager.cs b/src/coreclr/src/mscorlib/shared/System/Runtime/Serialization/ISafeSerializationData.cs similarity index 90% rename from src/coreclr/src/mscorlib/src/System/Runtime/Serialization/SafeSerializationManager.cs rename to src/coreclr/src/mscorlib/shared/System/Runtime/Serialization/ISafeSerializationData.cs index 45173db..12c2e34 100644 --- a/src/coreclr/src/mscorlib/src/System/Runtime/Serialization/SafeSerializationManager.cs +++ b/src/coreclr/src/mscorlib/shared/System/Runtime/Serialization/ISafeSerializationData.cs @@ -2,13 +2,6 @@ // 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; -using System.Collections; -using System.Collections.Generic; -using System.Diagnostics.Contracts; -using System.Reflection; -using System.Security; - namespace System.Runtime.Serialization { // @@ -203,33 +196,6 @@ namespace System.Runtime.Serialization // } // - // SafeSerializationEventArgs are provided to the delegates which do safe serialization. Each delegate - // serializes its own state into an IDeserializationCallback instance which must, itself, be serializable. - // These indivdiual states are then added to the SafeSerializationEventArgs in order to be saved away when - // the original ISerializable type is serialized. - public sealed class SafeSerializationEventArgs : EventArgs - { - private StreamingContext m_streamingContext; - private List m_serializedStates = new List(); - - internal SafeSerializationEventArgs() { } - - public void AddSerializedState(ISafeSerializationData serializedState) - { - if (serializedState == null) - throw new ArgumentNullException(nameof(serializedState)); - if (!serializedState.GetType().IsSerializable) - throw new ArgumentException(Environment.GetResourceString("Serialization_NonSerType", serializedState.GetType(), serializedState.GetType().Assembly.FullName)); - - m_serializedStates.Add(serializedState); - } - - public StreamingContext StreamingContext - { - get { return m_streamingContext; } - } - } - // Interface to be supported by objects which are stored in safe serialization stores public interface ISafeSerializationData { diff --git a/src/coreclr/src/mscorlib/shared/System/Runtime/Serialization/SafeSerializationEventArgs.cs b/src/coreclr/src/mscorlib/shared/System/Runtime/Serialization/SafeSerializationEventArgs.cs new file mode 100644 index 0000000..896b91f --- /dev/null +++ b/src/coreclr/src/mscorlib/shared/System/Runtime/Serialization/SafeSerializationEventArgs.cs @@ -0,0 +1,31 @@ +// Licensed to the .NET Foundation under one or more agreements. +// 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.Collections.Generic; + +namespace System.Runtime.Serialization +{ + // SafeSerializationEventArgs are provided to the delegates which do safe serialization. Each delegate + // serializes its own state into an IDeserializationCallback instance which must, itself, be serializable. + // These indivdiual states are then added to the SafeSerializationEventArgs in order to be saved away when + // the original ISerializable type is serialized. + public sealed class SafeSerializationEventArgs : EventArgs + { + private readonly List _serializedStates = new List(); + + internal SafeSerializationEventArgs() { } + + public void AddSerializedState(ISafeSerializationData serializedState) + { + if (serializedState == null) + throw new ArgumentNullException(nameof(serializedState)); + if (!serializedState.GetType().IsSerializable) + throw new ArgumentException(SR.Format(SR.Serialization_NonSerType, serializedState.GetType(), serializedState.GetType().Assembly.FullName)); + + _serializedStates.Add(serializedState); + } + + public StreamingContext StreamingContext { get; } + } +} diff --git a/src/coreclr/src/mscorlib/src/SR.cs b/src/coreclr/src/mscorlib/src/SR.cs index 50316ae..9ee565e 100644 --- a/src/coreclr/src/mscorlib/src/SR.cs +++ b/src/coreclr/src/mscorlib/src/SR.cs @@ -871,4 +871,9 @@ internal static class SR { get { return Environment.GetResourceString("Lazy_ToString_ValueNotCreated"); } } + + internal static string Serialization_NonSerType + { + get { return Environment.GetResourceString("Serialization_NonSerType"); } + } } diff --git a/src/coreclr/src/mscorlib/src/System.Private.CoreLib.txt b/src/coreclr/src/mscorlib/src/System.Private.CoreLib.txt index cb4a62c..c24a025 100644 --- a/src/coreclr/src/mscorlib/src/System.Private.CoreLib.txt +++ b/src/coreclr/src/mscorlib/src/System.Private.CoreLib.txt @@ -1963,3 +1963,7 @@ Globalization.cp_28591 = Western European (ISO) ; ValueTuple ArgumentException_ValueTupleIncorrectType=Argument must be of type {0}. ArgumentException_ValueTupleLastArgumentNotAValueTuple=The last element of an eight element ValueTuple must be a ValueTuple. + +; SafeSerializationEventArgs +Serialization_NonSerType=Type '{0}' in Assembly '{1}' is not marked as serializable. + diff --git a/src/coreclr/src/mscorlib/src/System/Reflection/ObfuscateAssemblyAttribute.cs b/src/coreclr/src/mscorlib/src/System/Reflection/ObfuscateAssemblyAttribute.cs deleted file mode 100644 index 99b2891..0000000 --- a/src/coreclr/src/mscorlib/src/System/Reflection/ObfuscateAssemblyAttribute.cs +++ /dev/null @@ -1,45 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// 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; -using System.Reflection; - - -namespace System.Reflection -{ - [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] - public sealed class ObfuscateAssemblyAttribute : Attribute - { - private bool m_assemblyIsPrivate; - private bool m_strip = true; - - public ObfuscateAssemblyAttribute(bool assemblyIsPrivate) - { - m_assemblyIsPrivate = assemblyIsPrivate; - } - - public bool AssemblyIsPrivate - { - get - { - return m_assemblyIsPrivate; - } - } - - public bool StripAfterObfuscation - { - get - { - return m_strip; - } - set - { - m_strip = value; - } - } - } -} - diff --git a/src/coreclr/src/mscorlib/src/System/Reflection/ObfuscationAttribute.cs b/src/coreclr/src/mscorlib/src/System/Reflection/ObfuscationAttribute.cs deleted file mode 100644 index 1dfadf1..0000000 --- a/src/coreclr/src/mscorlib/src/System/Reflection/ObfuscationAttribute.cs +++ /dev/null @@ -1,74 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// 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; -using System.Reflection; - -namespace System.Reflection -{ - [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Parameter | AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Event | AttributeTargets.Interface | AttributeTargets.Enum | AttributeTargets.Delegate, - AllowMultiple = true, Inherited = false)] - public sealed class ObfuscationAttribute : Attribute - { - private bool m_strip = true; - private bool m_exclude = true; - private bool m_applyToMembers = true; - private string m_feature = "all"; - - public ObfuscationAttribute() - { - } - - public bool StripAfterObfuscation - { - get - { - return m_strip; - } - set - { - m_strip = value; - } - } - - public bool Exclude - { - get - { - return m_exclude; - } - set - { - m_exclude = value; - } - } - - public bool ApplyToMembers - { - get - { - return m_applyToMembers; - } - set - { - m_applyToMembers = value; - } - } - - public string Feature - { - get - { - return m_feature; - } - set - { - m_feature = value; - } - } - } -} - diff --git a/src/coreclr/src/mscorlib/src/System/Reflection/TypeDelegator.cs b/src/coreclr/src/mscorlib/src/System/Reflection/TypeDelegator.cs deleted file mode 100644 index 748293a..0000000 --- a/src/coreclr/src/mscorlib/src/System/Reflection/TypeDelegator.cs +++ /dev/null @@ -1,269 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -// TypeDelegator -// -// This class wraps a Type object and delegates all methods to that Type. - -namespace System.Reflection -{ - using System; - using System.Runtime.InteropServices; - using System.Diagnostics.Contracts; - using CultureInfo = System.Globalization.CultureInfo; - - [Serializable] - public class TypeDelegator : TypeInfo - { - public override bool IsAssignableFrom(System.Reflection.TypeInfo typeInfo) - { - if (typeInfo == null) return false; - return IsAssignableFrom(typeInfo.AsType()); - } - - protected Type typeImpl; - - protected TypeDelegator() { } - - public TypeDelegator(Type delegatingType) - { - if (delegatingType == null) - throw new ArgumentNullException(nameof(delegatingType)); - Contract.EndContractBlock(); - - typeImpl = delegatingType; - } - - public override Guid GUID - { - get { return typeImpl.GUID; } - } - - public override int MetadataToken { get { return typeImpl.MetadataToken; } } - - public override Object InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, - Object[] args, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParameters) - { - return typeImpl.InvokeMember(name, invokeAttr, binder, target, args, modifiers, culture, namedParameters); - } - - public override Module Module - { - get { return typeImpl.Module; } - } - - public override Assembly Assembly - { - get { return typeImpl.Assembly; } - } - - public override RuntimeTypeHandle TypeHandle - { - get { return typeImpl.TypeHandle; } - } - - public override String Name - { - get { return typeImpl.Name; } - } - - public override String FullName - { - get { return typeImpl.FullName; } - } - - public override String Namespace - { - get { return typeImpl.Namespace; } - } - - public override String AssemblyQualifiedName - { - get - { - return typeImpl.AssemblyQualifiedName; - } - } - - public override Type BaseType - { - get { return typeImpl.BaseType; } - } - - protected override ConstructorInfo GetConstructorImpl(BindingFlags bindingAttr, Binder binder, - CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers) - { - return typeImpl.GetConstructor(bindingAttr, binder, callConvention, types, modifiers); - } - - public override ConstructorInfo[] GetConstructors(BindingFlags bindingAttr) - { - return typeImpl.GetConstructors(bindingAttr); - } - - protected override MethodInfo GetMethodImpl(String name, BindingFlags bindingAttr, Binder binder, - CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers) - { - // This is interesting there are two paths into the impl. One that validates - // type as non-null and one where type may be null. - if (types == null) - return typeImpl.GetMethod(name, bindingAttr); - else - return typeImpl.GetMethod(name, bindingAttr, binder, callConvention, types, modifiers); - } - - public override MethodInfo[] GetMethods(BindingFlags bindingAttr) - { - return typeImpl.GetMethods(bindingAttr); - } - - public override FieldInfo GetField(String name, BindingFlags bindingAttr) - { - return typeImpl.GetField(name, bindingAttr); - } - - public override FieldInfo[] GetFields(BindingFlags bindingAttr) - { - return typeImpl.GetFields(bindingAttr); - } - - public override Type GetInterface(String name, bool ignoreCase) - { - return typeImpl.GetInterface(name, ignoreCase); - } - - public override Type[] GetInterfaces() - { - return typeImpl.GetInterfaces(); - } - - public override EventInfo GetEvent(String name, BindingFlags bindingAttr) - { - return typeImpl.GetEvent(name, bindingAttr); - } - - public override EventInfo[] GetEvents() - { - return typeImpl.GetEvents(); - } - - protected override PropertyInfo GetPropertyImpl(String name, BindingFlags bindingAttr, Binder binder, - Type returnType, Type[] types, ParameterModifier[] modifiers) - { - if (returnType == null && types == null) - return typeImpl.GetProperty(name, bindingAttr); - else - return typeImpl.GetProperty(name, bindingAttr, binder, returnType, types, modifiers); - } - - public override PropertyInfo[] GetProperties(BindingFlags bindingAttr) - { - return typeImpl.GetProperties(bindingAttr); - } - - public override EventInfo[] GetEvents(BindingFlags bindingAttr) - { - return typeImpl.GetEvents(bindingAttr); - } - - public override Type[] GetNestedTypes(BindingFlags bindingAttr) - { - return typeImpl.GetNestedTypes(bindingAttr); - } - - public override Type GetNestedType(String name, BindingFlags bindingAttr) - { - return typeImpl.GetNestedType(name, bindingAttr); - } - - public override MemberInfo[] GetMember(String name, MemberTypes type, BindingFlags bindingAttr) - { - return typeImpl.GetMember(name, type, bindingAttr); - } - - public override MemberInfo[] GetMembers(BindingFlags bindingAttr) - { - return typeImpl.GetMembers(bindingAttr); - } - - protected override TypeAttributes GetAttributeFlagsImpl() - { - return typeImpl.Attributes; - } - - protected override bool IsArrayImpl() - { - return typeImpl.IsArray; - } - - protected override bool IsPrimitiveImpl() - { - return typeImpl.IsPrimitive; - } - - protected override bool IsByRefImpl() - { - return typeImpl.IsByRef; - } - - protected override bool IsPointerImpl() - { - return typeImpl.IsPointer; - } - - protected override bool IsValueTypeImpl() - { - return typeImpl.IsValueType; - } - - protected override bool IsCOMObjectImpl() - { - return typeImpl.IsCOMObject; - } - - public override bool IsConstructedGenericType - { - get - { - return typeImpl.IsConstructedGenericType; - } - } - - public override Type GetElementType() - { - return typeImpl.GetElementType(); - } - - protected override bool HasElementTypeImpl() - { - return typeImpl.HasElementType; - } - - public override Type UnderlyingSystemType - { - get { return typeImpl.UnderlyingSystemType; } - } - - // ICustomAttributeProvider - public override Object[] GetCustomAttributes(bool inherit) - { - return typeImpl.GetCustomAttributes(inherit); - } - - public override Object[] GetCustomAttributes(Type attributeType, bool inherit) - { - return typeImpl.GetCustomAttributes(attributeType, inherit); - } - - public override bool IsDefined(Type attributeType, bool inherit) - { - return typeImpl.IsDefined(attributeType, inherit); - } - - public override InterfaceMapping GetInterfaceMap(Type interfaceType) - { - return typeImpl.GetInterfaceMap(interfaceType); - } - } -} -- 2.7.4