public static void AssertSpec(Type type, ITypeSpecBuilder spec) { Assert.AreEqual(new IdentifierImpl(type.FullName), spec.Identifier); Assert.AreEqual(type.FullName, spec.FullName); Assert.AreEqual(TypeNameUtils.GetShortName(type.Name), spec.ShortName); Assert.AreEqual(type, spec.Type); }
private ITypeSpecBuilder GetPlaceholder(Type type, ImmutableDictionary <string, ITypeSpecBuilder> metamodel) { ITypeSpecBuilder specification = CreateSpecification(type, metamodel); if (specification == null) { throw new ReflectionException(Log.LogAndReturn($"unrecognised type {type.FullName}")); } return(specification); }
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); }
private Tuple <ITypeSpecBuilder, ImmutableDictionary <string, ITypeSpecBuilder> > LoadSpecificationAndCache(Type type, ImmutableDictionary <string, ITypeSpecBuilder> metamodel) { ITypeSpecBuilder specification = metamodel[ClassStrategy.GetKeyForType(type)]; if (specification == null) { throw new ReflectionException(Log.LogAndReturn($"unrecognised type {type.FullName}")); } metamodel = specification.Introspect(facetDecoratorSet, new Introspector(this), metamodel); return(new Tuple <ITypeSpecBuilder, ImmutableDictionary <string, ITypeSpecBuilder> >(specification, metamodel)); }
private Tuple <ITypeSpecBuilder, ImmutableDictionary <string, ITypeSpecBuilder> > LoadPlaceholder(Type type, ImmutableDictionary <string, ITypeSpecBuilder> metamodel) { ITypeSpecBuilder specification = CreateSpecification(type, metamodel); if (specification == null) { throw new ReflectionException(Log.LogAndReturn($"unrecognised type {type.FullName}")); } metamodel = metamodel.Add(ClassStrategy.GetKeyForType(type), specification); return(new Tuple <ITypeSpecBuilder, ImmutableDictionary <string, ITypeSpecBuilder> >(specification, metamodel)); }
public IImmutableDictionary <string, ITypeSpecBuilder> IntrospectType(Type typeToIntrospect, ITypeSpecImmutable spec, IImmutableDictionary <string, ITypeSpecBuilder> metamodel) { if (!TypeUtils.IsPublic(typeToIntrospect)) { throw new ReflectionException(Log.LogAndReturn(string.Format(Resources.NakedObjects.DomainClassReflectionError, typeToIntrospect))); } IntrospectedType = typeToIntrospect; SpecificationType = GetSpecificationType(typeToIntrospect); properties = typeToIntrospect.GetProperties(); methods = GetNonPropertyMethods(); identifier = new IdentifierImpl(FullName); // Process facets at object level // this will also remove some methods, such as the superclass methods. var methodRemover = new IntrospectorMethodRemover(methods); metamodel = FacetFactorySet.Process(reflector, IntrospectedType, methodRemover, spec, metamodel); if (SuperclassType != null && ClassStrategy.IsTypeToBeIntrospected(SuperclassType)) { var result = reflector.LoadSpecification(SuperclassType, metamodel); metamodel = result.Item2; Superclass = result.Item1; } AddAsSubclass(spec); var interfaces = new List <ITypeSpecBuilder>(); foreach (Type interfaceType in InterfacesTypes) { if (interfaceType != null && ClassStrategy.IsTypeToBeIntrospected(interfaceType)) { var result = reflector.LoadSpecification(interfaceType, metamodel); metamodel = result.Item2; var interfaceSpec = result.Item1; interfaceSpec.AddSubclass(spec); interfaces.Add(interfaceSpec); } } Interfaces = interfaces.ToArray(); metamodel = IntrospectPropertiesAndCollections(spec, metamodel); metamodel = IntrospectActions(spec, metamodel); return(metamodel); }
private void PopulateContributedFunctions(ITypeSpecBuilder spec, ITypeSpecImmutable[] functions, IMetamodel metamodel) { var result = functions.AsParallel().SelectMany(functionsSpec => { var serviceActions = functionsSpec.ObjectActions.Where(sa => sa != null).ToArray(); var matchingActionsForObject = new List <IActionSpecImmutable>(); foreach (var sa in serviceActions) { if (IsContributedFunction(sa, spec)) { matchingActionsForObject.Add(sa); } } return(matchingActionsForObject); }).ToList(); spec.AddContributedFunctions(result); }
public void IntrospectType(Type typeToIntrospect, ITypeSpecImmutable spec) { Log.InfoFormat("introspecting {0}: class-level details", typeToIntrospect.FullName); if (!TypeUtils.IsPublic(typeToIntrospect)) { throw new ReflectionException(string.Format(Resources.NakedObjects.DomainClassReflectionError, typeToIntrospect)); } IntrospectedType = typeToIntrospect; properties = typeToIntrospect.GetProperties(); methods = GetNonPropertyMethods(); // Process facets at object level // this will also remove some methods, such as the superclass methods. var methodRemover = new IntrospectorMethodRemover(methods); FacetFactorySet.Process(reflector, IntrospectedType, methodRemover, spec); if (SuperclassType != null && ClassStrategy.IsTypeToBeIntrospected(SuperclassType)) { Superclass = reflector.LoadSpecification(SuperclassType); } AddAsSubclass(spec); var interfaces = new List <ITypeSpecBuilder>(); foreach (Type interfaceType in InterfacesTypes) { if (interfaceType != null && ClassStrategy.IsTypeToBeIntrospected(interfaceType)) { var interfaceSpec = reflector.LoadSpecification(interfaceType); interfaceSpec.AddSubclass(spec); interfaces.Add(interfaceSpec); } } Interfaces = interfaces.ToArray(); IntrospectPropertiesAndCollections(spec); IntrospectActions(spec); }
private ITypeSpecBuilder LoadSpecificationAndCache(Type type) { Type actualType = classStrategy.GetType(type); if (actualType == null) { throw new ReflectionException(Log.LogAndReturn($"Attempting to introspect a non-introspectable type {type.FullName} ")); } ITypeSpecBuilder specification = CreateSpecification(actualType); if (specification == null) { throw new ReflectionException(Log.LogAndReturn($"unrecognised type {actualType.FullName}")); } // We need the specification available in cache even though not yet fully introspected metamodel.Add(actualType, specification); specification.Introspect(facetDecoratorSet, new Introspector(this)); return(specification); }
public void Add(Type type, ITypeSpecBuilder spec) => cache.Cache(classStrategy.GetKeyForType(type), spec);
public void Add(Type type, ITypeSpecBuilder spec) { cache.Cache(classStrategy.GetKeyForType(type), spec); }
public void Add(Type type, ITypeSpecBuilder spec) => cache.Cache(TypeKeyUtils.GetKeyForType(type), spec);