public (ITypeSpecBuilder, IImmutableDictionary <string, ITypeSpecBuilder>) LoadSpecification(Type type, IImmutableDictionary <string, ITypeSpecBuilder> metamodel) { if (type == null) { throw new NakedObjectSystemException("cannot load specification for null"); } var actualType = ClassStrategy.GetType(type) ?? type; var typeKey = ClassStrategy.GetKeyForType(actualType); return(!metamodel.ContainsKey(typeKey) ? LoadPlaceholder(actualType, metamodel) : (metamodel[typeKey], metamodel)); }
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 Tuple <ITypeSpecBuilder, ImmutableDictionary <string, ITypeSpecBuilder> > IntrospectSpecification(Type actualType, ImmutableDictionary <string, ITypeSpecBuilder> metamodel) { Assert.AssertNotNull(actualType); var typeKey = ClassStrategy.GetKeyForType(actualType); if (string.IsNullOrEmpty(metamodel[typeKey].FullName)) { return(LoadSpecificationAndCache(actualType, metamodel)); } return(new Tuple <ITypeSpecBuilder, ImmutableDictionary <string, ITypeSpecBuilder> >(metamodel[typeKey], metamodel)); }
public (ITypeSpecBuilder typeSpecBuilder, IImmutableDictionary <string, ITypeSpecBuilder> metamodel) IntrospectSpecification(Type actualType, IImmutableDictionary <string, ITypeSpecBuilder> metamodel, Func <IIntrospector> getIntrospector) { if (actualType == null) { throw new ReflectionException("cannot introspect null"); } var typeKey = ClassStrategy.GetKeyForType(actualType); return(string.IsNullOrEmpty(metamodel[typeKey].FullName) ? LoadSpecificationAndCache(actualType, metamodel, getIntrospector) : (metamodel[typeKey], metamodel)); }
public Tuple <ITypeSpecBuilder, ImmutableDictionary <string, ITypeSpecBuilder> > LoadSpecification(Type type, ImmutableDictionary <string, ITypeSpecBuilder> metamodel) { Assert.AssertNotNull(type); var actualType = ClassStrategy.GetType(type); var typeKey = ClassStrategy.GetKeyForType(actualType); if (!metamodel.ContainsKey(typeKey)) { return(LoadPlaceholder(actualType, metamodel)); } return(new Tuple <ITypeSpecBuilder, ImmutableDictionary <string, ITypeSpecBuilder> >(metamodel[typeKey], metamodel)); }
private (ITypeSpecBuilder, IImmutableDictionary <string, ITypeSpecBuilder>) LoadSpecificationAndCache(Type type, IImmutableDictionary <string, ITypeSpecBuilder> metamodel, Func <IIntrospector> getIntrospector) { var specification = metamodel[ClassStrategy.GetKeyForType(type)]; if (specification == null) { throw new ReflectionException(logger.LogAndReturn($"unrecognised type {type.FullName}")); } //metamodel = specification.Introspect(facetDecoratorSet, new Introspector(this, loggerFactory.CreateLogger<Introspector>()), metamodel); metamodel = specification.Introspect(facetDecoratorSet, getIntrospector(), metamodel); return(specification, metamodel); }
private Type GetSpecificationType(Type type) { var actualType = ClassStrategy.GetType(type); if (IsGenericEnumerableOrSet(type)) { return(type.GetGenericTypeDefinition()); } if (type.IsArray && !(type.GetElementType().IsValueType || type.GetElementType() == typeof(string))) { return(typeof(System.Array)); } return(actualType); }
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); }
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) { var actualType = ClassStrategy.GetType(type); if (actualType == null) { throw new ReflectionException(logger.LogAndReturn($"Attempting to introspect a non-introspectable type {type.FullName} ")); } var specification = CreateSpecification(actualType); if (specification == null) { throw new ReflectionException(logger.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, loggerFactory.CreateLogger <Introspector>())); return(specification); }
private ImmutableDictionary <string, ITypeSpecBuilder> GetPlaceholders(Type[] types) { return(types.Select(t => ClassStrategy.GetType(t)).Where(t => t != null).Distinct(new DR(ClassStrategy)).ToDictionary(t => ClassStrategy.GetKeyForType(t), t => GetPlaceholder(t, null)).ToImmutableDictionary()); }
private Type GetSpecificationType(Type type) => FasterTypeUtils.IsGenericCollection(type) ? type.GetGenericTypeDefinition() : FasterTypeUtils.IsObjectArray(type) ? typeof(Array) : ClassStrategy.GetType(type);