Path: redb-route/redb.Route.Sql/Batch/BatchSource.cs Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route.Sql/Batch/BatchSource.cs ---- using System.Collections; using System.Diagnostics.CodeAnalysis; using System.Text.Json; using System.Text.Json.Nodes; using System.Xml; namespace redb.Route.Sql.Batch; /// /// Decides whether a message body is a batch source and opens a reader over its items. A source is a list, any other /// sequence (a HashSet, a LINQ query, a yield method), an IAsyncEnumerable of a reference type (a /// streamed query result), or a JSON array (, a whose root is an array, /// ). A value that merely happens to be enumerable is one value, not a batch: a string or any other /// sequence of characters, a byte[] or any other sequence of bytes, a dictionary or JSON object (a map of named /// values), and an XML document or node — XML carries no batch shape of its own, as in Apache Camel. /// internal static class BatchSource { /// Opens a reader over the items of when it is a batch source. internal static bool TryOpen(object? body, CancellationToken ct, [NotNullWhen(true)] out BatchItemReader? reader) { reader = body switch { null or string or byte[] => null, IEnumerable or IEnumerable => null, JsonElement { ValueKind: JsonValueKind.Array } array => BatchItemReader.Over(array.EnumerateArray().Cast(), ct), JsonDocument { RootElement.ValueKind: JsonValueKind.Array } document => BatchItemReader.Over(document.RootElement.EnumerateArray().Cast(), ct), JsonElement or JsonDocument => null, IDictionary or XmlNode => null, _ when IsGenericMap(body.GetType()) => null, IAsyncEnumerable stream => BatchItemReader.Over(stream, ct), IEnumerable sequence => BatchItemReader.Over(sequence, ct), _ => null, }; return reader is not null; } /// A generic dictionary — included — is a map of named values, not a sequence of items. private static bool IsGenericMap(Type type) => type.GetInterfaces().Any(i => i.IsGenericType && (i.GetGenericTypeDefinition() == typeof(IDictionary<,>) || i.GetGenericTypeDefinition() == typeof(IReadOnlyDictionary<,>))); }