ConfigurationDocument.cs (2116B)
1 // ----------------------------------------------------------------------------- 2 // <copyright file="ConfigurationDocument.cs" company="Microsoft Corporation"> 3 // Copyright (c) Microsoft Corporation. Licensed under the MIT License. 4 // </copyright> 5 // ----------------------------------------------------------------------------- 6 7 namespace Microsoft.Management.Configuration.Processor.DSCv3.Schema_2024_04.Outputs 8 { 9 using System.Collections.Generic; 10 using System.IO; 11 using System.Linq; 12 using System.Text.Json; 13 using System.Text.Json.Serialization; 14 using Microsoft.Management.Configuration.Processor.DSCv3.Model; 15 16 /// <summary> 17 /// A configuration document. 18 /// </summary> 19 internal class ConfigurationDocument 20 { 21 /// <summary> 22 /// Gets or sets the list of resources in the document. 23 /// </summary> 24 public List<ResourceItem> Resources { get; set; } = new List<ResourceItem>(); 25 26 /// <summary> 27 /// Gets the list of resources as the interface version. 28 /// </summary> 29 [JsonIgnore] 30 public IList<IResourceExportItem> InterfaceResources 31 { 32 get 33 { 34 return new List<IResourceExportItem>(this.Resources.AsEnumerable<IResourceExportItem>()); 35 } 36 } 37 38 /// <summary> 39 /// Initializes a new instance of the ConfigurationDocument class. 40 /// </summary> 41 /// <param name="document">The document to construct from.</param> 42 /// <param name="options">The options to use.</param> 43 /// <returns>The item created.</returns> 44 public static ConfigurationDocument CreateFrom(JsonDocument document, JsonSerializerOptions options) 45 { 46 ConfigurationDocument? result = JsonSerializer.Deserialize<ConfigurationDocument>(document, options); 47 48 if (result == null) 49 { 50 throw new InvalidDataException("Unable to deserialize ConfigurationDocument."); 51 } 52 53 return result; 54 } 55 } 56 }