private PartitionKey CosmosElementToPartitionKeyObject(CosmosElement cosmosElement)
        {
            // TODO: Leverage original serialization and avoid re-serialization (bug)
            switch (cosmosElement.Type)
            {
            case CosmosElementType.String:
                CosmosString cosmosString = cosmosElement as CosmosString;
                return(new PartitionKey(cosmosString.Value));

            case CosmosElementType.Number:
                CosmosNumber cosmosNumber = cosmosElement as CosmosNumber;
                double       value        = Number64.ToDouble(cosmosNumber.Value);
                return(new PartitionKey(value));

            case CosmosElementType.Boolean:
                CosmosBoolean cosmosBool = cosmosElement as CosmosBoolean;
                return(new PartitionKey(cosmosBool.Value));

            case CosmosElementType.Null:
                return(PartitionKey.Null);

            default:
                throw new ArgumentException(
                          string.Format(CultureInfo.InvariantCulture, RMResources.UnsupportedPartitionKeyComponentValue, cosmosElement));
            }
        }
        private static PartitionKey CosmosElementToPartitionKeyObject(IReadOnlyList <CosmosElement> cosmosElementList)
        {
            PartitionKeyBuilder partitionKeyBuilder = new PartitionKeyBuilder();

            foreach (CosmosElement cosmosElement in cosmosElementList)
            {
                if (cosmosElement == null)
                {
                    partitionKeyBuilder.AddNoneType();
                }
                else
                {
                    _ = cosmosElement switch
                    {
                        CosmosString cosmosString => partitionKeyBuilder.Add(cosmosString.Value),
                        CosmosNumber cosmosNumber => partitionKeyBuilder.Add(Number64.ToDouble(cosmosNumber.Value)),
                        CosmosBoolean cosmosBoolean => partitionKeyBuilder.Add(cosmosBoolean.Value),
                        CosmosNull _ => partitionKeyBuilder.AddNullValue(),
                        _ => throw new ArgumentException(
                                  string.Format(
                                      CultureInfo.InvariantCulture,
                                      RMResources.UnsupportedPartitionKeyComponentValue,
                                      cosmosElement)),
                    };
                }
            }

            return(partitionKeyBuilder.Build());
        }
            public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
            {
                Number64 number64 = (Number64)value;

                if (number64.IsDouble)
                {
                    writer.WriteValue(Number64.ToDouble(number64));
                }
                else
                {
                    writer.WriteValue(Number64.ToLong(number64));
                }
            }