/// <summary> /// Gets the <see href="Attribute"/>s associated with the enumeration given in <paramref name="provider"/>. /// The resulting list of attributes can optionally be filtered by suppliying a list of <paramref name="attributeTypes"/> /// to include. /// </summary> /// <returns>A list of the attributes found on the supplied source. This value will never be null.</returns> public static IList <Attribute> Attributes(this Enum provider, params Type[] attributeTypes) { Type type = provider.GetType(); MemberInfo info = type.Member(provider.ToString(), Flags.StaticAnyVisibility | Flags.DeclaredOnly); return(info.Attributes(attributeTypes)); }
/// <summary> /// Runs all preprocessor in chains, piping the output of this one with the next. /// The preprocessor with higher priority will run first /// </summary> /// <param name="prop">The prop.</param> /// <param name="valueString">The value string.</param> /// <returns></returns> private static string PreProcess(MemberInfo prop, string valueString) { var preProcessors = prop.Attributes <PreRetrievalProcessingAttribute>() .OrderBy(p => p.Priority); valueString = preProcessors.Aggregate ( valueString, (current, preProcessor) => { try { return(preProcessor.Process(current)); } catch (Exception) { if (!preProcessor.SuppressException) { throw; } return(current); } } ); return(valueString); }
/// <summary> /// <para>Returns a custom <see cref="Attribute"/>, identified by specified <see cref="Type"/>, that is applied to current <see cref="Type"/>'s member.</para> /// <para>Returns a <c>null</c> reference if attribute cannot be found.</para> /// </summary> /// <param name="self">Member of <see cref="Type"/>, whose attribute is to be returned.</param> /// <param name="attributeType">Type of custom attribute.</param> /// <returns>Instance of attribute, whose type equals to <paramref name="attributeType"/>.</returns> /// <exception cref="ArgumentNullException">If either <paramref name="self"/> or <paramref name="attributeType"/> is a <c>null</c> reference.</exception> /// <seealso cref="MemberInfo.GetCustomAttributes(Type, bool)"/> public static object Attribute(this MemberInfo self, Type attributeType) { Assertion.NotNull(self); Assertion.NotNull(attributeType); return(self.Attributes(attributeType).FirstOrDefault()); }
static private TInjectable AsInjectableBase <TInjectable>( MemberInfo memberInfo, Type memberType, IInjectionExpression injectionExpression, Func <IInjectionExpression, TInjectable> injectableFactory) { return(injectableFactory(injectionExpression ?? memberInfo.Attributes().ResolvableAttribute().GetInjectionScenario(memberType))); }
/// <summary> /// Run all the validation attributes. /// </summary> /// <param name="prop">The prop.</param> /// <param name="value">The value.</param> private static void ValidateValue(MemberInfo prop, object value) { foreach (var validator in prop.Attributes <ValidationAttribute>()) { if (!validator.IsValid(value)) { throw new ValidationException(validator.FormatErrorMessage(prop.Name)); } } }
private void ReflectUserMetadata(MemberInfo member, TypeDefinition typeDef) { foreach (var attr in member.Attributes <FlatBuffersMetadataAttribute>()) { if (!attr.HasValue) { typeDef.Metadata.Add(attr.Name, true); } else { typeDef.Metadata.Add(attr.Name, attr.Value, true); } } foreach (var attr in member.Attributes <FlatBuffersCommentAttribute>().OrderBy(i => i.Order)) { typeDef.AddComment(attr.Comment); } }
private void ProceedAttributes(MemberInfo member) { IList <Attribute> entityAttrs = member.Attributes(); foreach (var entityAttr in entityAttrs) { if (_actions.ContainsKey(entityAttr.GetType())) { _actions[entityAttr.GetType()](member, this); } } }
public static T Attribute <T>(this MemberInfo member) where T : Attribute { var attribute = member.Attributes <T>().SingleOrDefault(); if (attribute == null) { throw new NotImplementedException($"Single instance of {nameof(T)} is required."); } return(attribute); }
static private ResolvableInjectable <IResolvable <TResolvableValue>, TInjectable, TTarget, TResolvableValue, TInjectableValue> AsResolvableInjectableBase <TInjectable, TTarget, TResolvableValue, TInjectableValue>(MemberInfo memberInfo, Type defaultType, Func <IInjectionExpression, TInjectable> injectableFactory) where TInjectable : IInjectable <TTarget, TInjectableValue> where TResolvableValue : TInjectableValue { Attribute[] attributes = memberInfo.Attributes(); ResolvableAttributeBase resolvableAttribute = attributes.ResolvableAttribute(); IResolvable <TResolvableValue> resolvable = resolvableAttribute.GetResolvable <TResolvableValue>(defaultType, attributes); TInjectable injectable = injectableFactory(resolvableAttribute.GetInjectionScenario(defaultType)); return(new ResolvableInjectable <IResolvable <TResolvableValue>, TInjectable, TTarget, TResolvableValue, TInjectableValue>(resolvable, injectable)); }
/// <summary> /// <para>Returns a collection of all custom attributes, identified by specified <see cref="Type"/>, which are applied to current <see cref="Type"/>'s member.</para> /// </summary> /// <typeparam name="T">Type of custom attributes.</typeparam> /// <param name="self">Member of <see cref="Type"/>, whose attributes are to be returned.</param> /// <returns>Collection of custom attributes, whose type equals to <typeparamref name="T"/>.</returns> /// <exception cref="ArgumentNullException">If <paramref name="self"/> is a <c>null</c> reference.</exception> /// <seealso cref="MemberInfo.GetCustomAttributes(Type, bool)"/> public static IEnumerable <T> Attributes <T>(this MemberInfo self) { Assertion.NotNull(self); return(self.Attributes(typeof(T)).Cast <T>()); }
/// <summary> /// <para>Returns a custom <see cref="Attribute"/>, identified by specified <see cref="Type"/>, that is applied to current <see cref="Type"/>'s member.</para> /// <para>Returns a <c>null</c> reference if attribute cannot be found.</para> /// </summary> /// <typeparam name="T">Type of custom attribute.</typeparam> /// <param name="self">Member of <see cref="Type"/>, whose attribute is to be returned.</param> /// <returns>Instance of attribute, whose type equals to <typeparamref name="T"/>.</returns> /// <exception cref="ArgumentNullException">If <paramref name="self"/> is a <c>null</c> reference.</exception> /// <seealso cref="MemberInfo.GetCustomAttributes(Type, bool)"/> public static T Attribute <T>(this MemberInfo self) { Assertion.NotNull(self); return(self.Attributes <T>().FirstOrDefault()); }
static private IResolvable AsResolvableBase(MemberInfo memberInfo, Type memberType) { Attribute[] attributes = memberInfo.Attributes(); return(attributes.ResolvableAttribute().GetResolvable(memberType, attributes)); }