public override void Process(IReflector reflector, MethodInfo method, IMethodRemover methodRemover, ISpecificationBuilder specification) { var attribute = method.GetCustomAttribute <EagerlyAttribute>(); FacetUtils.AddFacet(Create(attribute, specification)); }
public override ImmutableDictionary <string, ITypeSpecBuilder> Process(IReflector reflector, MethodInfo method, IMethodRemover methodRemover, ISpecificationBuilder specification, ImmutableDictionary <string, ITypeSpecBuilder> metamodel) { FacetUtils.AddFacet(method.ReturnType.IsPrimitive ? CreateMandatory(specification) : CreateOptional(specification)); return(metamodel); }
public override ImmutableDictionary <string, ITypeSpecBuilder> Process(IReflector reflector, PropertyInfo property, IMethodRemover methodRemover, ISpecificationBuilder specification, ImmutableDictionary <string, ITypeSpecBuilder> metamodel) { FacetUtils.AddFacet(property.PropertyType.IsPrimitive || property.GetGetMethod() == null ? CreateMandatory(specification) : CreateOptional(specification)); return(metamodel); }
private static void Process(Func <Attribute> getHidden, Func <Attribute> getScaffold, ISpecification specification) { var attribute = getHidden(); FacetUtils.AddFacet(attribute != null ? Create((HiddenAttribute)attribute, specification) : Create((ScaffoldColumnAttribute)getScaffold(), specification)); }
public override void ProcessParams(IReflector reflector, MethodInfo method, int paramNum, ISpecificationBuilder holder) { FacetUtils.AddFacet(Create(holder)); }
public override void Process(IReflector reflector, MethodInfo method, IMethodRemover methodRemover, ISpecificationBuilder specification) { FacetUtils.AddFacet(method.ReturnType.IsPrimitive ? CreateMandatory(specification) : CreateOptional(specification)); }
public override void ProcessParams(IReflector reflector, MethodInfo method, int paramNum, ISpecificationBuilder holder) { ParameterInfo parameter = method.GetParameters()[paramNum]; FacetUtils.AddFacet(parameter.ParameterType.IsPrimitive ? CreateMandatory(holder) : CreateOptional(holder)); }
public override IImmutableDictionary <string, ITypeSpecBuilder> Process(IReflector reflector, MethodInfo method, IMethodRemover methodRemover, ISpecificationBuilder specification, IImmutableDictionary <string, ITypeSpecBuilder> metamodel) { FacetUtils.AddFacet(Create(specification)); return(metamodel); }
public override IImmutableDictionary <string, ITypeSpecBuilder> ProcessParams(IReflector reflector, MethodInfo method, int paramNum, ISpecificationBuilder holder, IImmutableDictionary <string, ITypeSpecBuilder> metamodel) { FacetUtils.AddFacet(Create(holder)); return(metamodel); }
public override void Process(IReflector reflector, Type type, IMethodRemover methodRemover, ISpecificationBuilder specification) { Attribute attribute = type.GetCustomAttribute <RegularExpressionAttribute>() ?? (Attribute)type.GetCustomAttribute <RegExAttribute>(); FacetUtils.AddFacet(Create(attribute, specification)); }
private static void Process(MemberInfo member, ISpecification holder) { Attribute attribute = member.GetCustomAttribute <RegularExpressionAttribute>() ?? (Attribute)member.GetCustomAttribute <RegExAttribute>(); FacetUtils.AddFacet(Create(attribute, holder)); }
private static void Process(MemberInfo member, bool isDate, ISpecification specification) { var attribute = member.GetCustomAttribute <RangeAttribute>(); FacetUtils.AddFacet(Create(attribute, isDate, specification)); }
private static void Process(HiddenAttribute attribute, ISpecification specification) => FacetUtils.AddFacet(Create(attribute, specification));
public override void Process(IReflector reflector, PropertyInfo property, IMethodRemover methodRemover, ISpecificationBuilder specification) { Attribute attribute = property.GetCustomAttribute <ConcurrencyCheckAttribute>(); FacetUtils.AddFacet(Create(reflector, attribute, specification)); }
private static void Process(MemberInfo member, ISpecification holder) { Attribute attribute = member.GetCustomAttribute <DescriptionAttribute>() ?? (Attribute)member.GetCustomAttribute <DescribedAsAttribute>(); FacetUtils.AddFacet(Create(attribute, holder)); }
public override void ProcessParams(IReflector reflector, MethodInfo method, int paramNum, ISpecificationBuilder holder) { ParameterInfo parameter = method.GetParameters()[paramNum]; var attribute = parameter.GetCustomAttribute<DataTypeAttribute>(); FacetUtils.AddFacet(Create(attribute, holder)); }
private static void AddFacetDerivedFromTypeIfPresent(ISpecification holder, Type type, IClassStrategy classStrategy) => FacetUtils.AddFacet(GetTypicalLengthFacet(type, holder, classStrategy));
public override void Process(IReflector reflector, Type type, IMethodRemover methodRemover, ISpecificationBuilder specification) { var attribute = type.GetCustomAttribute <TypicalLengthAttribute>(); FacetUtils.AddFacet(Create(attribute, specification)); }
public override void Process(IReflector reflector, PropertyInfo property, IMethodRemover methodRemover, ISpecificationBuilder specification) { FacetUtils.AddFacet(property.PropertyType.IsPrimitive || property.GetGetMethod() == null ? CreateMandatory(specification) : CreateOptional(specification)); }
/// <summary> /// If no title or ToString can be used then will use Facets provided by /// <see cref="FallbackFacetFactory" /> instead. /// </summary> public override void Process(IReflector reflector, Type type, IMethodRemover methodRemover, ISpecificationBuilder specification) { IList <MethodInfo> attributedMethods = new List <MethodInfo>(); foreach (PropertyInfo propertyInfo in type.GetProperties(BindingFlags.Public | BindingFlags.Instance)) { if (propertyInfo.GetCustomAttribute <TitleAttribute>() != null) { if (attributedMethods.Count > 0) { Log.Warn("Title annotation is used more than once in " + type.Name + ", this time on property " + propertyInfo.Name + "; this will be ignored"); } attributedMethods.Add(propertyInfo.GetGetMethod()); } } if (attributedMethods.Count > 0) { // attributes takes priority FacetUtils.AddFacet(new TitleFacetViaProperty(attributedMethods.First(), specification)); return; } try { MethodInfo titleMethod = FindMethod(reflector, type, MethodType.Object, RecognisedMethodsAndPrefixes.TitleMethod, typeof(string), Type.EmptyTypes); IFacet titleFacet = null; if (titleMethod != null) { methodRemover.RemoveMethod(titleMethod); titleFacet = new TitleFacetViaTitleMethod(titleMethod, specification); } MethodInfo toStringMethod = FindMethod(reflector, type, MethodType.Object, RecognisedMethodsAndPrefixes.ToStringMethod, typeof(string), Type.EmptyTypes); if (toStringMethod != null && !(toStringMethod.DeclaringType == typeof(object))) { methodRemover.RemoveMethod(toStringMethod); } else { // on object do not use toStringMethod = null; } MethodInfo maskMethod = FindMethod(reflector, type, MethodType.Object, RecognisedMethodsAndPrefixes.ToStringMethod, typeof(string), new[] { typeof(string) }); if (maskMethod != null) { methodRemover.RemoveMethod(maskMethod); } if (titleFacet == null && toStringMethod != null) { titleFacet = new TitleFacetViaToStringMethod(maskMethod, specification); } FacetUtils.AddFacet(titleFacet); } catch (Exception e) { Log.Warn("Unexpected Exception", e); } }
private static void Process(MemberInfo member, ISpecification holder) { Attribute attribute = member.GetCustomAttribute <StringLengthAttribute>() ?? (Attribute)member.GetCustomAttribute <MaxLengthAttribute>(); FacetUtils.AddFacet(Create(attribute, holder)); }
private IImmutableDictionary <string, ITypeSpecBuilder> FindAndRemoveParametersChoicesMethod(IReflector reflector, IMethodRemover methodRemover, Type type, string capitalizedName, Type[] paramTypes, string[] paramNames, IActionParameterSpecImmutable[] parameters, IImmutableDictionary <string, ITypeSpecBuilder> metamodel) { for (int i = 0; i < paramTypes.Length; i++) { Type paramType = paramTypes[i]; string paramName = paramNames[i]; bool isMultiple = false; if (CollectionUtils.IsGenericEnumerable(paramType)) { paramType = paramType.GetGenericArguments().First(); isMultiple = true; } Type returnType = typeof(IEnumerable <>).MakeGenericType(paramType); string methodName = RecognisedMethodsAndPrefixes.ParameterChoicesPrefix + i + capitalizedName; MethodInfo[] methods = FindMethods( reflector, type, MethodType.Object, methodName, returnType); if (methods.Length > 1) { methods.Skip(1).ForEach(m => Log.WarnFormat("Found multiple action choices methods: {0} in type: {1} ignoring method(s) with params: {2}", methodName, type, m.GetParameters().Select(p => p.Name).Aggregate("", (s, t) => s + " " + t))); } MethodInfo methodUsingIndex = methods.FirstOrDefault(); MethodInfo methodUsingName = FindMethod( reflector, type, MethodType.Object, RecognisedMethodsAndPrefixes.ParameterChoicesPrefix + capitalizedName, returnType, new[] { paramType }, new[] { paramName }); if (methodUsingIndex != null && methodUsingName != null) { Log.WarnFormat("Duplicate choices parameter methods {0} and {1} using {1}", methodUsingIndex.Name, methodUsingName.Name); } MethodInfo methodToUse = methodUsingName ?? methodUsingIndex; if (methodToUse != null) { // deliberately not removing both if duplicate to show that method is duplicate RemoveMethod(methodRemover, methodToUse); // add facets directly to parameters, not to actions var parameterNamesAndTypes = new List <Tuple <string, IObjectSpecImmutable> >(); //methodToUse.GetParameters(). // Select(p => new Tuple<string, IObjectSpecImmutable>(p.Name.ToLower(), reflector.LoadSpecification<IObjectSpecImmutable>(p.ParameterType, metamodel))).ToArray(); foreach (var p in methodToUse.GetParameters()) { var result = reflector.LoadSpecification(p.ParameterType, metamodel); metamodel = result.Item2; var spec = result.Item1 as IObjectSpecImmutable; var name = p.Name.ToLower(); parameterNamesAndTypes.Add(new Tuple <string, IObjectSpecImmutable>(name, spec)); } FacetUtils.AddFacet(new ActionChoicesFacetViaMethod(methodToUse, parameterNamesAndTypes.ToArray(), returnType, parameters[i], isMultiple)); AddOrAddToExecutedWhereFacet(methodToUse, parameters[i]); } } return(metamodel); }
private static void Process(MemberInfo member, ISpecification holder) { var attribute = member.GetCustomAttribute <MultiLineAttribute>(); FacetUtils.AddFacet(Create(attribute, holder)); }
public override void Process(IReflector reflector, MethodInfo method, IMethodRemover methodRemover, ISpecificationBuilder specification) { FacetUtils.AddFacet(Create(specification)); }