src/CsvHelper.Website/input/migration/v20/index.md
ConvertUsing was renamed to Convert.
// v19
Map(m => m.Property).ConvertUsing(row => row.GetField<int>(0) + row.GetField<int>(1));
// v20
Map(m => m.Property).Convert(row => row.GetField<int>(0) + row.GetField<int>(1));
All properties changed from get; set; to get; init;.
// v19
var config = new CsvConfiguration(CultureInfo.InvariantCulture);
config.Delimiter = ";";
// v20
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
Delimiter = ";",
}
CsvConfiguration changed from a class to a record.
// v19
class MyConfig : CsvConfiguration {}
// v20
record MyConfig : CsvConfiguration {}
ShouldQuote now takes in IWriterRow instead of CsvContext.
// v19
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
ShouldQuote = (field, row) => true,
};
// v20
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
ShouldQuote = (field, context) => true,
};
Changed from enum NewLines to char?.
// v19
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
NewLine = NewLines.LF,
};
// v20
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
NewLine = '\n',
};
This was removed. Any code referencing this should be deleted.
This moved to CsvContext.
// v19
csv.Configuration.RegisterClassMap<MyMap>();
// v20
csv.Context.RegisterClassMap<MyMap>();
This moved to CsvContext.
// v19
csv.Configuration.UnregisterClassMap<MyMap>();
// v20
csv.Context.UnregisterClassMap<MyMap>();
This moved to CsvContext.
// v19
csv.Configuration.AutoMap<MyType>();
// v20
csv.Context.AutoMap<MyType>();
All setters removed.
// v19
var config = new CsvConfiguration(CultureInfo.InvariantCulture);
config.Delimiter = ";";
// v20
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
Delimiter = ";",
};
bool CacheFields.bool LeaveOpen.char? NewLine.ParserMode Mode.char[] WhiteSpaceChars.bool IgnoreQuotes.Any classes that implement IParserConfiguration will need these changes.
All setters removed.
// v19
var config = new CsvConfiguration(CultureInfo.InvariantCulture);
config.Delimiter = ";";
// v20
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
Delimiter = ";",
};
TypeConverterOptionsCache.TypeConverterCache.Maps.RegisterClassMap.UnregisterClassMap.AutoMap.Any classes that implement IReaderConfiguration will need these changes.
This interface was removed and it's properties were added to IWriteConfiguration.
// v19
class MyConfig : ISerializerConfiguration {}
// v20
class MyConfig : IWriterConfiguration {}
All setters removed.
// v19
var config = new CsvConfiguration(CultureInfo.InvariantCulture);
config.Delimiter = ";";
// v20
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
Delimiter = ";",
};
QuoteString.TypeConverterCache.MemberTypes.Maps.RegisterClassMap.UnregisterClassMap.AutoMap.Any classes that implement IWriterConfiguration will need these changes.
ConvertUsing renamed to Convert.
// v19
Map(m => m.Property).ConvertUsing(row => row.Get(0));
Map(m => m.Property).ConvertUsing(value => value?.ToString() ?? string.Empty);
// v20
Map(m => m.Property).Convert(row => row.Get(0));
Map(m => m.Property).Convert(value => value?.ToString() ?? string.Empty);
string[] Read() changed to bool Read().
// v19
string[] record;
while ((record = parser.Read()) != null)
{
}
// v20
while (parser.Read())
{
// Only get fields you need.
var field1 = parser[0];
var field2 = parser[1];
// Get all fields.
var record = parser.Record;
}
Constructor paramter IFieldReader fieldReader removed from all constructors.
// v19
var parser = new CsvParser(fieldReader);
// v20
var parser = new CsvParser();
Removed. Functionality moved into CsvWriter.
Removed. Functionality moved into CsvParser.
long ByteCount.long CharCount.int Count.string this[int index].string[] Record.string RawRecord.int Row.int RawRow.string[] Read to bool Read.Task<string[]> ReadAsync to Task<bool> ReadAsync.Any classes that implement IParser will need these changes.
ICsvParser Parser.Any classes that implement IReader will need these changes.
int ColumnCount.int CurrentIndex.string[] HeaderRecord.IParser Parser.Any classes that implement IReaderRow will need these changes.
Removed. Functionality moved into IWriter.
string[] HeaderRecord.int Row.int Index.Removed. Functionality moved into CsvWriter.
enum Caches was removed. Modifying internal caches is not supported anymore.
Any code referencing this should be removed.
ReadingContext and WritingContext was merged into a single CsvContext.
Anywhere either of these was used should change to CsvContext.
Any place a Func or Action was used now has a dedicated delegate.
This should only affect classes that are inheriting ClassMap
or CsvConfiguration.
Class removed. Code was wrapped into CsvParser.