示例#1
0
 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);
     }
 }
示例#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);
     }
 }
示例#3
0
        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);
        }
示例#4
0
 public static bool IsSupportedProtocol(NetworkProtocol protocol)
 {
     return(NetworkProtocol.supportedNetworkProtocols.ContainsValue(protocol));
 }
示例#5
0
 public static NetworkProtocol[] GetSupportedProtocols()
 {
     NetworkProtocol[] array = new NetworkProtocol[NetworkProtocol.supportedNetworkProtocols.Count];
     NetworkProtocol.supportedNetworkProtocols.Values.CopyTo(array, 0);
     return(array);
 }
示例#6
0
 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)
 {
 }