Ejemplo n.º 1
0
 /// <summary>
 /// Determines whether the current ZIP code instance is equal to the specified one.
 /// </summary>
 /// <param name="zip">The US ZIP code instance to be compared with the current one.</param>
 /// <returns>True, if the current US ZIP code instance is equal to the specified one; otherwise, false.</returns>
 public bool IsEqualTo(ZipCode zip)
 {
     return Value == zip.Value;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Determines whether the current ZIP code instance is equivalent to the specified one.
        /// </summary>
        /// <param name="zip">The US ZIP code instance to be compared with the current one.</param>
        /// <returns>True, if the current US ZIP code instance is equivalent to the specified one; otherwise, false.</returns>
        public bool IsEquivalentTo(ZipCode zip)
        {
            if(IsBlank)
                return zip.IsBlank;

            return !zip.IsBlank && Value.Substring(0, BASIC_LENGTH) == zip.Value.Substring(0, BASIC_LENGTH);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Tries to convert the specified string representing the US ZIP code value to <see cref="ZipCode"/> instance.
        /// A return value indicates whether conversion is succeeded or failed.
        /// </summary>
        /// <param name="value">The US ZIP code value to be parsed.</param>
        /// <param name="zipCode">The instance of <see cref="ZipCode"/> or null.</param>
        /// <returns>True, if the US ZIP code value is converted successfully, otherwise, false.</returns>
        /// <remarks>This method does never throw any exception.</remarks>
        public static bool TryParse(string value, out ZipCode? zipCode)
        {
            zipCode = null;
            if(value.IsBlank())
                return false;

            var parsedValue = ParseValue(value, false);
            if(IsValid(parsedValue))
            {
                zipCode = new ZipCode { Value = parsedValue };
                return true;
            }
            return false;
        }