예제 #1
0
        public static bool ValidateAny <T>([NotNullWhen(true)] IEnumerable <T>?argumentValue, string argumentName, uint?tagId)
        {
            if (!ValidateArgument(argumentValue, argumentName, tagId))
            {
                return(false);
            }

            if (!argumentValue.Any())
            {
                if (tagId != null)
                {
                    UntaggedLogging.LogTraceTag(tagId.Value, Categories.ArgumentValidation, Levels.Error,
                                                ValidationFailed, HasAnyErrorMessage, argumentName);
                }

                return(false);
            }

            return(true);
        }
예제 #2
0
파일: Code.cs 프로젝트: tanmayeekamath/Omex
        public static bool ValidateNotNullOrWhiteSpaceArgument([NotNullWhen(true)] string?argumentValue, string argumentName, uint?tagId = null)
        {
            if (string.IsNullOrWhiteSpace(argumentValue))
            {
                if (ValidateArgument(argumentValue, argumentName, tagId))
                {
                    if (tagId != null)
                    {
                        UntaggedLogging.LogTraceTag(tagId.Value, Categories.ArgumentValidation, Levels.Error,
                                                    ValidationFailed,
                                                    argumentName.Length == 0 ? ArgumentContainsEmptyString : ArgumentContainsWhiteSpaceString,
                                                    argumentName);
                    }
                }

                return(false);
            }

            return(true);
        }
예제 #3
0
파일: Code.cs 프로젝트: tharshada/Omex
        public static bool ValidateNotEmptyAndAllNotNull <T>([NotNullWhen(true)] ICollection <T>?argumentValue, string argumentName, uint?tagId)
            where T : class
        {
            if (!ValidateArgument(argumentValue, argumentName, tagId))
            {
                return(false);
            }

            if (!argumentValue.Any() || argumentValue.Any(x => x == null))
            {
                if (tagId != null)
                {
                    UntaggedLogging.LogTraceTag(tagId.Value, Categories.ArgumentValidation, Levels.Error,
                                                ValidationFailed, AllErrorMessage, argumentName);
                }

                return(false);
            }

            return(true);
        }
예제 #4
0
        /// <summary>
        /// Checks that the enumerable argument is not null and doesn't contain any nulls
        /// </summary>
        /// <remarks>Be careful to not pass enumerables that can be enumerated only once</remarks>
        /// <typeparam name="T">Type of the enumerable</typeparam>
        /// <param name="argumentValue">The argument value.</param>
        /// <param name="argumentName">Name of the argument.</param>
        /// <param name="tagId">Tag Id to log, leave null if no logging is needed</param>
        /// <returns>True if the argument <paramref name="argumentValue"/> is not null and contains only non-null elements; false otherwise.</returns>
        public static bool ValidateAllNotNull <T>(IEnumerable <T> argumentValue, string argumentName, uint?tagId)
            where T : class
        {
            if (!ValidateArgument(argumentValue, argumentName, tagId))
            {
                return(false);
            }

            if (argumentValue.Any(x => x == null))
            {
                if (tagId != null)
                {
                    UntaggedLogging.LogTraceTag(tagId.Value, Categories.ArgumentValidation, Levels.Error,
                                                ValidationFailed, AllErrorMessage, argumentName);
                }

                return(false);
            }

            return(true);
        }