ExtensionLoadingInformation.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using PixiEditor.SDK.FileParsers;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace PixiEditor.SDK
  8. {
  9. public class ExtensionLoadingInformation
  10. {
  11. internal Extension Extension { get; }
  12. internal List<DocumentParserInfo> DocumentParsers { get; set; } = new List<DocumentParserInfo>();
  13. internal List<ImageParserInfo> ImageParsers { get; set; } = new List<ImageParserInfo>();
  14. internal ExtensionLoadingInformation(Extension extension)
  15. {
  16. Extension = extension;
  17. }
  18. public ExtensionLoadingInformation AddDocumentParser(Type documentParserType)
  19. {
  20. DocumentParserInfo parserInfo = new DocumentParserInfo(documentParserType);
  21. DocumentParsers.Add(parserInfo);
  22. foreach (string s in parserInfo.SupportedFileExtensions)
  23. {
  24. Extension.SupportedDocumentFileExtensions.Add(s);
  25. }
  26. return this;
  27. }
  28. public ExtensionLoadingInformation AddDocumentParser<TParser>()
  29. where TParser : DocumentParser => AddDocumentParser(typeof(TParser));
  30. public ExtensionLoadingInformation AddImageParser(Type documentParserType)
  31. {
  32. ImageParserInfo parserInfo = new ImageParserInfo(documentParserType);
  33. ImageParsers.Add(parserInfo);
  34. foreach (string s in parserInfo.SupportedFileExtensions)
  35. {
  36. Extension.SupportedImageFileExtensions.Add(s);
  37. }
  38. return this;
  39. }
  40. public ExtensionLoadingInformation AddImageParser<TParser>()
  41. where TParser : ImageParser => AddImageParser(typeof(TParser));
  42. }
  43. }