Ejemplo n.º 1
0
        private bool TryInferTypes()
        {
            var inferred = false;

            foreach (ExtendedTypeReference unresolvedType in
                     _typeRegistrar.GetUnresolved().OfType <ExtendedTypeReference>())
            {
                if (Scalars.TryGetScalar(unresolvedType.Type.Type, out Type? scalarType))
                {
                    inferred = true;

                    ExtendedTypeReference typeReference = _typeInspector.GetTypeRef(scalarType);
                    _unregistered.Add(typeReference);
                    _typeRegistrar.MarkResolved(unresolvedType);
                    _typeRegistry.TryRegister(unresolvedType, typeReference);
                }
                else if (SchemaTypeResolver.TryInferSchemaType(
                             _typeInspector, unresolvedType, out ExtendedTypeReference schemaType))
                {
                    inferred = true;

                    _unregistered.Add(schemaType);
                    _typeRegistrar.MarkResolved(unresolvedType);
                }
            }

            return(inferred);
        }
Ejemplo n.º 2
0
        public void Register(
            TypeSystemObjectBase typeSystemObject,
            string?scope,
            bool isInferred = false)
        {
            if (typeSystemObject is null)
            {
                throw new ArgumentNullException(nameof(typeSystemObject));
            }

            RegisteredType registeredType = InitializeType(typeSystemObject, scope, isInferred);

            if (registeredType.References.Count > 0)
            {
                ResolveReferences(registeredType);

                if (typeSystemObject is IHasRuntimeType hasRuntimeType &&
                    hasRuntimeType.RuntimeType != typeof(object))
                {
                    ExtendedTypeReference runtimeTypeRef =
                        _context.TypeInspector.GetTypeRef(
                            hasRuntimeType.RuntimeType,
                            SchemaTypeReference.InferTypeContext(typeSystemObject),
                            scope: scope);

                    var explicitBind = typeSystemObject is ScalarType scalar &&
                                       scalar.Bind == BindingBehavior.Explicit;

                    if (!explicitBind)
                    {
                        MarkResolved(runtimeTypeRef);
                        _typeRegistry.TryRegister(runtimeTypeRef, registeredType.References[0]);
                    }
                }
            }
        }