public static T GetAttribute <T>(object attributeProvider, bool inherit) where T : Attribute { T[] attributes = ReflectionUtils.GetAttributes <T>(attributeProvider, inherit); if (attributes == null) { return(default(T)); } return(attributes.SingleOrDefault <T>()); }
// Token: 0x06000E3B RID: 3643 RVA: 0x000523E4 File Offset: 0x000505E4 public static T[] GetAttributes <[Nullable(0)] T>(object attributeProvider, bool inherit) where T : Attribute { Attribute[] attributes = ReflectionUtils.GetAttributes(attributeProvider, typeof(T), inherit); T[] array = attributes as T[]; if (array != null) { return(array); } return(attributes.Cast <T>().ToArray <T>()); }
public static T GetAttribute <T>(ICustomAttributeProvider attributeProvider, bool inherit) where T : Attribute { T[] attributes = ReflectionUtils.GetAttributes <T>(attributeProvider, inherit); if (attributes != null) { return(attributes.FirstOrDefault <T>()); } return(default(T)); }
public static Attribute[] GetAttributes(object attributeProvider, Type attributeType, bool inherit) { ValidationUtils.ArgumentNotNull(attributeProvider, "attributeProvider"); object obj = attributeProvider; if (obj is Type) { Type type = (Type)obj; Attribute[] array = ((attributeType != null ? type.GetCustomAttributes(attributeType, inherit) : type.GetCustomAttributes(inherit))).Cast <Attribute>().ToArray <Attribute>(); if (inherit && type.BaseType != null) { array = array.Union <Attribute>(ReflectionUtils.GetAttributes(type.BaseType, attributeType, inherit)).ToArray <Attribute>(); } return(array); } if (obj is Assembly) { Assembly assembly = (Assembly)obj; if (attributeType == null) { return(Attribute.GetCustomAttributes(assembly)); } return(Attribute.GetCustomAttributes(assembly, attributeType)); } if (obj is MemberInfo) { MemberInfo memberInfo = (MemberInfo)obj; if (attributeType == null) { return(Attribute.GetCustomAttributes(memberInfo, inherit)); } return(Attribute.GetCustomAttributes(memberInfo, attributeType, inherit)); } if (obj is Module) { Module module = (Module)obj; if (attributeType == null) { return(Attribute.GetCustomAttributes(module, inherit)); } return(Attribute.GetCustomAttributes(module, attributeType, inherit)); } if (obj is ParameterInfo) { ParameterInfo parameterInfo = (ParameterInfo)obj; if (attributeType == null) { return(Attribute.GetCustomAttributes(parameterInfo, inherit)); } return(Attribute.GetCustomAttributes(parameterInfo, attributeType, inherit)); } ICustomAttributeProvider customAttributeProvider = (ICustomAttributeProvider)attributeProvider; return((Attribute[])((attributeType != null ? customAttributeProvider.GetCustomAttributes(attributeType, inherit) : customAttributeProvider.GetCustomAttributes(inherit)))); }
public static T[] GetAttributes <T>(ICustomAttributeProvider attributeProvider, bool inherit) where T : Attribute { Attribute[] attributes = ReflectionUtils.GetAttributes(attributeProvider, typeof(T), inherit); T[] tArray = attributes as T[]; T[] tArray1 = tArray; if (tArray != null) { return(tArray1); } return(attributes.Cast <T>().ToArray <T>()); }
// Token: 0x06000E31 RID: 3633 RVA: 0x00051EDC File Offset: 0x000500DC public static bool IsByRefLikeType(Type type) { if (!type.IsValueType()) { return(false); } Attribute[] attributes = ReflectionUtils.GetAttributes(type, null, false); for (int i = 0; i < attributes.Length; i++) { if (string.Equals(attributes[i].GetType().FullName, "System.Runtime.CompilerServices.IsByRefLikeAttribute", StringComparison.Ordinal)) { return(true); } } return(false); }
public static T GetAttribute <T>(ICustomAttributeProvider attributeProvider, bool inherit) where T : Attribute { return(CollectionUtils.GetSingleItem <T>(ReflectionUtils.GetAttributes <T>(attributeProvider, inherit), true)); }
public static T GetAttribute <T>(ICustomAttributeProvider attributeProvider, bool inherit) where T : Attribute { return(Enumerable.SingleOrDefault <T>((IEnumerable <T>)ReflectionUtils.GetAttributes <T>(attributeProvider, inherit))); }
public static Attribute[] GetAttributes( object attributeProvider, Type attributeType, bool inherit) { ValidationUtils.ArgumentNotNull(attributeProvider, nameof(attributeProvider)); object obj = attributeProvider; switch (obj) { case Type _: Type type = (Type)obj; Attribute[] array = (attributeType != null ? (IEnumerable)type.GetCustomAttributes(attributeType, inherit) : (IEnumerable)type.GetCustomAttributes(inherit)).Cast <Attribute>().ToArray <Attribute>(); if (inherit && type.BaseType != null) { array = ((IEnumerable <Attribute>)array).Union <Attribute>((IEnumerable <Attribute>)ReflectionUtils.GetAttributes((object)type.BaseType, attributeType, inherit)).ToArray <Attribute>(); } return(array); case Assembly _: Assembly element1 = (Assembly)obj; return(attributeType == null?Attribute.GetCustomAttributes(element1) : Attribute.GetCustomAttributes(element1, attributeType)); case MemberInfo _: MemberInfo element2 = (MemberInfo)obj; return(attributeType == null?Attribute.GetCustomAttributes(element2, inherit) : Attribute.GetCustomAttributes(element2, attributeType, inherit)); case Module _: Module element3 = (Module)obj; return(attributeType == null?Attribute.GetCustomAttributes(element3, inherit) : Attribute.GetCustomAttributes(element3, attributeType, inherit)); case ParameterInfo _: ParameterInfo element4 = (ParameterInfo)obj; return(attributeType == null?Attribute.GetCustomAttributes(element4, inherit) : Attribute.GetCustomAttributes(element4, attributeType, inherit)); default: ICustomAttributeProvider attributeProvider1 = (ICustomAttributeProvider)attributeProvider; return(attributeType != null ? (Attribute[])attributeProvider1.GetCustomAttributes(attributeType, inherit) : (Attribute[])attributeProvider1.GetCustomAttributes(inherit)); } }
public static T[] GetAttributes <T>(object attributeProvider, bool inherit) where T : Attribute { Attribute[] attributes = ReflectionUtils.GetAttributes(attributeProvider, typeof(T), inherit); return(attributes is T[] objArray ? objArray : attributes.Cast <T>().ToArray <T>()); }
public static T GetAttribute <T>(object attributeProvider, bool inherit) where T : Attribute { T[] attributes = ReflectionUtils.GetAttributes <T>(attributeProvider, inherit); return(attributes == null ? default(T) : ((IEnumerable <T>)attributes).FirstOrDefault <T>()); }