public static TypeReferenceBuilder ToEntityIdBuilder(
            this ITypeDescriptor typeDescriptor,
            TypeReferenceBuilder?builder = null,
            bool isNonNull = false)
        {
            TypeReferenceBuilder actualBuilder = builder ?? TypeReferenceBuilder.New();

            switch (typeDescriptor)
            {
            case ListTypeDescriptor listTypeDescriptor:
                actualBuilder.SetIsNullable(!isNonNull);
                actualBuilder.SetListType();
                ToEntityIdBuilder(
                    listTypeDescriptor.InnerType,
                    actualBuilder);
                break;

            case NamedTypeDescriptor namedTypeDescriptor:
                actualBuilder.SetIsNullable(!isNonNull);
                if (namedTypeDescriptor.IsLeafType() && !namedTypeDescriptor.IsEnum)
                {
                    actualBuilder.SetName(
                        $"{namedTypeDescriptor.Namespace}.{namedTypeDescriptor.Name}");
                }
                else if (namedTypeDescriptor.IsDataType())
                {
                    actualBuilder.SetName(
                        namedTypeDescriptor.Kind == TypeKind.ComplexDataType
                                ? $"global::{namedTypeDescriptor.Namespace}.State.I" +
                        DataTypeNameFromTypeName(
                            namedTypeDescriptor.ComplexDataTypeParent !)
                                : $"global::{namedTypeDescriptor.Namespace}.State." +
                        DataTypeNameFromTypeName(
                            namedTypeDescriptor.GraphQLTypeName !));
                }
                else if (namedTypeDescriptor.IsEntityType())
                {
                    actualBuilder.SetName(TypeNames.EntityId);
                }
                else
                {
                    actualBuilder.SetName(typeDescriptor.Name);
                }
                break;

            case NonNullTypeDescriptor nonNullTypeDescriptor:
                ToEntityIdBuilder(
                    nonNullTypeDescriptor.InnerType,
                    actualBuilder,
                    true);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(typeDescriptor));
            }

            return(actualBuilder);
        }
Ejemplo n.º 2
0
        public static TypeReferenceBuilder ToTypeReference(
            this ITypeDescriptor typeReferenceDescriptor,
            TypeReferenceBuilder?builder = null)
        {
            TypeReferenceBuilder actualBuilder = builder ?? TypeReferenceBuilder.New();

            if (typeReferenceDescriptor is NonNullTypeDescriptor n)
            {
                typeReferenceDescriptor = n.InnerType;
            }
            else
            {
                actualBuilder.SetIsNullable(true);
            }

            return(typeReferenceDescriptor switch
            {
                ListTypeDescriptor list =>
                ToTypeReference(list.InnerType, actualBuilder.SetListType()),

                EnumTypeDescriptor @enum =>
                actualBuilder.SetName(@enum.RuntimeType.ToString()),

                ILeafTypeDescriptor leaf =>
                actualBuilder.SetName(leaf.RuntimeType.ToString()),

                INamedTypeDescriptor named =>
                actualBuilder.SetName(named.RuntimeType.ToString()),

                _ => throw new ArgumentOutOfRangeException(nameof(typeReferenceDescriptor))
            });