public DomainValueObjectMetadata Build()
        {
            var propertyDescriptors = Descriptor.PropertyDescriptors
                                      .Where(x => (Configuration == null || !Configuration.IgnoredMembers.Contains(x.Property.Name)) && x.Property.Name != "Parent");

            ValidateModel(propertyDescriptors);

            var properties = new List <DomainPropertyMetadata>();

            foreach (var prop in propertyDescriptors)
            {
                DomainPropertyMetadata propertyMetadata = null;
                var configuration = Configuration?.PropertyModelConfigurations.FirstOrDefault(x => x.Property.Name == prop.Property.Name);

                if (prop is ValuePropertyDescriptor valuePropertyDescriptor)
                {
                    propertyMetadata = new DomainValuePropertyMetadata(valuePropertyDescriptor, configuration, null);
                }
                else if (prop is ValueListPropertyDescriptor valueListPropertyDescriptor)
                {
                    propertyMetadata = new DomainValueListPropertyMetadata(valueListPropertyDescriptor, configuration);
                }
                else if (prop is AggregatePropertyDescriptor aggregatePropertyDescriptor)
                {
                    propertyMetadata = new DomainAggregatePropertyMetadata(aggregatePropertyDescriptor, configuration);
                }
                else if (prop is AggregateListPropertyDescriptor aggregateListPropertyDescriptor)
                {
                    propertyMetadata = new DomainAggregateListPropertyMetadata(aggregateListPropertyDescriptor, configuration);
                }
                else if (prop is UnsupportedPropertyDescriptor unsupportedPropertyDescriptor)
                {
                    throw new InvalidOperationException($"Unsupported property {prop.Property.Name} of Type {prop.Property.Type.Name} in Entity {Descriptor.Type.Name}");
                }

                properties.Add(propertyMetadata);
            }

            return(new DomainValueObjectMetadata(Descriptor.Type, properties));
        }
        public DomainEntityMetadata Build()
        {
            var propertyDescriptors = Descriptor.PropertyDescriptors
                                      .Where(x => (Configuration == null || !Configuration.IgnoredMembers.Contains(x.Property.Name)) && !x.Property.PropertyInfo.DeclaringType.IsFrameworkType());

            ValidateModel(propertyDescriptors);

            var properties = new List <DomainPropertyMetadata>();

            foreach (var prop in propertyDescriptors)
            {
                DomainPropertyMetadata propertyMetadata = null;
                var configuration = Configuration?.PropertyModelConfigurations.FirstOrDefault(x => x.Property.Name == prop.Property.Name);
                var keyPosition   = GetKeyPosition(prop);

                if (prop is ValuePropertyDescriptor valuePropertyDescriptor)
                {
                    propertyMetadata = new DomainValuePropertyMetadata(valuePropertyDescriptor, configuration, keyPosition >= 0 ? keyPosition : null);
                }
                else if (prop is ValueListPropertyDescriptor valueListPropertyDescriptor)
                {
                    propertyMetadata = new DomainValueListPropertyMetadata(valueListPropertyDescriptor, configuration);
                }
                else if (prop is AggregatePropertyDescriptor aggregatePropertyDescriptor)
                {
                    propertyMetadata = new DomainAggregatePropertyMetadata(aggregatePropertyDescriptor, configuration);
                }
                else if (prop is AggregateListPropertyDescriptor aggregateListPropertyDescriptor)
                {
                    propertyMetadata = new DomainAggregateListPropertyMetadata(aggregateListPropertyDescriptor, configuration);
                }

                properties.Add(propertyMetadata);
            }

            return(new DomainEntityMetadata(Descriptor.Type, properties, Configuration.IgnoredMembers));
        }