public object InheritedCollections(
            ResourceProfileData profileData,
            ResourceClassBase resource,
            TemplateContext templateContext)
        {
            if (resource.IsDescriptorEntity())
            {
                return(ResourceRenderer.DoRenderProperty);
            }

            string ns = profileData.GetProfileNamespace(resource);

            var activeResource = profileData.GetProfileActiveResource(resource);

            return(activeResource.IsDerived && activeResource.Collections.Any()
                ? new
            {
                Inherited =
                    activeResource.Collections
                    .Where(x => x.IsInherited)
                    .OrderBy(x => x.PropertyName)
                    .Select(
                        x => new
                {
                    BaseEntity =
                        $"{resource.Entity.BaseEntity.Name}.{resource.Entity.BaseEntity.SchemaProperCaseName()}",
                    BaseEntityInterfaceName = $"I{resource.Entity.BaseEntity.Name}",
                    ItemTypeNamespacePrefix = GetContextualNamespacePrefix(x.ItemType),
                    ItemType = x.ItemType.Name,
                    Collection = x.ItemType.PluralName,
                    PropertyName = x.PropertyName,
                    JsonPropertyName =
                        x.IsDerivedEntityATypeEntity()
                                            ? x.Association.OtherEntity.PluralName.ToCamelCase()
                                            : x.JsonPropertyName,
                    PropertyFieldName = x.ItemType.PluralName.ToCamelCase(),
                    ParentName = x.ParentFullName.Name,
                    PropertyNamespace = ns,
                    ResourceName = resource.Name,
                    Standard =
                        profileData.IsIncluded(resource, x) &&
                        !profileData.IsFilteredCollection(resource, x),
                    Null = !profileData.IsIncluded(resource, x),
                    Filtered = profileData.IsIncluded(resource, x) &&
                               profileData.IsFilteredCollection(
                        resource,
                        x)
                })
                    .ToList()
            }
                : ResourceRenderer.DoNotRenderProperty);
        }
Ejemplo n.º 2
0
        private object AssembleConstructor(ResourceProfileData profileData, ResourceClassBase resource)
        {
            string ns = profileData.GetProfileNamespace(resource);

            var activeResource = profileData.GetProfileActiveResource(resource);

            return(activeResource.Collections.Any()
                ? new
            {
                Inherited = resource.IsDerived && activeResource.Collections.Any(x => x.IsInherited)
                        ? ResourceRenderer.DoRenderProperty
                        : ResourceRenderer.DoNotRenderProperty,
                InheritedCollections = resource.Collections
                                       .Where(x => x.IsInherited)
                                       .Select(
                    x =>
                    new
                {
                    BaseEntity =
                        $"{resource.Entity.BaseEntity.Name}.{resource.Entity.BaseEntity.SchemaProperCaseName()}",
                    PropertyName = x.ItemType.PluralName,
                    PropertyNamespace = ns,
                    CollectionName = x.ItemType.Name
                })
                                       .ToList(),
                Standard = resource.Collections.Any(x => !x.IsInherited)
                        ? ResourceRenderer.DoRenderProperty
                        : ResourceRenderer.DoNotRenderProperty,
                Collections = resource.Collections
                              .Where(
                    x =>
                    !x.IsInherited &&
                    profileData.IsIncluded(resource, x) &&
                    TemplateContext.ShouldRenderResourceClass(
                        x.ItemType))
                              .Select(
                    x => new
                {
                    PropertyName = x.ItemType.PluralName,
                    PropertyNamespace = ns,
                    CollectionName = x.ItemType.Name
                })
                              .ToList()
            }
                : ResourceRenderer.DoNotRenderProperty);
        }
        public object Collections(
            ResourceProfileData profileData,
            ResourceClassBase resourceClass,
            TemplateContext TemplateContext)
        {
            var collectionPairs = Resources.GetMemberItemPairs(resourceClass, r => r?.Collections);

            string ns = profileData.GetProfileNamespace(resourceClass);

            return(collectionPairs
                   .Where(
                       itemPair =>
                       !itemPair.Underlying.IsInherited)
                   .OrderBy(x => x.Underlying.PropertyName)
                   .Select(
                       itemPair => new
            {
                ItemTypeNamespacePrefix = GetContextualNamespacePrefix(itemPair.Underlying.ItemType),
                ItemType = itemPair.Underlying.ItemType.Name,
                Collection = itemPair.Underlying.ItemType.PluralName,
                PropertyName = itemPair.Underlying.PropertyName,
                JsonPropertyName = itemPair.Underlying.JsonPropertyName,
                PropertyFieldName = itemPair.Underlying.ItemType.PluralName.ToCamelCase(),
                ParentName = itemPair.Underlying.ParentFullName.Name,
                PropertyNamespace = ns,
                Standard =

                    // It's included
                    itemPair.Current != null

                    // It's not filtered
                    && !itemPair.Current.ValueFilters.Any(),
                Null = itemPair.Current == null,
                Filtered =

                    // It's included
                    itemPair.Current != null

                    // It's filtered
                    && itemPair.Current.ValueFilters.Any(),
                BaseEntity = resourceClass.Name
            })
                   .ToList());
        }