Example #1
0
        internal static PurchaseMeterDetails DeserializePurchaseMeterDetails(JsonElement element)
        {
            Optional <string>       productId    = default;
            Optional <string>       skuId        = default;
            Optional <string>       termId       = default;
            BillingType             billingType  = default;
            Optional <double>       multiplier   = default;
            Optional <ChargingType> chargingType = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("productId"))
                {
                    productId = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("skuId"))
                {
                    skuId = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("termId"))
                {
                    termId = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("billingType"))
                {
                    billingType = new BillingType(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("multiplier"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    multiplier = property.Value.GetDouble();
                    continue;
                }
                if (property.NameEquals("chargingType"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    chargingType = new ChargingType(property.Value.GetString());
                    continue;
                }
            }
            return(new PurchaseMeterDetails(billingType, Optional.ToNullable(multiplier), Optional.ToNullable(chargingType), productId.Value, skuId.Value, termId.Value));
        }
        internal static MeterDetails DeserializeMeterDetails(JsonElement element)
        {
            if (element.TryGetProperty("billingType", out JsonElement discriminator))
            {
                switch (discriminator.GetString())
                {
                case "Pav2": return(Pav2MeterDetails.DeserializePav2MeterDetails(element));

                case "Purchase": return(PurchaseMeterDetails.DeserializePurchaseMeterDetails(element));
                }
            }
            BillingType             billingType  = default;
            Optional <double>       multiplier   = default;
            Optional <ChargingType> chargingType = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("billingType"))
                {
                    billingType = new BillingType(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("multiplier"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    multiplier = property.Value.GetDouble();
                    continue;
                }
                if (property.NameEquals("chargingType"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    chargingType = new ChargingType(property.Value.GetString());
                    continue;
                }
            }
            return(new MeterDetails(billingType, Optional.ToNullable(multiplier), Optional.ToNullable(chargingType)));
        }