Skip to content

Instantly share code, notes, and snippets.

View inbarbarkai's full-sized avatar

Inbar Barkai inbarbarkai

View GitHub Profile
@inbarbarkai
inbarbarkai / BufferTextReader.cs
Created February 23, 2020 15:11
A text reader wrapper to a byte buffer.
/// <summary>
/// This class is a wrapped to read text from existing buffers.
/// </summary>
/// <seealso cref="System.IO.TextReader" />
public class BufferTextReader : TextReader
{
private const int CharBufferLength = 16;
private byte[] _buffer;
private readonly char[] _charBuffer = ArrayPool<char>.Shared.Rent(CharBufferLength);
private int _charPosition;
@inbarbarkai
inbarbarkai / FileUploadOperation.cs
Created January 21, 2020 08:20
Swashbuckle 5 file upload operation filter for streamed files.
public class FileUploadOperation : IOperationFilter
{
public void Apply(OpenApiOperation operation, OperationFilterContext context)
{
// Check FileUploadOperationAttribute exists on the action.
var fileUploadAttribute = context.MethodInfo.GetCustomAttribute(typeof(FileUploadOperationAttribute), true) as FileUploadOperationAttribute;
if (fileUploadAttribute != null)
{
var requestBody = operation.RequestBody;
// Optional: Clearing other parameters from the documentation.