60 lines
1.3 KiB
C#
60 lines
1.3 KiB
C#
namespace Blahblah.Library.Network;
|
|
|
|
public abstract class MultipartFormData
|
|
{
|
|
public string Name { get; }
|
|
|
|
public MultipartFormData(string name)
|
|
{
|
|
Name = name;
|
|
}
|
|
|
|
public static FieldFormData From(string name, string value)
|
|
{
|
|
return new(name, value);
|
|
}
|
|
|
|
public static ObjectFormData<T> From<T>(string name, T value)
|
|
{
|
|
return new(name, value);
|
|
}
|
|
|
|
public static FileFormData From(string name, Stream stream, string fileName, string mimeType = NSMultipartFormData.DefaultMimeType)
|
|
{
|
|
return new(name, stream, fileName, mimeType);
|
|
}
|
|
}
|
|
|
|
public class FieldFormData : MultipartFormData
|
|
{
|
|
public string? Value { get; }
|
|
|
|
public FieldFormData(string name, string? value) : base(name)
|
|
{
|
|
Value = value;
|
|
}
|
|
}
|
|
|
|
public class ObjectFormData<T> : FieldFormData
|
|
{
|
|
public ObjectFormData(string name, T value) : base(name, value?.ToString())
|
|
{
|
|
}
|
|
}
|
|
|
|
public class FileFormData : MultipartFormData
|
|
{
|
|
public Stream Stream { get; }
|
|
|
|
public string FileName { get; }
|
|
|
|
public string MimeType { get; }
|
|
|
|
public FileFormData(string name, Stream stream, string fileName, string mimeType = NSMultipartFormData.DefaultMimeType) : base(name)
|
|
{
|
|
Stream = stream;
|
|
FileName = fileName;
|
|
MimeType = mimeType;
|
|
}
|
|
}
|