From: Atsushi Kanamori Date: Fri, 17 Mar 2017 00:23:51 +0000 (-0700) Subject: Move the MemberInfo-derived Info classes to the shared partition. (dotnet/coreclr... X-Git-Tag: submit/tizen/20210909.063632~11030^2~7690 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b3f2069bbd137132d960251a71d8cff95207b380;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Move the MemberInfo-derived Info classes to the shared partition. (dotnet/coreclr#10236) * Copy over CoreRt prose member by member. * Transplant the CoreRt version of the files. This is now just a reordering. Verified by sorting the old and new versions of the file and diffin. * Move to shared partition. * Looks like the #if FEATURE_COMINTEROP wasn't just for show... Take EventInfo.cs back to unshared status for now... Commit migrated from https://github.com/dotnet/coreclr/commit/c6b82ac3d83ecebc124d6a39065f4e6723aa320b --- diff --git a/src/coreclr/src/mscorlib/System.Private.CoreLib.csproj b/src/coreclr/src/mscorlib/System.Private.CoreLib.csproj index a0fa860..3b8e16c 100644 --- a/src/coreclr/src/mscorlib/System.Private.CoreLib.csproj +++ b/src/coreclr/src/mscorlib/System.Private.CoreLib.csproj @@ -452,14 +452,12 @@ - - @@ -482,7 +480,6 @@ - @@ -493,7 +490,6 @@ - @@ -512,7 +508,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 0ceaefd..364c9ca 100644 --- a/src/coreclr/src/mscorlib/shared/System.Private.CoreLib.Shared.projitems +++ b/src/coreclr/src/mscorlib/shared/System.Private.CoreLib.Shared.projitems @@ -154,11 +154,16 @@ + + + + + diff --git a/src/coreclr/src/mscorlib/shared/System/Reflection/ConstructorInfo.cs b/src/coreclr/src/mscorlib/shared/System/Reflection/ConstructorInfo.cs new file mode 100644 index 0000000..3ee1dbf --- /dev/null +++ b/src/coreclr/src/mscorlib/shared/System/Reflection/ConstructorInfo.cs @@ -0,0 +1,40 @@ +// 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.Diagnostics; +using System.Globalization; + +namespace System.Reflection +{ + public abstract partial class ConstructorInfo : MethodBase + { + protected ConstructorInfo() { } + + public override MemberTypes MemberType => MemberTypes.Constructor; + + [DebuggerHidden] + [DebuggerStepThrough] + public object Invoke(object[] parameters) => Invoke(BindingFlags.Default, binder: null, parameters: parameters, culture: null); + public abstract object Invoke(BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture); + + public override bool Equals(object obj) => base.Equals(obj); + public override int GetHashCode() => base.GetHashCode(); + + public static bool operator ==(ConstructorInfo left, ConstructorInfo right) + { + if (object.ReferenceEquals(left, right)) + return true; + + if ((object)left == null || (object)right == null) + return false; + + return left.Equals(right); + } + + public static bool operator !=(ConstructorInfo left, ConstructorInfo right) => !(left == right); + + public static readonly string ConstructorName = ".ctor"; + public static readonly string TypeConstructorName = ".cctor"; + } +} diff --git a/src/coreclr/src/mscorlib/shared/System/Reflection/FieldInfo.cs b/src/coreclr/src/mscorlib/shared/System/Reflection/FieldInfo.cs new file mode 100644 index 0000000..0863c2b --- /dev/null +++ b/src/coreclr/src/mscorlib/shared/System/Reflection/FieldInfo.cs @@ -0,0 +1,72 @@ +// 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.Diagnostics; +using System.Globalization; + +namespace System.Reflection +{ + public abstract partial class FieldInfo : MemberInfo + { + protected FieldInfo() { } + + public override MemberTypes MemberType => MemberTypes.Field; + + public abstract FieldAttributes Attributes { get; } + public abstract Type FieldType { get; } + + public bool IsInitOnly => (Attributes & FieldAttributes.InitOnly) != 0; + public bool IsLiteral => (Attributes & FieldAttributes.Literal) != 0; + public bool IsNotSerialized => (Attributes & FieldAttributes.NotSerialized) != 0; + public bool IsPinvokeImpl => (Attributes & FieldAttributes.PinvokeImpl) != 0; + public bool IsSpecialName => (Attributes & FieldAttributes.SpecialName) != 0; + public bool IsStatic => (Attributes & FieldAttributes.Static) != 0; + + public bool IsAssembly => (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Assembly; + public bool IsFamily => (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Family; + public bool IsFamilyAndAssembly => (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.FamANDAssem; + public bool IsFamilyOrAssembly => (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.FamORAssem; + public bool IsPrivate => (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Private; + public bool IsPublic => (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Public; + + public virtual bool IsSecurityCritical => true; + public virtual bool IsSecuritySafeCritical => false; + public virtual bool IsSecurityTransparent => false; + + public abstract RuntimeFieldHandle FieldHandle { get; } + + public override bool Equals(object obj) => base.Equals(obj); + public override int GetHashCode() => base.GetHashCode(); + + public static bool operator ==(FieldInfo left, FieldInfo right) + { + if (object.ReferenceEquals(left, right)) + return true; + + if ((object)left == null || (object)right == null) + return false; + + return left.Equals(right); + } + + public static bool operator !=(FieldInfo left, FieldInfo right) => !(left == right); + + public abstract object GetValue(object obj); + + [DebuggerHidden] + [DebuggerStepThrough] + public void SetValue(object obj, object value) => SetValue(obj, value, BindingFlags.Default, Type.DefaultBinder, null); + public abstract void SetValue(object obj, object value, BindingFlags invokeAttr, Binder binder, CultureInfo culture); + + [CLSCompliant(false)] + public virtual void SetValueDirect(TypedReference obj, object value) { throw new NotSupportedException(SR.NotSupported_AbstractNonCLS); } + [CLSCompliant(false)] + public virtual object GetValueDirect(TypedReference obj) { throw new NotSupportedException(SR.NotSupported_AbstractNonCLS); } + + public virtual object GetRawConstantValue() { throw new NotSupportedException(SR.NotSupported_AbstractNonCLS); } + + public virtual Type[] GetOptionalCustomModifiers() { throw NotImplemented.ByDesign; } + public virtual Type[] GetRequiredCustomModifiers() { throw NotImplemented.ByDesign; } + } +} diff --git a/src/coreclr/src/mscorlib/shared/System/Reflection/MethodInfo.cs b/src/coreclr/src/mscorlib/shared/System/Reflection/MethodInfo.cs new file mode 100644 index 0000000..3f60149 --- /dev/null +++ b/src/coreclr/src/mscorlib/shared/System/Reflection/MethodInfo.cs @@ -0,0 +1,43 @@ +// 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 +{ + public abstract class MethodInfo : MethodBase + { + protected MethodInfo() { } + + public override MemberTypes MemberType => MemberTypes.Method; + + public virtual ParameterInfo ReturnParameter { get { throw NotImplemented.ByDesign; } } + public virtual Type ReturnType { get { throw NotImplemented.ByDesign; } } + + public override Type[] GetGenericArguments() { throw new NotSupportedException(SR.NotSupported_SubclassOverride); } + public virtual MethodInfo GetGenericMethodDefinition() { throw new NotSupportedException(SR.NotSupported_SubclassOverride); } + public virtual MethodInfo MakeGenericMethod(params Type[] typeArguments) { throw new NotSupportedException(SR.NotSupported_SubclassOverride); } + + public abstract MethodInfo GetBaseDefinition(); + + public abstract ICustomAttributeProvider ReturnTypeCustomAttributes { get; } + + public virtual Delegate CreateDelegate(Type delegateType) { throw new NotSupportedException(SR.NotSupported_SubclassOverride); } + public virtual Delegate CreateDelegate(Type delegateType, object target) { throw new NotSupportedException(SR.NotSupported_SubclassOverride); } + + public override bool Equals(object obj) => base.Equals(obj); + public override int GetHashCode() => base.GetHashCode(); + + public static bool operator ==(MethodInfo left, MethodInfo right) + { + if (object.ReferenceEquals(left, right)) + return true; + + if ((object)left == null || (object)right == null) + return false; + + return left.Equals(right); + } + + public static bool operator !=(MethodInfo left, MethodInfo right) => !(left == right); + } +} diff --git a/src/coreclr/src/mscorlib/shared/System/Reflection/PropertyInfo.cs b/src/coreclr/src/mscorlib/shared/System/Reflection/PropertyInfo.cs new file mode 100644 index 0000000..ff8a02e --- /dev/null +++ b/src/coreclr/src/mscorlib/shared/System/Reflection/PropertyInfo.cs @@ -0,0 +1,74 @@ +// 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.Diagnostics; +using System.Globalization; + +namespace System.Reflection +{ + public abstract class PropertyInfo : MemberInfo + { + protected PropertyInfo() { } + + public override MemberTypes MemberType => MemberTypes.Property; + + public abstract Type PropertyType { get; } + public abstract ParameterInfo[] GetIndexParameters(); + + public abstract PropertyAttributes Attributes { get; } + public bool IsSpecialName => (Attributes & PropertyAttributes.SpecialName) != 0; + + public abstract bool CanRead { get; } + public abstract bool CanWrite { get; } + + public MethodInfo[] GetAccessors() => GetAccessors(nonPublic: false); + public abstract MethodInfo[] GetAccessors(bool nonPublic); + + public virtual MethodInfo GetMethod => GetGetMethod(nonPublic: true); + public MethodInfo GetGetMethod() => GetGetMethod(nonPublic: false); + public abstract MethodInfo GetGetMethod(bool nonPublic); + + public virtual MethodInfo SetMethod => GetSetMethod(nonPublic: true); + public MethodInfo GetSetMethod() => GetSetMethod(nonPublic: false); + public abstract MethodInfo GetSetMethod(bool nonPublic); + + public virtual Type[] GetOptionalCustomModifiers() => Array.Empty(); + public virtual Type[] GetRequiredCustomModifiers() => Array.Empty(); + + [DebuggerHidden] + [DebuggerStepThrough] + public object GetValue(object obj) => GetValue(obj, index: null); + [DebuggerHidden] + [DebuggerStepThrough] + public virtual object GetValue(object obj, object[] index) => GetValue(obj, BindingFlags.Default, binder: null, index: index, culture: null); + public abstract object GetValue(object obj, BindingFlags invokeAttr, Binder binder, object[] index, CultureInfo culture); + + public virtual object GetConstantValue() { throw NotImplemented.ByDesign; } + public virtual object GetRawConstantValue() { throw NotImplemented.ByDesign; } + + [DebuggerHidden] + [DebuggerStepThrough] + public void SetValue(object obj, object value) => SetValue(obj, value, index: null); + [DebuggerHidden] + [DebuggerStepThrough] + public virtual void SetValue(object obj, object value, object[] index) => SetValue(obj, value, BindingFlags.Default, binder: null, index: index, culture: null); + public abstract void SetValue(object obj, object value, BindingFlags invokeAttr, Binder binder, object[] index, CultureInfo culture); + + public override bool Equals(object obj) => base.Equals(obj); + public override int GetHashCode() => base.GetHashCode(); + + public static bool operator ==(PropertyInfo left, PropertyInfo right) + { + if (object.ReferenceEquals(left, right)) + return true; + + if ((object)left == null || (object)right == null) + return false; + + return left.Equals(right); + } + + public static bool operator !=(PropertyInfo left, PropertyInfo right) => !(left == right); + } +} diff --git a/src/coreclr/src/mscorlib/shared/System/Reflection/TypeInfo.cs b/src/coreclr/src/mscorlib/shared/System/Reflection/TypeInfo.cs new file mode 100644 index 0000000..f4add73 --- /dev/null +++ b/src/coreclr/src/mscorlib/shared/System/Reflection/TypeInfo.cs @@ -0,0 +1,84 @@ +// 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.Reflection +{ + public abstract partial class TypeInfo : Type, IReflectableType + { + protected TypeInfo() { } + + TypeInfo IReflectableType.GetTypeInfo() => this; + public virtual Type AsType() => this; + + public virtual Type[] GenericTypeParameters => IsGenericTypeDefinition ? GetGenericArguments() : Type.EmptyTypes; + + public virtual EventInfo GetDeclaredEvent(string name) => GetEvent(name, TypeInfo.DeclaredOnlyLookup); + public virtual FieldInfo GetDeclaredField(string name) => GetField(name, TypeInfo.DeclaredOnlyLookup); + public virtual MethodInfo GetDeclaredMethod(string name) => GetMethod(name, TypeInfo.DeclaredOnlyLookup); + public virtual TypeInfo GetDeclaredNestedType(string name) => GetNestedType(name, TypeInfo.DeclaredOnlyLookup)?.GetTypeInfo(); + public virtual PropertyInfo GetDeclaredProperty(string name) => GetProperty(name, TypeInfo.DeclaredOnlyLookup); + + public virtual IEnumerable GetDeclaredMethods(string name) + { + foreach (MethodInfo method in GetMethods(TypeInfo.DeclaredOnlyLookup)) + { + if (method.Name == name) + yield return method; + } + } + + public virtual IEnumerable DeclaredConstructors => GetConstructors(TypeInfo.DeclaredOnlyLookup); + public virtual IEnumerable DeclaredEvents => GetEvents(TypeInfo.DeclaredOnlyLookup); + public virtual IEnumerable DeclaredFields => GetFields(TypeInfo.DeclaredOnlyLookup); + public virtual IEnumerable DeclaredMembers => GetMembers(TypeInfo.DeclaredOnlyLookup); + public virtual IEnumerable DeclaredMethods => GetMethods(TypeInfo.DeclaredOnlyLookup); + public virtual IEnumerable DeclaredNestedTypes + { + get + { + foreach (Type t in GetNestedTypes(TypeInfo.DeclaredOnlyLookup)) + { + yield return t.GetTypeInfo(); + } + } + } + public virtual IEnumerable DeclaredProperties => GetProperties(TypeInfo.DeclaredOnlyLookup); + + public virtual IEnumerable ImplementedInterfaces => GetInterfaces(); + + //a re-implementation of ISAF from Type, skipping the use of UnderlyingType + public virtual bool IsAssignableFrom(TypeInfo typeInfo) + { + if (typeInfo == null) + return false; + + if (this == typeInfo) + return true; + + // If c is a subclass of this class, then c can be cast to this type. + if (typeInfo.IsSubclassOf(this)) + return true; + + if (this.IsInterface) + { + return typeInfo.ImplementInterface(this); + } + else if (IsGenericParameter) + { + Type[] constraints = GetGenericParameterConstraints(); + for (int i = 0; i < constraints.Length; i++) + if (!constraints[i].IsAssignableFrom(typeInfo)) + return false; + + return true; + } + + return false; + } + + private const BindingFlags DeclaredOnlyLookup = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly; + } +} diff --git a/src/coreclr/src/mscorlib/src/SR.cs b/src/coreclr/src/mscorlib/src/SR.cs index 17bc05e..e013a56 100644 --- a/src/coreclr/src/mscorlib/src/SR.cs +++ b/src/coreclr/src/mscorlib/src/SR.cs @@ -945,4 +945,16 @@ internal static class SR internal static string Arg_EnumIllegalVal => Environment.GetResourceString("Arg_EnumIllegalVal"); + + internal static string InvalidOperation_NoPublicAddMethod => + Environment.GetResourceString("InvalidOperation_NoPublicAddMethod"); + + internal static string InvalidOperation_NoPublicRemoveMethod => + Environment.GetResourceString("InvalidOperation_NoPublicRemoveMethod"); + + internal static string InvalidOperation_NotSupportedOnWinRTEvent => + Environment.GetResourceString("InvalidOperation_NotSupportedOnWinRTEvent"); + + internal static string NotSupported_AbstractNonCLS => + Environment.GetResourceString("NotSupported_AbstractNonCLS"); } diff --git a/src/coreclr/src/mscorlib/src/System/Reflection/ConstructorInfo.cs b/src/coreclr/src/mscorlib/src/System/Reflection/ConstructorInfo.cs deleted file mode 100644 index df76ac5..0000000 --- a/src/coreclr/src/mscorlib/src/System/Reflection/ConstructorInfo.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.Diagnostics; -using System.Globalization; - -namespace System.Reflection -{ - [Serializable] - public abstract partial class ConstructorInfo : MethodBase - { - #region Static Members - public readonly static String ConstructorName = ".ctor"; - - public readonly static String TypeConstructorName = ".cctor"; - #endregion - - #region Constructor - protected ConstructorInfo() { } - #endregion - - public static bool operator ==(ConstructorInfo left, ConstructorInfo right) - { - if (ReferenceEquals(left, right)) - return true; - - if ((object)left == null || (object)right == null || - left is RuntimeConstructorInfo || right is RuntimeConstructorInfo) - { - return false; - } - return left.Equals(right); - } - - public static bool operator !=(ConstructorInfo left, ConstructorInfo right) - { - return !(left == right); - } - - public override bool Equals(object obj) - { - return base.Equals(obj); - } - - public override int GetHashCode() - { - return base.GetHashCode(); - } - - #region MemberInfo Overrides - public override MemberTypes MemberType { get { return System.Reflection.MemberTypes.Constructor; } } - #endregion - - #region Public Abstract\Virtual Members - public abstract Object Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture); - #endregion - - #region Public Members - [DebuggerStepThroughAttribute] - [Diagnostics.DebuggerHidden] - public Object Invoke(Object[] parameters) - { - // Theoretically we should set up a LookForMyCaller stack mark here and pass that along. - // But to maintain backward compatibility we can't switch to calling an - // internal overload that takes a stack mark. - // Fortunately the stack walker skips all the reflection invocation frames including this one. - // So this method will never be returned by the stack walker as the caller. - // See SystemDomain::CallersMethodCallbackWithStackMark in AppDomain.cpp. - return Invoke(BindingFlags.Default, null, parameters, null); - } - #endregion - } -} diff --git a/src/coreclr/src/mscorlib/src/System/Reflection/EventInfo.cs b/src/coreclr/src/mscorlib/src/System/Reflection/EventInfo.cs index 0ec89da..ccd9acf 100644 --- a/src/coreclr/src/mscorlib/src/System/Reflection/EventInfo.cs +++ b/src/coreclr/src/mscorlib/src/System/Reflection/EventInfo.cs @@ -4,175 +4,112 @@ using System.Diagnostics; +#if FEATURE_COMINTEROP +using EventRegistrationToken = System.Runtime.InteropServices.WindowsRuntime.EventRegistrationToken; +#endif //#if FEATURE_COMINTEROP + namespace System.Reflection { - [Serializable] public abstract class EventInfo : MemberInfo { - #region Constructor protected EventInfo() { } - #endregion - - public static bool operator ==(EventInfo left, EventInfo right) - { - if (ReferenceEquals(left, right)) - return true; - - if ((object)left == null || (object)right == null || - left is RuntimeEventInfo || right is RuntimeEventInfo) - { - return false; - } - return left.Equals(right); - } - public static bool operator !=(EventInfo left, EventInfo right) - { - return !(left == right); - } + public override MemberTypes MemberType => MemberTypes.Event; - public override bool Equals(object obj) - { - return base.Equals(obj); - } + public abstract EventAttributes Attributes { get; } + public bool IsSpecialName => (Attributes & EventAttributes.SpecialName) != 0; - public override int GetHashCode() - { - return base.GetHashCode(); - } + public MethodInfo[] GetOtherMethods() => GetOtherMethods(nonPublic: false); + public virtual MethodInfo[] GetOtherMethods(bool nonPublic) { throw NotImplemented.ByDesign; } - #region MemberInfo Overrides - public override MemberTypes MemberType { get { return MemberTypes.Event; } } - #endregion + public virtual MethodInfo AddMethod => GetAddMethod(nonPublic: true); + public virtual MethodInfo RemoveMethod => GetRemoveMethod(nonPublic: true); + public virtual MethodInfo RaiseMethod => GetRaiseMethod(nonPublic: true); - #region Public Abstract\Virtual Members - public virtual MethodInfo[] GetOtherMethods(bool nonPublic) - { - throw new NotImplementedException(); - } + public MethodInfo GetAddMethod() => GetAddMethod(nonPublic: false); + public MethodInfo GetRemoveMethod() => GetRemoveMethod(nonPublic: false); + public MethodInfo GetRaiseMethod() => GetRaiseMethod(nonPublic: false); public abstract MethodInfo GetAddMethod(bool nonPublic); - public abstract MethodInfo GetRemoveMethod(bool nonPublic); - public abstract MethodInfo GetRaiseMethod(bool nonPublic); - public abstract EventAttributes Attributes { get; } - #endregion - - #region Public Members - public virtual MethodInfo AddMethod - { - get - { - return GetAddMethod(true); - } - } - - public virtual MethodInfo RemoveMethod + public virtual bool IsMulticast { get { - return GetRemoveMethod(true); + Type cl = EventHandlerType; + Type mc = typeof(MulticastDelegate); + return mc.IsAssignableFrom(cl); } } - public virtual MethodInfo RaiseMethod + public virtual Type EventHandlerType { get { - return GetRaiseMethod(true); + MethodInfo m = GetAddMethod(true); + ParameterInfo[] p = m.GetParametersNoCopy(); + Type del = typeof(Delegate); + for (int i = 0; i < p.Length; i++) + { + Type c = p[i].ParameterType; + if (c.IsSubclassOf(del)) + return c; + } + return null; } } - public MethodInfo[] GetOtherMethods() { return GetOtherMethods(false); } - - public MethodInfo GetAddMethod() { return GetAddMethod(false); } - - public MethodInfo GetRemoveMethod() { return GetRemoveMethod(false); } - - public MethodInfo GetRaiseMethod() { return GetRaiseMethod(false); } - - [DebuggerStepThroughAttribute] - [Diagnostics.DebuggerHidden] - public virtual void AddEventHandler(Object target, Delegate handler) + [DebuggerHidden] + [DebuggerStepThrough] + public virtual void AddEventHandler(object target, Delegate handler) { - MethodInfo addMethod = GetAddMethod(); + MethodInfo addMethod = GetAddMethod(nonPublic: false); if (addMethod == null) - throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NoPublicAddMethod")); + throw new InvalidOperationException(SR.InvalidOperation_NoPublicAddMethod); #if FEATURE_COMINTEROP - if (addMethod.ReturnType == typeof(System.Runtime.InteropServices.WindowsRuntime.EventRegistrationToken)) - throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NotSupportedOnWinRTEvent")); - - // Must be a normal non-WinRT event - Debug.Assert(addMethod.ReturnType == typeof(void)); -#endif // FEATURE_COMINTEROP + if (addMethod.ReturnType == typeof(EventRegistrationToken)) + throw new InvalidOperationException(SR.InvalidOperation_NotSupportedOnWinRTEvent); +#endif //#if FEATURE_COMINTEROP addMethod.Invoke(target, new object[] { handler }); } - [DebuggerStepThroughAttribute] - [Diagnostics.DebuggerHidden] - public virtual void RemoveEventHandler(Object target, Delegate handler) + [DebuggerHidden] + [DebuggerStepThrough] + public virtual void RemoveEventHandler(object target, Delegate handler) { - MethodInfo removeMethod = GetRemoveMethod(); + MethodInfo removeMethod = GetRemoveMethod(nonPublic: false); if (removeMethod == null) - throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NoPublicRemoveMethod")); + throw new InvalidOperationException(SR.InvalidOperation_NoPublicRemoveMethod); #if FEATURE_COMINTEROP ParameterInfo[] parameters = removeMethod.GetParametersNoCopy(); - Debug.Assert(parameters != null && parameters.Length == 1); - - if (parameters[0].ParameterType == typeof(System.Runtime.InteropServices.WindowsRuntime.EventRegistrationToken)) - throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NotSupportedOnWinRTEvent")); - - // Must be a normal non-WinRT event - Debug.Assert(parameters[0].ParameterType.BaseType == typeof(MulticastDelegate)); -#endif // FEATURE_COMINTEROP + if (parameters[0].ParameterType == typeof(EventRegistrationToken)) + throw new InvalidOperationException(SR.InvalidOperation_NotSupportedOnWinRTEvent); +#endif //#if FEATURE_COMINTEROP removeMethod.Invoke(target, new object[] { handler }); } - public virtual Type EventHandlerType - { - get - { - MethodInfo m = GetAddMethod(true); - - ParameterInfo[] p = m.GetParametersNoCopy(); + public override bool Equals(object obj) => base.Equals(obj); + public override int GetHashCode() => base.GetHashCode(); - Type del = typeof(Delegate); + public static bool operator ==(EventInfo left, EventInfo right) + { + if (object.ReferenceEquals(left, right)) + return true; - for (int i = 0; i < p.Length; i++) - { - Type c = p[i].ParameterType; + if ((object)left == null || (object)right == null) + return false; - if (c.IsSubclassOf(del)) - return c; - } - return null; - } - } - public bool IsSpecialName - { - get - { - return (Attributes & EventAttributes.SpecialName) != 0; - } + return left.Equals(right); } - public virtual bool IsMulticast - { - get - { - Type cl = EventHandlerType; - Type mc = typeof(MulticastDelegate); - return mc.IsAssignableFrom(cl); - } - } - #endregion + public static bool operator !=(EventInfo left, EventInfo right) => !(left == right); } } diff --git a/src/coreclr/src/mscorlib/src/System/Reflection/FieldInfo.cs b/src/coreclr/src/mscorlib/src/System/Reflection/FieldInfo.cs deleted file mode 100644 index c16df73..0000000 --- a/src/coreclr/src/mscorlib/src/System/Reflection/FieldInfo.cs +++ /dev/null @@ -1,141 +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.Diagnostics; -using System.Globalization; - -namespace System.Reflection -{ - [Serializable] - public abstract partial class FieldInfo : MemberInfo - { - #region Constructor - protected FieldInfo() { } - #endregion - - public static bool operator ==(FieldInfo left, FieldInfo right) - { - if (ReferenceEquals(left, right)) - return true; - - if ((object)left == null || (object)right == null || - left is RuntimeFieldInfo || right is RuntimeFieldInfo) - { - return false; - } - return left.Equals(right); - } - - public static bool operator !=(FieldInfo left, FieldInfo right) - { - return !(left == right); - } - - public override bool Equals(object obj) - { - return base.Equals(obj); - } - - public override int GetHashCode() - { - return base.GetHashCode(); - } - - #region MemberInfo Overrides - public override MemberTypes MemberType { get { return System.Reflection.MemberTypes.Field; } } - #endregion - - #region Public Abstract\Virtual Members - - public virtual Type[] GetRequiredCustomModifiers() - { - throw new NotImplementedException(); - } - - public virtual Type[] GetOptionalCustomModifiers() - { - throw new NotImplementedException(); - } - - [CLSCompliant(false)] - public virtual void SetValueDirect(TypedReference obj, Object value) - { - throw new NotSupportedException(Environment.GetResourceString("NotSupported_AbstractNonCLS")); - } - - [CLSCompliant(false)] - public virtual Object GetValueDirect(TypedReference obj) - { - throw new NotSupportedException(Environment.GetResourceString("NotSupported_AbstractNonCLS")); - } - - public abstract RuntimeFieldHandle FieldHandle { get; } - - public abstract Type FieldType { get; } - - public abstract Object GetValue(Object obj); - - public virtual Object GetRawConstantValue() { throw new NotSupportedException(Environment.GetResourceString("NotSupported_AbstractNonCLS")); } - - public abstract void SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, CultureInfo culture); - - public abstract FieldAttributes Attributes { get; } - #endregion - - #region Public Members - [DebuggerStepThroughAttribute] - [Diagnostics.DebuggerHidden] - public void SetValue(Object obj, Object value) - { - // Theoretically we should set up a LookForMyCaller stack mark here and pass that along. - // But to maintain backward compatibility we can't switch to calling an - // internal overload that takes a stack mark. - // Fortunately the stack walker skips all the reflection invocation frames including this one. - // So this method will never be returned by the stack walker as the caller. - // See SystemDomain::CallersMethodCallbackWithStackMark in AppDomain.cpp. - SetValue(obj, value, BindingFlags.Default, Type.DefaultBinder, null); - } - - public bool IsPublic { get { return (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Public; } } - - public bool IsPrivate { get { return (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Private; } } - - public bool IsFamily { get { return (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Family; } } - - public bool IsAssembly { get { return (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Assembly; } } - - public bool IsFamilyAndAssembly { get { return (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.FamANDAssem; } } - - public bool IsFamilyOrAssembly { get { return (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.FamORAssem; } } - - public bool IsStatic { get { return (Attributes & FieldAttributes.Static) != 0; } } - - public bool IsInitOnly { get { return (Attributes & FieldAttributes.InitOnly) != 0; } } - - public bool IsLiteral { get { return (Attributes & FieldAttributes.Literal) != 0; } } - - public bool IsNotSerialized { get { return (Attributes & FieldAttributes.NotSerialized) != 0; } } - - public bool IsSpecialName { get { return (Attributes & FieldAttributes.SpecialName) != 0; } } - - public bool IsPinvokeImpl { get { return (Attributes & FieldAttributes.PinvokeImpl) != 0; } } - - public virtual bool IsSecurityCritical - { - get { return FieldHandle.IsSecurityCritical(); } - } - - public virtual bool IsSecuritySafeCritical - { - get { return FieldHandle.IsSecuritySafeCritical(); } - } - - public virtual bool IsSecurityTransparent - { - get { return FieldHandle.IsSecurityTransparent(); } - } - - #endregion - } -} diff --git a/src/coreclr/src/mscorlib/src/System/Reflection/MethodInfo.cs b/src/coreclr/src/mscorlib/src/System/Reflection/MethodInfo.cs deleted file mode 100644 index 807be0f..0000000 --- a/src/coreclr/src/mscorlib/src/System/Reflection/MethodInfo.cs +++ /dev/null @@ -1,65 +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. - -namespace System.Reflection -{ - [Serializable] - public abstract class MethodInfo : MethodBase - { - #region Constructor - protected MethodInfo() { } - #endregion - - public static bool operator ==(MethodInfo left, MethodInfo right) - { - if (ReferenceEquals(left, right)) - return true; - - if ((object)left == null || (object)right == null || - left is RuntimeMethodInfo || right is RuntimeMethodInfo) - { - return false; - } - return left.Equals(right); - } - - public static bool operator !=(MethodInfo left, MethodInfo right) - { - return !(left == right); - } - - public override bool Equals(object obj) - { - return base.Equals(obj); - } - - public override int GetHashCode() - { - return base.GetHashCode(); - } - - #region MemberInfo Overrides - public override MemberTypes MemberType { get { return System.Reflection.MemberTypes.Method; } } - #endregion - - #region Public Abstract\Virtual Members - public virtual Type ReturnType { get { throw new NotImplementedException(); } } - - public virtual ParameterInfo ReturnParameter { get { throw new NotImplementedException(); } } - - public abstract ICustomAttributeProvider ReturnTypeCustomAttributes { get; } - - public abstract MethodInfo GetBaseDefinition(); - - public override Type[] GetGenericArguments() { throw new NotSupportedException(Environment.GetResourceString("NotSupported_SubclassOverride")); } - - public virtual MethodInfo GetGenericMethodDefinition() { throw new NotSupportedException(Environment.GetResourceString("NotSupported_SubclassOverride")); } - - public virtual MethodInfo MakeGenericMethod(params Type[] typeArguments) { throw new NotSupportedException(Environment.GetResourceString("NotSupported_SubclassOverride")); } - - public virtual Delegate CreateDelegate(Type delegateType) { throw new NotSupportedException(Environment.GetResourceString("NotSupported_SubclassOverride")); } - public virtual Delegate CreateDelegate(Type delegateType, Object target) { throw new NotSupportedException(Environment.GetResourceString("NotSupported_SubclassOverride")); } - #endregion - } -} diff --git a/src/coreclr/src/mscorlib/src/System/Reflection/PropertyInfo.cs b/src/coreclr/src/mscorlib/src/System/Reflection/PropertyInfo.cs deleted file mode 100644 index 68811f8..0000000 --- a/src/coreclr/src/mscorlib/src/System/Reflection/PropertyInfo.cs +++ /dev/null @@ -1,139 +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.Diagnostics; -using System.Globalization; - -namespace System.Reflection -{ - [Serializable] - public abstract class PropertyInfo : MemberInfo - { - #region Constructor - protected PropertyInfo() { } - #endregion - - public static bool operator ==(PropertyInfo left, PropertyInfo right) - { - if (ReferenceEquals(left, right)) - return true; - - if ((object)left == null || (object)right == null || - left is RuntimePropertyInfo || right is RuntimePropertyInfo) - { - return false; - } - return left.Equals(right); - } - - public static bool operator !=(PropertyInfo left, PropertyInfo right) - { - return !(left == right); - } - - public override bool Equals(object obj) - { - return base.Equals(obj); - } - - public override int GetHashCode() - { - return base.GetHashCode(); - } - - #region MemberInfo Overrides - public override MemberTypes MemberType { get { return System.Reflection.MemberTypes.Property; } } - #endregion - - #region Public Abstract\Virtual Members - public virtual object GetConstantValue() - { - throw new NotImplementedException(); - } - - public virtual object GetRawConstantValue() - { - throw new NotImplementedException(); - } - - public abstract Type PropertyType { get; } - - public abstract void SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture); - - public abstract MethodInfo[] GetAccessors(bool nonPublic); - - public abstract MethodInfo GetGetMethod(bool nonPublic); - - public abstract MethodInfo GetSetMethod(bool nonPublic); - - public abstract ParameterInfo[] GetIndexParameters(); - - public abstract PropertyAttributes Attributes { get; } - - public abstract bool CanRead { get; } - - public abstract bool CanWrite { get; } - - [DebuggerStepThroughAttribute] - [Diagnostics.DebuggerHidden] - public Object GetValue(Object obj) - { - return GetValue(obj, null); - } - - [DebuggerStepThroughAttribute] - [Diagnostics.DebuggerHidden] - public virtual Object GetValue(Object obj, Object[] index) - { - return GetValue(obj, BindingFlags.Default, null, index, null); - } - - public abstract Object GetValue(Object obj, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture); - - [DebuggerStepThroughAttribute] - [Diagnostics.DebuggerHidden] - public void SetValue(Object obj, Object value) - { - SetValue(obj, value, null); - } - - [DebuggerStepThroughAttribute] - [Diagnostics.DebuggerHidden] - public virtual void SetValue(Object obj, Object value, Object[] index) - { - SetValue(obj, value, BindingFlags.Default, null, index, null); - } - #endregion - - #region Public Members - public virtual Type[] GetRequiredCustomModifiers() { return EmptyArray.Value; } - - public virtual Type[] GetOptionalCustomModifiers() { return EmptyArray.Value; } - - public MethodInfo[] GetAccessors() { return GetAccessors(false); } - - public virtual MethodInfo GetMethod - { - get - { - return GetGetMethod(true); - } - } - - public virtual MethodInfo SetMethod - { - get - { - return GetSetMethod(true); - } - } - - public MethodInfo GetGetMethod() { return GetGetMethod(false); } - - public MethodInfo GetSetMethod() { return GetSetMethod(false); } - - public bool IsSpecialName { get { return (Attributes & PropertyAttributes.SpecialName) != 0; } } - #endregion - } -} diff --git a/src/coreclr/src/mscorlib/src/System/Reflection/TypeInfo.cs b/src/coreclr/src/mscorlib/src/System/Reflection/TypeInfo.cs deleted file mode 100644 index aaf5c73..0000000 --- a/src/coreclr/src/mscorlib/src/System/Reflection/TypeInfo.cs +++ /dev/null @@ -1,201 +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. - -/*============================================================================= -** -** -** -** -** -** Purpose: Notion of a type definition -** -** -=============================================================================*/ - -using System; -using System.Runtime.CompilerServices; -using System.Collections.Generic; -using System.Diagnostics.Contracts; - -namespace System.Reflection -{ - //all today's runtime Type derivations derive now from TypeInfo - //we make TypeInfo implement IRCT - simplifies work - [Serializable] - public abstract class TypeInfo : Type, IReflectableType - { - [FriendAccessAllowed] - internal TypeInfo() { } - - TypeInfo IReflectableType.GetTypeInfo() - { - return this; - } - public virtual Type AsType() - { - return (Type)this; - } - - public virtual Type[] GenericTypeParameters - { - get - { - if (IsGenericTypeDefinition) - { - return GetGenericArguments(); - } - else - { - return Type.EmptyTypes; - } - } - } - //a re-implementation of ISAF from Type, skipping the use of UnderlyingType - [Pure] - public virtual bool IsAssignableFrom(TypeInfo typeInfo) - { - if (typeInfo == null) - return false; - - if (this == typeInfo) - return true; - - // If c is a subclass of this class, then c can be cast to this type. - if (typeInfo.IsSubclassOf(this)) - return true; - - if (this.IsInterface) - { - return typeInfo.ImplementInterface(this); - } - else if (IsGenericParameter) - { - Type[] constraints = GetGenericParameterConstraints(); - for (int i = 0; i < constraints.Length; i++) - if (!constraints[i].IsAssignableFrom(typeInfo)) - return false; - - return true; - } - - return false; - } - #region moved over from Type - // Fields - - public virtual EventInfo GetDeclaredEvent(String name) - { - return GetEvent(name, Type.DeclaredOnlyLookup); - } - public virtual FieldInfo GetDeclaredField(String name) - { - return GetField(name, Type.DeclaredOnlyLookup); - } - public virtual MethodInfo GetDeclaredMethod(String name) - { - return GetMethod(name, Type.DeclaredOnlyLookup); - } - - public virtual IEnumerable GetDeclaredMethods(String name) - { - foreach (MethodInfo method in GetMethods(Type.DeclaredOnlyLookup)) - { - if (method.Name == name) - yield return method; - } - } - public virtual System.Reflection.TypeInfo GetDeclaredNestedType(String name) - { - var nt = GetNestedType(name, Type.DeclaredOnlyLookup); - if (nt == null) - { - return null; //the extension method GetTypeInfo throws for null - } - else - { - return nt.GetTypeInfo(); - } - } - public virtual PropertyInfo GetDeclaredProperty(String name) - { - return GetProperty(name, Type.DeclaredOnlyLookup); - } - - - - - - // Properties - - public virtual IEnumerable DeclaredConstructors - { - get - { - return GetConstructors(Type.DeclaredOnlyLookup); - } - } - - public virtual IEnumerable DeclaredEvents - { - get - { - return GetEvents(Type.DeclaredOnlyLookup); - } - } - - public virtual IEnumerable DeclaredFields - { - get - { - return GetFields(Type.DeclaredOnlyLookup); - } - } - - public virtual IEnumerable DeclaredMembers - { - get - { - return GetMembers(Type.DeclaredOnlyLookup); - } - } - - public virtual IEnumerable DeclaredMethods - { - get - { - return GetMethods(Type.DeclaredOnlyLookup); - } - } - public virtual IEnumerable DeclaredNestedTypes - { - get - { - foreach (var t in GetNestedTypes(Type.DeclaredOnlyLookup)) - { - yield return t.GetTypeInfo(); - } - } - } - - public virtual IEnumerable DeclaredProperties - { - get - { - return GetProperties(Type.DeclaredOnlyLookup); - } - } - - - public virtual IEnumerable ImplementedInterfaces - { - get - { - return GetInterfaces(); - } - } - - #endregion - } -} - diff --git a/src/coreclr/src/mscorlib/src/System/Type.cs b/src/coreclr/src/mscorlib/src/System/Type.cs index cb6c9ab..78e587d 100644 --- a/src/coreclr/src/mscorlib/src/System/Type.cs +++ b/src/coreclr/src/mscorlib/src/System/Type.cs @@ -1862,6 +1862,5 @@ namespace System // private convenience data private const BindingFlags DefaultLookup = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public; - internal const BindingFlags DeclaredOnlyLookup = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly; } }