[System.Private.CoreLib] Align on CA naming for easier sharing
authorMarek Safar <marek.safar@gmail.com>
Mon, 17 Jun 2019 18:19:40 +0000 (20:19 +0200)
committerMarek Safar <marek.safar@gmail.com>
Tue, 18 Jun 2019 08:10:16 +0000 (10:10 +0200)
Commit migrated from https://github.com/mono/mono/commit/879c8501c946571d4c9e0bdfa70662d1aa2c249a

18 files changed:
src/mono/mono/metadata/icall-def-netcore.h
src/mono/netcore/System.Private.CoreLib/System.Private.CoreLib.csproj
src/mono/netcore/System.Private.CoreLib/src/System.Reflection.Emit/AssemblyBuilder.cs
src/mono/netcore/System.Private.CoreLib/src/System.Reflection.Emit/FieldBuilder.cs
src/mono/netcore/System.Private.CoreLib/src/System.Reflection.Emit/MethodBuilder.cs
src/mono/netcore/System.Private.CoreLib/src/System.Reflection.Emit/MonoArrayMethod.cs
src/mono/netcore/System.Private.CoreLib/src/System.Reflection.Emit/TypeBuilder.cs
src/mono/netcore/System.Private.CoreLib/src/System.Reflection/CustomAttribute.cs [new file with mode: 0644]
src/mono/netcore/System.Private.CoreLib/src/System.Reflection/CustomAttributeData.cs
src/mono/netcore/System.Private.CoreLib/src/System.Reflection/RuntimeAssembly.cs
src/mono/netcore/System.Private.CoreLib/src/System.Reflection/RuntimeEventInfo.cs
src/mono/netcore/System.Private.CoreLib/src/System.Reflection/RuntimeFieldInfo.cs
src/mono/netcore/System.Private.CoreLib/src/System.Reflection/RuntimeMethodInfo.cs
src/mono/netcore/System.Private.CoreLib/src/System.Reflection/RuntimeModule.cs
src/mono/netcore/System.Private.CoreLib/src/System.Reflection/RuntimeParameterInfo.cs
src/mono/netcore/System.Private.CoreLib/src/System.Reflection/RuntimePropertyInfo.cs
src/mono/netcore/System.Private.CoreLib/src/System/Attribute.cs
src/mono/netcore/System.Private.CoreLib/src/System/RuntimeType.cs

index d68f78d..7d548eb 100644 (file)
@@ -168,11 +168,6 @@ NOHANDLES(ICALL(MATHF_19, "Sqrt", ves_icall_System_MathF_Sqrt))
 NOHANDLES(ICALL(MATHF_20, "Tan", ves_icall_System_MathF_Tan))
 NOHANDLES(ICALL(MATHF_21, "Tanh", ves_icall_System_MathF_Tanh))
 
-ICALL_TYPE(MCATTR, "System.MonoCustomAttrs", MCATTR_1)
-HANDLES(MCATTR_1, "GetCustomAttributesDataInternal", ves_icall_MonoCustomAttrs_GetCustomAttributesDataInternal, MonoArray, 1, (MonoObject))
-HANDLES(MCATTR_2, "GetCustomAttributesInternal", ves_icall_MonoCustomAttrs_GetCustomAttributesInternal, MonoArray, 3, (MonoObject, MonoReflectionType, MonoBoolean))
-HANDLES(MCATTR_3, "IsDefinedInternal", ves_icall_MonoCustomAttrs_IsDefinedInternal, MonoBoolean, 2, (MonoObject, MonoReflectionType))
-
 ICALL_TYPE(OBJ, "System.Object", OBJ_1)
 HANDLES(OBJ_1, "GetType", ves_icall_System_Object_GetType, MonoReflectionType, 1, (MonoObject))
 ICALL(OBJ_2, "InternalGetHashCode", mono_object_hash_internal)
@@ -191,6 +186,11 @@ NOHANDLES(ICALL(ASSEMN_0, "GetNativeName", ves_icall_System_Reflection_AssemblyN
 NOHANDLES(ICALL(ASSEMN_3, "ParseAssemblyName", ves_icall_System_Reflection_AssemblyName_ParseAssemblyName))
 NOHANDLES(ICALL(ASSEMN_2, "get_public_token", mono_digest_get_public_token))
 
+ICALL_TYPE(MCATTR, "System.Reflection.CustomAttribute", MCATTR_1)
+HANDLES(MCATTR_1, "GetCustomAttributesDataInternal", ves_icall_MonoCustomAttrs_GetCustomAttributesDataInternal, MonoArray, 1, (MonoObject))
+HANDLES(MCATTR_2, "GetCustomAttributesInternal", ves_icall_MonoCustomAttrs_GetCustomAttributesInternal, MonoArray, 3, (MonoObject, MonoReflectionType, MonoBoolean))
+HANDLES(MCATTR_3, "IsDefinedInternal", ves_icall_MonoCustomAttrs_IsDefinedInternal, MonoBoolean, 2, (MonoObject, MonoReflectionType))
+
 ICALL_TYPE(CATTR_DATA, "System.Reflection.CustomAttributeData", CATTR_DATA_1)
 ICALL(CATTR_DATA_1, "ResolveArgumentsInternal", ves_icall_System_Reflection_CustomAttributeData_ResolveArgumentsInternal)
 
index 1489629..ab0e747 100644 (file)
       <Compile Include="src\System.IO\FileLoadException.cs" />
       <Compile Include="src\System.Reflection\Assembly.cs" />
       <Compile Include="src\System.Reflection\AssemblyName.cs" />
+      <Compile Include="src\System.Reflection\CustomAttribute.cs" />
       <Compile Include="src\System.Reflection\CustomAttributeData.cs" />
       <Compile Include="src\System.Reflection\CustomAttributeTypedArgument.cs" />
       <Compile Include="src\System.Reflection\FieldInfo.cs" />
       <Compile Include="..\..\mcs\class\corlib\Mono\SafeStringMarshal.cs" />
       <Compile Include="..\..\mcs\class\corlib\Mono\SafeGPtrArrayHandle.cs" />
 
-      <Compile Include="..\..\mcs\class\corlib\System\MonoCustomAttrs.cs" />
       <Compile Include="..\..\mcs\class\corlib\System\TypeSpec.cs" />
 
       <Compile Include="..\..\mcs\class\corlib\System.Runtime.CompilerServices\PreserveDependencyAttribute.cs" />
index 280da14..a357382 100644 (file)
@@ -563,17 +563,17 @@ namespace System.Reflection.Emit
 
                public override bool IsDefined (Type attributeType, bool inherit)
                {
-                       return MonoCustomAttrs.IsDefined (this, attributeType, inherit);
+                       return CustomAttribute.IsDefined (this, attributeType, inherit);
                }
 
                public override object[] GetCustomAttributes (bool inherit)
                {
-                       return MonoCustomAttrs.GetCustomAttributes (this, inherit);
+                       return CustomAttribute.GetCustomAttributes (this, inherit);
                }
 
                public override object[] GetCustomAttributes (Type attributeType, bool inherit)
                {
-                       return MonoCustomAttrs.GetCustomAttributes (this, attributeType, inherit);
+                       return CustomAttribute.GetCustomAttributes (this, attributeType, inherit);
                }
 
                public override IList<CustomAttributeData> GetCustomAttributesData ()
index 4f5039f..a16592e 100644 (file)
@@ -108,14 +108,14 @@ namespace System.Reflection.Emit {
                         * dynamically created ctors.
                         */
                        if (typeb.is_created)
-                               return MonoCustomAttrs.GetCustomAttributes (this, inherit);
+                               return CustomAttribute.GetCustomAttributes (this, inherit);
                        else
                                throw CreateNotSupportedException ();
                }
 
                public override object[] GetCustomAttributes(Type attributeType, bool inherit) {
                        if (typeb.is_created)
-                               return MonoCustomAttrs.GetCustomAttributes (this, attributeType, inherit);
+                               return CustomAttribute.GetCustomAttributes (this, attributeType, inherit);
                        else
                                throw CreateNotSupportedException ();
                }
index 76082cd..8d2caaf 100644 (file)
@@ -279,7 +279,7 @@ namespace System.Reflection.Emit
                         * dynamically created ctors.
                         */
                        if (type.is_created)
-                               return MonoCustomAttrs.GetCustomAttributes (this, inherit);
+                               return CustomAttribute.GetCustomAttributes (this, inherit);
                        else
                                throw NotSupported ();
                }
@@ -287,7 +287,7 @@ namespace System.Reflection.Emit
                public override object[] GetCustomAttributes (Type attributeType, bool inherit)
                {
                        if (type.is_created)
-                               return MonoCustomAttrs.GetCustomAttributes (this, attributeType, inherit);
+                               return CustomAttribute.GetCustomAttributes (this, attributeType, inherit);
                        else
                                throw NotSupported ();
                }
index d9a1657..eebe6ef 100644 (file)
@@ -130,14 +130,14 @@ namespace System.Reflection {
                }
                
                public override bool IsDefined (Type attributeType, bool inherit) {
-                       return MonoCustomAttrs.IsDefined (this, attributeType, inherit);
+                       return CustomAttribute.IsDefined (this, attributeType, inherit);
                }
 
                public override object[] GetCustomAttributes( bool inherit) {
-                       return MonoCustomAttrs.GetCustomAttributes (this, inherit);
+                       return CustomAttribute.GetCustomAttributes (this, inherit);
                }
                public override object[] GetCustomAttributes( Type attributeType, bool inherit) {
-                       return MonoCustomAttrs.GetCustomAttributes (this, attributeType, inherit);
+                       return CustomAttribute.GetCustomAttributes (this, attributeType, inherit);
                }
 
                public override string ToString () {
index 852af89..efa7cda 100644 (file)
@@ -325,7 +325,7 @@ namespace System.Reflection.Emit
                         * MS throws NotSupported here, but we can't because some corlib
                         * classes make calls to IsDefined.
                         */
-                       return MonoCustomAttrs.IsDefined (this, attributeType, inherit);
+                       return CustomAttribute.IsDefined (this, attributeType, inherit);
                }
                
                public override object[] GetCustomAttributes(bool inherit)
diff --git a/src/mono/netcore/System.Private.CoreLib/src/System.Reflection/CustomAttribute.cs b/src/mono/netcore/System.Private.CoreLib/src/System.Reflection/CustomAttribute.cs
new file mode 100644 (file)
index 0000000..2b5c73a
--- /dev/null
@@ -0,0 +1,722 @@
+//
+// (c) 2002,2003 Ximian, Inc. (http://www.ximian.com)
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2013 Xamarin, Inc (http://www.xamarin.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Reflection;
+using System.Collections;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+#if !FULL_AOT_RUNTIME
+using System.Reflection.Emit;
+#endif
+
+using System.Collections.Generic;
+
+namespace System.Reflection
+{
+       static class CustomAttribute
+       {
+               static Assembly corlib;
+               [ThreadStatic]
+               static Dictionary<Type, AttributeUsageAttribute> usage_cache;
+
+               /* Treat as user types all corlib types extending System.Type that are not RuntimeType and TypeBuilder */
+               static bool IsUserCattrProvider (object obj)
+               {
+                       Type type = obj as Type;
+#if !FULL_AOT_RUNTIME
+                       if ((type is RuntimeType) || (RuntimeFeature.IsDynamicCodeSupported && type is TypeBuilder))
+#else
+                       if (type is RuntimeType)
+#endif
+                               return false;
+                       if ((obj is Type))
+                               return true;
+                       if (corlib == null)
+                                corlib = typeof (int).Assembly;
+                       return obj.GetType ().Assembly != corlib;
+               }
+       
+               [MethodImplAttribute (MethodImplOptions.InternalCall)]
+               internal static extern object[] GetCustomAttributesInternal (ICustomAttributeProvider obj, Type attributeType, bool pseudoAttrs);
+
+               internal static object[] GetPseudoCustomAttributes (ICustomAttributeProvider obj, Type attributeType) {
+                       object[] pseudoAttrs = null;
+                       /* FIXME: Add other types */
+                       if (obj is RuntimeMethodInfo monoMethod)
+                               pseudoAttrs = monoMethod.GetPseudoCustomAttributes ();
+                       else if (obj is RuntimeFieldInfo fieldInfo)
+                               pseudoAttrs = fieldInfo.GetPseudoCustomAttributes ();
+                       else if (obj is RuntimeParameterInfo monoParamInfo)
+                               pseudoAttrs = monoParamInfo.GetPseudoCustomAttributes ();
+                       else if (obj is Type t)
+                               pseudoAttrs = GetPseudoCustomAttributes (t);
+
+                       if ((attributeType != null) && (pseudoAttrs != null)) {
+                               for (int i = 0; i < pseudoAttrs.Length; ++i)
+                                       if (attributeType.IsAssignableFrom (pseudoAttrs [i].GetType ()))
+                                               if (pseudoAttrs.Length == 1)
+                                                       return pseudoAttrs;
+                                               else
+                                                       return new object [] { pseudoAttrs [i] };
+                               return Array.Empty<object> ();
+                       }
+
+                       return pseudoAttrs;
+               }
+
+               static object[] GetPseudoCustomAttributes (Type type)
+               {
+                       int count = 0;
+                       var Attributes = type.Attributes;
+
+                       /* IsSerializable returns true for delegates/enums as well */
+                       if ((Attributes & TypeAttributes.Serializable) != 0)
+                               count ++;
+                       if ((Attributes & TypeAttributes.Import) != 0)
+                               count ++;
+
+                       if (count == 0)
+                               return null;
+                       object[] attrs = new object [count];
+                       count = 0;
+
+                       if ((Attributes & TypeAttributes.Serializable) != 0)
+                               attrs [count ++] = new SerializableAttribute ();
+                       if ((Attributes & TypeAttributes.Import) != 0)
+                               attrs [count ++] = new ComImportAttribute ();
+
+                       return attrs;
+               }
+
+               internal static object[] GetCustomAttributesBase (ICustomAttributeProvider obj, Type attributeType, bool inheritedOnly)
+               {
+                       object[] attrs;
+
+                       if (IsUserCattrProvider (obj))
+                               attrs = obj.GetCustomAttributes (attributeType, true);
+                       else
+                               attrs = GetCustomAttributesInternal (obj, attributeType, false);
+
+                       //
+                       // All pseudo custom attributes are Inherited = false hence we can avoid
+                       // building attributes array which would be discarded by inherited checks
+                       //
+                       if (!inheritedOnly) {
+                               object[] pseudoAttrs = GetPseudoCustomAttributes (obj, attributeType);
+                               if (pseudoAttrs != null) {
+                                       object[] res = new object [attrs.Length + pseudoAttrs.Length];
+                                       System.Array.Copy (attrs, res, attrs.Length);
+                                       System.Array.Copy (pseudoAttrs, 0, res, attrs.Length, pseudoAttrs.Length);
+                                       return res;
+                               }
+                       }
+
+                       return attrs;
+               }
+
+               internal static object[] GetCustomAttributes (ICustomAttributeProvider obj, Type attributeType, bool inherit)
+               {
+                       if (obj == null)
+                               throw new ArgumentNullException (nameof (obj));
+                       if (attributeType == null)
+                               throw new ArgumentNullException (nameof (attributeType));       
+
+                       if (attributeType == typeof (CustomAttribute))
+                               attributeType = null;
+
+                       if (attributeType == typeof (Attribute))
+                               attributeType = null;
+
+                       object[] r;
+                       object[] res = GetCustomAttributesBase (obj, attributeType, false);
+                       // shortcut
+                       if (!inherit && res.Length == 1) {
+                               if (res [0] == null)
+                                       throw new CustomAttributeFormatException ("Invalid custom attribute format");
+
+                               if (attributeType != null) {
+                                       if (attributeType.IsAssignableFrom (res[0].GetType ())) {
+                                               r = (object[]) Array.CreateInstance (attributeType, 1);
+                                               r[0] = res[0];
+                                       } else {
+                                               r = (object[]) Array.CreateInstance (attributeType, 0);
+                                       }
+                               } else {
+                                       r = (object[]) Array.CreateInstance (res[0].GetType (), 1);
+                                       r[0] = res[0];
+                               }
+                               return r;
+                       }
+
+                       if (inherit && GetBase (obj) == null)
+                               inherit = false;
+
+                       // if AttributeType is sealed, and Inherited is set to false, then 
+                       // there's no use in scanning base types 
+                       if ((attributeType != null && attributeType.IsSealed) && inherit) {
+                               AttributeUsageAttribute usageAttribute = RetrieveAttributeUsage (
+                                       attributeType);
+                               if (!usageAttribute.Inherited)
+                                       inherit = false;
+                       }
+
+                       var initialSize = Math.Max (res.Length, 16);
+                       List<Object> a = null;
+                       ICustomAttributeProvider btype = obj;
+                       object[] array;
+
+                       /* Non-inherit case */
+                       if (!inherit) {
+                               if (attributeType == null) {
+                                       foreach (object attr in res) {
+                                               if (attr == null)
+                                                       throw new CustomAttributeFormatException ("Invalid custom attribute format");
+                                       }
+                                       var result = new Attribute [res.Length];
+                                       res.CopyTo (result, 0);
+                                       return result;
+                               }
+
+                               a = new List<object> (initialSize);
+                               foreach (object attr in res) {
+                                       if (attr == null)
+                                               throw new CustomAttributeFormatException ("Invalid custom attribute format");
+
+                                       Type attrType = attr.GetType ();
+                                       if (attributeType != null && !attributeType.IsAssignableFrom (attrType))
+                                               continue;
+                                       a.Add (attr);
+                               }
+
+                               if (attributeType == null || attributeType.IsValueType)
+                                       array = new Attribute [a.Count];
+                               else
+                                       array = Array.CreateInstance (attributeType, a.Count) as object[];
+                               a.CopyTo (array, 0);
+                               return array;
+                       }
+
+                       /* Inherit case */
+                       var attributeInfos = new Dictionary<Type, AttributeInfo> (initialSize);
+                       int inheritanceLevel = 0;
+                       a = new List<object> (initialSize);
+
+                       do {
+                               foreach (object attr in res) {
+                                       AttributeUsageAttribute usage;
+                                       if (attr == null)
+                                               throw new CustomAttributeFormatException ("Invalid custom attribute format");
+
+                                       Type attrType = attr.GetType ();
+                                       if (attributeType != null) {
+                                               if (!attributeType.IsAssignableFrom (attrType))
+                                                       continue;
+                                       }
+
+                                       AttributeInfo firstAttribute;
+                                       if (attributeInfos.TryGetValue (attrType, out firstAttribute))
+                                               usage = firstAttribute.Usage;
+                                       else
+                                               usage = RetrieveAttributeUsage (attrType);
+
+                                       // only add attribute to the list of attributes if 
+                                       // - we are on the first inheritance level, or the attribute can be inherited anyway
+                                       // and (
+                                       // - multiple attributes of the type are allowed
+                                       // or (
+                                       // - this is the first attribute we've discovered
+                                       // or
+                                       // - the attribute is on same inheritance level than the first 
+                                       //   attribute that was discovered for this attribute type ))
+                                       if ((inheritanceLevel == 0 || usage.Inherited) && (usage.AllowMultiple || 
+                                               (firstAttribute == null || (firstAttribute != null 
+                                                       && firstAttribute.InheritanceLevel == inheritanceLevel))))
+                                               a.Add (attr);
+
+                                       if (firstAttribute == null)
+                                               attributeInfos.Add (attrType, new AttributeInfo (usage, inheritanceLevel));
+                               }
+
+                               if ((btype = GetBase (btype)) != null) {
+                                       inheritanceLevel++;
+                                       res = GetCustomAttributesBase (btype, attributeType, true);
+                               }
+                       } while (inherit && btype != null);
+
+                       if (attributeType == null || attributeType.IsValueType)
+                               array = new Attribute [a.Count];
+                       else
+                               array = Array.CreateInstance (attributeType, a.Count) as object[];
+
+                       // copy attributes to array
+                       a.CopyTo (array, 0);
+
+                       return array;
+               }
+
+               internal static object[] GetCustomAttributes (ICustomAttributeProvider obj, bool inherit)
+               {
+                       if (obj == null)
+                               throw new ArgumentNullException ("obj");
+
+                       if (!inherit)
+                               return (object[]) GetCustomAttributesBase (obj, null, false).Clone ();
+
+                       return GetCustomAttributes (obj, typeof (CustomAttribute), inherit);
+               }
+
+               [MethodImplAttribute (MethodImplOptions.InternalCall)]
+               [PreserveDependency(".ctor(System.Reflection.ConstructorInfo,System.Reflection.Assembly,System.IntPtr,System.UInt32)", "System.Reflection.CustomAttributeData")]
+               [PreserveDependency(".ctor(System.Reflection.MemberInfo,System.Object)", "System.Reflection.CustomAttributeNamedArgument")]
+               [PreserveDependency(".ctor(System.Type,System.Object)", "System.Reflection.CustomAttributeTypedArgument")]
+               static extern CustomAttributeData [] GetCustomAttributesDataInternal (ICustomAttributeProvider obj);
+
+               internal static IList<CustomAttributeData> GetCustomAttributesData (ICustomAttributeProvider obj, bool inherit = false)
+               {
+                       if (obj == null)
+                               throw new ArgumentNullException (nameof (obj));
+
+                       if (!inherit)
+                               return GetCustomAttributesDataBase (obj, null, false);
+
+                       return GetCustomAttributesData (obj, typeof (CustomAttribute), inherit);
+               }
+
+               internal static IList<CustomAttributeData> GetCustomAttributesData (ICustomAttributeProvider obj, Type attributeType, bool inherit)
+               {
+                       if (obj == null)
+                               throw new ArgumentNullException (nameof (obj));
+                       if (attributeType == null)
+                               throw new ArgumentNullException (nameof (attributeType));
+
+                       if (attributeType == typeof (CustomAttribute))
+                               attributeType = null;
+
+                       const string Message = "Invalid custom attribute data format";
+                       IList<CustomAttributeData> r;
+                       IList<CustomAttributeData> res = GetCustomAttributesDataBase (obj, attributeType, false);
+                       // shortcut
+                       if (!inherit && res.Count == 1) {
+                               if (res [0] == null)
+                                       throw new CustomAttributeFormatException (Message);
+                               if (attributeType != null) {
+                                       if (attributeType.IsAssignableFrom (res [0].AttributeType))
+                                               r = new CustomAttributeData[] { res [0] };
+                                       else
+                                               r = Array.Empty<CustomAttributeData> ();
+                               } else {
+                                       r = new CustomAttributeData[] { res [0] };
+                               }
+
+                               return r;
+                       }
+
+                       if (inherit && GetBase (obj) == null)
+                               inherit = false;
+
+                       // if AttributeType is sealed, and Inherited is set to false, then 
+                       // there's no use in scanning base types 
+                       if ((attributeType != null && attributeType.IsSealed) && inherit) {
+                               var usageAttribute = RetrieveAttributeUsage (attributeType);
+                               if (!usageAttribute.Inherited)
+                                       inherit = false;
+                       }
+
+                       var initialSize = Math.Max (res.Count, 16);
+                       List<CustomAttributeData> a = null;
+                       ICustomAttributeProvider btype = obj;
+
+                       /* Non-inherit case */
+                       if (!inherit) {
+                               if (attributeType == null) {
+                                       foreach (CustomAttributeData attrData in res) {
+                                               if (attrData == null)
+                                                       throw new CustomAttributeFormatException (Message);
+                                       }
+
+                                       var result = new CustomAttributeData [res.Count];
+                                       res.CopyTo (result, 0);
+                                       return result;
+                               } else {
+                                       a = new List<CustomAttributeData> (initialSize);
+                                       foreach (CustomAttributeData attrData in res) {
+                                               if (attrData == null)
+                                                       throw new CustomAttributeFormatException (Message);
+                                               if (!attributeType.IsAssignableFrom (attrData.AttributeType))
+                                                       continue;
+                                               a.Add (attrData);
+                                       }
+
+                                       return a.ToArray ();
+                               }
+                       }
+
+                       /* Inherit case */
+                       var attributeInfos = new Dictionary<Type, AttributeInfo> (initialSize);
+                       int inheritanceLevel = 0;
+                       a = new List<CustomAttributeData> (initialSize);
+
+                       do {
+                               foreach (CustomAttributeData attrData in res) {
+                                       AttributeUsageAttribute usage;
+                                       if (attrData == null)
+                                               throw new CustomAttributeFormatException (Message);
+
+                                       Type attrType = attrData.AttributeType;
+                                       if (attributeType != null) {
+                                               if (!attributeType.IsAssignableFrom (attrType))
+                                                       continue;
+                                       }
+
+                                       AttributeInfo firstAttribute;
+                                       if (attributeInfos.TryGetValue (attrType, out firstAttribute))
+                                               usage = firstAttribute.Usage;
+                                       else
+                                               usage = RetrieveAttributeUsage (attrType);
+
+                                       // The same as for CustomAttributes.
+                                       //
+                                       // Only add attribute to the list of attributes if 
+                                       // - we are on the first inheritance level, or the attribute can be inherited anyway
+                                       // and (
+                                       // - multiple attributes of the type are allowed
+                                       // or (
+                                       // - this is the first attribute we've discovered
+                                       // or
+                                       // - the attribute is on same inheritance level than the first 
+                                       //   attribute that was discovered for this attribute type ))
+                                       if ((inheritanceLevel == 0 || usage.Inherited) && (usage.AllowMultiple ||
+                                               (firstAttribute == null || (firstAttribute != null
+                                                       && firstAttribute.InheritanceLevel == inheritanceLevel))))
+                                               a.Add(attrData);
+
+                                       if (firstAttribute == null)
+                                               attributeInfos.Add (attrType, new AttributeInfo (usage, inheritanceLevel));
+                               }
+
+                               if ((btype = GetBase (btype)) != null) {
+                                       inheritanceLevel++;
+                                       res = GetCustomAttributesDataBase (btype, attributeType, true);
+                               }
+                       } while (inherit && btype != null);
+
+                       return a.ToArray ();
+               }
+
+               internal static IList<CustomAttributeData> GetCustomAttributesDataBase (ICustomAttributeProvider obj, Type attributeType, bool inheritedOnly)
+               {
+                       CustomAttributeData[] attrsData;
+                       if (IsUserCattrProvider (obj)) {
+                               //FIXME resolve this case if it makes sense. Assign empty array for now.
+                               //attrsData = obj.GetCustomAttributesData(attributeType, true);
+                               attrsData = Array.Empty<CustomAttributeData> ();
+                       } else
+                               attrsData = GetCustomAttributesDataInternal (obj);
+
+                       //
+                       // All pseudo custom attributes are Inherited = false hence we can avoid
+                       // building attributes data array which would be discarded by inherited checks
+                       //
+                       if (!inheritedOnly) {
+                               CustomAttributeData[] pseudoAttrsData = GetPseudoCustomAttributesData (obj, attributeType);
+                               if (pseudoAttrsData != null) {
+                                       if (attrsData.Length == 0)
+                                               return Array.AsReadOnly (pseudoAttrsData);
+                                       CustomAttributeData[] res = new CustomAttributeData [attrsData.Length + pseudoAttrsData.Length];
+                                       Array.Copy (attrsData, res, attrsData.Length);
+                                       Array.Copy (pseudoAttrsData, 0, res, attrsData.Length, pseudoAttrsData.Length);
+                                       return Array.AsReadOnly (res);
+                               }
+                       }
+
+                       return Array.AsReadOnly (attrsData);
+               }
+
+               internal static CustomAttributeData[] GetPseudoCustomAttributesData (ICustomAttributeProvider obj, Type attributeType)
+               {
+                       CustomAttributeData[] pseudoAttrsData = null;
+
+                       /* FIXME: Add other types */
+                       if (obj is RuntimeMethodInfo monoMethod)
+                               pseudoAttrsData = monoMethod.GetPseudoCustomAttributesData ();
+                       else if (obj is RuntimeFieldInfo fieldInfo)
+                               pseudoAttrsData = fieldInfo.GetPseudoCustomAttributesData ();
+                       else if (obj is RuntimeParameterInfo monoParamInfo)
+                               pseudoAttrsData = monoParamInfo.GetPseudoCustomAttributesData ();
+                       else if (obj is Type t)
+                               pseudoAttrsData = GetPseudoCustomAttributesData (t);
+
+                       if ((attributeType != null) && (pseudoAttrsData != null)) {
+                               for (int i = 0; i < pseudoAttrsData.Length; ++i) {
+                                       if (attributeType.IsAssignableFrom (pseudoAttrsData [i].AttributeType)) {
+                                               if (pseudoAttrsData.Length == 1)
+                                                       return pseudoAttrsData;
+                                               else
+                                                       return new CustomAttributeData[] { pseudoAttrsData[i] };
+                                       }
+                               }
+
+                               return Array.Empty<CustomAttributeData> ();
+                       }
+
+                       return pseudoAttrsData;
+               }
+
+               static CustomAttributeData[] GetPseudoCustomAttributesData (Type type)
+               {
+                       int count = 0;
+                       var Attributes = type.Attributes;
+
+                       /* IsSerializable returns true for delegates/enums as well */
+                       if ((Attributes & TypeAttributes.Serializable) != 0)
+                               count++;
+                       if ((Attributes & TypeAttributes.Import) != 0)
+                               count++;
+
+                       if (count == 0)
+                               return null;
+                       CustomAttributeData[] attrsData = new CustomAttributeData [count];
+                       count = 0;
+
+                       if ((Attributes & TypeAttributes.Serializable) != 0)
+                               attrsData [count++] = new CustomAttributeData ((typeof (SerializableAttribute)).GetConstructor (Type.EmptyTypes));
+                       if ((Attributes & TypeAttributes.Import) != 0)
+                               attrsData [count++] = new CustomAttributeData ((typeof (ComImportAttribute)).GetConstructor (Type.EmptyTypes));
+
+                       return attrsData;
+               }
+
+               internal static bool IsDefined (ICustomAttributeProvider obj, Type attributeType, bool inherit)
+               {
+                       if (attributeType == null)
+                               throw new ArgumentNullException ("attributeType");
+
+                       AttributeUsageAttribute usage = null;
+                       do {
+                               if (IsUserCattrProvider (obj))
+                                       return obj.IsDefined (attributeType, inherit);
+
+                               if (IsDefinedInternal (obj, attributeType))
+                                       return true;
+
+                               object[] pseudoAttrs = GetPseudoCustomAttributes (obj, attributeType);
+                               if (pseudoAttrs != null) {
+                                       for (int i = 0; i < pseudoAttrs.Length; ++i)
+                                               if (attributeType.IsAssignableFrom (pseudoAttrs[i].GetType ()))
+                                                       return true;
+                               }
+
+                               if (usage == null) {
+                                       if (!inherit)
+                                               return false;
+
+                                       usage = RetrieveAttributeUsage (attributeType);
+                                       if (!usage.Inherited)
+                                               return false;
+                               }
+
+                               obj = GetBase (obj);
+                       } while (obj != null);
+
+                       return false;
+               }
+
+               [MethodImplAttribute (MethodImplOptions.InternalCall)]
+               static extern bool IsDefinedInternal (ICustomAttributeProvider obj, Type AttributeType);
+
+               static PropertyInfo GetBasePropertyDefinition (RuntimePropertyInfo property)
+               {
+                       MethodInfo method = property.GetGetMethod (true);
+                       if (method == null || !method.IsVirtual)
+                               method = property.GetSetMethod (true);
+                       if (method == null || !method.IsVirtual)
+                               return null;
+
+                       MethodInfo baseMethod = ((RuntimeMethodInfo)method).GetBaseMethod ();
+                       if (baseMethod != null && baseMethod != method) {
+                               ParameterInfo[] parameters = property.GetIndexParameters ();
+                               if (parameters != null && parameters.Length > 0) {
+                                       Type[] paramTypes = new Type[parameters.Length];
+                                       for (int i=0; i < paramTypes.Length; i++)
+                                               paramTypes[i] = parameters[i].ParameterType;
+                                       return baseMethod.DeclaringType.GetProperty (property.Name, property.PropertyType, 
+                                                                                    paramTypes);
+                               } else {
+                                       return baseMethod.DeclaringType.GetProperty (property.Name, property.PropertyType);
+                               }
+                       }
+                       return null;
+
+               }
+
+               static EventInfo GetBaseEventDefinition (RuntimeEventInfo evt)
+               {
+                       MethodInfo method = evt.GetAddMethod (true);
+                       if (method == null || !method.IsVirtual)
+                               method = evt.GetRaiseMethod (true);
+                       if (method == null || !method.IsVirtual)
+                               method = evt.GetRemoveMethod (true);
+                       if (method == null || !method.IsVirtual)
+                               return null;
+
+                       MethodInfo baseMethod = ((RuntimeMethodInfo)method).GetBaseMethod ();
+                       if (baseMethod != null && baseMethod != method) {
+                               BindingFlags flags = method.IsPublic ? BindingFlags.Public : BindingFlags.NonPublic;
+                               flags |= method.IsStatic ? BindingFlags.Static : BindingFlags.Instance;
+
+                               return baseMethod.DeclaringType.GetEvent (evt.Name, flags);
+                       }
+                       return null;
+               }
+
+               // Handles Type, RuntimePropertyInfo and RuntimeMethodInfo.
+               // The runtime has also cases for RuntimeEventInfo, RuntimeFieldInfo, Assembly and ParameterInfo,
+               // but for those we return null here.
+               static ICustomAttributeProvider GetBase (ICustomAttributeProvider obj)
+               {
+                       if (obj == null)
+                               return null;
+
+                       if (obj is Type)
+                               return ((Type) obj).BaseType;
+
+                       MethodInfo method = null;
+                       if (obj is RuntimePropertyInfo)
+                               return GetBasePropertyDefinition ((RuntimePropertyInfo) obj);
+                       else if (obj is RuntimeEventInfo)
+                               return GetBaseEventDefinition ((RuntimeEventInfo)obj);
+                       else if (obj is RuntimeMethodInfo)
+                               method = (MethodInfo) obj;
+                       if (obj is RuntimeParameterInfo parinfo) {
+                               var member = parinfo.Member;
+                               if (member is MethodInfo) {
+                                       method = (MethodInfo)member;
+                                       MethodInfo bmethod = ((RuntimeMethodInfo)method).GetBaseMethod ();
+                                       if (bmethod == method)
+                                               return null;
+                                       return bmethod.GetParameters ()[parinfo.Position];
+                               }
+                       }
+                       /*
+                        * ParameterInfo -> null
+                        * Assembly -> null
+                        * RuntimeEventInfo -> null
+                        * RuntimeFieldInfo -> null
+                        */
+                       if (method == null || !method.IsVirtual)
+                               return null;
+
+                       MethodInfo baseMethod = ((RuntimeMethodInfo)method).GetBaseMethod ();
+                       if (baseMethod == method)
+                               return null;
+
+                       return baseMethod;
+               }
+
+               private static AttributeUsageAttribute RetrieveAttributeUsageNoCache (Type attributeType)
+               {
+                       if (attributeType == typeof (AttributeUsageAttribute))
+                               /* Avoid endless recursion */
+                               return new AttributeUsageAttribute (AttributeTargets.Class);
+
+                       AttributeUsageAttribute usageAttribute = null;
+                       object[] attribs = GetCustomAttributes (attributeType, typeof(AttributeUsageAttribute), false);
+                       if (attribs.Length == 0)
+                       {
+                               // if no AttributeUsage was defined on the attribute level, then
+                               // try to retrieve if from its base type
+                               if (attributeType.BaseType != null)
+                               {
+                                       usageAttribute = RetrieveAttributeUsage (attributeType.BaseType);
+
+                               }
+                               if (usageAttribute != null)
+                               {
+                                       // return AttributeUsage of base class
+                                       return usageAttribute;
+
+                               }
+                               // return default AttributeUsageAttribute if no AttributeUsage 
+                               // was defined on attribute, or its base class
+                               return DefaultAttributeUsage;
+                       }
+                       // check if more than one AttributeUsageAttribute has been specified 
+                       // on the type
+                       // NOTE: compilers should prevent this, but that doesn't prevent
+                       // anyone from using IL ofcourse
+                       if (attribs.Length > 1)
+                       {
+                               throw new FormatException ("Duplicate AttributeUsageAttribute cannot be specified on an attribute type.");
+                       }
+
+                       return ((AttributeUsageAttribute) attribs[0]);
+               }
+
+               static AttributeUsageAttribute RetrieveAttributeUsage (Type attributeType)
+               {
+                       AttributeUsageAttribute usageAttribute = null;
+                       /* Usage a thread-local cache to speed this up, since it is called a lot from GetCustomAttributes () */
+                       if (usage_cache == null)
+                               usage_cache = new Dictionary<Type, AttributeUsageAttribute> ();
+                       if (usage_cache.TryGetValue (attributeType, out usageAttribute))
+                               return usageAttribute;
+                       usageAttribute = RetrieveAttributeUsageNoCache (attributeType);
+                       usage_cache [attributeType] = usageAttribute;
+                       return usageAttribute;
+               }
+
+               private static readonly AttributeUsageAttribute DefaultAttributeUsage =
+                       new AttributeUsageAttribute (AttributeTargets.All);
+
+               private class AttributeInfo
+               {
+                       private AttributeUsageAttribute _usage;
+                       private int _inheritanceLevel;
+
+                       public AttributeInfo (AttributeUsageAttribute usage, int inheritanceLevel)
+                       {
+                               _usage = usage;
+                               _inheritanceLevel = inheritanceLevel;
+                       }
+
+                       public AttributeUsageAttribute Usage
+                       {
+                               get
+                               {
+                                       return _usage;
+                               }
+                       }
+
+                       public int InheritanceLevel
+                       {
+                               get
+                               {
+                                       return _inheritanceLevel;
+                               }
+                       }
+               }
+       }
+}
index 93313e8..979a521 100644 (file)
@@ -117,23 +117,23 @@ namespace System.Reflection
                }
 
                public static IList<CustomAttributeData> GetCustomAttributes (Assembly target) {
-                       return MonoCustomAttrs.GetCustomAttributesData (target);
+                       return CustomAttribute.GetCustomAttributesData (target);
                }
 
                public static IList<CustomAttributeData> GetCustomAttributes (MemberInfo target) {
-                       return MonoCustomAttrs.GetCustomAttributesData (target);
+                       return CustomAttribute.GetCustomAttributesData (target);
                }
 
                internal static IList<CustomAttributeData> GetCustomAttributesInternal (RuntimeType target) {
-                       return MonoCustomAttrs.GetCustomAttributesData (target);
+                       return CustomAttribute.GetCustomAttributesData (target);
                }
 
                public static IList<CustomAttributeData> GetCustomAttributes (Module target) {
-                       return MonoCustomAttrs.GetCustomAttributesData (target);
+                       return CustomAttribute.GetCustomAttributesData (target);
                }
 
                public static IList<CustomAttributeData> GetCustomAttributes (ParameterInfo target) {
-                       return MonoCustomAttrs.GetCustomAttributesData (target);
+                       return CustomAttribute.GetCustomAttributesData (target);
                }
 
                virtual public Type AttributeType {
index 1dec520..17b0741 100644 (file)
@@ -205,7 +205,7 @@ namespace System.Reflection
 
                public override bool IsDefined (Type attributeType, bool inherit)
                {
-                       return MonoCustomAttrs.IsDefined (this, attributeType, inherit);
+                       return CustomAttribute.IsDefined (this, attributeType, inherit);
                }
 
                public override IList<CustomAttributeData> GetCustomAttributesData ()
@@ -215,12 +215,12 @@ namespace System.Reflection
 
                public override object[] GetCustomAttributes (bool inherit)
                {
-                       return MonoCustomAttrs.GetCustomAttributes (this, inherit);
+                       return CustomAttribute.GetCustomAttributes (this, inherit);
                }
 
                public override object[] GetCustomAttributes (Type attributeType, bool inherit)
                {
-                       return MonoCustomAttrs.GetCustomAttributes (this, attributeType, inherit);
+                       return CustomAttribute.GetCustomAttributes (this, attributeType, inherit);
                }
 
                public override Module GetModule (string name)
index ac98791..d2e178f 100644 (file)
@@ -176,17 +176,17 @@ namespace System.Reflection
 
                public override bool IsDefined (Type attributeType, bool inherit)
                {
-                       return MonoCustomAttrs.IsDefined (this, attributeType, inherit);
+                       return CustomAttribute.IsDefined (this, attributeType, inherit);
                }
 
                public override object[] GetCustomAttributes( bool inherit)
                {
-                       return MonoCustomAttrs.GetCustomAttributes (this, inherit);
+                       return CustomAttribute.GetCustomAttributes (this, inherit);
                }
 
                public override object[] GetCustomAttributes( Type attributeType, bool inherit)
                {
-                       return MonoCustomAttrs.GetCustomAttributes (this, attributeType, inherit);
+                       return CustomAttribute.GetCustomAttributes (this, attributeType, inherit);
                }
 
                public override IList<CustomAttributeData> GetCustomAttributesData () {
index 39cb780..0dc5765 100644 (file)
@@ -178,14 +178,14 @@ namespace System.Reflection
                }
 
                public override bool IsDefined (Type attributeType, bool inherit) {
-                       return MonoCustomAttrs.IsDefined (this, attributeType, inherit);
+                       return CustomAttribute.IsDefined (this, attributeType, inherit);
                }
 
                public override object[] GetCustomAttributes( bool inherit) {
-                       return MonoCustomAttrs.GetCustomAttributes (this, inherit);
+                       return CustomAttribute.GetCustomAttributes (this, inherit);
                }
                public override object[] GetCustomAttributes( Type attributeType, bool inherit) {
-                       return MonoCustomAttrs.GetCustomAttributes (this, attributeType, inherit);
+                       return CustomAttribute.GetCustomAttributes (this, attributeType, inherit);
                }
 
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
index ac82ab4..5e2c72a 100644 (file)
@@ -428,14 +428,14 @@ namespace System.Reflection
                }
                
                public override bool IsDefined (Type attributeType, bool inherit) {
-                       return MonoCustomAttrs.IsDefined (this, attributeType, inherit);
+                       return CustomAttribute.IsDefined (this, attributeType, inherit);
                }
 
                public override object[] GetCustomAttributes( bool inherit) {
-                       return MonoCustomAttrs.GetCustomAttributes (this, inherit);
+                       return CustomAttribute.GetCustomAttributes (this, inherit);
                }
                public override object[] GetCustomAttributes( Type attributeType, bool inherit) {
-                       return MonoCustomAttrs.GetCustomAttributes (this, attributeType, inherit);
+                       return CustomAttribute.GetCustomAttributes (this, attributeType, inherit);
                }
 
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
@@ -871,15 +871,15 @@ namespace System.Reflection
                }
 
                public override bool IsDefined (Type attributeType, bool inherit) {
-                       return MonoCustomAttrs.IsDefined (this, attributeType, inherit);
+                       return CustomAttribute.IsDefined (this, attributeType, inherit);
                }
 
                public override object[] GetCustomAttributes( bool inherit) {
-                       return MonoCustomAttrs.GetCustomAttributes (this, inherit);
+                       return CustomAttribute.GetCustomAttributes (this, inherit);
                }
 
                public override object[] GetCustomAttributes( Type attributeType, bool inherit) {
-                       return MonoCustomAttrs.GetCustomAttributes (this, attributeType, inherit);
+                       return CustomAttribute.GetCustomAttributes (this, attributeType, inherit);
                }
 
                public override MethodBody GetMethodBody () {
index 49a8f4c..60e6708 100644 (file)
@@ -112,13 +112,13 @@ namespace System.Reflection {
                public override
                object[] GetCustomAttributes(bool inherit) 
                {
-                       return MonoCustomAttrs.GetCustomAttributes (this, inherit);
+                       return CustomAttribute.GetCustomAttributes (this, inherit);
                }
 
                public override
                object[] GetCustomAttributes(Type attributeType, bool inherit) 
                {
-                       return MonoCustomAttrs.GetCustomAttributes (this, attributeType, inherit);
+                       return CustomAttribute.GetCustomAttributes (this, attributeType, inherit);
                }
 
                public override
@@ -194,7 +194,7 @@ namespace System.Reflection {
                public override
                bool IsDefined (Type attributeType, bool inherit) 
                {
-                       return MonoCustomAttrs.IsDefined (this, attributeType, inherit);
+                       return CustomAttribute.IsDefined (this, attributeType, inherit);
                }
 
                public
index 70007bb..4420cf2 100644 (file)
@@ -158,14 +158,14 @@ namespace System.Reflection
                override
                object[] GetCustomAttributes (bool inherit)
                {
-                       return MonoCustomAttrs.GetCustomAttributes (this, inherit);
+                       return CustomAttribute.GetCustomAttributes (this, inherit);
                }
 
                public
                override
                object[] GetCustomAttributes (Type attributeType, bool inherit)
                {
-                       return MonoCustomAttrs.GetCustomAttributes (this, attributeType, inherit);
+                       return CustomAttribute.GetCustomAttributes (this, attributeType, inherit);
                }
 
                internal object GetDefaultValueImpl (ParameterInfo pinfo)
@@ -177,7 +177,7 @@ namespace System.Reflection
                public
                override
                bool IsDefined( Type attributeType, bool inherit) {
-                       return MonoCustomAttrs.IsDefined (this, attributeType, inherit);
+                       return CustomAttribute.IsDefined (this, attributeType, inherit);
                }
 
                public override IList<CustomAttributeData> GetCustomAttributesData () {
index e8608a9..b52b6f6 100644 (file)
@@ -295,17 +295,17 @@ namespace System.Reflection
                //
                public override bool IsDefined (Type attributeType, bool inherit)
                {
-                       return MonoCustomAttrs.IsDefined (this, attributeType, false);
+                       return CustomAttribute.IsDefined (this, attributeType, false);
                }
 
                public override object[] GetCustomAttributes (bool inherit)
                {
-                       return MonoCustomAttrs.GetCustomAttributes (this, false);
+                       return CustomAttribute.GetCustomAttributes (this, false);
                }
                
                public override object[] GetCustomAttributes (Type attributeType, bool inherit)
                {
-                       return MonoCustomAttrs.GetCustomAttributes (this, attributeType, false);
+                       return CustomAttribute.GetCustomAttributes (this, attributeType, false);
                }
 
 
index 6c00bbd..ca05813 100644 (file)
@@ -13,10 +13,10 @@ namespace System
                {
                        if (attributeType == null)
                                throw new ArgumentNullException (nameof (attributeType));
-                       if (!attributeType.IsSubclassOf (typeof (Attribute)) && attributeType != typeof (Attribute) && attributeType != typeof (MonoCustomAttrs))
+                       if (!attributeType.IsSubclassOf (typeof (Attribute)) && attributeType != typeof (Attribute) && attributeType != typeof (CustomAttribute))
                                throw new ArgumentException (SR.Argument_MustHaveAttributeBaseClass + " " + attributeType.FullName);
 
-                       var attrs = MonoCustomAttrs.GetCustomAttributes (element, attributeType, inherit);
+                       var attrs = CustomAttribute.GetCustomAttributes (element, attributeType, inherit);
                        if (attrs == null || attrs.Length == 0)
                                return null;
                        if (attrs.Length != 1)
@@ -33,20 +33,20 @@ namespace System
                public static Attribute GetCustomAttribute(ParameterInfo element, Type attributeType) => GetAttr (element, attributeType, true);
                public static Attribute GetCustomAttribute(ParameterInfo element, Type attributeType, bool inherit) => GetAttr (element, attributeType, inherit);
 
-               public static Attribute[] GetCustomAttributes (Assembly element) => (Attribute[])MonoCustomAttrs.GetCustomAttributes (element, true);
-               public static Attribute[] GetCustomAttributes (Assembly element, bool inherit) => (Attribute[])MonoCustomAttrs.GetCustomAttributes (element, inherit);
+               public static Attribute[] GetCustomAttributes (Assembly element) => (Attribute[])CustomAttribute.GetCustomAttributes (element, true);
+               public static Attribute[] GetCustomAttributes (Assembly element, bool inherit) => (Attribute[])CustomAttribute.GetCustomAttributes (element, inherit);
                public static Attribute[] GetCustomAttributes (Assembly element, Type attributeType) => (Attribute[])GetCustomAttributes ((ICustomAttributeProvider)element, attributeType, true);
                public static Attribute[] GetCustomAttributes (Assembly element, Type attributeType, bool inherit) => (Attribute[])GetCustomAttributes ((ICustomAttributeProvider)element, attributeType, inherit);
-               public static Attribute[] GetCustomAttributes (MemberInfo element) => (Attribute[])MonoCustomAttrs.GetCustomAttributes (element, true);
-               public static Attribute[] GetCustomAttributes (MemberInfo element, bool inherit) => (Attribute[])MonoCustomAttrs.GetCustomAttributes (element, inherit);
+               public static Attribute[] GetCustomAttributes (MemberInfo element) => (Attribute[])CustomAttribute.GetCustomAttributes (element, true);
+               public static Attribute[] GetCustomAttributes (MemberInfo element, bool inherit) => (Attribute[])CustomAttribute.GetCustomAttributes (element, inherit);
                public static Attribute[] GetCustomAttributes (MemberInfo element, Type attributeType) => (Attribute[])GetCustomAttributes ((ICustomAttributeProvider)element, attributeType, true);
                public static Attribute[] GetCustomAttributes (MemberInfo element, Type attributeType, bool inherit) => (Attribute[])GetCustomAttributes ((ICustomAttributeProvider)element, attributeType, inherit);
-               public static Attribute[] GetCustomAttributes (Module element) => (Attribute[])MonoCustomAttrs.GetCustomAttributes (element, true);
-               public static Attribute[] GetCustomAttributes (Module element, bool inherit) => (Attribute[])MonoCustomAttrs.GetCustomAttributes (element, inherit);
+               public static Attribute[] GetCustomAttributes (Module element) => (Attribute[])CustomAttribute.GetCustomAttributes (element, true);
+               public static Attribute[] GetCustomAttributes (Module element, bool inherit) => (Attribute[])CustomAttribute.GetCustomAttributes (element, inherit);
                public static Attribute[] GetCustomAttributes (Module element, Type attributeType) => (Attribute[])GetCustomAttributes ((ICustomAttributeProvider)element, attributeType, true);
                public static Attribute[] GetCustomAttributes (Module element, Type attributeType, bool inherit) => (Attribute[])GetCustomAttributes ((ICustomAttributeProvider)element, attributeType, inherit);
-               public static Attribute[] GetCustomAttributes (ParameterInfo element) => (Attribute[])MonoCustomAttrs.GetCustomAttributes (element, true);
-               public static Attribute[] GetCustomAttributes (ParameterInfo element, bool inherit) => (Attribute[])MonoCustomAttrs.GetCustomAttributes (element, inherit);
+               public static Attribute[] GetCustomAttributes (ParameterInfo element) => (Attribute[])CustomAttribute.GetCustomAttributes (element, true);
+               public static Attribute[] GetCustomAttributes (ParameterInfo element, bool inherit) => (Attribute[])CustomAttribute.GetCustomAttributes (element, inherit);
                public static Attribute[] GetCustomAttributes (ParameterInfo element, Type attributeType) => (Attribute[])GetCustomAttributes ((ICustomAttributeProvider)element, attributeType, true);
                public static Attribute[] GetCustomAttributes (ParameterInfo element, Type attributeType, bool inherit) => (Attribute[])GetCustomAttributes ((ICustomAttributeProvider)element, attributeType, inherit);
 
@@ -57,7 +57,7 @@ namespace System
                        if (!attributeType.IsSubclassOf (typeof (Attribute)) && attributeType != typeof (Attribute))
                                throw new ArgumentException (SR.Argument_MustHaveAttributeBaseClass + " " + attributeType.FullName);
 
-                       return (Attribute[])MonoCustomAttrs.GetCustomAttributes (element, attributeType, inherit);
+                       return (Attribute[])CustomAttribute.GetCustomAttributes (element, attributeType, inherit);
                }
 
                public static bool IsDefined (Assembly element, Type attributeType) => IsDefined ((ICustomAttributeProvider)element, attributeType, true);
@@ -76,7 +76,7 @@ namespace System
                        if (!attributeType.IsSubclassOf (typeof (Attribute)) && attributeType != typeof (Attribute))
                                throw new ArgumentException (SR.Argument_MustHaveAttributeBaseClass + " " + attributeType.FullName);
 
-                       return MonoCustomAttrs.IsDefined (element, attributeType, inherit);
+                       return CustomAttribute.IsDefined (element, attributeType, inherit);
                }
        }
 }
index 046c8f0..56c3c96 100644 (file)
@@ -2,7 +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.Reflection;
 using System.Globalization;
 using System.Threading;
@@ -10,10 +9,9 @@ using System.Collections.Generic;
 using System.Runtime.Serialization;    
 using System.Runtime.CompilerServices;
 using System.Security;
-using DebuggerStepThroughAttribute = System.Diagnostics.DebuggerStepThroughAttribute;
 using System.Diagnostics.Contracts;
 using System.Runtime.InteropServices;
-using CustomAttribute=System.MonoCustomAttrs;
+using System.Diagnostics;
 
 namespace System 
 {