Exemplo n.º 1
0
 internal NetworkInterface(string name, string label, IReadOnlyList <string> ipAddresses, string macAddress, string networkId, NICType?nicType, PowerOnBootOption?powerOnBoot, string networkMoRefId, string networkMoName, int?deviceKey, NicIPSettings ipSettings)
 {
     Name           = name;
     Label          = label;
     IpAddresses    = ipAddresses;
     MacAddress     = macAddress;
     NetworkId      = networkId;
     NicType        = nicType;
     PowerOnBoot    = powerOnBoot;
     NetworkMoRefId = networkMoRefId;
     NetworkMoName  = networkMoName;
     DeviceKey      = deviceKey;
     IpSettings     = ipSettings;
 }
        internal static NetworkInterface DeserializeNetworkInterface(JsonElement element)
        {
            Optional <string> name  = default;
            Optional <string> label = default;
            Optional <IReadOnlyList <string> > ipAddresses = default;
            Optional <string>            macAddress        = default;
            Optional <string>            networkId         = default;
            Optional <NICType>           nicType           = default;
            Optional <PowerOnBootOption> powerOnBoot       = default;
            Optional <string>            networkMoRefId    = default;
            Optional <string>            networkMoName     = default;
            Optional <int>           deviceKey             = default;
            Optional <NicIPSettings> ipSettings            = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("name"))
                {
                    name = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("label"))
                {
                    label = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("ipAddresses"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <string> array = new List <string>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(item.GetString());
                    }
                    ipAddresses = array;
                    continue;
                }
                if (property.NameEquals("macAddress"))
                {
                    macAddress = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("networkId"))
                {
                    networkId = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("nicType"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    nicType = new NICType(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("powerOnBoot"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    powerOnBoot = new PowerOnBootOption(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("networkMoRefId"))
                {
                    networkMoRefId = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("networkMoName"))
                {
                    networkMoName = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("deviceKey"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    deviceKey = property.Value.GetInt32();
                    continue;
                }
                if (property.NameEquals("ipSettings"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    ipSettings = NicIPSettings.DeserializeNicIPSettings(property.Value);
                    continue;
                }
            }
            return(new NetworkInterface(name.Value, label.Value, Optional.ToList(ipAddresses), macAddress.Value, networkId.Value, Optional.ToNullable(nicType), Optional.ToNullable(powerOnBoot), networkMoRefId.Value, networkMoName.Value, Optional.ToNullable(deviceKey), ipSettings.Value));
        }