Beispiel #1
0
        public TypeRef(TypeRef parent, TypeKind kind)
        {
            Inner     = parent;
            Kind      = kind;
            TypeDef   = parent.TypeDef;
            KindsPath = new List <TypeKind>(parent.KindsPath);
            KindsPath.Add(kind);
            // for this constructor we should have only List or NotNull kinds
            switch (Kind)
            {
            case TypeKind.NonNull:
                Rank = parent.Rank;
                break;

            case TypeKind.List:
                Rank = parent.Rank + 1;
                break;

            default:
                throw new Exception($"FATAL: Invalid type kind '{kind}', expected List or NotNull."); // should never happen
            }
            Name    = this.GetTypeRefName();
            IsList  = kind == TypeKind.List || parent.Kind == TypeKind.List;
            ClrType = this.GetClrType();
        }
Beispiel #2
0
 public TypeRef(TypeDefBase typeDef)
 {
     TypeDef   = typeDef;
     Kind      = TypeDef.Kind;
     Name      = this.GetTypeRefName();
     KindsPath = new[] { Kind };
     ClrType   = this.GetClrType();
 }
Beispiel #3
0
 public static bool IsDataType(this TypeDefBase typeDef)
 {
     if (typeDef is ComplexTypeDef cpxTypeDef)
     {
         return(cpxTypeDef.TypeRole == TypeRole.Data);
     }
     return(true); // non-object types: Scalars, enums, input types
 }
Beispiel #4
0
        public static bool IsSchemaType(this TypeDefBase typeDef)
        {
            switch (typeDef.TypeRole)
            {
            case ObjectTypeRole.ModuleMutation:
            case ObjectTypeRole.ModuleQuery:
            case ObjectTypeRole.ModuleSubscription:
                return(false);

            default:
                return(true);
            }
        }
        public static bool IsComplexReturnType(this TypeDefBase typeDef)
        {
            switch (typeDef.Kind)
            {
            case TypeKind.Object:
            case TypeKind.Interface:
            case TypeKind.Union:
                return(true);

            default:
                return(false);
            }
        }
Beispiel #6
0
        public static bool IsModuleTransientType(this TypeDefBase typeDef)
        {
            var cpxTypeDef = typeDef as ComplexTypeDef;

            if (cpxTypeDef == null)
            {
                return(false);
            }
            switch (cpxTypeDef.TypeRole)
            {
            case TypeRole.ModuleMutation:
            case TypeRole.ModuleQuery:
            case TypeRole.ModuleSubscription: return(true);

            default: return(false);
            }
        }
        public static TypeRef GetCreateTypeRef(this TypeDefBase typeDef, IList <TypeKind> kinds)
        {
            var typeRef = typeDef.FindTypeRef(kinds);

            if (typeRef != null)
            {
                return(typeRef);
            }
            // no existing match; create new one; first find/create its parent, recursively
            // remove last kind in list, but remember it
            var lastKind    = kinds.Last();
            var parentKinds = kinds.Take(kinds.Count - 1).ToList();
            // At some point we must hit the exising TypeRef - either typeDef.typeRefNull or TypeRefNotNull
            var parent = typeDef.GetCreateTypeRef(parentKinds);

            typeRef = new TypeRef(parent, lastKind);
            typeDef.TypeRefs.Add(typeRef);
            return(typeRef);
        }
Beispiel #8
0
 public static bool IsEnumFlagArray(this TypeDefBase typeDef)
 {
     return(typeDef.Kind == TypeKind.Enum && (typeDef is EnumTypeDef etd && etd.IsFlagSet));
 }
 public static TypeRef FindTypeRef(this TypeDefBase typeDef, IList <TypeKind> kinds)
 {
     return(typeDef.TypeRefs.FirstOrDefault(tr => tr.KindsPath.Matches(kinds)));
 }