internal static object[] GetCustomAttributes(RuntimeMethodInfo method, RuntimeType caType, bool inherit) { if (method.IsGenericMethod && !method.IsGenericMethodDefinition) { method = (method.GetGenericMethodDefinition() as RuntimeMethodInfo); } int i = 0; Attribute[] customAttributes = PseudoCustomAttribute.GetCustomAttributes(method, caType, true, out i); if (!inherit || (caType.IsSealed && !CustomAttribute.GetAttributeUsage(caType).Inherited)) { object[] customAttributes2 = CustomAttribute.GetCustomAttributes(method.GetRuntimeModule(), method.MetadataToken, i, caType, !CustomAttribute.AllowCriticalCustomAttributes(method)); if (i > 0) { Array.Copy(customAttributes, 0, customAttributes2, customAttributes2.Length - i, i); } return(customAttributes2); } List <object> list = new List <object>(); bool mustBeInheritable = false; Type elementType = (caType == null || caType.IsValueType || caType.ContainsGenericParameters) ? typeof(object) : caType; while (i > 0) { list.Add(customAttributes[--i]); } while (method != null) { object[] customAttributes3 = CustomAttribute.GetCustomAttributes(method.GetRuntimeModule(), method.MetadataToken, 0, caType, mustBeInheritable, list, !CustomAttribute.AllowCriticalCustomAttributes(method)); mustBeInheritable = true; for (int j = 0; j < customAttributes3.Length; j++) { list.Add(customAttributes3[j]); } method = method.GetParentDefinition(); } object[] array = CustomAttribute.CreateAttributeArrayHelper(elementType, list.Count); Array.Copy(list.ToArray(), 0, array, 0, list.Count); return(array); }
internal static object[] GetCustomAttributes(RuntimeMethodInfo method, RuntimeType caType, bool inherit) { if (method.IsGenericMethod && !method.IsGenericMethodDefinition) { method = method.GetGenericMethodDefinition() as RuntimeMethodInfo; } int count = 0; Attribute[] sourceArray = PseudoCustomAttribute.GetCustomAttributes(method, caType, true, out count); if (!inherit || (caType.IsSealed && !GetAttributeUsage(caType).Inherited)) { object[] objArray = GetCustomAttributes(method.GetRuntimeModule(), method.MetadataToken, count, caType, !AllowCriticalCustomAttributes(method)); if (count > 0) { Array.Copy(sourceArray, 0, objArray, objArray.Length - count, count); } return(objArray); } List <object> derivedAttributes = new List <object>(); bool mustBeInheritable = false; Type elementType = (((caType == null) || caType.IsValueType) || caType.ContainsGenericParameters) ? typeof(object) : caType; while (count > 0) { derivedAttributes.Add(sourceArray[--count]); } while (method != null) { object[] objArray2 = GetCustomAttributes(method.GetRuntimeModule(), method.MetadataToken, 0, caType, mustBeInheritable, derivedAttributes, !AllowCriticalCustomAttributes(method)); mustBeInheritable = true; for (int i = 0; i < objArray2.Length; i++) { derivedAttributes.Add(objArray2[i]); } method = method.GetParentDefinition(); } object[] destinationArray = CreateAttributeArrayHelper(elementType, derivedAttributes.Count); Array.Copy(derivedAttributes.ToArray(), 0, destinationArray, 0, derivedAttributes.Count); return(destinationArray); }
internal static object[] GetCustomAttributes(RuntimeMethodInfo method, RuntimeType caType, bool inherit) { if (method.IsGenericMethod && !method.IsGenericMethodDefinition) { method = method.GetGenericMethodDefinition() as RuntimeMethodInfo; } int count = 0; Attribute[] customAttributes1 = PseudoCustomAttribute.GetCustomAttributes(method, caType, true, out count); if (!inherit || caType.IsSealed && !CustomAttribute.GetAttributeUsage(caType).Inherited) { object[] customAttributes2 = CustomAttribute.GetCustomAttributes(method.GetRuntimeModule(), method.MetadataToken, count, caType, !CustomAttribute.AllowCriticalCustomAttributes((MethodBase)method)); if (count > 0) { Array.Copy((Array)customAttributes1, 0, (Array)customAttributes2, customAttributes2.Length - count, count); } return(customAttributes2); } List <object> objectList = new List <object>(); bool mustBeInheritable = false; Type elementType = (caType == (RuntimeType)null || caType.IsValueType ? 1 : (caType.ContainsGenericParameters ? 1 : 0)) != 0 ? typeof(object) : (Type)caType; while (count > 0) { objectList.Add((object)customAttributes1[--count]); } for (; (MethodInfo)method != (MethodInfo)null; method = method.GetParentDefinition()) { object[] customAttributes2 = CustomAttribute.GetCustomAttributes(method.GetRuntimeModule(), method.MetadataToken, 0, caType, mustBeInheritable, (IList)objectList, !CustomAttribute.AllowCriticalCustomAttributes((MethodBase)method)); mustBeInheritable = true; for (int index = 0; index < customAttributes2.Length; ++index) { objectList.Add(customAttributes2[index]); } } object[] attributeArrayHelper = CustomAttribute.CreateAttributeArrayHelper(elementType, objectList.Count); Array.Copy((Array)objectList.ToArray(), 0, (Array)attributeArrayHelper, 0, objectList.Count); return(attributeArrayHelper); }
[System.Security.SecurityCritical] // auto-generated internal static Object[] GetCustomAttributes(RuntimeMethodInfo method, RuntimeType caType, bool inherit) { Contract.Requires(method != null); Contract.Requires(caType != null); if (method.IsGenericMethod && !method.IsGenericMethodDefinition) method = method.GetGenericMethodDefinition() as RuntimeMethodInfo; int pcaCount = 0; Attribute[] pca = PseudoCustomAttribute.GetCustomAttributes(method, caType, true, out pcaCount); // if we are asked to go up the hierarchy chain we have to do it now and regardless of the // attribute usage for the specific attribute because a derived attribute may override the usage... // ... however if the attribute is sealed we can rely on the attribute usage if (!inherit || (caType.IsSealed && !CustomAttribute.GetAttributeUsage(caType).Inherited)) { object[] attributes = GetCustomAttributes(method.GetRuntimeModule(), method.MetadataToken, pcaCount, caType, !AllowCriticalCustomAttributes(method)); if (pcaCount > 0) Array.Copy(pca, 0, attributes, attributes.Length - pcaCount, pcaCount); return attributes; } List<object> result = new List<object>(); bool mustBeInheritable = false; bool useObjectArray = (caType == null || caType.IsValueType || caType.ContainsGenericParameters); Type arrayType = useObjectArray ? typeof(object) : caType; while (pcaCount > 0) result.Add(pca[--pcaCount]); while (method != null) { object[] attributes = GetCustomAttributes(method.GetRuntimeModule(), method.MetadataToken, 0, caType, mustBeInheritable, result, !AllowCriticalCustomAttributes(method)); mustBeInheritable = true; for (int i = 0; i < attributes.Length; i++) result.Add(attributes[i]); method = method.GetParentDefinition(); } object[] typedResult = CreateAttributeArrayHelper(arrayType, result.Count); Array.Copy(result.ToArray(), 0, typedResult, 0, result.Count); return typedResult; }
internal static object[] GetCustomAttributes(RuntimeMethodInfo method, RuntimeType caType, bool inherit) { if (method.IsGenericMethod && !method.IsGenericMethodDefinition) { method = method.GetGenericMethodDefinition() as RuntimeMethodInfo; } int count = 0; Attribute[] sourceArray = PseudoCustomAttribute.GetCustomAttributes(method, caType, true, out count); if (!inherit || (caType.IsSealed && !GetAttributeUsage(caType).Inherited)) { object[] objArray = GetCustomAttributes(method.Module, method.MetadataToken, count, caType); if (count > 0) { Array.Copy(sourceArray, 0, objArray, objArray.Length - count, count); } return objArray; } List<object> derivedAttributes = new List<object>(); bool mustBeInheritable = false; Type elementType = (((caType == null) || caType.IsValueType) || caType.ContainsGenericParameters) ? typeof(object) : caType; while (count > 0) { derivedAttributes.Add(sourceArray[--count]); } while (method != null) { object[] objArray2 = GetCustomAttributes(method.Module, method.MetadataToken, 0, caType, mustBeInheritable, derivedAttributes); mustBeInheritable = true; for (int i = 0; i < objArray2.Length; i++) { derivedAttributes.Add(objArray2[i]); } method = method.GetParentDefinition() as RuntimeMethodInfo; } object[] destinationArray = Array.CreateInstance(elementType, derivedAttributes.Count) as object[]; Array.Copy(derivedAttributes.ToArray(), 0, destinationArray, 0, derivedAttributes.Count); return destinationArray; }