2using System.Collections.Generic;
 
    4using System.Threading.Tasks;
 
   32            "application/xhtml+xml" 
   86        public Task<object> 
DecodeAsync(
string ContentType, 
byte[] Data, Encoding Encoding, KeyValuePair<string, string>[] Fields, Uri BaseUri)
 
  100            switch (FileExtension.ToLower())
 
  109                    ContentType = 
"application/xhtml+xml";
 
  113                    ContentType = 
string.Empty;
 
  126            switch (ContentType.ToLower())
 
  129                    FileExtension = 
"html";
 
  132                case "application/xhtml+xml":
 
  133                    FileExtension = 
"xhtml";
 
  137                    FileExtension = 
string.Empty;
 
  151            if (Object is 
HtmlDocument || (Object is 
string s && s.TrimEnd().EndsWith(
"</html>", StringComparison.OrdinalIgnoreCase)))
 
  172        public Task<KeyValuePair<byte[], string>> 
EncodeAsync(
object Object, Encoding Encoding, params 
string[] AcceptedContentTypes)
 
  175                throw new ArgumentException(
"Unable to encode object, or content type not accepted.", nameof(Object));
 
  181                Html = HtmlDoc.HtmlText;
 
  182            else if (Object is 
string s)
 
  189                if (Encoding is 
null)
 
  191                    ContentType += 
"; charset=utf-8";
 
  192                    Bin = Encoding.UTF8.GetBytes(Html);
 
  196                    ContentType += 
"; charset=" + Encoding.WebName;
 
  197                    Bin = Encoding.GetBytes(Html);
 
  201            return Task.FromResult(
new KeyValuePair<
byte[], 
string>(Bin, ContentType));
 
Helps with parsing of commong data types.
static string GetString(byte[] Data, Encoding DefaultEncoding)
Gets a string from its binary representation, taking any Byte Order Mark (BOM) into account.
static readonly string[] HtmlFileExtensions
HTML file extensions.
bool Encodes(object Object, out Grade Grade, params string[] AcceptedContentTypes)
If the encoder encodes a given object.
string[] FileExtensions
Supported file extensions.
bool Decodes(string ContentType, out Grade Grade)
If the decoder decodes an object with a given content type.
bool TryGetContentType(string FileExtension, out string ContentType)
Tries to get the content type of an item, given its file extension.
HtmlCodec()
HTML encoder/decoder.
Task< object > DecodeAsync(string ContentType, byte[] Data, Encoding Encoding, KeyValuePair< string, string >[] Fields, Uri BaseUri)
Decodes an object.
string[] ContentTypes
Supported content types.
static readonly string[] HtmlContentTypes
HTML content types.
Task< KeyValuePair< byte[], string > > EncodeAsync(object Object, Encoding Encoding, params string[] AcceptedContentTypes)
Encodes an object.
bool TryGetFileExtension(string ContentType, out string FileExtension)
Tries to get the file extension of an item, given its Content-Type.
const string DefaultContentType
Default Content-Type for HTML: text/html
Static class managing encoding and decoding of internet content.
static bool IsAccepted(string ContentType, params string[] AcceptedContentTypes)
Checks if a given content type is acceptable.
Basic interface for Internet Content decoders. A class implementing this interface and having a defau...
Basic interface for Internet Content encoders. A class implementing this interface and having a defau...