InternalUtility.cs 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System.Collections.Generic;
  2. using System.IO;
  3. using System.Linq;
  4. using AngleSharp;
  5. using AngleSharp.Html.Parser;
  6. namespace Rac.Tools
  7. {
  8. internal static class InternalUtility
  9. {
  10. public static byte[] ToBytes(this Stream stream)
  11. {
  12. using var ms = new MemoryStream();
  13. stream.CopyTo(ms);
  14. return ms.ToArray();
  15. }
  16. public static bool In<T>(this T value, params T[] checkIn)
  17. {
  18. return checkIn.Contains(value);
  19. }
  20. public static string LoadHtml(byte[] body, out string charset)
  21. {
  22. using var stream = new MemoryStream(body);
  23. var htmlDocument = new HtmlParser().ParseDocument(stream);
  24. charset = htmlDocument.CharacterSet;
  25. return htmlDocument.ToHtml();
  26. }
  27. public static void AddRange<T>(this HashSet<T> hashSet, IEnumerable<T> toAdd)
  28. {
  29. foreach (var item in toAdd)
  30. {
  31. hashSet.Add(item);
  32. }
  33. }
  34. }
  35. }