Files
fil/packages/csharp/src/Kreuzberg/ExtractionMethod.cs

54 lines
1.6 KiB
C#
Raw Normal View History

2026-06-01 23:40:55 +02:00
// This file is auto-generated by alef. DO NOT EDIT.
// alef:hash:4e15143f4af1ae8bafbdb1506ef057da924484c66a19483966333558ad437e75
#nullable enable
using System;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Kreuzberg;
/// <summary>
/// How the extracted text was produced.
/// </summary>
[JsonConverter(typeof(ExtractionMethodJsonConverter))]
public enum ExtractionMethod
{
[JsonPropertyName("native")]
Native,
[JsonPropertyName("ocr")]
Ocr,
[JsonPropertyName("mixed")]
Mixed,
}
/// <summary>
/// Custom JSON converter for <see cref="ExtractionMethod"/> that respects explicit variant names.
/// </summary>
internal sealed class ExtractionMethodJsonConverter : JsonConverter<ExtractionMethod>
{
public override ExtractionMethod Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var value = reader.GetString();
return value switch
{
"native" => ExtractionMethod.Native,
"ocr" => ExtractionMethod.Ocr,
"mixed" => ExtractionMethod.Mixed,
_ => throw new JsonException($"Unknown ExtractionMethod value: {value}")
};
}
public override void Write(Utf8JsonWriter writer, ExtractionMethod value, JsonSerializerOptions options)
{
var str = value switch
{
ExtractionMethod.Native => "native",
ExtractionMethod.Ocr => "ocr",
ExtractionMethod.Mixed => "mixed",
_ => throw new JsonException($"Unknown ExtractionMethod value: {value}")
};
writer.WriteStringValue(str);
}
}