protected NetworkAddress(NetworkProtocol protocol, string address) : base(protocol, address)
 {
     if (protocol == null)
     {
         throw new ArgumentNullException("protocol");
     }
     if (!NetworkProtocol.IsSupportedProtocol(protocol))
     {
         throw new ArgumentException(DataStrings.ExceptionUnsupportedNetworkProtocol);
     }
 }
Exemple #2
0
 public NetworkAddress this[NetworkProtocol protocol]
 {
     get
     {
         NetworkAddress result = null;
         foreach (NetworkAddress networkAddress in this)
         {
             if (networkAddress.ProtocolType == protocol)
             {
                 result = networkAddress;
                 break;
             }
         }
         return(result);
     }
 }
        private static bool InternalTryParse(string expression, out NetworkAddress address, out NetworkAddress.ErrorCode error)
        {
            bool result = false;

            address = null;
            error   = (NetworkAddress.ErrorCode) 0;
            string[] array = expression.Split(new char[]
            {
                ':'
            }, 2, StringSplitOptions.RemoveEmptyEntries);
            if (array.Length != 2)
            {
                error = NetworkAddress.ErrorCode.InvalidFormat;
            }
            else
            {
                NetworkProtocol networkProtocol = null;
                try
                {
                    networkProtocol = NetworkProtocol.Parse(array[0].Trim());
                }
                catch (ArgumentException)
                {
                    error = NetworkAddress.ErrorCode.UnsupportProtocol;
                }
                if (networkProtocol == null)
                {
                    error = NetworkAddress.ErrorCode.UnsupportProtocol;
                }
                else
                {
                    try
                    {
                        address = networkProtocol.GetNetworkAddress(array[1].Trim());
                        result  = true;
                    }
                    catch (ArgumentOutOfRangeException)
                    {
                        error = NetworkAddress.ErrorCode.InvalidAddress;
                    }
                }
            }
            return(result);
        }
 public static bool IsSupportedProtocol(NetworkProtocol protocol)
 {
     return(NetworkProtocol.supportedNetworkProtocols.ContainsValue(protocol));
 }
 public static NetworkProtocol[] GetSupportedProtocols()
 {
     NetworkProtocol[] array = new NetworkProtocol[NetworkProtocol.supportedNetworkProtocols.Count];
     NetworkProtocol.supportedNetworkProtocols.Values.CopyTo(array, 0);
     return(array);
 }
 public static bool TryParse(string expression, out NetworkProtocol protocol)
 {
     return(NetworkProtocol.supportedNetworkProtocols.TryGetValue(expression, out protocol));
 }
 public CustomNetworkAddress(NetworkProtocol protocol, string address) : base(protocol, address)
 {
 }