Example #1
0
        private Lazy <IReadOnlyList <ResourceChildItem> > LazyInitializeContainedTypes()
        {
            return(new Lazy <IReadOnlyList <ResourceChildItem> >(
                       () =>

                       // Collections
                       Collections
                       .Where(c => FilterContext.MemberFilter.ShouldInclude(c.PropertyName))
                       .Select(c => c.ItemType)
                       .Concat(Collections.SelectMany(c => c.ItemType.ContainedItemTypes))

                       // EmbeddedObjects
                       .Concat(
                           EmbeddedObjects
                           .Where(o => FilterContext.MemberFilter.ShouldInclude(o.PropertyName))
                           .Select(o => o.ObjectType))
                       .Concat(EmbeddedObjects.SelectMany(o => o.ObjectType.ContainedItemTypes))

                       // Extensions
                       .Concat(
                           Extensions
                           .Where(x => FilterContext.MemberFilter.ShouldIncludeExtension(x.PropertyName))
                           .Select(x => x.ObjectType))
                       .Concat(Extensions.SelectMany(x => x.ObjectType.ContainedItemTypes))
                       .ToList()
                       ));
        }
Example #2
0
 private Lazy <IReadOnlyList <Reference> > LazyInitializeContainedReferences()
 {
     return(new Lazy <IReadOnlyList <Reference> >(
                () =>
                References
                .Concat(Collections.SelectMany(c => c.ItemType.ContainedReferences))
                .Concat(EmbeddedObjects.SelectMany(o => o.ObjectType.ContainedReferences))
                .Concat(Extensions.SelectMany(o => o.ObjectType.ContainedReferences))
                .Distinct(ModelComparers.ReferenceTypeNameOnly)
                .ToList()
                ));
 }
Example #3
0
        private void LazyInitializeDerivedCollections()
        {
            _allProperties = new Lazy <IReadOnlyList <ResourceProperty> >(
                () =>

                // Add locally defined identifying properties first
                Properties.Where(p => p.IsIdentifying)

                // Add reference properties, identifying references first, followed by required, and then optional
                .Concat(
                    References
                    .OrderByDescending(
                        r => (r.Association.IsIdentifying ? 100: 0)
                        + (r.IsRequired ? 10 : 0))
                    .SelectMany(r => r.Properties))

                // Add non-identifying properties
                .Concat(Properties.Where(p => !p.IsIdentifying))
                .Distinct(ModelComparers.ResourcePropertyNameOnly)
                .ToList());

            _allPropertyByName = new Lazy <IReadOnlyDictionary <string, ResourceProperty> >(
                () =>
                AllProperties.ToDictionary(x => x.PropertyName, x => x, StringComparer.InvariantCultureIgnoreCase));

            _propertyByName = new Lazy <IReadOnlyDictionary <string, ResourceProperty> >(
                () =>
                Properties
                .ToDictionary(x => x.PropertyName, x => x, StringComparer.InvariantCultureIgnoreCase));

            _embeddedObjectByName = new Lazy <IReadOnlyDictionary <string, EmbeddedObject> >(
                () =>
                EmbeddedObjects.ToDictionary(
                    x => x.PropertyName,
                    x => x,
                    StringComparer.InvariantCultureIgnoreCase));

            // Added lazy initialization of dictionary
            _extensionByName = new Lazy <IReadOnlyDictionary <string, Extension> >(
                () =>
                Extensions.ToDictionary(
                    x => x.PropertyName,
                    x => x,
                    StringComparer.InvariantCultureIgnoreCase));

            _collectionByName = new Lazy <IReadOnlyDictionary <string, Collection> >(
                () =>
                Collections.ToDictionary(x => x.PropertyName, x => x, StringComparer.InvariantCultureIgnoreCase));

            _referenceByName = new Lazy <IReadOnlyDictionary <string, Reference> >(
                () =>
                References.ToDictionary(x => x.PropertyName, x => x, StringComparer.InvariantCultureIgnoreCase));

            _allMembers = new Lazy <IReadOnlyList <ResourceMemberBase> >(
                () => LazyInitializeAllMembers()
                .ToList());

            _memberByName = new Lazy <IReadOnlyDictionary <string, ResourceMemberBase> >(
                () => AllMembers.ToDictionary(x => x.PropertyName, x => x, StringComparer.InvariantCultureIgnoreCase));

            _memberNamesInvolvedInJsonCollisions = new Lazy <IReadOnlyList <string> >(
                () =>
            {
                var allProposedNames =
                    AllMembers.Select(
                        p =>
                        Tuple.Create(
                            p.PropertyName,
                            JsonNamingConvention.ProposeJsonPropertyName(p.ParentFullName.Name, p.PropertyName)))
                    .ToList();

                var proposedJsonNames = new HashSet <string>();
                var rejectedJsonNames = new HashSet <string>();

                foreach (var nameAndProposedName in allProposedNames)
                {
                    if (!proposedJsonNames.Add(nameAndProposedName.Item2))
                    {
                        rejectedJsonNames.Add(nameAndProposedName.Item2);
                    }
                }

                return(allProposedNames
                       .Where(t => rejectedJsonNames.Contains(t.Item2))
                       .Select(t => t.Item1)
                       .ToList());
            }
                );
        }