public static void LetAttributesReceiveAttributeMemberInfo <T>(this AttributeMemberInfo <T> attrVarInfo) where T : Attribute, IAttributeMemberInfoReceiver <T> { foreach (var attribute in attrVarInfo.Attributes) { attribute.ReceiveAttributeVariableInfo(attrVarInfo); } }
// // // ORDERED // // BASE-TYPE-LOOP // TYPED /// <returns>Returns null if passed attribute allows multiple declarations.</returns> public static AttributeMemberInfo <TAttribute>[]? TryGetOrderedAttributeMemberInfos <TAttribute>(this Type type, Type?interruptingBaseType = null, VariableInfoDescriptor?descriptor = null, bool?getCustomAttributesInherit = null) where TAttribute : Attribute, IZeroBasedIndex { var customAttribute = typeof(TAttribute).GetCustomAttribute <AttributeUsageAttribute>(); if (customAttribute is null || customAttribute.AllowMultiple) { return(null); } var vars = GetAttributeVariableMembers <TAttribute>(type, interruptingBaseType, descriptor, getCustomAttributesInherit).ToList(); var array = new AttributeMemberInfo <TAttribute> [vars.Count]; foreach (var variable in vars) { array[variable.FirstAttribute().Index] = variable; } return(array); }
/// <param name="memberInfo">Pass <see cref="PropertyInfo"/> or <see cref="FieldInfo"/>.</param> public static bool TryGetAttributeVariableMember(this MemberInfo memberInfo, Type attributeType, [MaybeNull] out AttributeMemberInfo attrVarInfo, bool?getCustomAttributesInherit = null) { bool _getCustomAttributesInherit = getCustomAttributesInherit ?? true; // Library.DefaultCustomAttributesInherit if (!MemberInfoTools.IsVariable(memberInfo, attributeType, _getCustomAttributesInherit)) { attrVarInfo = null; return(false); } attrVarInfo = GetAttributeVariableMember(memberInfo, attributeType, getCustomAttributesInherit); return(true); }
/// <param name="memberInfo">Pass <see cref="PropertyInfo"/> or <see cref="FieldInfo"/>.</param> public static bool TryGetAttributeVariableMember <T>(this MemberInfo memberInfo, [MaybeNull] out AttributeMemberInfo <T> attrVarInfo, bool?getCustomAttributesInherit = null) where T : Attribute { bool _getCustomAttributesInherit = getCustomAttributesInherit ?? true; // Library.DefaultCustomAttributesInherit if (!MemberInfoTools.IsVariable(memberInfo, typeof(T), _getCustomAttributesInherit)) { attrVarInfo = null; return(false); } attrVarInfo = GetAttributeVariableMember <T>(memberInfo, getCustomAttributesInherit); return(true); }