Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
        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));
        }
Exemplo n.º 3
0
        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));
        }
Exemplo n.º 4
0
        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));
        }
Exemplo n.º 5
0
        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));
        }
Exemplo n.º 6
0
        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));
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
 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());
 }