static InjectableInfo CreateInjectableInfoForParam( Type parentType, ParameterInfo paramInfo) { var injectAttributes = paramInfo.AllAttributes <InjectAttribute>().ToList(); var injectOptionalAttributes = paramInfo.AllAttributes <InjectOptionalAttribute>().ToList(); string identifier = null; Assert.That(injectAttributes.IsEmpty() || injectOptionalAttributes.IsEmpty(), "Found both 'InjectOptional' and 'Inject' attributes on type parameter '{0}' of type '{1}'. Parameter should only have one or the other.", paramInfo.Name, parentType.Name()); if (injectAttributes.Any()) { identifier = injectAttributes.Single().Identifier; } else if (injectOptionalAttributes.Any()) { identifier = injectOptionalAttributes.Single().Identifier; } bool isOptionalWithADefaultValue = (paramInfo.Attributes & ParameterAttributes.HasDefault) == ParameterAttributes.HasDefault; return(new InjectableInfo( isOptionalWithADefaultValue || injectOptionalAttributes.Any(), identifier, paramInfo.Name, paramInfo.ParameterType, parentType, null, isOptionalWithADefaultValue ? paramInfo.DefaultValue : null)); }
static InjectableInfo CreateInjectableInfoForParam( Type parentType, ParameterInfo paramInfo) { var identifier = paramInfo.AllAttributes <InjectAttribute>().Select(x => x.Identifier) .Concat(paramInfo.AllAttributes <InjectOptionalAttribute>().Select(x => x.Identifier)).FirstOrDefault(); return(new InjectableInfo( paramInfo.HasAttribute(typeof(InjectOptionalAttribute)), identifier, paramInfo.Name, paramInfo.ParameterType, parentType, null)); }
static InjectableInfo CreateInjectableInfoForParam( Type parentType, ParameterInfo paramInfo) { var injectAttributes = paramInfo.AllAttributes <InjectAttributeBase>().ToList(); Assert.That(injectAttributes.Count <= 1, "Found multiple 'Inject' attributes on type parameter '{0}' of type '{1}'. Parameter should only have one", paramInfo.Name, parentType); var injectAttr = injectAttributes.SingleOrDefault(); object identifier = null; bool isOptional = false; InjectSources sourceType = InjectSources.Any; if (injectAttr != null) { identifier = injectAttr.Id; isOptional = injectAttr.Optional; sourceType = injectAttr.Source; } bool isOptionalWithADefaultValue = (paramInfo.Attributes & ParameterAttributes.HasDefault) == ParameterAttributes.HasDefault; return(new InjectableInfo( isOptionalWithADefaultValue || isOptional, identifier, paramInfo.Name, paramInfo.ParameterType, parentType, null, isOptionalWithADefaultValue ? paramInfo.DefaultValue : null, sourceType)); }
public static TAttribute FirstAttribute <TAttribute>(this ParameterInfo paramInfo) { #if NETFX_CORE var attrs = paramInfo.GetCustomAttributes <TAttribute>(inherit); return((TAttribute)(attrs.Count() > 0 ? attrs.ElementAt(0) : null)); #else return(paramInfo.AllAttributes <TAttribute>().FirstOrDefault()); #endif }
public MetadataPropertyType ToProperty(ParameterInfo pi) { var propertyAttrs = pi.AllAttributes(); var property = new MetadataPropertyType { Name = pi.Name, Attributes = ToAttributes(propertyAttrs), Type = pi.ParameterType.GetOperationName(), Description = pi.GetDescription(), }; return(property); }
public static MetadataPropertyType ToProperty(this ParameterInfo pi) { var propertyAttrs = pi.AllAttributes(); var property = new MetadataPropertyType { Name = pi.Name, Attributes = propertyAttrs.ToAttributes(), Type = pi.ParameterType.Name, Description = pi.GetDescription(), }; return(property); }
static InjectableInfo CreateForConstructorParam( Type enclosingType, ParameterInfo paramInfo) { var injectAttr = paramInfo.AllAttributes <InjectAttribute>().FirstOrDefault(); return(new InjectableInfo() { Optional = paramInfo.HasAttribute(typeof(InjectOptionalAttribute)), Identifier = (injectAttr == null ? null : injectAttr.Identifier), SourceName = paramInfo.Name, ContractType = paramInfo.ParameterType, EnclosingType = enclosingType, }); }
public MetadataPropertyType ToProperty(ParameterInfo pi) { var propertyAttrs = pi.AllAttributes(); var property = new MetadataPropertyType { Name = pi.Name, Attributes = ToAttributes(propertyAttrs), Type = pi.ParameterType.GetOperationName(), IsValueType = pi.ParameterType.IsValueType ? true : (bool?)null, TypeNamespace = pi.ParameterType.Namespace, Description = pi.GetDescription(), }; return(property); }
static InjectableInfo CreateInjectableInfoForParam(Type parentType, ParameterInfo paramInfo) { var injectAttributes = paramInfo.AllAttributes <InjectAttribute>().ToList(); var injectAttr = injectAttributes.SingleOrDefault(); object identifier = null; if (injectAttr != null) { identifier = injectAttr.Id; } return(new InjectableInfo( paramInfo.ParameterType, identifier, null, parentType)); }
public static TAttribute FirstAttribute <TAttribute>(this ParameterInfo paramInfo) { return(paramInfo.AllAttributes <TAttribute>().FirstOrDefault()); }
public static TAttr[] AllAttributes <TAttr>(this ParameterInfo pi) => pi.AllAttributes(typeof(TAttr)).Cast <TAttr>().ToArray();
public static IEnumerable <T> AllAttributes <T>( this ParameterInfo provider) where T : Attribute { return(provider.AllAttributes(typeof(T)).Cast <T>()); }
public static bool HasAttribute <T>(this ParameterInfo provider) where T : Attribute { return(provider.AllAttributes(typeof(T)).Any()); }
// We could avoid this duplication here by using ICustomAttributeProvider but this class // does not exist on the WP8 platform public static bool HasAttribute( this ParameterInfo provider, params Type[] attributeTypes) { return(provider.AllAttributes(attributeTypes).Any()); }
public static TAttribute FirstAttribute <TAttribute>(this ParameterInfo paramInfo) { return(((IEnumerable <TAttribute>)paramInfo.AllAttributes <TAttribute>()).FirstOrDefault <TAttribute>()); }
public static TAttr[] AllAttributes <TAttr>(this ParameterInfo pi) { return(pi.AllAttributes(typeof(TAttr)).Cast <TAttr>().ToArray <TAttr>()); }