コード例 #1
0
ファイル: Sample.cs プロジェクト: yelloweiffel/openicf
        /// <summary>
        ///     {@inheritDoc}
        /// </summary>
        public override void Validate()
        {
            if (String.IsNullOrEmpty(Host))
            {
                throw new ArgumentException("Host cannot be null or empty.");
            }

            Assertions.BlankCheck(RemoteUser, "RemoteUser");

            Assertions.NullCheck(Password, "Password");
        }
コード例 #2
0
        /// <summary>
        /// Creates a version range from the specified string.
        ///
        /// <p>
        /// Version range string grammar:
        ///
        /// <pre>
        /// range ::= interval | at least
        /// interval ::= ( '[' | '(' ) left ',' right ( ']' | ')' )
        /// left ::= version
        /// right ::= version
        /// at least ::= version
        /// </pre>
        /// </summary>
        /// <param name="range">
        ///            String representation of the version range. The versions in
        ///            the range must contain no whitespace. Other whitespace in the
        ///            range string is ignored. </param>
        /// <exception cref="IllegalArgumentException">
        ///             If {@code range} is improperly formatted. </exception>
        public static VersionRange Parse(string range)
        {
            Assertions.BlankCheck(range, "range");
            int idx = range.IndexOf(ENDPOINT_DELIMITER);

            // Check if the version is an interval.
            if (idx > 1 && idx == range.LastIndexOf(ENDPOINT_DELIMITER))
            {
                string vlo = range.Substring(0, idx).Trim();
                string vhi = range.Substring(idx + 1).Trim();

                bool isLowInclusive  = true;
                bool isHighInclusive = true;
                if (vlo[0] == LEFT_OPEN)
                {
                    isLowInclusive = false;
                }
                else if (vlo[0] != LEFT_CLOSED)
                {
                    throw new System.ArgumentException("invalid range \"" + range + "\": invalid format");
                }
                vlo = vlo.Substring(1).Trim();

                if (vhi[vhi.Length - 1] == RIGHT_OPEN)
                {
                    isHighInclusive = false;
                }
                else if (vhi[vhi.Length - 1] != RIGHT_CLOSED)
                {
                    throw new System.ArgumentException("invalid range \"" + range + "\": invalid format");
                }
                vhi = vhi.Substring(0, vhi.Length - 1).Trim();

                return(new VersionRange(parseVersion(vlo, range), isLowInclusive, parseVersion(vhi, range), isHighInclusive));
            }
            else if (idx == -1)
            {
                return(new VersionRange(VersionRange.parseVersion(range.Trim(), range), true, null, false));
            }
            else
            {
                throw new System.ArgumentException("invalid range \"" + range + "\": invalid format");
            }
        }