public override void Process(IReflector reflector, Type type, IMethodRemover methodRemover, ISpecificationBuilder specification) { IFacet facet = null; if (!type.IsInterface && typeof (IViewModel).IsAssignableFrom(type)) { MethodInfo deriveMethod = type.GetMethod("DeriveKeys", new Type[] {}); MethodInfo populateMethod = type.GetMethod("PopulateUsingKeys", new[] {typeof (string[])}); var toRemove = new List<MethodInfo> {deriveMethod, populateMethod}; if (typeof (IViewModelEdit).IsAssignableFrom(type)) { facet = new ViewModelEditFacetConvention(specification); } else if (typeof (IViewModelSwitchable).IsAssignableFrom(type)) { MethodInfo isEditViewMethod = type.GetMethod("IsEditView"); toRemove.Add(isEditViewMethod); facet = new ViewModelSwitchableFacetConvention(specification); } else { facet = new ViewModelFacetConvention(specification); } methodRemover.RemoveMethods(toRemove.ToArray()); } FacetUtils.AddFacet(facet); }
public override void Process(IReflector reflector, MethodInfo method, IMethodRemover methodRemover, ISpecificationBuilder specification) { if ((method.ReturnType.IsPrimitive || TypeUtils.IsEnum(method.ReturnType)) && method.GetCustomAttribute<OptionallyAttribute>() != null) { Log.Warn("Ignoring Optionally annotation on primitive parameter on " + method.ReflectedType + "." + method.Name); return; } Process(method, specification); }
public override void Process(IReflector reflector, PropertyInfo method, IMethodRemover methodRemover, ISpecificationBuilder specification) { if (method.PropertyType.IsAssignableFrom(typeof(ContactType))) { FacetUtils.AddFacet(new NotNavigableFacet(specification)); } if (method.PropertyType.IsAssignableFrom(typeof(AddressType))) { FacetUtils.AddFacet(new NotNavigableFacet(specification)); } if (method.PropertyType.IsAssignableFrom(typeof(ContactType))) { FacetUtils.AddFacet(new NotNavigableFacet(specification)); } if (method.PropertyType.IsAssignableFrom(typeof(Culture))) { FacetUtils.AddFacet(new NotNavigableFacet(specification)); } if (method.PropertyType.IsAssignableFrom(typeof(SalesReason))) { FacetUtils.AddFacet(new NotNavigableFacet(specification)); } if (method.PropertyType.IsAssignableFrom(typeof(UnitMeasure))) { FacetUtils.AddFacet(new NotNavigableFacet(specification)); } if (method.PropertyType.IsAssignableFrom(typeof(ScrapReason))) { FacetUtils.AddFacet(new NotNavigableFacet(specification)); } if (method.PropertyType.IsAssignableFrom(typeof(ProductSubcategory))) { FacetUtils.AddFacet(new NotNavigableFacet(specification)); } if (method.PropertyType.IsAssignableFrom(typeof(ProductCategory))) { FacetUtils.AddFacet(new NotNavigableFacet(specification)); } }
public override void ProcessParams(IReflector reflector, MethodInfo method, int paramNum, ISpecificationBuilder holder) { ParameterInfo parameter = method.GetParameters()[paramNum]; if (TypeUtils.IsString(parameter.ParameterType)) { var attribute = parameter.GetCustomAttribute<MultiLineAttribute>(); FacetUtils.AddFacet(Create(attribute, holder)); } }
public override void Process(IReflector reflector, Type type, IMethodRemover methodRemover, ISpecificationBuilder spec) { var attr = type.GetCustomAttribute<NakedObjectsTypeAttribute>(); if (attr == null) { RemoveExplicitlyIgnoredMembers(type, methodRemover); } else { switch (attr.ReflectionScope) { case ReflectOver.All: RemoveExplicitlyIgnoredMembers(type, methodRemover); break; case ReflectOver.TypeOnlyNoMembers: foreach (MethodInfo method in type.GetMethods()) { methodRemover.RemoveMethod(method); } break; case ReflectOver.ExplicitlyIncludedMembersOnly: foreach (MethodInfo method in type.GetMethods()) { if (method.GetCustomAttribute<NakedObjectsIncludeAttribute>() == null) { methodRemover.RemoveMethod(method); } } break; case ReflectOver.None: throw new ReflectionException("Attempting to introspect a class that has been marked with NakedObjectsType with ReflectOver.None"); default: throw new ReflectionException(String.Format("Unhandled value for ReflectOver: {0}", attr.ReflectionScope)); } } }
public override void Process(IReflector reflector, Type type, IMethodRemover methodRemover, ISpecificationBuilder specification) { FacetUtils.AddFacets( new IFacet[] { new DescribedAsFacetNone(specification), new ImmutableFacetNever(specification), new TitleFacetNone(specification) }); }
public override void Process(IReflector reflector, PropertyInfo property, IMethodRemover methodRemover, ISpecificationBuilder specification) { if (CollectionUtils.IsCollectionButNotArray(property.PropertyType)) { specification.AddFacet(new CollectionResetFacet(property, specification)); } else { base.Process(reflector, property, methodRemover, specification); } }
public override void Process(IReflector reflector, Type type, IMethodRemover methodRemover, ISpecificationBuilder specification) { if (typeof (IEnumerable).IsAssignableFrom(type) && !TypeUtils.IsSystem(type)) { MethodInfo method = FindMethod(reflector, type, MethodType.Object, RecognisedMethodsAndPrefixes.GetEnumeratorMethod, null, Type.EmptyTypes); if (method != null) { methodRemover.RemoveMethod(method); } } }
public override void Process(IReflector reflector, Type type, IMethodRemover methodRemover, ISpecificationBuilder specification) { if (IsDynamicProxyType(type)) { foreach (MethodInfo method in type.GetMethods().Join(MethodsToRemove, mi => mi.Name, s => s, (mi, s) => mi)) { if (methodRemover != null && method != null) { methodRemover.RemoveMethod(method); } } } }
public override void ProcessParams(IReflector reflector, MethodInfo method, int paramNum, ISpecificationBuilder holder) { ParameterInfo parameter = method.GetParameters()[paramNum]; if (IsDatetimeOrNullableDateTime(parameter.ParameterType)) { var dataTypeAttribute = parameter.GetCustomAttribute<DataTypeAttribute>(); var concurrencyCheckAttribute = parameter.GetCustomAttribute<ConcurrencyCheckAttribute>(); FacetUtils.AddFacet(Create(dataTypeAttribute, concurrencyCheckAttribute, holder)); } }
public override void Process(IReflector reflector, PropertyInfo property, IMethodRemover methodRemover, ISpecificationBuilder specification) { if ((property.PropertyType.IsPrimitive || TypeUtils.IsEnum(property.PropertyType)) && property.GetCustomAttribute<OptionallyAttribute>() != null) { Log.Warn("Ignoring Optionally annotation on primitive or un-readable parameter on " + property.ReflectedType + "." + property.Name); return; } if (property.GetGetMethod() != null && !property.PropertyType.IsPrimitive) { Process(property, specification); } }
public override void Process(IReflector reflector, Type type, IMethodRemover methodRemover, ISpecificationBuilder specification) { Type currentType = type; while (currentType != null) { if (TypeUtils.IsSystem(currentType)) { ProcessSystemType(currentType, methodRemover, specification); } currentType = currentType.BaseType; } }
public override void Process(IReflector reflector, Type type, IMethodRemover methodRemover, ISpecificationBuilder specification) { if (typeof (Enum).IsAssignableFrom(type)) { Type semanticsProviderType = typeof (EnumValueSemanticsProvider<>).MakeGenericType(type); var spec = reflector.LoadSpecification<IObjectSpecImmutable>(type); object semanticsProvider = Activator.CreateInstance(semanticsProviderType, spec, specification); MethodInfo method = typeof (ValueUsingValueSemanticsProviderFacetFactory).GetMethod("AddValueFacets", BindingFlags.Static | BindingFlags.Public).MakeGenericMethod(type); method.Invoke(null, new[] {semanticsProvider, specification}); } }
public override void Process(IReflector reflector, Type type, IMethodRemover methodRemover, ISpecificationBuilder specification) { MethodInfo method = FindMethod(reflector, type, MethodType.Class, RecognisedMethodsAndPrefixes.MenuMethod, null, null); if (method != null) { RemoveMethod(methodRemover, method); FacetUtils.AddFacet(new MenuFacetViaMethod(method, specification)); } else { FacetUtils.AddFacet(new MenuFacetDefault(specification)); } }
public override void Process(IReflector reflector, Type type, IMethodRemover methodRemover, ISpecificationBuilder specification) { var facets = new List<IFacet> { new TypeIsAbstractFacet(specification, IsAbstract(type)), new TypeIsInterfaceFacet(specification, IsInterface(type)), new TypeIsSealedFacet(specification, IsSealed(type)), new TypeIsVoidFacet(specification, IsVoid(type)) }; FacetUtils.AddFacets(facets); }
public override void Process(IReflector reflector, Type type, IMethodRemover methodRemover, ISpecificationBuilder specification) { MethodInfo method = FindMethod(reflector, type, MethodType.Object, RecognisedMethodsAndPrefixes.IconNameMethod, typeof (string), Type.EmptyTypes); var attribute = type.GetCustomAttribute<IconNameAttribute>(); if (method != null) { RemoveMethod(methodRemover, method); FacetUtils.AddFacet(new IconFacetViaMethod(method, specification, attribute == null ? null : attribute.Value)); } else { FacetUtils.AddFacet(Create(attribute, specification)); } }
public override void ProcessParams(IReflector reflector, MethodInfo method, int paramNum, ISpecificationBuilder holder) { ParameterInfo parameter = method.GetParameters()[paramNum]; if (parameter.ParameterType.IsPrimitive || TypeUtils.IsEnum(parameter.ParameterType)) { if (method.GetCustomAttribute<OptionallyAttribute>() != null) { Log.Warn("Ignoring Optionally annotation on primitive parameter " + paramNum + " on " + method.ReflectedType + "." + method.Name); } return; } var attribute = parameter.GetCustomAttribute<OptionallyAttribute>(); FacetUtils.AddFacet(Create(attribute, holder)); }
public override void Process(IReflector reflector, Type type, IMethodRemover methodRemover, ISpecificationBuilder specification) { if (CollectionUtils.IsGenericEnumerable(type)) { ProcessGenericEnumerable(type, specification); } else if (type.IsArray) { ProcessArray(reflector, type, specification); } else if (CollectionUtils.IsCollectionButNotArray(type)) { ProcessCollection(reflector, specification); } }
public override void Process(IReflector reflector, MethodInfo method, IMethodRemover methodRemover, ISpecificationBuilder specification) { Type declaringType = method.DeclaringType; var classAttribute = declaringType.GetCustomAttribute<AuthorizeActionAttribute>(); var methodAttribute = method.GetCustomAttribute<AuthorizeActionAttribute>(); if (classAttribute != null && methodAttribute != null) { string declaringTypeName = declaringType == null ? "Unknown Type" : declaringType.FullName; Log.WarnFormat("Class and method level AuthorizeAttributes applied to class {0} - ignoring attribute on method {1}", declaringTypeName, method.Name); } Create(classAttribute ?? methodAttribute, specification); }
public override void Process(IReflector reflector, Type type, IMethodRemover methodRemover, ISpecificationBuilder specification) { try { foreach (string methodName in FixedPrefixes) { MethodInfo methodInfo = FindMethod(reflector, type, MethodType.Object, methodName, typeof (string), Type.EmptyTypes); if (methodInfo != null) { methodRemover.RemoveMethod(methodInfo); } } } catch (Exception e) { Log.Error("Unexpected exception", e); } }
public override void Process(IReflector reflector, PropertyInfo property, IMethodRemover methodRemover, ISpecificationBuilder specification) { Type declaringType = property.DeclaringType; var classAttribute = declaringType.GetCustomAttribute<AuthorizePropertyAttribute>(); var propertyAttribute = property.GetCustomAttribute<AuthorizePropertyAttribute>(); if (classAttribute != null && propertyAttribute != null) { string declaringTypeName = declaringType == null ? "Unknown Type" : declaringType.FullName; Log.WarnFormat("Class and property level AuthorizeAttributes applied to class {0} - ignoring attribute on property {1}", declaringTypeName, property.Name); } Create(classAttribute ?? propertyAttribute, 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); } }
public override void Process(IReflector reflector, PropertyInfo property, IMethodRemover methodRemover, ISpecificationBuilder collection) { string capitalizedName = property.Name; Type type = property.DeclaringType; var facets = new List<IFacet> {new PropertyAccessorFacet(property, collection)}; AddSetFacet(facets, property, collection); AddHideForSessionFacetNone(facets, collection); AddDisableFacetAlways(facets, collection); FindDefaultHideMethod(reflector, facets, methodRemover, property.DeclaringType, MethodType.Object, "PropertyDefault", collection); FindAndRemoveHideMethod(reflector, facets, methodRemover, type, MethodType.Object, capitalizedName, collection); FacetUtils.AddFacets(facets); }
public override void Process(IReflector reflector, MethodInfo actionMethod, IMethodRemover methodRemover, ISpecificationBuilder action) { string capitalizedName = NameUtils.CapitalizeName(actionMethod.Name); Type type = actionMethod.DeclaringType; var facets = new List<IFacet>(); ITypeSpecBuilder onType = reflector.LoadSpecification(type); var returnSpec = reflector.LoadSpecification<IObjectSpecBuilder>(actionMethod.ReturnType); IObjectSpecImmutable elementSpec = null; bool isQueryable = IsQueryOnly(actionMethod) || CollectionUtils.IsQueryable(actionMethod.ReturnType); if (returnSpec != null && returnSpec.IsCollection) { Type elementType = CollectionUtils.ElementType(actionMethod.ReturnType); elementSpec = reflector.LoadSpecification<IObjectSpecImmutable>(elementType); } RemoveMethod(methodRemover, actionMethod); facets.Add(new ActionInvocationFacetViaMethod(actionMethod, onType, returnSpec, elementSpec, action, isQueryable)); MethodType methodType = actionMethod.IsStatic ? MethodType.Class : MethodType.Object; Type[] paramTypes = actionMethod.GetParameters().Select(p => p.ParameterType).ToArray(); FindAndRemoveValidMethod(reflector, facets, methodRemover, type, methodType, capitalizedName, paramTypes, action); DefaultNamedFacet(facets, actionMethod.Name, action); // must be called after the checkForXxxPrefix methods AddHideForSessionFacetNone(facets, action); AddDisableForSessionFacetNone(facets, action); FindDefaultHideMethod(reflector, facets, methodRemover, type, methodType, "ActionDefault", action); FindAndRemoveHideMethod(reflector, facets, methodRemover, type, methodType, capitalizedName, action); FindDefaultDisableMethod(reflector, facets, methodRemover, type, methodType, "ActionDefault", action); FindAndRemoveDisableMethod(reflector, facets, methodRemover, type, methodType, capitalizedName, action); var actionSpecImmutable = action as IActionSpecImmutable; if (actionSpecImmutable != null) { // Process the action's parameters names, descriptions and optional // an alternative design would be to have another facet factory processing just ActionParameter, and have it remove these // supporting methods. However, the FacetFactory API doesn't allow for methods of the class to be removed while processing // action parameters, only while processing Methods (ie actions) IActionParameterSpecImmutable[] actionParameters = actionSpecImmutable.Parameters; string[] paramNames = actionMethod.GetParameters().Select(p => p.Name).ToArray(); FindAndRemoveParametersAutoCompleteMethod(reflector, methodRemover, type, capitalizedName, paramTypes, actionParameters); FindAndRemoveParametersChoicesMethod(reflector, methodRemover, type, capitalizedName, paramTypes, paramNames, actionParameters); FindAndRemoveParametersDefaultsMethod(reflector, methodRemover, type, capitalizedName, paramTypes, paramNames, actionParameters); FindAndRemoveParametersValidateMethod(reflector, methodRemover, type, capitalizedName, paramTypes, paramNames, actionParameters); } FacetUtils.AddFacets(facets); }
public override void Process(IReflector reflector, Type type, IMethodRemover methodRemover, ISpecificationBuilder specification) { var facets = new List<IFacet>(); var namedFacet = specification.GetFacet<INamedFacet>(); if (namedFacet == null) { namedFacet = new NamedFacetInferred(type.Name, specification); facets.Add(namedFacet); } var pluralFacet = specification.GetFacet<IPluralFacet>(); if (pluralFacet == null) { string pluralName = NameUtils.PluralName(namedFacet.NaturalName); pluralFacet = new PluralFacetInferred(pluralName, specification); facets.Add(pluralFacet); } FacetUtils.AddFacets(facets); }
public override void ProcessParams(IReflector reflector, MethodInfo method, int paramNum, ISpecificationBuilder holder) { var facets = new List<IFacet>(); var param = holder as IActionParameterSpecImmutable; if (param != null) { string name = method.GetParameters()[paramNum].Name ?? method.GetParameters()[paramNum].ParameterType.FullName; INamedFacet namedFacet = new NamedFacetInferred(name, holder); facets.Add(namedFacet); facets.Add(new DescribedAsFacetNone(holder)); facets.Add(new MultiLineFacetNone(holder)); facets.Add(new MaxLengthFacetZero(holder)); facets.Add(new TypicalLengthFacetZero(holder)); DefaultTypicalLength(facets, param.Specification, param); } FacetUtils.AddFacets(facets); }
public override void Process(IReflector reflector, Type type, IMethodRemover methodRemover, ISpecificationBuilder specification) { var methodPeers = new List<ValidateObjectFacet.NakedObjectValidationMethod>(); MethodInfo[] methods = FindMethods(reflector, type, MethodType.Object, RecognisedMethodsAndPrefixes.ValidatePrefix, typeof (string)); if (methods.Any()) { foreach (MethodInfo method in methods) { ParameterInfo[] parameters = method.GetParameters(); if (parameters.Length >= 2) { bool parametersMatch = parameters.Select(parameter => parameter.Name).Select(name => name[0].ToString(Thread.CurrentThread.CurrentCulture).ToUpper() + name.Substring(1)).All(p => ContainsField(p, type)); if (parametersMatch) { methodPeers.Add(new ValidateObjectFacet.NakedObjectValidationMethod(method)); methodRemover.RemoveMethod(method); } } } } IValidateObjectFacet validateFacet = methodPeers.Any() ? (IValidateObjectFacet) new ValidateObjectFacet(specification, methodPeers) : new ValidateObjectFacetNull(specification); FacetUtils.AddFacet(validateFacet); }
public override void Process(IReflector reflector, PropertyInfo property, IMethodRemover methodRemover, ISpecificationBuilder specification) { string capitalizedName = property.Name; var paramTypes = new[] {property.PropertyType}; var facets = new List<IFacet> {new PropertyAccessorFacet(property, specification)}; if (property.PropertyType.IsGenericType && (property.PropertyType.GetGenericTypeDefinition() == typeof (Nullable<>))) { facets.Add(new NullableFacetAlways(specification)); } if (property.GetSetMethod() != null) { if (property.PropertyType == typeof (byte[])) { facets.Add(new DisabledFacetAlways(specification)); } else { facets.Add(new PropertySetterFacetViaSetterMethod(property, specification)); } facets.Add(new PropertyInitializationFacet(property, specification)); } else { facets.Add(new NotPersistedFacet(specification)); facets.Add(new DisabledFacetAlways(specification)); } FindAndRemoveModifyMethod(reflector, facets, methodRemover, property.DeclaringType, capitalizedName, paramTypes, specification); FindAndRemoveClearMethod(reflector, facets, methodRemover, property.DeclaringType, capitalizedName, specification); FindAndRemoveAutoCompleteMethod(reflector, facets, methodRemover, property.DeclaringType, capitalizedName, property.PropertyType, specification); FindAndRemoveChoicesMethod(reflector, facets, methodRemover, property.DeclaringType, capitalizedName, property.PropertyType, specification); FindAndRemoveDefaultMethod(reflector, facets, methodRemover, property.DeclaringType, capitalizedName, property.PropertyType, specification); FindAndRemoveValidateMethod(reflector, facets, methodRemover, property.DeclaringType, paramTypes, capitalizedName, specification); AddHideForSessionFacetNone(facets, specification); AddDisableForSessionFacetNone(facets, specification); FindDefaultHideMethod(reflector, facets, methodRemover, property.DeclaringType, MethodType.Object, "PropertyDefault", specification); FindAndRemoveHideMethod(reflector, facets, methodRemover, property.DeclaringType, MethodType.Object, capitalizedName, specification); FindDefaultDisableMethod(reflector, facets, methodRemover, property.DeclaringType, MethodType.Object, "PropertyDefault", specification); FindAndRemoveDisableMethod(reflector, facets, methodRemover, property.DeclaringType, MethodType.Object, capitalizedName, specification); FacetUtils.AddFacets(facets); }
public override void Process(IReflector reflector, MethodInfo method, IMethodRemover methodRemover, ISpecificationBuilder specification) => Process(reflector, method.ReturnType, specification);
public override void Process(IReflector reflector, PropertyInfo property, IMethodRemover methodRemover, ISpecificationBuilder specification) { if (property.GetGetMethod() != null && TypeUtils.IsString(property.PropertyType)) { Process(property, specification); } }
public override ImmutableDictionary <string, ITypeSpecBuilder> Process(IReflector reflector, PropertyInfo property, IMethodRemover methodRemover, ISpecificationBuilder collection, ImmutableDictionary <string, ITypeSpecBuilder> metamodel) { string capitalizedName = property.Name; Type type = property.DeclaringType; var facets = new List <IFacet> { new PropertyAccessorFacet(property, collection) }; AddSetFacet(facets, property, collection); AddHideForSessionFacetNone(facets, collection); AddDisableFacetAlways(facets, collection); FindDefaultHideMethod(reflector, facets, methodRemover, property.DeclaringType, MethodType.Object, "PropertyDefault", collection); FindAndRemoveHideMethod(reflector, facets, methodRemover, type, MethodType.Object, capitalizedName, collection); FacetUtils.AddFacets(facets); return(metamodel); }
public override IImmutableDictionary <string, ITypeSpecBuilder> Process(IReflector reflector, PropertyInfo property, ISpecificationBuilder specification, IImmutableDictionary <string, ITypeSpecBuilder> metamodel) => property.HasPublicGetter() ? Process(reflector, property.PropertyType, specification, metamodel) : metamodel;
public override void Process(IReflector reflector, Type type, IMethodRemover methodRemover, ISpecificationBuilder specification) { var attribute = type.GetCustomAttribute <ImmutableAttribute>(); FacetUtils.AddFacet(Create(attribute, specification)); }
public override void ProcessParams(IReflector reflector, MethodInfo method, int paramNum, ISpecificationBuilder holder) { ParameterInfo parameter = method.GetParameters()[paramNum]; var facets = new List <IFacet>(); if (parameter.ParameterType.IsGenericType && (parameter.ParameterType.GetGenericTypeDefinition() == typeof(Nullable <>))) { facets.Add(new NullableFacetAlways(holder)); } var returnSpec = reflector.LoadSpecification <IObjectSpecBuilder>(parameter.ParameterType); if (returnSpec != null && returnSpec.IsCollection) { Type elementType = CollectionUtils.ElementType(parameter.ParameterType); var elementSpec = reflector.LoadSpecification <IObjectSpecImmutable>(elementType); facets.Add(new ElementTypeFacet(holder, elementType, elementSpec)); } FacetUtils.AddFacets(facets); }
public override IImmutableDictionary <string, ITypeSpecBuilder> Process(IReflector reflector, PropertyInfo property, IMethodRemover methodRemover, ISpecificationBuilder specification, IImmutableDictionary <string, ITypeSpecBuilder> metamodel) => property.GetGetMethod() != null ? Process(reflector, property.PropertyType, specification, metamodel) : metamodel;
public IImmutableDictionary <string, ITypeSpecBuilder> Process(IReflector reflector, Type type, IMethodRemover methodRemover, ISpecificationBuilder specification, IImmutableDictionary <string, ITypeSpecBuilder> metamodel) { if (type.IsInterface) { foreach (var facetFactory in GetFactoryByFeatureType(FeatureType.Interfaces)) { metamodel = facetFactory.Process(reflector, type, specification, metamodel); } } else { foreach (var facetFactory in GetFactoryByFeatureType(FeatureType.Objects)) { metamodel = facetFactory.Process(reflector, type, specification, metamodel); } } return(metamodel); }
public override void Process(IReflector reflector, PropertyInfo property, IMethodRemover methodRemover, ISpecificationBuilder specification) { Process(property, specification); }
public override IImmutableDictionary <string, ITypeSpecBuilder> Process(IReflector reflector, Type type, IMethodRemover methodRemover, ISpecificationBuilder specification, IImmutableDictionary <string, ITypeSpecBuilder> metamodel) { if (StringValueSemanticsProvider.IsAdaptedType(type)) { var result = reflector.LoadSpecification(StringValueSemanticsProvider.AdaptedType, metamodel); metamodel = result.Item2; var spec = result.Item1 as IObjectSpecImmutable; AddValueFacets(new StringValueSemanticsProvider(spec, specification), specification); } return(metamodel); }
public IImmutableDictionary <string, ITypeSpecBuilder> Process(IReflector reflector, PropertyInfo property, IMethodRemover methodRemover, ISpecificationBuilder specification, FeatureType featureType, IImmutableDictionary <string, ITypeSpecBuilder> metamodel) { foreach (var facetFactory in GetFactoryByFeatureType(featureType)) { metamodel = facetFactory.Process(reflector, property, specification, metamodel); } return(metamodel); }
public override IImmutableDictionary <string, ITypeSpecBuilder> Process(IReflector reflector, PropertyInfo property, IMethodRemover methodRemover, ISpecificationBuilder specification, IImmutableDictionary <string, ITypeSpecBuilder> metamodel) { Process(specification); return(metamodel); }
public override IImmutableDictionary <string, ITypeSpecBuilder> ProcessParams(IReflector reflector, MethodInfo method, int paramNum, ISpecificationBuilder holder, IImmutableDictionary <string, ITypeSpecBuilder> metamodel) { var facets = new List <IFacet>(); var param = holder as IActionParameterSpecImmutable; if (param != null) { string name = method.GetParameters()[paramNum].Name ?? method.GetParameters()[paramNum].ParameterType.FullName; INamedFacet namedFacet = new NamedFacetInferred(name, holder); facets.Add(namedFacet); facets.Add(new DescribedAsFacetNone(holder)); facets.Add(new MultiLineFacetNone(holder)); facets.Add(new MaxLengthFacetZero(holder)); facets.Add(new TypicalLengthFacetZero(holder)); DefaultTypicalLength(facets, param.Specification, param); } FacetUtils.AddFacets(facets); return(metamodel); }
public override void Process(IReflector reflector, MethodInfo actionMethod, IMethodRemover methodRemover, ISpecificationBuilder action) { string capitalizedName = NameUtils.CapitalizeName(actionMethod.Name); Type type = actionMethod.DeclaringType; var facets = new List <IFacet>(); ITypeSpecBuilder onType = reflector.LoadSpecification(type); var returnSpec = reflector.LoadSpecification <IObjectSpecBuilder>(actionMethod.ReturnType); IObjectSpecImmutable elementSpec = null; bool isQueryable = IsQueryOnly(actionMethod) || CollectionUtils.IsQueryable(actionMethod.ReturnType); if (returnSpec != null && returnSpec.IsCollection) { Type elementType = CollectionUtils.ElementType(actionMethod.ReturnType); elementSpec = reflector.LoadSpecification <IObjectSpecImmutable>(elementType); } RemoveMethod(methodRemover, actionMethod); facets.Add(new ActionInvocationFacetViaMethod(actionMethod, onType, returnSpec, elementSpec, action, isQueryable)); MethodType methodType = actionMethod.IsStatic ? MethodType.Class : MethodType.Object; Type[] paramTypes = actionMethod.GetParameters().Select(p => p.ParameterType).ToArray(); FindAndRemoveValidMethod(reflector, facets, methodRemover, type, methodType, capitalizedName, paramTypes, action); DefaultNamedFacet(facets, actionMethod.Name, action); // must be called after the checkForXxxPrefix methods AddHideForSessionFacetNone(facets, action); AddDisableForSessionFacetNone(facets, action); FindDefaultHideMethod(reflector, facets, methodRemover, type, methodType, "ActionDefault", action); FindAndRemoveHideMethod(reflector, facets, methodRemover, type, methodType, capitalizedName, action); FindDefaultDisableMethod(reflector, facets, methodRemover, type, methodType, "ActionDefault", action); FindAndRemoveDisableMethod(reflector, facets, methodRemover, type, methodType, capitalizedName, action); var actionSpecImmutable = action as IActionSpecImmutable; if (actionSpecImmutable != null) { // Process the action's parameters names, descriptions and optional // an alternative design would be to have another facet factory processing just ActionParameter, and have it remove these // supporting methods. However, the FacetFactory API doesn't allow for methods of the class to be removed while processing // action parameters, only while processing Methods (ie actions) IActionParameterSpecImmutable[] actionParameters = actionSpecImmutable.Parameters; string[] paramNames = actionMethod.GetParameters().Select(p => p.Name).ToArray(); FindAndRemoveParametersAutoCompleteMethod(reflector, methodRemover, type, capitalizedName, paramTypes, actionParameters); FindAndRemoveParametersChoicesMethod(reflector, methodRemover, type, capitalizedName, paramTypes, paramNames, actionParameters); FindAndRemoveParametersDefaultsMethod(reflector, methodRemover, type, capitalizedName, paramTypes, paramNames, actionParameters); FindAndRemoveParametersValidateMethod(reflector, methodRemover, type, capitalizedName, paramTypes, paramNames, actionParameters); } FacetUtils.AddFacets(facets); }
public override IImmutableDictionary <string, ITypeSpecBuilder> Process(IReflector reflector, MethodInfo method, IMethodRemover methodRemover, ISpecificationBuilder specification, IImmutableDictionary <string, ITypeSpecBuilder> metamodel) { var attribute = method.GetCustomAttribute <EagerlyAttribute>(); FacetUtils.AddFacet(Create(attribute, specification)); return(metamodel); }
/// <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.Error("Unexpected Exception", e); } }
public override void Process(IReflector reflector, Type type, IMethodRemover methodRemover, ISpecificationBuilder specification) { var facets = new List <IFacet>(); var namedFacet = specification.GetFacet <INamedFacet>(); if (namedFacet == null) { string inferredName = NameUtils.NaturalName(ShortName(type)); namedFacet = new NamedFacetInferred(inferredName, specification); facets.Add(namedFacet); Log.InfoFormat("No name facet found inferring name {0}", inferredName); } var pluralFacet = specification.GetFacet <IPluralFacet>(); if (pluralFacet == null) { string pluralName = NameUtils.PluralName(namedFacet.Value); pluralFacet = new PluralFacetInferred(pluralName, specification); facets.Add(pluralFacet); Log.InfoFormat("No plural facet found inferring name {0}", pluralName); } FacetUtils.AddFacets(facets); }
public virtual void ProcessParams(IReflector reflector, MethodInfo method, int paramNum, ISpecificationBuilder holder) {}
public override void Process(IReflector reflector, Type type, IMethodRemover methodRemover, ISpecificationBuilder specification) => FindAndRemoveEventHandlerMethods(type, methodRemover);
public override void Process(IReflector reflector, MethodInfo method, IMethodRemover methodRemover, ISpecificationBuilder specification) { if (TypeUtils.IsString(method.ReturnType)) { Process(method, specification); } }
public override void Process(IReflector reflector, Type type, IMethodRemover methodRemover, ISpecificationBuilder specification) { if (FileAttachmentValueSemanticsProvider.IsAdaptedType(type)) { IObjectSpecBuilder spec = reflector.LoadSpecification(FileAttachmentValueSemanticsProvider.AdaptedType); AddValueFacets(new FileAttachmentValueSemanticsProvider(spec, specification), specification); } }
public override IImmutableDictionary <string, ITypeSpecBuilder> Process(IReflector reflector, Type type, IMethodRemover methodRemover, ISpecificationBuilder specification, IImmutableDictionary <string, ITypeSpecBuilder> metamodel) { var facets = new List <IFacet> { new TypeIsAbstractFacet(specification, IsAbstract(type)), new TypeIsInterfaceFacet(specification, IsInterface(type)), new TypeIsSealedFacet(specification, IsSealed(type)), new TypeIsVoidFacet(specification, IsVoid(type)) }; FacetUtils.AddFacets(facets); return(metamodel); }
public override void ProcessParams(IReflector reflector, MethodInfo method, int paramNum, ISpecificationBuilder holder) { ParameterInfo parameter = method.GetParameters()[paramNum]; if (TypeUtils.IsString(parameter.ParameterType)) { var attribute = parameter.GetCustomAttribute <MultiLineAttribute>(); FacetUtils.AddFacet(Create(attribute, holder)); } }
public override IImmutableDictionary <string, ITypeSpecBuilder> Process(IReflector reflector, Type type, IMethodRemover methodRemover, ISpecificationBuilder specification, IImmutableDictionary <string, ITypeSpecBuilder> metamodel) { FacetUtils.AddFacets( new IFacet[] { new DescribedAsFacetNone(specification), new ImmutableFacetNever(specification), new TitleFacetNone(specification) }); return(metamodel); }
public override void Process(IReflector reflector, MethodInfo method, IMethodRemover methodRemover, ISpecificationBuilder specification) { Process(method, specification); }
public override void Process(IReflector reflector, PropertyInfo property, IMethodRemover methodRemover, ISpecificationBuilder specification) { if (property.GetGetMethod() != null) { Process(reflector, property.PropertyType, specification); } }
public override void Process(IReflector reflector, Type type, IMethodRemover methodRemover, ISpecificationBuilder specification) { IFacet facet = null; if (!type.IsInterface && typeof(IViewModel).IsAssignableFrom(type)) { var deriveMethod = type.GetMethod("DeriveKeys", new Type[] { }); var populateMethod = type.GetMethod("PopulateUsingKeys", new[] { typeof(string[]) }); var toRemove = new List <MethodInfo> { deriveMethod, populateMethod }; if (typeof(IViewModelEdit).IsAssignableFrom(type)) { facet = new ViewModelEditFacetConvention(specification); } else if (typeof(IViewModelSwitchable).IsAssignableFrom(type)) { var isEditViewMethod = type.GetMethod("IsEditView"); toRemove.Add(isEditViewMethod); facet = new ViewModelSwitchableFacetConvention(specification); } else { facet = new ViewModelFacetConvention(specification); } methodRemover.RemoveMethods(toRemove.ToArray()); } FacetUtils.AddFacet(facet); }
public override IImmutableDictionary <string, ITypeSpecBuilder> ProcessParams(IReflector reflector, MethodInfo method, int paramNum, ISpecificationBuilder holder, IImmutableDictionary <string, ITypeSpecBuilder> metamodel) { var parameter = method.GetParameters()[paramNum]; var dataTypeAttribute = parameter.GetCustomAttribute <DataTypeAttribute>(); FacetUtils.AddFacet(Create(dataTypeAttribute, holder)); return(metamodel); }
public override void ProcessParams(IReflector reflector, MethodInfo method, int paramNum, ISpecificationBuilder holder) { ParameterInfo parameter = method.GetParameters()[paramNum]; var attribute = parameter.GetCustomAttribute <TypicalLengthAttribute>(); FacetUtils.AddFacet(Create(attribute, holder)); }
public IImmutableDictionary <string, ITypeSpecBuilder> ProcessParams(IReflector reflector, MethodInfo method, int paramNum, ISpecificationBuilder specification, IImmutableDictionary <string, ITypeSpecBuilder> metamodel) { foreach (var facetFactory in GetFactoryByFeatureType(FeatureType.ActionParameters)) { metamodel = facetFactory.ProcessParams(reflector, method, paramNum, specification, metamodel); } return(metamodel); }
public override void Process(IReflector reflector, Type type, IMethodRemover methodRemover, ISpecificationBuilder specification) { if (BooleanValueSemanticsProvider.IsAdaptedType(type)) { var spec = reflector.LoadSpecification<IObjectSpecImmutable>(BooleanValueSemanticsProvider.AdaptedType); AddValueFacets(new BooleanValueSemanticsProvider(spec, specification), specification); } }
public override IImmutableDictionary <string, ITypeSpecBuilder> Process(IReflector reflector, MethodInfo method, IMethodRemover methodRemover, ISpecificationBuilder specification, IImmutableDictionary <string, ITypeSpecBuilder> metamodel) => Process(reflector, method.ReturnType, specification, metamodel);