Skip to content

Latest commit

 

History

History
45 lines (34 loc) · 1.14 KB

README.md

File metadata and controls

45 lines (34 loc) · 1.14 KB

CSV Type Generator for C#

Actions NuGet NuGet Downloads

Usage

  1. Install package
dotnet add package wk.CsvGenerator
  1. Include CSV template as additional file in .csproj
  <ItemGroup>
    <AdditionalFiles Include="B.csv" />
  </ItemGroup>
  1. Create partial class and place CsvGeneratorAttribute
  2. Parse CSV with loader utility
using System;
using System.IO;

namespace MyApp {
    [CsvGenerator(Template = "B.csv")]
    public partial class Industry { }

    public class Program {
        public static void Main() {
            var csv = File.ReadAllText("resource/csv/B.csv");
            var data = IndustryLoader.Parse(csv);

            foreach (var item in data) {
                Console.WriteLine($"{item.Year} {item.VariableCategory,50}");
            }
        }
    }
}