Note
In the following code examples - for easier readability - exception
handling has been omitted.
public CsvMappingBuilder AddProperty<T>(
string propertyName,
TypeConverter<T> converter
)
Public Function AddProperty(Of T) (
propertyName As String,
converter As TypeConverter(Of T)
) As CsvMappingBuilder
public:
generic<typename T>
CsvMappingBuilder^ AddProperty(
String^ propertyName,
TypeConverter<T>^ converter
)
member AddProperty :
propertyName : string *
converter : TypeConverter<'T> -> CsvMappingBuilder
When using this method, propertyName and the referenced CSV column name must match, and propertyName must meet the requirements for C# identifiers. Use the HasCaseSensitiveColumnNames property to determine whether the comparison is case-sensitive.
If the column name of the CSV file does not meet the requirements of C# identifiers, use AddPropertyT(String, IEnumerableString, TypeConverterT) instead.
Object serialization with CSV:
using FolkerKinzel.CsvTools;
using FolkerKinzel.CsvTools.Mappings;
using FolkerKinzel.CsvTools.Mappings.TypeConverters;
namespace Benchmarks;
internal static partial class CalculationWriter
{
internal static string WriteDefault(Calculation[] data)
{
var doubleConverter = new DoubleConverter();
CsvMapping mapping = CsvMappingBuilder
.Create()
.AddProperty("First", doubleConverter)
.AddProperty("Operator", new CharConverter())
.AddProperty("Second", doubleConverter)
.AddProperty("Result", doubleConverter)
.Build();
return data.ToCsv(
mapping,
static (calculation, mapping) =>
{
mapping.First = calculation.First;
mapping.Operator = calculation.Operator;
mapping.Second = calculation.Second;
mapping.Result = calculation.Result;
});
}
}
ArgumentNullException | propertyName or converter is null. |
ArgumentException | propertyName does not conform to the rules for C# identifiers (only ASCII characters) - or - a DynamicProperty with the same PropertyName has already been added. |
RegexMatchTimeoutException | Validating of propertyName takes too long. |