Esempio n. 1
0
        internal static Topology DeserializeTopology(JsonElement element)
        {
            string         id = default;
            DateTimeOffset?createdDateTime             = default;
            DateTimeOffset?lastModified                = default;
            IReadOnlyList <TopologyResource> resources = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("id"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    id = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("createdDateTime"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    createdDateTime = property.Value.GetDateTimeOffset("O");
                    continue;
                }
                if (property.NameEquals("lastModified"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    lastModified = property.Value.GetDateTimeOffset("O");
                    continue;
                }
                if (property.NameEquals("resources"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    List <TopologyResource> array = new List <TopologyResource>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        if (item.ValueKind == JsonValueKind.Null)
                        {
                            array.Add(null);
                        }
                        else
                        {
                            array.Add(TopologyResource.DeserializeTopologyResource(item));
                        }
                    }
                    resources = array;
                    continue;
                }
            }
            return(new Topology(id, createdDateTime, lastModified, resources));
        }
Esempio n. 2
0
        internal static Topology DeserializeTopology(JsonElement element)
        {
            Optional <string>         id = default;
            Optional <DateTimeOffset> createdDateTime = default;
            Optional <DateTimeOffset> lastModified    = default;
            Optional <IReadOnlyList <TopologyResource> > resources = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("id"))
                {
                    id = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("createdDateTime"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    createdDateTime = property.Value.GetDateTimeOffset("O");
                    continue;
                }
                if (property.NameEquals("lastModified"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    lastModified = property.Value.GetDateTimeOffset("O");
                    continue;
                }
                if (property.NameEquals("resources"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <TopologyResource> array = new List <TopologyResource>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(TopologyResource.DeserializeTopologyResource(item));
                    }
                    resources = array;
                    continue;
                }
            }
            return(new Topology(id.Value, Optional.ToNullable(createdDateTime), Optional.ToNullable(lastModified), Optional.ToList(resources)));
        }