< Summary

Information
Class: ArturRios.Data.Export.Configuration.TxtOptions
Assembly: ArturRios.Data.Export
File(s): /home/runner/work/dotnet-data/dotnet-data/src/ArturRios.Data.Export/Configuration/ExportOptions.cs
Line coverage
100%
Covered lines: 2
Uncovered lines: 0
Coverable lines: 2
Total lines: 97
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage
100%
Covered methods: 2
Fully covered methods: 2
Total methods: 2
Method coverage: 100%
Full method coverage: 100%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Encoding()100%11100%
get_NewLine()100%11100%

File(s)

/home/runner/work/dotnet-data/dotnet-data/src/ArturRios.Data.Export/Configuration/ExportOptions.cs

#LineLine coverage
 1using System.Text;
 2using System.Text.Json;
 3using MessagePack;
 4using MessagePack.Resolvers;
 5
 6namespace ArturRios.Data.Export.Configuration;
 7
 8/// <summary>Options for the CSV exporter.</summary>
 9public class CsvOptions
 10{
 11    /// <summary>Field delimiter. Default ','.</summary>
 12    public char Delimiter { get; set; } = ',';
 13
 14    /// <summary>Whether to write a header row from the column map. Default true.</summary>
 15    public bool IncludeHeader { get; set; } = true;
 16
 17    /// <summary>Text encoding. Default UTF-8 without BOM.</summary>
 18    public Encoding Encoding { get; set; } = new UTF8Encoding(false);
 19}
 20
 21/// <summary>Options for the JSON exporter.</summary>
 22public class JsonOptions
 23{
 24    private JsonSerializerOptions? _effective;
 25    private bool _writeIndented;
 26    private JsonSerializerOptions? _serializerOptions;
 27
 28    /// <summary>Whether to indent the JSON. Ignored when <see cref="SerializerOptions" /> is set.</summary>
 29    public bool WriteIndented
 30    {
 31        get => _writeIndented;
 32        set
 33        {
 34            _writeIndented = value;
 35            _effective = null;
 36        }
 37    }
 38
 39    /// <summary>Explicit serializer options; when set, used as-is.</summary>
 40    public JsonSerializerOptions? SerializerOptions
 41    {
 42        get => _serializerOptions;
 43        set
 44        {
 45            _serializerOptions = value;
 46            _effective = null;
 47        }
 48    }
 49
 50    /// <summary>
 51    ///     The options actually used: caller-supplied, else one derived from <see cref="WriteIndented" />.
 52    /// </summary>
 53    /// <remarks>
 54    ///     The derived instance is built once and reused. System.Text.Json caches its serialization metadata
 55    ///     per <see cref="JsonSerializerOptions" /> instance, so handing it a fresh instance on every export -
 56    ///     as this used to - rebuilt that cache every time and made each export pay full reflection cost.
 57    /// </remarks>
 58    public JsonSerializerOptions Effective =>
 59        _effective ??= SerializerOptions ?? new JsonSerializerOptions { WriteIndented = WriteIndented };
 60}
 61
 62/// <summary>Options for the TXT exporter.</summary>
 63public class TxtOptions
 64{
 65    /// <summary>Text encoding. Default UTF-8 without BOM.</summary>
 3466    public Encoding Encoding { get; set; } = new UTF8Encoding(false);
 67
 68    /// <summary>Line terminator. Default <see cref="Environment.NewLine" />.</summary>
 4069    public string NewLine { get; set; } = Environment.NewLine;
 70}
 71
 72/// <summary>Options for the MessagePack exporter.</summary>
 73public class MessagePackOptions
 74{
 75    /// <summary>Explicit serializer options; when set, used as-is.</summary>
 76    public MessagePackSerializerOptions? SerializerOptions { get; set; }
 77
 78    /// <summary>The options actually used: caller-supplied, else contractless standard (no attributes required).</summa
 79    public MessagePackSerializerOptions Effective =>
 80        SerializerOptions ?? MessagePackSerializerOptions.Standard.WithResolver(ContractlessStandardResolver.Instance);
 81}
 82
 83/// <summary>Aggregate options for the core exporters, configured via <c>AddExport</c>.</summary>
 84public class ExportOptions
 85{
 86    /// <summary>CSV options.</summary>
 87    public CsvOptions Csv { get; set; } = new();
 88
 89    /// <summary>JSON options.</summary>
 90    public JsonOptions Json { get; set; } = new();
 91
 92    /// <summary>TXT options.</summary>
 93    public TxtOptions Txt { get; set; } = new();
 94
 95    /// <summary>MessagePack options.</summary>
 96    public MessagePackOptions MessagePack { get; set; } = new();
 97}

Methods/Properties

get_Encoding()
get_NewLine()