<Compile Include="$(BclSourcesRoot)\System\Reflection\Binder.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\BindingFlags.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\CallingConventions.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Reflection\ConstructorInfo.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\ConstructorInfo.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\CustomAttribute.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\DefaultMemberAttribute.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\EventAttributes.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\EventInfo.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\FieldAttributes.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Reflection\FieldInfo.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\FieldInfo.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\GenericParameterAttributes.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\ICustomAttributeProvider.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\MethodAttributes.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\MethodBase.CoreCLR.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\MethodImplAttributes.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Reflection\MethodInfo.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\Missing.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\Module.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\ModuleResolveEventHandler.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\Pointer.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\PortableExecutableKinds.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\PropertyAttributes.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Reflection\PropertyInfo.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\ReflectionContext.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\ReflectionTypeLoadException.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\ResourceAttributes.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\TargetParameterCountException.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\TypeAttributes.cs" />
<Compile Include="$(BclSourcesRoot)\System\Reflection\TypeFilter.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Reflection\TypeInfo.cs" />
</ItemGroup>
<ItemGroup>
<Compile Include="$(BclSourcesRoot)\System\Reflection\Emit\AssemblyBuilder.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\ParamArrayAttribute.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\PlatformNotSupportedException.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\RankException.cs"/>
+ <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\ConstructorInfo.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\FieldInfo.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\MemberInfo.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\MethodInfo.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\MethodBase.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\ObfuscateAssemblyAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\ObfuscationAttribute.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\PropertyInfo.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\TypeDelegator.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)System\Reflection\TypeInfo.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\ExtensionAttribute.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\FormattableStringFactory.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\IsVolatile.cs"/>
--- /dev/null
+// 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";
+ }
+}
--- /dev/null
+// 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; }
+ }
+}
--- /dev/null
+// 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);
+ }
+}
--- /dev/null
+// 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<Type>();
+ public virtual Type[] GetRequiredCustomModifiers() => Array.Empty<Type>();
+
+ [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);
+ }
+}
--- /dev/null
+// 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<MethodInfo> GetDeclaredMethods(string name)
+ {
+ foreach (MethodInfo method in GetMethods(TypeInfo.DeclaredOnlyLookup))
+ {
+ if (method.Name == name)
+ yield return method;
+ }
+ }
+
+ public virtual IEnumerable<ConstructorInfo> DeclaredConstructors => GetConstructors(TypeInfo.DeclaredOnlyLookup);
+ public virtual IEnumerable<EventInfo> DeclaredEvents => GetEvents(TypeInfo.DeclaredOnlyLookup);
+ public virtual IEnumerable<FieldInfo> DeclaredFields => GetFields(TypeInfo.DeclaredOnlyLookup);
+ public virtual IEnumerable<MemberInfo> DeclaredMembers => GetMembers(TypeInfo.DeclaredOnlyLookup);
+ public virtual IEnumerable<MethodInfo> DeclaredMethods => GetMethods(TypeInfo.DeclaredOnlyLookup);
+ public virtual IEnumerable<System.Reflection.TypeInfo> DeclaredNestedTypes
+ {
+ get
+ {
+ foreach (Type t in GetNestedTypes(TypeInfo.DeclaredOnlyLookup))
+ {
+ yield return t.GetTypeInfo();
+ }
+ }
+ }
+ public virtual IEnumerable<PropertyInfo> DeclaredProperties => GetProperties(TypeInfo.DeclaredOnlyLookup);
+
+ public virtual IEnumerable<Type> 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;
+ }
+}
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");
}
+++ /dev/null
-// 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
- }
-}
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);
}
}
+++ /dev/null
-// 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
- }
-}
+++ /dev/null
-// 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
- }
-}
+++ /dev/null
-// 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<Type>.Value; }
-
- public virtual Type[] GetOptionalCustomModifiers() { return EmptyArray<Type>.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
- }
-}
+++ /dev/null
-// 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<MethodInfo> 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<ConstructorInfo> DeclaredConstructors
- {
- get
- {
- return GetConstructors(Type.DeclaredOnlyLookup);
- }
- }
-
- public virtual IEnumerable<EventInfo> DeclaredEvents
- {
- get
- {
- return GetEvents(Type.DeclaredOnlyLookup);
- }
- }
-
- public virtual IEnumerable<FieldInfo> DeclaredFields
- {
- get
- {
- return GetFields(Type.DeclaredOnlyLookup);
- }
- }
-
- public virtual IEnumerable<MemberInfo> DeclaredMembers
- {
- get
- {
- return GetMembers(Type.DeclaredOnlyLookup);
- }
- }
-
- public virtual IEnumerable<MethodInfo> DeclaredMethods
- {
- get
- {
- return GetMethods(Type.DeclaredOnlyLookup);
- }
- }
- public virtual IEnumerable<System.Reflection.TypeInfo> DeclaredNestedTypes
- {
- get
- {
- foreach (var t in GetNestedTypes(Type.DeclaredOnlyLookup))
- {
- yield return t.GetTypeInfo();
- }
- }
- }
-
- public virtual IEnumerable<PropertyInfo> DeclaredProperties
- {
- get
- {
- return GetProperties(Type.DeclaredOnlyLookup);
- }
- }
-
-
- public virtual IEnumerable<Type> ImplementedInterfaces
- {
- get
- {
- return GetInterfaces();
- }
- }
-
- #endregion
- }
-}
-
// 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;
}
}