internal static MetricFeedback DeserializeMetricFeedback(JsonElement element)
        {
            if (element.TryGetProperty("feedbackType", out JsonElement discriminator))
            {
                var discriminatorString = discriminator.GetString();

                switch (discriminatorString)
                {
                case "Anomaly":
                    return(MetricAnomalyFeedback.DeserializeMetricAnomalyFeedback(element));

                case "ChangePoint":
                    return(MetricChangePointFeedback.DeserializeMetricChangePointFeedback(element));

                case "Comment":
                    return(MetricCommentFeedback.DeserializeMetricCommentFeedback(element));

                case "Period":
                    return(MetricPeriodFeedback.DeserializeMetricPeriodFeedback(element));

                default:
                    throw new ArgumentException($"Unknown feedback type returned by the service: {discriminatorString}");
                }
            }
            else
            {
                throw new ArgumentException("The feedback type was not returned by the service");
            }
        }
Example #2
0
        internal static MetricFeedback DeserializeMetricFeedback(JsonElement element)
        {
            if (element.TryGetProperty("feedbackType", out JsonElement discriminator))
            {
                switch (discriminator.GetString())
                {
                case "Anomaly": return(MetricAnomalyFeedback.DeserializeMetricAnomalyFeedback(element));

                case "ChangePoint": return(MetricChangePointFeedback.DeserializeMetricChangePointFeedback(element));

                case "Comment": return(MetricCommentFeedback.DeserializeMetricCommentFeedback(element));

                case "Period": return(MetricPeriodFeedback.DeserializeMetricPeriodFeedback(element));
                }
            }
            FeedbackType              feedbackType  = default;
            Optional <string>         feedbackId    = default;
            Optional <DateTimeOffset> createdTime   = default;
            Optional <string>         userPrincipal = default;
            string metricId = default;
            FeedbackDimensionFilter dimensionFilter = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("feedbackType"))
                {
                    feedbackType = new FeedbackType(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("feedbackId"))
                {
                    feedbackId = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("createdTime"))
                {
                    createdTime = property.Value.GetDateTimeOffset("O");
                    continue;
                }
                if (property.NameEquals("userPrincipal"))
                {
                    userPrincipal = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("metricId"))
                {
                    metricId = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("dimensionFilter"))
                {
                    dimensionFilter = FeedbackDimensionFilter.DeserializeFeedbackDimensionFilter(property.Value);
                    continue;
                }
            }
            return(new MetricFeedback(feedbackType, feedbackId.Value, Optional.ToNullable(createdTime), userPrincipal.Value, metricId, dimensionFilter));
        }