| | | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | | 2 | | // Licensed under the MIT License. |
| | | 3 | | |
| | | 4 | | using System.Text.Json; |
| | | 5 | | |
| | | 6 | | namespace Azure.Security.KeyVault.Certificates |
| | | 7 | | { |
| | | 8 | | /// <summary> |
| | | 9 | | /// Details of an administrator of a <see cref="CertificateIssuer"/>. |
| | | 10 | | /// </summary> |
| | | 11 | | public class AdministratorContact |
| | | 12 | | { |
| | | 13 | | /// <summary> |
| | | 14 | | /// Initializes a new instance of the <see cref="AdministratorContact"/> class. |
| | | 15 | | /// </summary> |
| | 18 | 16 | | public AdministratorContact() |
| | | 17 | | { |
| | 18 | 18 | | } |
| | | 19 | | |
| | | 20 | | /// <summary> |
| | | 21 | | /// Gets or sets the email address of the administrator. |
| | | 22 | | /// </summary> |
| | 36 | 23 | | public string Email { get; set; } |
| | | 24 | | |
| | | 25 | | /// <summary> |
| | | 26 | | /// Gets or sets the first name of the administrator. |
| | | 27 | | /// </summary> |
| | 36 | 28 | | public string FirstName { get; set; } |
| | | 29 | | |
| | | 30 | | /// <summary> |
| | | 31 | | /// Gets or sets the last name of the administrator. |
| | | 32 | | /// </summary> |
| | 36 | 33 | | public string LastName { get; set; } |
| | | 34 | | |
| | | 35 | | /// <summary> |
| | | 36 | | /// Gets or sets the phone number of the administrator. |
| | | 37 | | /// </summary> |
| | 36 | 38 | | public string Phone { get; set; } |
| | | 39 | | |
| | | 40 | | private const string FirstNamePropertyName = "first_name"; |
| | | 41 | | private const string LastNamePropertyName = "last_name"; |
| | | 42 | | private const string EmailPropertyName = "email"; |
| | | 43 | | private const string PhonePropertyName = "phone"; |
| | | 44 | | |
| | | 45 | | internal void ReadProperties(JsonElement json) |
| | | 46 | | { |
| | 120 | 47 | | foreach (JsonProperty prop in json.EnumerateObject()) |
| | | 48 | | { |
| | 48 | 49 | | switch (prop.Name) |
| | | 50 | | { |
| | | 51 | | case FirstNamePropertyName: |
| | 12 | 52 | | FirstName = prop.Value.GetString(); |
| | 12 | 53 | | break; |
| | | 54 | | case LastNamePropertyName: |
| | 12 | 55 | | LastName = prop.Value.GetString(); |
| | 12 | 56 | | break; |
| | | 57 | | case EmailPropertyName: |
| | 12 | 58 | | Email = prop.Value.GetString(); |
| | 12 | 59 | | break; |
| | | 60 | | case PhonePropertyName: |
| | 12 | 61 | | Phone = prop.Value.GetString(); |
| | | 62 | | break; |
| | | 63 | | } |
| | | 64 | | } |
| | 12 | 65 | | } |
| | | 66 | | |
| | 2 | 67 | | private static readonly JsonEncodedText s_firstNamePropertyNameBytes = JsonEncodedText.Encode(FirstNamePropertyN |
| | 2 | 68 | | private static readonly JsonEncodedText s_lastNamePropertyNameBytes = JsonEncodedText.Encode(LastNamePropertyNam |
| | 2 | 69 | | private static readonly JsonEncodedText s_emailPropertyNameBytes = JsonEncodedText.Encode(EmailPropertyName); |
| | 2 | 70 | | private static readonly JsonEncodedText s_phonePropertyNameBytes = JsonEncodedText.Encode(PhonePropertyName); |
| | | 71 | | |
| | | 72 | | internal void WriteProperties(Utf8JsonWriter json) |
| | | 73 | | { |
| | 6 | 74 | | if (!string.IsNullOrEmpty(FirstName)) |
| | | 75 | | { |
| | 6 | 76 | | json.WriteString(s_firstNamePropertyNameBytes, FirstName); |
| | | 77 | | } |
| | | 78 | | |
| | 6 | 79 | | if (!string.IsNullOrEmpty(LastName)) |
| | | 80 | | { |
| | 6 | 81 | | json.WriteString(s_lastNamePropertyNameBytes, LastName); |
| | | 82 | | } |
| | | 83 | | |
| | 6 | 84 | | if (!string.IsNullOrEmpty(Email)) |
| | | 85 | | { |
| | 6 | 86 | | json.WriteString(s_emailPropertyNameBytes, Email); |
| | | 87 | | } |
| | | 88 | | |
| | 6 | 89 | | if (!string.IsNullOrEmpty(Phone)) |
| | | 90 | | { |
| | 6 | 91 | | json.WriteString(s_phonePropertyNameBytes, Phone); |
| | | 92 | | } |
| | 6 | 93 | | } |
| | | 94 | | } |
| | | 95 | | } |