コード例 #1
0
        private static string TryFindDestinationPropertyName(Type entityType, Type dtoType, PropertyInfo propertyInfo)
        {
            var dtoPropertyName = PropertyNameMapper.GetDistinctDestinationPropertyName(entityType, dtoType, propertyInfo.Name);

            if (dtoPropertyName == null)
            {
                foreach (var subPropertyInfo in entityType.GetProperties())
                {
                    if (typeof(IAggregateRoot).IsAssignableFrom(subPropertyInfo.PropertyType) ||
                        typeof(IAggregateRoot).IsAssignableFrom(subPropertyInfo.PropertyType))
                    {
                        dtoPropertyName = TryFindDestinationPropertyName(entityType, dtoType, subPropertyInfo);
                    }
                    else
                    {
                        dtoPropertyName = PropertyNameMapper.GetDistinctDestinationPropertyName(entityType, dtoType, subPropertyInfo.Name);
                    }

                    if (dtoPropertyName != null)
                    {
                        break;
                    }
                }
            }

            return(dtoPropertyName);
        }
コード例 #2
0
        private static void MapRecursive(IMetadata metadata, Type entityType, Type dtoType, MetadataDto dtoMetadata)
        {
            dtoMetadata.AddMetadataItemRange(MapMetadataItems(metadata.MetadataItems));

            foreach (var propertyInfo in entityType.GetProperties())
            {
                if ((typeof(IAggregateRoot).IsAssignableFrom(propertyInfo.PropertyType) ||
                     typeof(IAggregateRoot).IsAssignableFrom(propertyInfo.PropertyType)) &&
                    metadata.HasChild(propertyInfo.PropertyType.FullName))
                {
                    var dtoPropertyName = TryFindDestinationPropertyName(entityType, dtoType, propertyInfo);
                    if (dtoPropertyName == null)
                    {
                        continue;
                    }

                    var dtoPropertyInfo = dtoType.GetProperty(dtoPropertyName);
                    if (typeof(IDataTransferObject).IsAssignableFrom(dtoPropertyInfo.PropertyType))
                    {
                        MapRecursive(
                            metadata.FindChildMetadata(propertyInfo.PropertyType.FullName),
                            propertyInfo.PropertyType,
                            dtoPropertyInfo.PropertyType,
                            dtoMetadata.GetChildMetadata(dtoPropertyInfo.PropertyType.FullName));
                    }
                    else
                    {
                        var subDtoPropertyMetadata = dtoMetadata.GetChildMetadata(dtoPropertyInfo.Name);
                        var subPropertyMetadata    = metadata.FindChildMetadata(propertyInfo.PropertyType.FullName);
                        subDtoPropertyMetadata.AddMetadataItemRange(
                            MapMetadataItems(subPropertyMetadata.MetadataItems));
                    }
                }
                else if (metadata.HasChild(propertyInfo.Name))
                {
                    var dtoPropertyName = PropertyNameMapper.GetDistinctDestinationPropertyName(entityType, dtoType, propertyInfo.Name);
                    if (dtoPropertyName == null)
                    {
                        continue;
                    }

                    var subDtoPropertyMetadata = dtoMetadata.GetChildMetadata(dtoPropertyName);
                    var subPropertyMetadata    = metadata.FindChildMetadata(propertyInfo.Name);
                    subDtoPropertyMetadata.AddMetadataItemRange(
                        MapMetadataItems(subPropertyMetadata.MetadataItems));
                }
            }
        }