public static Attribute[] CullDuplicateAttributes(IList <Attribute> attributes) { HashSet <object> objs = new HashSet <object>(); int count = attributes.Count; for (int i = 0; i < attributes.Count; i++) { Attribute item = attributes[i]; if (objs.Contains(item.TypeId)) { attributes[i] = null; count--; } else if (!AttributeDataCache.GetAttributeData(item.GetType()).AllowsMultiple) { objs.Add(item.TypeId); } } Attribute[] attributeArray = new Attribute[count]; int num = 0; int num1 = 0; while (num < attributes.Count) { if (attributes[num] != null) { int num2 = num1; num1 = num2 + 1; attributeArray[num2] = attributes[num]; } num++; } return(attributeArray); }
private static IEnumerable <object> MergeAttributesIterator(Type type, MemberInfo member, bool includeClrAttributes) { string str = TypeUtilities.GetMemberName(member); if (str == null) { foreach (object attribute in MetadataStore.GetAttributes(type)) { yield return(attribute); } } else { foreach (object obj in MetadataStore.GetAttributes(type, str)) { yield return(obj); } } if (includeClrAttributes) { foreach (object clrAttribute in AttributeDataCache.GetClrAttributes(member)) { yield return(clrAttribute); } } }
internal static MemberInfo GetBaseMemberInfo(MemberInfo member) { object item = AttributeDataCache._baseMemberMap[member]; if (item == AttributeDataCache._noMemberInfo) { return(null); } if (item == null) { item = AttributeDataCache.CalculateBaseMemberInfo(member); lock (AttributeDataCache._syncObject) { AttributeDataCache._baseMemberMap[member] = item ?? AttributeDataCache._noMemberInfo; } } return((MemberInfo)item); }
private static MemberInfo GetBasePropertyInfo(MemberInfo info, Type targetType) { PropertyInfo propertyInfo = info as PropertyInfo; return(targetType.GetProperty(propertyInfo.Name, AttributeDataCache._getInfoBindingFlags, null, propertyInfo.PropertyType, AttributeDataCache.ToTypeArray(propertyInfo.GetIndexParameters()), null)); }
private static MemberInfo GetBaseMethodInfo(MemberInfo info, Type targetType) { MethodInfo methodInfo = info as MethodInfo; return(targetType.GetMethod(methodInfo.Name, AttributeDataCache._getInfoBindingFlags, null, AttributeDataCache.ToTypeArray(methodInfo.GetParameters()), null)); }
public static Attribute[] GetAttributes(MemberInfo memberInfo, Type attributeType, bool inherit) { bool flag; if (memberInfo == null) { return(new Attribute[0]); } List <Attribute> attributes = new List <Attribute>(); Type declaringType = memberInfo as Type; Type valueType = null; if (declaringType == null) { flag = false; declaringType = memberInfo.DeclaringType; valueType = TypeUtilities.GetValueType(memberInfo); } else { flag = true; } bool flag1 = true; bool flag2 = (flag ? true : memberInfo.DeclaringType == declaringType); while (declaringType != null && memberInfo != null) { foreach (object obj in TypeUtilities.MergeAttributesIterator(declaringType, memberInfo, flag2)) { if (attributeType != null && !attributeType.IsAssignableFrom(obj.GetType())) { continue; } AttributeData attributeData = AttributeDataCache.GetAttributeData(obj.GetType()); if (!flag1 && !attributeData.IsInheritable) { continue; } Attribute attribute = obj as Attribute; if (attribute == null) { continue; } attributes.Add(attribute); } if (!inherit || memberInfo.MemberType == MemberTypes.Field) { break; } if (flag || memberInfo.DeclaringType == declaringType) { memberInfo = AttributeDataCache.GetBaseMemberInfo(memberInfo); } declaringType = declaringType.BaseType; flag2 = (flag || memberInfo == null || memberInfo.DeclaringType == declaringType ? true : false); flag1 = false; } if (valueType != null && inherit) { attributes.AddRange(TypeUtilities.GetAttributes(valueType, attributeType, true)); } return(TypeUtilities.CullDuplicateAttributes(attributes)); }