< Summary

Information
Class: ContextProviders.Kicktipp.Csv.CsvWriterExtensions
Assembly: ContextProviders.Kicktipp
File(s): /home/runner/work/KicktippAi/KicktippAi/src/ContextProviders.Kicktipp/Csv/CsvWriterExtensions.cs
Line coverage
100%
Covered lines: 6
Uncovered lines: 0
Coverable lines: 6
Total lines: 31
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
WriteToCsv<T, TMap>(...)100%11100%

File(s)

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

#LineLine coverage
 1using System.Globalization;
 2using CsvHelper;
 3using CsvHelper.Configuration;
 4
 5namespace ContextProviders.Kicktipp.Csv;
 6
 7/// <summary>
 8/// Extension methods for writing objects to CSV using CsvHelper.
 9/// </summary>
 10public static class CsvWriterExtensions
 11{
 12    /// <summary>
 13    /// Writes a collection of records to CSV format using the specified ClassMap.
 14    /// </summary>
 15    /// <typeparam name="T">The type of records to write.</typeparam>
 16    /// <typeparam name="TMap">The ClassMap defining the CSV schema.</typeparam>
 17    /// <param name="records">The collection of records to write.</param>
 18    /// <returns>The CSV content as a string.</returns>
 19    public static string WriteToCsv<T, TMap>(this IEnumerable<T> records)
 20        where T : class
 21        where TMap : ClassMap<T>, new()
 22    {
 123        using var stringWriter = new StringWriter();
 124        using var csvWriter = new CsvWriter(stringWriter, CultureInfo.InvariantCulture);
 25
 126        csvWriter.Context.RegisterClassMap<TMap>();
 127        csvWriter.WriteRecords(records);
 28
 129        return stringWriter.ToString();
 130    }
 31}