/// <summary> /// Creates a new instance of the attributed type resolver. /// </summary> /// <param name="types">An enumerable of attributed types.</param> /// <param name="inherit">A boolean flag to search the type's inheritance chain to find the attribute.</param> /// <returns>Returns a new instance of the attributed type resolver.</returns> public static AttributedTypeResolver <TAttribute> Create(IEnumerable <Type> types, bool inherit = false) { var resolver = new AttributedTypeResolver <TAttribute>(); resolver.Initialize(types, inherit); return(resolver); }
/// <summary> /// Tries to get the associated attribute for a given object type. /// </summary> /// <typeparam name="TAttribute"></typeparam> /// <param name="objectType">The object type.</param> /// <param name="attribute">The attribute.</param> /// <param name="inherit">A boolean flag to search the type's inheritance chain to find the attribute.</param> /// <returns>Returns the associated attribute for the given object-type.</returns> public static bool TryGetTypeAttribute <TAttribute>(Type objectType, out TAttribute attribute, bool inherit = false) where TAttribute : Attribute { if (AttributedTypeResolver <TAttribute> .HasCurrent == false) { AttributedTypeResolver <TAttribute> .Current = AttributedTypeResolver <TAttribute> .Create(new[] { objectType }, inherit); } return(AttributedTypeResolver <TAttribute> .Current.TryGetTypeAttribute(objectType, out attribute, inherit)); }