/// <summary>
        /// Throw an <see cref="Exception"/> if the upper-case string value is invalid.
        /// </summary>
        public static void Validate(this UppercaseString uppercaseString)
        {
            var isValid = uppercaseString.IsValid();

            if (!isValid)
            {
                throw new Exception($"Value '{uppercaseString.Value}' was not an upper-case string.");
            }
        }
        /// <summary>
        /// Determines if a string really is an uppercase string.
        /// </summary>
        public static bool IsValid(this UppercaseString uppercaseString)
        {
            // Is the result of ToUpperInvariant() the same as the input?
            var uppered = uppercaseString.Value.ToUpperInvariant();

            var output = uppercaseString.Value == uppered;

            return(output);
        }
Ejemplo n.º 3
0
        public static bool TryValidate(this UppercaseStringUnvalidated uppercaseStringUnvalidated, out UppercaseString uppercaseString)
        {
            var isValid = uppercaseStringUnvalidated.IsValid();

            if (isValid)
            {
                uppercaseString = new UppercaseString(uppercaseStringUnvalidated.Value);
            }
            else
            {
                uppercaseString = UppercaseString.Invalid;
            }

            return(isValid);
        }