internal static AnomalyState DeserializeAnomalyState(JsonElement element)
        {
            DateTimeOffset          timestamp = default;
            Optional <AnomalyValue> value     = default;
            Optional <IReadOnlyList <ErrorResponse> > errors = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("timestamp"))
                {
                    timestamp = property.Value.GetDateTimeOffset("O");
                    continue;
                }
                if (property.NameEquals("value"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    value = AnomalyValue.DeserializeAnomalyValue(property.Value);
                    continue;
                }
                if (property.NameEquals("errors"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <ErrorResponse> array = new List <ErrorResponse>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(ErrorResponse.DeserializeErrorResponse(item));
                    }
                    errors = array;
                    continue;
                }
            }
            return(new AnomalyState(timestamp, value.Value, Optional.ToList(errors)));
        }
        public static AnomalyState AnomalyState(DateTimeOffset timestamp = default, AnomalyValue value = null, IEnumerable <ErrorResponse> errors = null)
        {
            errors ??= new List <ErrorResponse>();

            return(new AnomalyState(timestamp, value, errors?.ToList()));
        }
Esempio n. 3
0
 internal AnomalyState(DateTimeOffset timestamp, AnomalyValue value, IReadOnlyList <ErrorResponse> errors)
 {
     Timestamp = timestamp;
     Value     = value;
     Errors    = errors;
 }