AI-Studio/app/MindWork AI Studio/Tools/MIME/TextBuilder.cs

49 lines
1.2 KiB
C#
Raw Normal View History

2026-01-07 11:56:11 +00:00
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
}