< Summary

Class:Azure.Security.KeyVault.SerializationExtensions
Assembly:Azure.Security.KeyVault.Administration
File(s):C:\Git\azure-sdk-for-net\sdk\keyvault\Azure.Security.KeyVault.Shared\src\IJsonSerializable.cs
Covered lines:0
Uncovered lines:11
Coverable lines:11
Total lines:46
Line coverage:0% (0 of 11)
Covered branches:0
Total branches:0

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
Deserialize(...)-0%100%
Serialize(...)-0%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\keyvault\Azure.Security.KeyVault.Shared\src\IJsonSerializable.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using Azure.Core;
 5using System;
 6using System.IO;
 7using System.Text.Json;
 8
 9namespace Azure.Security.KeyVault
 10{
 11    internal interface IJsonSerializable
 12    {
 13        void WriteProperties(Utf8JsonWriter json);
 14    }
 15
 16    internal interface IJsonDeserializable
 17    {
 18        void ReadProperties(JsonElement json);
 19    }
 20
 21    internal static class SerializationExtensions
 22    {
 23        public static void Deserialize(this IJsonDeserializable obj, Stream content)
 24        {
 025            using JsonDocument json = JsonDocument.Parse(content, default);
 026            obj.ReadProperties(json.RootElement);
 027        }
 28
 29        public static ReadOnlyMemory<byte> Serialize(this IJsonSerializable obj)
 30        {
 031            var writer = new ArrayBufferWriter<byte>();
 32
 033            using (var json = new Utf8JsonWriter(writer))
 34            {
 035                json.WriteStartObject();
 36
 037                obj.WriteProperties(json);
 38
 039                json.WriteEndObject();
 040                json.Flush();
 041            }
 42
 043            return writer.WrittenMemory;
 44        }
 45    }
 46}

Methods/Properties

Deserialize(...)
Serialize(...)