public bool TryGetDirectiveType( IDirectiveReference typeRef, [NotNullWhen(true)] out DirectiveType?directiveType) { if (typeRef is null) { throw new ArgumentNullException(nameof(typeRef)); } if (!_typeLookup.TryNormalizeReference(typeRef, out ITypeReference? namedTypeRef)) { directiveType = null; return(false); } if (_typeRegistry.TryGetType(namedTypeRef, out RegisteredType? registeredType) && registeredType.Type is DirectiveType d) { directiveType = d; return(true); } directiveType = null; return(false); }
public bool TryNormalizeReference( IDirectiveReference directiveRef, [NotNullWhen(true)] out ITypeReference?namedTypeRef) { if (directiveRef is null) { throw new ArgumentNullException(nameof(directiveRef)); } if (directiveRef is ClrTypeDirectiveReference cr) { ExtendedTypeReference directiveTypeRef = _typeInspector.GetTypeRef(cr.ClrType); if (!_typeRegistry.TryGetTypeRef(directiveTypeRef, out namedTypeRef)) { namedTypeRef = directiveTypeRef; } return(true); } if (directiveRef is NameDirectiveReference nr) { namedTypeRef = _typeRegistry.Types .FirstOrDefault(t => t.Type is DirectiveType && t.Type.Name.Equals(nr.Name))? .References[0]; return(namedTypeRef is not null); } namedTypeRef = null; return(false); }
public DirectiveType GetDirectiveType(IDirectiveReference directiveRef) { return(_typeReferenceResolver.TryGetDirectiveType( directiveRef, out DirectiveType directiveType) ? directiveType : null); }
public void RegisterDependency(IDirectiveReference reference) { if (reference == null) { throw new ArgumentNullException(nameof(reference)); } _directiveReferences.Add(reference); }
public bool TryGetDirectiveType(IDirectiveReference directiveRef, [NotNullWhen(true)] out DirectiveType?directiveType) { if (_typeReferenceResolver is null) { throw new InvalidOperationException(RegisteredType_Completion_NotYetReady); } return(_typeReferenceResolver.TryGetDirectiveType(directiveRef, out directiveType)); }
public DirectiveType GetDirectiveType(IDirectiveReference reference) { if (Status == TypeStatus.Initialized) { throw new NotSupportedException(); } if (reference is ClrTypeDirectiveReference cr) { ITypeReference clrTypeReference = new ClrTypeReference( cr.ClrType, TypeContext.None); if (!_typeInitializer.ClrTypes.TryGetValue( clrTypeReference, out ITypeReference internalReference)) { internalReference = clrTypeReference; } if (_typeInitializer.TryGetRegisteredType( internalReference, out RegisteredType registeredType)) { return((DirectiveType)registeredType.Type); } } if (reference is NameDirectiveReference nr) { return(_typeInitializer.Types.Values .Select(t => t.Type) .OfType <DirectiveType>() .FirstOrDefault(t => t.Name.Equals(nr.Name))); } return(null); }
public bool TryGetDirectiveType( IDirectiveReference directiveRef, [NotNullWhen(true)] out DirectiveType directiveType) => _typeReferenceResolver.TryGetDirectiveType(directiveRef, out directiveType);