< Summary

Information
Class: ContextProviders.Kicktipp.Csv.CsvDocumentContextExtensions
Assembly: ContextProviders.Kicktipp
File(s): /home/runner/work/KicktippAi/KicktippAi/src/ContextProviders.Kicktipp/Csv/CsvDocumentContext.cs
Line coverage
100%
Covered lines: 2
Uncovered lines: 0
Coverable lines: 2
Total lines: 41
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
ToCsvDocumentContext<T, TMap>(...)100%11100%

File(s)

/home/runner/work/KicktippAi/KicktippAi/src/ContextProviders.Kicktipp/Csv/CsvDocumentContext.cs

#LineLine coverage
 1using CsvHelper.Configuration;
 2using EHonda.KicktippAi.Core;
 3
 4namespace ContextProviders.Kicktipp.Csv;
 5
 6/// <summary>
 7/// Extension methods for creating <see cref="DocumentContext"/> from CSV data.
 8/// </summary>
 9public static class CsvDocumentContextExtensions
 10{
 11    /// <summary>
 12    /// Creates a <see cref="DocumentContext"/> from a collection of records using the specified ClassMap.
 13    /// </summary>
 14    /// <remarks>
 15    /// <para>
 16    /// This method requires both <typeparamref name="T"/> and <typeparamref name="TMap"/> to be specified
 17    /// explicitly at call sites, even though <typeparamref name="T"/> could theoretically be inferred from
 18    /// the <paramref name="records"/> parameter.
 19    /// </para>
 20    /// <para>
 21    /// C# 14 extension blocks would allow defining this as a method where only <typeparamref name="TMap"/>
 22    /// needs to be specified. However, extension block methods with non-inferable type parameters (i.e.,
 23    /// type parameters that only appear in constraints, not in the parameter list) are not supported in
 24    /// the current preview. Since <typeparamref name="TMap"/> only appears in the constraint
 25    /// <c>where TMap : ClassMap&lt;T&gt;, new()</c> and not as a method parameter, this pattern cannot
 26    /// be used.
 27    /// </para>
 28    /// </remarks>
 29    /// <typeparam name="T">The type of records to write.</typeparam>
 30    /// <typeparam name="TMap">The ClassMap defining the CSV schema.</typeparam>
 31    /// <param name="records">The collection of records to write.</param>
 32    /// <param name="fileName">The file name for the document (without .csv extension).</param>
 33    /// <returns>A DocumentContext containing the CSV content.</returns>
 34    public static DocumentContext ToCsvDocumentContext<T, TMap>(this IEnumerable<T> records, string fileName)
 35        where T : class
 36        where TMap : ClassMap<T>, new()
 37    {
 138        var csvContent = records.WriteToCsv<T, TMap>();
 139        return new DocumentContext(Name: $"{fileName}.csv", Content: csvContent);
 40    }
 41}