mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-02-12 09:41:36 +00:00
49 lines
1.2 KiB
C#
49 lines
1.2 KiB
C#
|
|
namespace AIStudio.Tools.MIME;
|
||
|
|
|
||
|
|
public class TextBuilder : ISubtype
|
||
|
|
{
|
||
|
|
private const BaseType BASE_TYPE = BaseType.TEXT;
|
||
|
|
|
||
|
|
private TextBuilder()
|
||
|
|
{
|
||
|
|
}
|
||
|
|
|
||
|
|
public static TextBuilder Create() => new();
|
||
|
|
|
||
|
|
private TextSubtype subtype;
|
||
|
|
|
||
|
|
public TextBuilder UseSubtype(string subType)
|
||
|
|
{
|
||
|
|
this.subtype = subType.ToLowerInvariant() switch
|
||
|
|
{
|
||
|
|
"plain" => TextSubtype.PLAIN,
|
||
|
|
"html" => TextSubtype.HTML,
|
||
|
|
"css" => TextSubtype.CSS,
|
||
|
|
"csv" => TextSubtype.CSV,
|
||
|
|
"javascript" => TextSubtype.JAVASCRIPT,
|
||
|
|
"xml" => TextSubtype.XML,
|
||
|
|
"markdown" => TextSubtype.MARKDOWN,
|
||
|
|
"json" => TextSubtype.JSON,
|
||
|
|
|
||
|
|
_ => throw new ArgumentException("Unsupported MIME text subtype.", nameof(subType))
|
||
|
|
};
|
||
|
|
|
||
|
|
return this;
|
||
|
|
}
|
||
|
|
|
||
|
|
public TextBuilder UseSubtype(TextSubtype subType)
|
||
|
|
{
|
||
|
|
this.subtype = subType;
|
||
|
|
return this;
|
||
|
|
}
|
||
|
|
|
||
|
|
#region Implementation of IMIMESubtype
|
||
|
|
|
||
|
|
public MIMEType Build() => new()
|
||
|
|
{
|
||
|
|
Type = this,
|
||
|
|
TextRepresentation = $"{BASE_TYPE}/{this.subtype}".ToLowerInvariant()
|
||
|
|
};
|
||
|
|
|
||
|
|
#endregion
|
||
|
|
}
|