| | 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 | | /// A contact for certificate management issues for a key vault. |
| | 10 | | /// </summary> |
| | 11 | | public class CertificateContact : IJsonDeserializable, IJsonSerializable |
| | 12 | | { |
| | 13 | | private const string NamePropertyName = "name"; |
| | 14 | | private const string EmailPropertyName = "email"; |
| | 15 | | private const string PhonePropertyName = "phone"; |
| | 16 | |
|
| 2 | 17 | | private static readonly JsonEncodedText s_namePropertyNameBytes = JsonEncodedText.Encode(NamePropertyName); |
| 2 | 18 | | private static readonly JsonEncodedText s_emailPropertyNameBytes = JsonEncodedText.Encode(EmailPropertyName); |
| 2 | 19 | | private static readonly JsonEncodedText s_phonePropertyNameBytes = JsonEncodedText.Encode(PhonePropertyName); |
| | 20 | |
|
| | 21 | | /// <summary> |
| | 22 | | /// Initializes a new instance of the <see cref="CertificateContact"/> class. |
| | 23 | | /// </summary> |
| 24 | 24 | | public CertificateContact() |
| | 25 | | { |
| 24 | 26 | | } |
| | 27 | |
|
| | 28 | | /// <summary> |
| | 29 | | /// Gets or sets the email address of the contact. |
| | 30 | | /// </summary> |
| 56 | 31 | | public string Email { get; set; } |
| | 32 | |
|
| | 33 | | /// <summary> |
| | 34 | | /// Gets or sets the name of the contact. |
| | 35 | | /// </summary> |
| 72 | 36 | | public string Name { get; set; } |
| | 37 | |
|
| | 38 | | /// <summary> |
| | 39 | | /// Gets or sets the phone number of the contact. |
| | 40 | | /// </summary> |
| 56 | 41 | | public string Phone { get; set; } |
| | 42 | |
|
| | 43 | | void IJsonDeserializable.ReadProperties(JsonElement json) |
| | 44 | | { |
| 128 | 45 | | foreach (JsonProperty prop in json.EnumerateObject()) |
| | 46 | | { |
| 48 | 47 | | switch (prop.Name) |
| | 48 | | { |
| | 49 | | case NamePropertyName: |
| 16 | 50 | | Name = prop.Value.GetString(); |
| 16 | 51 | | break; |
| | 52 | |
|
| | 53 | | case EmailPropertyName: |
| 16 | 54 | | Email = prop.Value.GetString(); |
| 16 | 55 | | break; |
| | 56 | |
|
| | 57 | | case PhonePropertyName: |
| 16 | 58 | | Phone = prop.Value.GetString(); |
| | 59 | | break; |
| | 60 | | } |
| | 61 | | } |
| 16 | 62 | | } |
| | 63 | |
|
| | 64 | | void IJsonSerializable.WriteProperties(Utf8JsonWriter json) |
| | 65 | | { |
| 8 | 66 | | if (!string.IsNullOrEmpty(Name)) |
| | 67 | | { |
| 8 | 68 | | json.WriteString(s_namePropertyNameBytes, Name); |
| | 69 | | } |
| | 70 | |
|
| 8 | 71 | | if (!string.IsNullOrEmpty(Email)) |
| | 72 | | { |
| 8 | 73 | | json.WriteString(s_emailPropertyNameBytes, Email); |
| | 74 | | } |
| | 75 | |
|
| 8 | 76 | | if (!string.IsNullOrEmpty(Phone)) |
| | 77 | | { |
| 8 | 78 | | json.WriteString(s_phonePropertyNameBytes, Phone); |
| | 79 | | } |
| 8 | 80 | | } |
| | 81 | | } |
| | 82 | | } |