Beispiel #1
0
        public static bool TryParse(string source, out AccessListEntry target)
        {
            if (String.IsNullOrEmpty(source))
                throw new ArgumentException("source can neither be null nor empty", "source");

            string[] parts = source.Split('-');
            if (parts.Length == 2)
            {
                IPAddress start;
                IPAddress end;

                if (IPAddress.TryParse(parts[0].Trim(), out start) && IPAddress.TryParse(parts[1].Trim(), out end))
                {
                    for (int i = 0; i < start.GetAddressBytes().Length; i++)
                    {
                        if (start.GetAddressBytes()[i] > end.GetAddressBytes()[i])
                        {
                            target = null;
                            return false;
                        }
                    }

                    target = new AccessIPRange(start, end);
                    return true;
                }
            }
            target = null;
            return false;
        }
        public static bool TryParse(string source, out AccessListEntry target)
        {
            if (String.IsNullOrEmpty(source))
            {
                throw new ArgumentException("source can neither be null nor empty", "source");
            }

            string[] parts = source.Split('-');
            if (parts.Length == 2)
            {
                IPAddress start;
                IPAddress end;

                if (IPAddress.TryParse(parts[0].Trim(), out start) && IPAddress.TryParse(parts[1].Trim(), out end))
                {
                    for (int i = 0; i < start.GetAddressBytes().Length; i++)
                    {
                        if (start.GetAddressBytes()[i] > end.GetAddressBytes()[i])
                        {
                            target = null;
                            return(false);
                        }
                    }

                    target = new AccessIPRange(start, end);
                    return(true);
                }
            }
            target = null;
            return(false);
        }
Beispiel #3
0
        /// <summary>
        /// Parses the given string to a new AccessIP
        /// </summary>
        /// <param name="source">A string representation of the entry</param>
        /// <param name="target"></param>
        /// <returns>True if parsing was succesful, otherwise false</returns>
        public static bool TryParse(string source, out AccessListEntry target)
        {
            IPAddress address;

            if (IPAddress.TryParse(source, out address))
            {
                target = new AccessIP(address);
                return(true);
            }

            target = null;
            return(false);
        }
Beispiel #4
0
        public static bool GenerateEntryFromString(string s, out AccessListEntry target)
        {
            if (!AccessIP.TryParse(s, out target))
                if (!AccessIPRange.TryParse(s, out target))
                    return false;

            return true;
        }
Beispiel #5
0
        /// <summary>
        /// Parses the given string to a new AccessIP
        /// </summary>
        /// <param name="source">A string representation of the entry</param>
        /// <param name="target"></param>
        /// <returns>True if parsing was succesful, otherwise false</returns>
        public static bool TryParse(string source, out AccessListEntry target)
        {
            IPAddress address;

            if (IPAddress.TryParse(source, out address))
            {
                target = new AccessIP(address);
                return true;
            }

            target = null;
            return false;
        }