< Summary

Information
Class: ArturRios.Data.Export.Configuration.CsvOptions
Assembly: ArturRios.Data.Export
File(s): /home/ci/agent/workspace/dotnet-data-docs_main/app/src/ArturRios.Data.Export/Configuration/ExportOptions.cs
Line coverage
100%
Covered lines: 4
Uncovered lines: 0
Coverable lines: 4
Total lines: 107
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage
100%
Covered methods: 4
Fully covered methods: 4
Total methods: 4
Method coverage: 100%
Full method coverage: 100%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Delimiter()100%11100%
get_IncludeHeader()100%11100%
get_Encoding()100%11100%
get_EscapeFormulas()100%11100%

File(s)

/home/ci/agent/workspace/dotnet-data-docs_main/app/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>
 22012    public char Delimiter { get; set; } = ',';
 13
 14    /// <summary>Whether to write a header row from the column map. Default true.</summary>
 10815    public bool IncludeHeader { get; set; } = true;
 16
 17    /// <summary>Text encoding. Default UTF-8 without BOM.</summary>
 8818    public Encoding Encoding { get; set; } = new UTF8Encoding(false);
 19
 20    /// <summary>
 21    ///     Whether to neutralize text that a spreadsheet would run as a formula (CSV / formula injection).
 22    ///     When on, a text value that starts with <c>=</c>, <c>+</c>, <c>-</c>, <c>@</c>, a tab or a carriage
 23    ///     return is written with a leading <c>'</c>, so Excel, LibreOffice and Google Sheets show it as text
 24    ///     instead of evaluating it. Numbers, dates and other formatted values are never changed, so a negative
 25    ///     number stays a number. Default true; turn it off only when the file is never opened in a spreadsheet
 26    ///     and the exact text matters.
 27    /// </summary>
 14628    public bool EscapeFormulas { get; set; } = true;
 29}
 30
 31/// <summary>Options for the JSON exporter.</summary>
 32public class JsonOptions
 33{
 34    private JsonSerializerOptions? _effective;
 35    private bool _writeIndented;
 36    private JsonSerializerOptions? _serializerOptions;
 37
 38    /// <summary>Whether to indent the JSON. Ignored when <see cref="SerializerOptions" /> is set.</summary>
 39    public bool WriteIndented
 40    {
 41        get => _writeIndented;
 42        set
 43        {
 44            _writeIndented = value;
 45            _effective = null;
 46        }
 47    }
 48
 49    /// <summary>Explicit serializer options; when set, used as-is.</summary>
 50    public JsonSerializerOptions? SerializerOptions
 51    {
 52        get => _serializerOptions;
 53        set
 54        {
 55            _serializerOptions = value;
 56            _effective = null;
 57        }
 58    }
 59
 60    /// <summary>
 61    ///     The options actually used: caller-supplied, else one derived from <see cref="WriteIndented" />.
 62    /// </summary>
 63    /// <remarks>
 64    ///     The derived instance is built once and reused. System.Text.Json caches its serialization metadata
 65    ///     per <see cref="JsonSerializerOptions" /> instance, so handing it a fresh instance on every export -
 66    ///     as this used to - rebuilt that cache every time and made each export pay full reflection cost.
 67    /// </remarks>
 68    public JsonSerializerOptions Effective =>
 69        _effective ??= SerializerOptions ?? new JsonSerializerOptions { WriteIndented = WriteIndented };
 70}
 71
 72/// <summary>Options for the TXT exporter.</summary>
 73public class TxtOptions
 74{
 75    /// <summary>Text encoding. Default UTF-8 without BOM.</summary>
 76    public Encoding Encoding { get; set; } = new UTF8Encoding(false);
 77
 78    /// <summary>Line terminator. Default <see cref="Environment.NewLine" />.</summary>
 79    public string NewLine { get; set; } = Environment.NewLine;
 80}
 81
 82/// <summary>Options for the MessagePack exporter.</summary>
 83public class MessagePackOptions
 84{
 85    /// <summary>Explicit serializer options; when set, used as-is.</summary>
 86    public MessagePackSerializerOptions? SerializerOptions { get; set; }
 87
 88    /// <summary>The options actually used: caller-supplied, else contractless standard (no attributes required).</summa
 89    public MessagePackSerializerOptions Effective =>
 90        SerializerOptions ?? MessagePackSerializerOptions.Standard.WithResolver(ContractlessStandardResolver.Instance);
 91}
 92
 93/// <summary>Aggregate options for the core exporters, configured via <c>AddExport</c>.</summary>
 94public class ExportOptions
 95{
 96    /// <summary>CSV options.</summary>
 97    public CsvOptions Csv { get; set; } = new();
 98
 99    /// <summary>JSON options.</summary>
 100    public JsonOptions Json { get; set; } = new();
 101
 102    /// <summary>TXT options.</summary>
 103    public TxtOptions Txt { get; set; } = new();
 104
 105    /// <summary>MessagePack options.</summary>
 106    public MessagePackOptions MessagePack { get; set; } = new();
 107}