Пример #1
0
        public static IAddress[] StringToAddresses(string str)
        {
            var remoteAddresses = new List <IAddress>();

            foreach (var remoteAddress in str.Split(','))
            {
                DNSService     dns;
                DHCPService    dhcp;
                WINSService    wins;
                LocalSubnet    localSubnet;
                DefaultGateway defaultGateway;
                IPRange        range;
                SingleIP       ip;
                NetworkAddress network;
                if (DNSService.TryParse(remoteAddress, out dns))
                {
                    remoteAddresses.Add(dns);
                }
                else if (DHCPService.TryParse(remoteAddress, out dhcp))
                {
                    remoteAddresses.Add(dhcp);
                }
                else if (WINSService.TryParse(remoteAddress, out wins))
                {
                    remoteAddresses.Add(wins);
                }
                else if (LocalSubnet.TryParse(remoteAddress, out localSubnet))
                {
                    remoteAddresses.Add(localSubnet);
                }
                else if (DefaultGateway.TryParse(remoteAddress, out defaultGateway))
                {
                    remoteAddresses.Add(defaultGateway);
                }
                else if (IPRange.TryParse(remoteAddress, out range))
                {
                    remoteAddresses.Add(range);
                }
                else if (SingleIP.TryParse(remoteAddress, out ip))
                {
                    remoteAddresses.Add(ip);
                }
                else if (NetworkAddress.TryParse(remoteAddress, out network))
                {
                    remoteAddresses.Add(network);
                }
            }
            return(remoteAddresses.ToArray());
        }
        // ReSharper disable once ExcessiveIndentation
        public static IAddress[] StringToAddresses(string str)
        {
            var remoteAddresses = new List <IAddress>();

            foreach (var remoteAddress in str.Split(','))
            {
                if (DNSService.TryParse(remoteAddress, out var dns))
                {
                    remoteAddresses.Add(dns);
                }
                else if (DHCPService.TryParse(remoteAddress, out var dhcp))
                {
                    remoteAddresses.Add(dhcp);
                }
                else if (WINSService.TryParse(remoteAddress, out var wins))
                {
                    remoteAddresses.Add(wins);
                }
                else if (LocalSubnet.TryParse(remoteAddress, out var localSubnet))
                {
                    remoteAddresses.Add(localSubnet);
                }
                else if (DefaultGateway.TryParse(remoteAddress, out var defaultGateway))
                {
                    remoteAddresses.Add(defaultGateway);
                }
                else if (IPRange.TryParse(remoteAddress, out var range))
                {
                    remoteAddresses.Add(range);
                }
                else if (SingleIP.TryParse(remoteAddress, out SingleIP ip))
                {
                    remoteAddresses.Add(ip);
                }
                else if (NetworkAddress.TryParse(remoteAddress, out var network))
                {
                    remoteAddresses.Add(network);
                }
            }

            return(remoteAddresses.ToArray());
        }