internal static AlertingHook DeserializeAlertingHook(JsonElement element) { if (element.TryGetProperty("hookType", out JsonElement discriminator)) { switch (discriminator.GetString()) { case "Email": return(EmailHook.DeserializeEmailHook(element)); case "Webhook": return(WebHook.DeserializeWebHook(element)); } } HookType hookType = default; Optional <string> hookId = default; string hookName = default; Optional <string> description = default; Optional <string> externalLink = default; Optional <IReadOnlyList <string> > admins = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("hookType")) { hookType = new HookType(property.Value.GetString()); continue; } if (property.NameEquals("hookId")) { hookId = property.Value.GetString(); continue; } if (property.NameEquals("hookName")) { hookName = property.Value.GetString(); continue; } if (property.NameEquals("description")) { description = property.Value.GetString(); continue; } if (property.NameEquals("externalLink")) { externalLink = property.Value.GetString(); continue; } if (property.NameEquals("admins")) { List <string> array = new List <string>(); foreach (var item in property.Value.EnumerateArray()) { array.Add(item.GetString()); } admins = array; continue; } } return(new AlertingHook(hookType, hookId.Value, hookName, description.Value, externalLink.Value, Optional.ToList(admins))); }
internal static HookInfoPatch GetPatchModel(AlertingHook hook) { return(hook switch { EmailHook h => new EmailHookInfoPatch() { HookName = h.Name, Description = h.Description, ExternalLink = h.ExternalLink, HookParameter = h.HookParameter, Admins = h.Administrators }, WebHook h => new WebhookHookInfoPatch() { HookName = h.Name, Description = h.Description, ExternalLink = h.ExternalLink, HookParameter = h.HookParameter, Admins = h.Administrators }, _ => throw new InvalidOperationException("Unknown AlertingHook type.") });