Ejemplo n.º 1
0
        private void MergeNextType(
            ISchemaMergeContext context,
            List <T> notMerged)
        {
            T left = notMerged[0];

            var readyToMerge = new List <T>();

            readyToMerge.Add(left);

            for (int i = 1; i < notMerged.Count; i++)
            {
                if (CanBeMerged(left, notMerged[i]))
                {
                    readyToMerge.Add(notMerged[i]);
                }
            }

            NameString newTypeName =
                TypeMergeHelpers.CreateName <T>(
                    context, readyToMerge);

            MergeTypes(context, readyToMerge, newTypeName);
            notMerged.RemoveAll(readyToMerge.Contains);
        }
Ejemplo n.º 2
0
        public void Merge(
            ISchemaMergeContext context,
            IReadOnlyList <ITypeInfo> types)
        {
            if (types.OfType <UnionTypeInfo>().Any())
            {
                var  notMerged    = types.OfType <UnionTypeInfo>().ToList();
                bool hasLeftovers = types.Count > notMerged.Count;

                for (int i = 0; i < notMerged.Count; i++)
                {
                    context.AddType(notMerged[i].Definition.Rename(
                                        TypeMergeHelpers.CreateName(context, notMerged[i]),
                                        notMerged[i].Schema.Name));
                }

                if (hasLeftovers)
                {
                    _next.Invoke(context, types.NotOfType <UnionTypeInfo>());
                }
            }
            else
            {
                _next.Invoke(context, types);
            }
        }
Ejemplo n.º 3
0
        private static void MergeType(
            ISchemaMergeContext context,
            IReadOnlyList <EnumTypeInfo> types)
        {
            var definition = types[0].Definition;

            EnumTypeDefinitionNode descriptionDef =
                types.Select(t => t.Definition)
                .FirstOrDefault(t => t.Description != null);

            if (descriptionDef != null)
            {
                definition = definition.WithDescription(
                    descriptionDef.Description);
            }

            context.AddType(definition.Rename(
                                TypeMergeHelpers.CreateName(context, types),
                                types.Select(t => t.Schema.Name)));
        }