From 05aa51bba3ed2b7d6d6ab75f48a98a62ea962925 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Sim=C3=B5es?= Date: Fri, 28 Sep 2018 09:58:39 +0100 Subject: [PATCH] Add GetCustomAttributes method to MemberInfo and derived classes (#27) --- source/System/Reflection/ConstructorInfo.cs | 12 +++++++++++- source/System/Reflection/FieldInfo.cs | 13 ++++++++++++- source/System/Reflection/MemberInfo.cs | 7 +++++++ source/System/Reflection/RuntimeMethodInfo.cs | 3 +++ source/System/RuntimeType.cs | 2 ++ 5 files changed, 35 insertions(+), 2 deletions(-) diff --git a/source/System/Reflection/ConstructorInfo.cs b/source/System/Reflection/ConstructorInfo.cs index 36a21b5e..ecc28ffd 100644 --- a/source/System/Reflection/ConstructorInfo.cs +++ b/source/System/Reflection/ConstructorInfo.cs @@ -6,8 +6,8 @@ namespace System.Reflection { - using System; using Runtime.CompilerServices; + using System; /// /// Discovers the attributes of a class constructor and provides access to constructor metadata. @@ -38,5 +38,15 @@ public override MemberTypes MemberType [Diagnostics.DebuggerHidden] [MethodImpl(MethodImplOptions.InternalCall)] public extern Object Invoke(Object[] parameters); + + /// + /// When overridden in a derived class, returns an array of all custom attributes applied to this member. + /// + /// true to search this member's inheritance chain to find the attributes; otherwise, false. This parameter is ignored for properties and events. + /// An array that contains all the custom attributes applied to this member, or an array with zero elements if no attributes are defined. + /// This method is not implemented in nanoFramework. + /// + [MethodImpl(MethodImplOptions.InternalCall)] + public extern override object[] GetCustomAttributes(bool inherit); } } diff --git a/source/System/Reflection/FieldInfo.cs b/source/System/Reflection/FieldInfo.cs index b42cae4a..1668b6cb 100644 --- a/source/System/Reflection/FieldInfo.cs +++ b/source/System/Reflection/FieldInfo.cs @@ -6,8 +6,8 @@ namespace System.Reflection { - using System; using Runtime.CompilerServices; + using System; /// /// Discovers the attributes of a field and provides access to field metadata. @@ -59,6 +59,17 @@ public abstract Type FieldType [Diagnostics.DebuggerHidden] [MethodImpl(MethodImplOptions.InternalCall)] public virtual extern void SetValue(Object obj, Object value); + + /// + /// When overridden in a derived class, returns an array of all custom attributes applied to this member. + /// + /// true to search this member's inheritance chain to find the attributes; otherwise, false. This parameter is ignored for properties and events. + /// An array that contains all the custom attributes applied to this member, or an array with zero elements if no attributes are defined. + /// This method is not implemented in nanoFramework. + /// This method is not implemente. + /// + [MethodImpl(MethodImplOptions.InternalCall)] + public extern override object[] GetCustomAttributes(bool inherit); } } diff --git a/source/System/Reflection/MemberInfo.cs b/source/System/Reflection/MemberInfo.cs index 17f50cf8..9532642a 100644 --- a/source/System/Reflection/MemberInfo.cs +++ b/source/System/Reflection/MemberInfo.cs @@ -46,5 +46,12 @@ public abstract Type DeclaringType { get; } + + /// + /// When overridden in a derived class, returns an array of all custom attributes applied to this member. + /// + /// true to search this member's inheritance chain to find the attributes; otherwise, false. This parameter is ignored for properties and events. + /// An array that contains all the custom attributes applied to this member, or an array with zero elements if no attributes are defined. + public abstract object[] GetCustomAttributes(bool inherit); } } diff --git a/source/System/Reflection/RuntimeMethodInfo.cs b/source/System/Reflection/RuntimeMethodInfo.cs index bf006f8b..33e16f22 100644 --- a/source/System/Reflection/RuntimeMethodInfo.cs +++ b/source/System/Reflection/RuntimeMethodInfo.cs @@ -17,5 +17,8 @@ public override extern Type ReturnType [MethodImpl(MethodImplOptions.InternalCall)] get; } + + [MethodImpl(MethodImplOptions.InternalCall)] + public override extern object[] GetCustomAttributes(bool inherit); } } diff --git a/source/System/RuntimeType.cs b/source/System/RuntimeType.cs index 52f58859..89f44092 100644 --- a/source/System/RuntimeType.cs +++ b/source/System/RuntimeType.cs @@ -80,5 +80,7 @@ public override extern Type BaseType [MethodImpl(MethodImplOptions.InternalCall)] public override extern Type GetElementType(); + [MethodImpl(MethodImplOptions.InternalCall)] + public override extern object[] GetCustomAttributes(bool inherit); } }