Beispiel #1
0
        /// <summary>
        ///     Creates a list of Association fields for all the properties that use NakedObjects.
        /// </summary>


        private Tuple <IEnumerable <IAssociationSpecImmutable>, IImmutableDictionary <string, ITypeSpecBuilder> > CreateRefPropertySpecs(IEnumerable <PropertyInfo> foundProperties, IObjectSpecImmutable spec, IImmutableDictionary <string, ITypeSpecBuilder> metamodel)
        {
            var specs = new List <IAssociationSpecImmutable>();

            foreach (PropertyInfo property in foundProperties)
            {
                // create a reference property spec
                var  identifier   = new IdentifierImpl(FullName, property.Name);
                Type propertyType = property.PropertyType;
                var  result       = reflector.LoadSpecification(propertyType, metamodel);
                metamodel = result.Item2;
                var propertySpec = result.Item1;
                if (propertySpec is IServiceSpecImmutable)
                {
                    throw new ReflectionException(Log.LogAndReturn($"Type {propertyType.Name} is a service and cannot be used in public property {property.Name} on type {property.DeclaringType?.Name}. If the property is intended to be an injected service it should have a protected get."));
                }
                var referenceProperty = ImmutableSpecFactory.CreateOneToOneAssociationSpecImmutable(identifier, spec, propertySpec as IObjectSpecImmutable);

                // Process facets for the property
                metamodel = FacetFactorySet.Process(reflector, property, new IntrospectorMethodRemover(methods), referenceProperty, FeatureType.Properties, metamodel);
                specs.Add(referenceProperty);
            }

            return(new Tuple <IEnumerable <IAssociationSpecImmutable>, IImmutableDictionary <string, ITypeSpecBuilder> >(specs, metamodel));
        }
Beispiel #2
0
        /// <summary>
        ///     Creates a list of Association fields for all the properties that use NakedObjects.
        /// </summary>
        private IEnumerable <IAssociationSpecImmutable> CreateRefPropertySpecs(IEnumerable <PropertyInfo> foundProperties, IObjectSpecImmutable spec)
        {
            var specs = new List <IAssociationSpecImmutable>();

            foreach (PropertyInfo property in foundProperties)
            {
                Log.DebugFormat("Identified 1-1 association method {0}", property);
                Log.DebugFormat("One-to-One association {0} -> {1}", property.Name, property);

                // create a reference property spec
                var  identifier   = new IdentifierImpl(FullName, property.Name);
                Type propertyType = property.PropertyType;
                var  propertySpec = reflector.LoadSpecification(propertyType);
                if (propertySpec is IServiceSpecImmutable)
                {
                    throw new ReflectionException(string.Format(
                                                      "Type {0} is a service and cannot be used in public property {1} on type {2}." +
                                                      " If the property is intended to be an injected service it should have a protected get.",
                                                      propertyType.Name, property.Name, property.DeclaringType.Name
                                                      ));
                }
                var referenceProperty = ImmutableSpecFactory.CreateOneToOneAssociationSpecImmutable(identifier, spec, propertySpec as IObjectSpecImmutable);

                // Process facets for the property
                FacetFactorySet.Process(reflector, property, new IntrospectorMethodRemover(methods), referenceProperty, FeatureType.Properties);
                specs.Add(referenceProperty);
            }

            return(specs);
        }