Ejemplo n.º 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();
        }
Ejemplo n.º 2
0
 public TypeRef(TypeDefBase typeDef)
 {
     TypeDef   = typeDef;
     Kind      = TypeDef.Kind;
     Name      = this.GetTypeRefName();
     KindsPath = new[] { Kind };
     ClrType   = this.GetClrType();
 }
Ejemplo n.º 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
 }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 5
0
        public static bool IsComplexReturnType(this TypeDefBase typeDef)
        {
            switch (typeDef.Kind)
            {
            case TypeKind.Object:
            case TypeKind.Interface:
            case TypeKind.Union:
                return(true);

            default:
                return(false);
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
 public static bool IsEnumFlagArray(this TypeDefBase typeDef)
 {
     return(typeDef.Kind == TypeKind.Enum && (typeDef is EnumTypeDef etd && etd.IsFlagSet));
 }
Ejemplo n.º 9
0
 public static TypeRef FindTypeRef(this TypeDefBase typeDef, IList <TypeKind> kinds)
 {
     return(typeDef.TypeRefs.FirstOrDefault(tr => tr.KindsPath.Matches(kinds)));
 }