Example #1
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;
        }
Example #2
0
        internal ProjectionConstructor ImplementProjectionClass(ProjectionStructureType projectionType)
        {
            var typeBuilder = module.DefineType
            (
                GetProjectionClassName(projectionType.UnderlyingType),
                TypeAttributes.Public | TypeAttributes.Class |
                TypeAttributes.Sealed | TypeAttributes.Serializable
            );

            typeBuilder.SetParent(typeof(Projection));
            typeBuilder.AddInterfaceImplementation(projectionType.UnderlyingType);

            // TODO: Implement mixin attributes
            //AddDebuggerDisplayAttribute(typeBuilder);

            var constructor =
            ImplementConstructor  (typeBuilder);
            ImplementFactoryMethod(typeBuilder, constructor);
            ImplementTypeProperty (typeBuilder);

            var properties =
            CollectProjectionProperties  (projectionType. Properties);
            ImplementProjectionProperties(typeBuilder, properties);

            var projectionClass = typeBuilder.CreateType();

            InitializeTypeProperty        (projectionClass, projectionType);
            InitializeProjectionProperties(projectionClass, properties);

            return CreateFactoryDelegate(projectionClass);
        }