Exemplo n.º 1
0
        internal static TopologyResource DeserializeTopologyResource(JsonElement element)
        {
            string name     = default;
            string id       = default;
            string location = default;
            IReadOnlyList <TopologyAssociation> associations = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("name"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    name = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("id"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    id = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("location"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    location = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("associations"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    List <TopologyAssociation> array = new List <TopologyAssociation>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        if (item.ValueKind == JsonValueKind.Null)
                        {
                            array.Add(null);
                        }
                        else
                        {
                            array.Add(TopologyAssociation.DeserializeTopologyAssociation(item));
                        }
                    }
                    associations = array;
                    continue;
                }
            }
            return(new TopologyResource(name, id, location, associations));
        }
Exemplo n.º 2
0
        internal static TopologyResource DeserializeTopologyResource(JsonElement element)
        {
            Optional <string> name     = default;
            Optional <string> id       = default;
            Optional <string> location = default;
            Optional <IReadOnlyList <TopologyAssociation> > associations = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("name"))
                {
                    name = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("id"))
                {
                    id = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("location"))
                {
                    location = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("associations"))
                {
                    List <TopologyAssociation> array = new List <TopologyAssociation>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(TopologyAssociation.DeserializeTopologyAssociation(item));
                    }
                    associations = array;
                    continue;
                }
            }
            return(new TopologyResource(name.Value, id.Value, location.Value, Optional.ToList(associations)));
        }