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));
                }
            }
Beispiel #2
0
        public static TryCatch <VersionedAndRidCheckedCompositeToken> MonadicCreateFromCosmosElement(CosmosElement cosmosElement)
        {
            if (cosmosElement == null)
            {
                throw new ArgumentNullException(nameof(cosmosElement));
            }

            if (!(cosmosElement is CosmosObject cosmosObject))
            {
                return(TryCatch <VersionedAndRidCheckedCompositeToken> .FromException(
                           new FormatException($"Expected object for {nameof(VersionedAndRidCheckedCompositeToken)}: {cosmosElement}.")));
            }

            if (!cosmosObject.TryGetValue(PropertyNames.Version, out CosmosNumber typeValue))
            {
                return(TryCatch <VersionedAndRidCheckedCompositeToken> .FromException(
                           new FormatException($"expected number {nameof(PropertyNames.Version)} property for {nameof(VersionedAndRidCheckedCompositeToken)}: {cosmosElement}.")));
            }

            if (!cosmosObject.TryGetValue(PropertyNames.Continuation, out CosmosElement continuationValue))
            {
                return(TryCatch <VersionedAndRidCheckedCompositeToken> .FromException(
                           new FormatException($"expected number {nameof(PropertyNames.Continuation)} property for {nameof(VersionedAndRidCheckedCompositeToken)}: {cosmosElement}.")));
            }

            if (!cosmosObject.TryGetValue(PropertyNames.Rid, out CosmosString ridValue))
            {
                return(TryCatch <VersionedAndRidCheckedCompositeToken> .FromException(
                           new FormatException($"expected number {nameof(PropertyNames.Version)} property for {nameof(VersionedAndRidCheckedCompositeToken)}: {cosmosElement}.")));
            }

            VersionedAndRidCheckedCompositeToken token = new VersionedAndRidCheckedCompositeToken(
                (Version)Number64.ToLong(typeValue.Value),
                continuationValue,
                ridValue.Value);

            return(TryCatch <VersionedAndRidCheckedCompositeToken> .FromResult(token));
        }