ImageMagick.Throw.IfInvalidFileName C# (CSharp) Метод

IfInvalidFileName() публичный статический Метод

public static IfInvalidFileName ( string fileName ) : void
fileName string
Результат void
    public static void IfInvalidFileName(string fileName)
    {
      IfNullOrEmpty(nameof(fileName), fileName);

      if (fileName.Length > 248)
        return;

      string path = fileName;

      int colonIndex = fileName.IndexOf(':');
      if (colonIndex != -1)
      {
        if (colonIndex + 1 == fileName.Length)
          return;

        if (!fileName.Contains("\\"))
          return;

        if (fileName[colonIndex + 1] != '/' && fileName[colonIndex + 1] != '\\')
          path = path.Substring(colonIndex + 1);

        if (path.Length > 1 && path[0] == '@')
          path = path.Substring(1);
      }

      try
      {
        path = Path.GetFullPath(path);
      }
      catch (ArgumentException)
      {
        return;
      }

      if (path.EndsWith("]", StringComparison.OrdinalIgnoreCase))
      {
        int endIndex = path.IndexOf("[", StringComparison.OrdinalIgnoreCase);
        if (endIndex != -1)
          path = path.Substring(0, endIndex);
      }

      IfFalse(nameof(fileName), File.Exists(path), "Unable to find file: {0}.", path);
    }

Usage Example

Пример #1
0
        ///<summary>
        /// Returns the format information of the specified format based on the extension of the
        /// file. If that fails the format will be determined by 'pinging' the file.
        ///</summary>
        ///<param name="fileName">The name of the file to get the format for.</param>
        public static MagickFormatInfo GetFormatInformation(string fileName)
        {
            string filePath = FileHelper.CheckForBaseDirectory(fileName);

            Throw.IfInvalidFileName(filePath);

            return(GetFormatInformation(new FileInfo(filePath)));
        }
All Usage Examples Of ImageMagick.Throw::IfInvalidFileName