public static Argument <T> ExistingOnly <T>(this Argument <T> argument)
            where T : IEnumerable <FileSystemInfo>
        {
            if (typeof(IEnumerable <FileInfo>).IsAssignableFrom(typeof(T)))
            {
                argument.AddValidator(
                    a => a.Tokens
                    .Select(t => t.Value)
                    .Where(filePath => !File.Exists(filePath))
                    .Select(a.ValidationMessages.FileDoesNotExist)
                    .FirstOrDefault());
            }
            else if (typeof(IEnumerable <DirectoryInfo>).IsAssignableFrom(typeof(T)))
            {
                argument.AddValidator(
                    a => a.Tokens
                    .Select(t => t.Value)
                    .Where(filePath => !Directory.Exists(filePath))
                    .Select(a.ValidationMessages.DirectoryDoesNotExist)
                    .FirstOrDefault());
            }
            else
            {
                argument.AddValidator(
                    a => a.Tokens
                    .Select(t => t.Value)
                    .Where(filePath => !Directory.Exists(filePath) && !File.Exists(filePath))
                    .Select(a.ValidationMessages.FileOrDirectoryDoesNotExist)
                    .FirstOrDefault());
            }

            return(argument);
        }
Esempio n. 2
0
        /// <summary>
        /// Configures an argument to accept only values corresponding to a existing files or directories.
        /// </summary>
        /// <param name="argument">The argument to configure.</param>
        /// <returns>The configured argument.</returns>
        public static Argument <T> ExistingOnly <T>(this Argument <T> argument)
            where T : IEnumerable <FileSystemInfo>
        {
            if (typeof(IEnumerable <FileInfo>).IsAssignableFrom(typeof(T)))
            {
                argument.AddValidator(Validate.FileExists);
            }
            else if (typeof(IEnumerable <DirectoryInfo>).IsAssignableFrom(typeof(T)))
            {
                argument.AddValidator(Validate.DirectoryExists);
            }
            else
            {
                argument.AddValidator(Validate.FileOrDirectoryExists);
            }

            return(argument);
        }
 public static Argument <FileSystemInfo> ExistingOnly(this Argument <FileSystemInfo> argument)
 {
     argument.AddValidator(symbol =>
                           symbol.Tokens
                           .Select(t => t.Value)
                           .Where(filePath => !Directory.Exists(filePath) && !File.Exists(filePath))
                           .Select(symbol.ValidationMessages.FileOrDirectoryDoesNotExist)
                           .FirstOrDefault());
     return(argument);
 }
Esempio n. 4
0
 public static Argument <DirectoryInfo> ExistingOnly(this Argument <DirectoryInfo> argument)
 {
     argument.AddValidator(symbol =>
                           symbol.Tokens
                           .Select(t => t.Value)
                           .Where(filePath => !Directory.Exists(filePath))
                           .Select(symbol.Resources.DirectoryDoesNotExist)
                           .FirstOrDefault());
     return(argument);
 }
 /// <summary>
 /// Configures an argument to accept only values corresponding to an existing file.
 /// </summary>
 /// <param name="argument">The argument to configure.</param>
 /// <returns>The configured argument.</returns>
 public static Argument <FileInfo> ExistingOnly(this Argument <FileInfo> argument)
 {
     argument.AddValidator(symbol =>
                           symbol.Tokens
                           .Select(t => t.Value)
                           .Where(filePath => !File.Exists(filePath))
                           .Select(symbol.LocalizationResources.FileDoesNotExist)
                           .FirstOrDefault());
     return(argument);
 }
Esempio n. 6
0
 /// <summary>
 /// Configures an argument to accept only values corresponding to an existing file.
 /// </summary>
 /// <param name="argument">The argument to configure.</param>
 /// <returns>The configured argument.</returns>
 public static Argument <FileInfo> ExistingOnly(this Argument <FileInfo> argument)
 {
     argument.AddValidator(Validate.FileExists);
     return(argument);
 }
Esempio n. 7
0
 /// <summary>
 /// Configures an argument to accept only values corresponding to an existing file or directory.
 /// </summary>
 /// <param name="argument">The argument to configure.</param>
 /// <returns>The configured argument.</returns>
 public static Argument <FileSystemInfo> ExistingOnly(this Argument <FileSystemInfo> argument)
 {
     argument.AddValidator(Validate.FileOrDirectoryExists);
     return(argument);
 }
Esempio n. 8
0
 /// <summary>
 /// Configures an argument to accept only values corresponding to an existing directory.
 /// </summary>
 /// <param name="argument">The argument to configure.</param>
 /// <returns>The configured argument.</returns>
 public static Argument <DirectoryInfo> ExistingOnly(this Argument <DirectoryInfo> argument)
 {
     argument.AddValidator(Validate.DirectoryExists);
     return(argument);
 }