Ejemplo n.º 1
0
        internal ProjectionStructureType(Type type, ProjectionFactory factory)
            : base(type, TypeKind.Structure, factory)
        {
            // Ensure base types exist before self
            //   - Safe because no type can have itself as a base (i.e. no cycles)
            //   - Causes inits to be called in order from more-base to more-derived
            int basePropertyCount;
            baseTypes = CollectBaseTypes(type, out basePropertyCount);

            // Register self
            //   - Required before creating metaobjects that can refer back to this type
            factory.RegisterProjectionType(this);

            // Create members after registration
            //   - Members can be of any type and thus can form cycles
            properties = CollectProperties(type, basePropertyCount);
        }
Ejemplo n.º 2
0
        internal ProjectionProperty(PropertyInfo property, ProjectionStructureType declaringType,
            ProjectionPropertyCollection properties, ProjectionFactory factory, ITraitResolution resolution)
        {
            this.name          = property.Name;
            this.declaringType = declaringType;
            this.propertyType  = factory.GetProjectionTypeUnsafe(property.PropertyType);
            this.accessors     = new IPropertyAccessor[4]; // factory.Providers.Count

            var getter = property.GetGetMethod();
            var setter = property.GetSetMethod();
            if (getter != null) { getterHandle = getter.MethodHandle; flags |= Flags.CanRead;  }
            if (setter != null) { setterHandle = setter.MethodHandle; flags |= Flags.CanWrite; }

            var aggregator = new ProjectionPropertyTraitAggregator(this, properties);
            resolution.ProvidePropertyTraits(this, property, aggregator);

            this.aggregator = aggregator;
            this.overrides  = aggregator.Overrides;
        }
Ejemplo n.º 3
0
        private static ProjectionPropertyInfo[] CollectProjectionProperties(ProjectionPropertyCollection properties)
        {
            var infos = new ProjectionPropertyInfo[properties.Count];
            var index = 0;

            foreach (var property in properties)
            {
                infos[index++] = new ProjectionPropertyInfo
                {
                    Property  = property,
                    FieldName = GetPropertyFieldName(property, index)
                };
            }

            return infos;
        }
Ejemplo n.º 4
0
        private ProjectionPropertyCollection CollectProperties(Type type, int basePropertyCount)
        {
            var properties = type.GetProperties();
            var count      = properties.Length + basePropertyCount;
            if (count != 0)
            {
                var collection = new ProjectionPropertyCollection(count);

                CollectInheritedProperties(baseTypes,  collection);
                CollectDeclaredProperties (properties, collection); // MUST come after inherited

                return collection;
            }
            else
            {
                return ProjectionPropertyCollection.Empty;
            }
        }
Ejemplo n.º 5
0
        private void CollectDeclaredProperties(PropertyInfo[] properties, ProjectionPropertyCollection collection)
        {
            var factory    = Factory;
            var resolution = TraitResolution;

            foreach (var property in properties)
            {
                collection.Add(new ProjectionProperty(property, this, collection, factory, resolution), true);
            }
        }
Ejemplo n.º 6
0
 private static void CollectInheritedProperties(ProjectionTypeCollection baseTypes, ProjectionPropertyCollection collection)
 {
     foreach (var baseType in baseTypes)
     foreach (var property in baseType.Properties)
         collection.Add(property, false);
 }