public static bool TryGetAttributeValues <T>(Type type, ITypeId attributeType, string propertyName, out List <T> results)
 {
     return(PlatformNeutralAttributeHelper.TryGetAttributeValues <T>(TypeUtilities.GetAttributes(type), attributeType, propertyName, out results));
 }
Exemplo n.º 2
0
 public static T GetAttribute <T>(Type type)
     where T : Attribute
 {
     return((T)(TypeUtilities.GetAttribute(type, typeof(T)) as T));
 }
Exemplo n.º 3
0
        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));
        }
Exemplo n.º 4
0
 public static Attribute GetAttribute(Type type, Type attributeType)
 {
     return(TypeUtilities.GetAttributes(type)[attributeType]);
 }