IDetector.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System.Collections.Generic;
  2. using System.IO;
  3. namespace Masuit.Tools.Files.FileDetector;
  4. public interface IDetector
  5. {
  6. /// <summary>
  7. /// 基础文件类型
  8. /// </summary>
  9. string Precondition { get; }
  10. /// <summary>
  11. /// 真实扩展名
  12. /// </summary>
  13. string Extension { get; }
  14. bool Detect(Stream stream);
  15. /// <summary>
  16. /// MimeType
  17. /// </summary>
  18. string MimeType { get; }
  19. /// <summary>
  20. /// 格式类别
  21. /// </summary>
  22. List<FormatCategory> FormatCategories { get; }
  23. }
  24. public class NoneDetector:IDetector
  25. {
  26. public string Precondition { get; }
  27. public string Extension { get; }
  28. public bool Detect(Stream stream)
  29. {
  30. return false;
  31. }
  32. public string MimeType { get; }
  33. public List<FormatCategory> FormatCategories { get; }=new List<FormatCategory>();
  34. /// <summary>Returns a string that represents the current object.</summary>
  35. /// <returns>A string that represents the current object.</returns>
  36. public override string ToString()
  37. {
  38. return "不支持的文件格式,请自己实现针对该文件的IDetector";
  39. }
  40. }