Ejemplo n.º 1
0
        private void MergeTypeExtension(
            IEnumerable <RegisteredType> extensions,
            RegisteredType registeredType,
            INamedType namedType)
        {
            foreach (RegisteredType extension in extensions)
            {
                if (extension.Type is INamedTypeExtensionMerger m)
                {
                    if (m.Kind != namedType.Kind)
                    {
                        throw new SchemaException(SchemaErrorBuilder.New()
                                                  .SetMessage(string.Format(
                                                                  CultureInfo.InvariantCulture,
                                                                  TypeInitializer_Merge_KindDoesNotMatch,
                                                                  namedType.Name))
                                                  .SetTypeSystemObject((ITypeSystemObject)namedType)
                                                  .Build());
                    }

                    TypeDiscoveryContext initContext = extension.DiscoveryContext;
                    foreach (FieldReference reference in initContext.Resolvers.Keys)
                    {
                        _resolvers[reference]
                            = initContext.Resolvers[reference].WithSourceType(registeredType.RuntimeType);
                    }

                    // merge
                    TypeCompletionContext context = extension.CompletionContext;
                    context.Status = TypeStatus.Named;
                    m.Merge(context, namedType);

                    // update dependencies
                    context = registeredType.CompletionContext;
                    registeredType.AddDependencies(extension.Dependencies);
                    _typeRegistry.Register(registeredType);
                    CopyAlternateNames(extension.CompletionContext, context);
                }
            }
        }
Ejemplo n.º 2
0
        private void MergeTypeExtensions()
        {
            var extensions = _types.Values
                             .Where(t => t.Type is INamedTypeExtensionMerger)
                             .Distinct()
                             .ToList();

            if (extensions.Count > 0)
            {
                var types = _types.Values
                            .Where(t => t.Type is INamedType)
                            .Distinct()
                            .ToList();

                foreach (RegisteredType extension in extensions)
                {
                    RegisteredType type = types.FirstOrDefault(t =>
                                                               t.Type.Name.Equals(extension.Type.Name));

                    if (type != null &&
                        extension.Type is INamedTypeExtensionMerger m &&
                        type.Type is INamedType n)
                    {
                        // merge
                        CompletionContext context = _cmpCtx[extension];
                        context.Status = TypeStatus.Named;
                        MergeTypeExtension(context, m, n);

                        // update dependencies
                        context = _cmpCtx[type];
                        type    = type.AddDependencies(extension.Dependencies);
                        type.Update(_types);
                        _cmpCtx[type] = context;
                        CopyAlternateNames(_cmpCtx[extension], context);
                    }
                }
            }
        }