2using System.Collections.Generic;
4using System.Threading.Tasks;
82 public Task<object>
DecodeAsync(
string ContentType,
byte[] Data, Encoding Encoding, KeyValuePair<string, string>[] Fields, Uri BaseUri)
96 switch (FileExtension.ToLower())
103 ContentType =
string.Empty;
116 switch (ContentType.ToLower())
123 FileExtension =
string.Empty;
158 public Task<KeyValuePair<byte[], string>>
EncodeAsync(
object Object, Encoding Encoding, params
string[] AcceptedContentTypes)
161 throw new ArgumentException(
"Unable to encode object, or content type not accepted.", nameof(Object));
166 s = JavaScriptDoc.JavaScript;
168 s = Object.ToString();
170 if (Encoding is
null)
172 ContentType +=
"; charset=utf-8";
173 Encoding = Encoding.UTF8;
176 ContentType +=
"; charset=" + Encoding.WebName;
178 return Task.FromResult(
new KeyValuePair<
byte[],
string>(Encoding.GetBytes(s), 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.
JavaScript encoder/decoder.
static readonly string[] JavaScriptFileExtensions
Plain text file extensions.
bool TryGetFileExtension(string ContentType, out string FileExtension)
Tries to get the file extension of an item, given its Content-Type.
bool Decodes(string ContentType, out Grade Grade)
If the decoder decodes an object with a given content type.
Task< KeyValuePair< byte[], string > > EncodeAsync(object Object, Encoding Encoding, params string[] AcceptedContentTypes)
Encodes an object.
string[] FileExtensions
Supported file extensions.
JavaScriptCodec()
JavaScript encoder/decoder.
static readonly string[] JavaScriptContentTypes
JavaScript content types.
bool TryGetContentType(string FileExtension, out string ContentType)
Tries to get the content type of an item, given its file extension.
Task< object > DecodeAsync(string ContentType, byte[] Data, Encoding Encoding, KeyValuePair< string, string >[] Fields, Uri BaseUri)
Decodes an object.
string[] ContentTypes
Supported content types.
bool Encodes(object Object, out Grade Grade, params string[] AcceptedContentTypes)
If the encoder encodes a given object.
const string DefaultContentType
application/javascript
Encapsulates a JavaScript Document
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...