// Copyright 2009-2022 Josh Close
// This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
// See LICENSE.txt for details or visit http://www.opensource.org/licenses/ms-pl.html for MS-PL and http://opensource.org/licenses/Apache-2.0 for Apache 2.0.
// https://github.com/JoshClose/CsvHelper
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CsvHelper.Configuration
{
///
/// Sets type converter options on a parameter map.
///
public class ParameterMapTypeConverterOption
{
private readonly ParameterMap parameterMap;
///
/// Creates a new instance using the given .
///
/// The member map the options are being applied to.
public ParameterMapTypeConverterOption(ParameterMap parameterMap)
{
this.parameterMap = parameterMap;
}
///
/// The used when type converting.
/// This will override the global
/// setting.
///
/// The culture info.
public virtual ParameterMap CultureInfo(CultureInfo cultureInfo)
{
parameterMap.Data.TypeConverterOptions.CultureInfo = cultureInfo;
return parameterMap;
}
///
/// The to use when type converting.
/// This is used when doing any conversions.
///
/// The date time style.
public virtual ParameterMap DateTimeStyles(DateTimeStyles dateTimeStyle)
{
parameterMap.Data.TypeConverterOptions.DateTimeStyle = dateTimeStyle;
return parameterMap;
}
///
/// The to use when type converting.
/// This is used when doing converting.
///
/// The time span styles.
public virtual ParameterMap TimespanStyles(TimeSpanStyles timeSpanStyles)
{
parameterMap.Data.TypeConverterOptions.TimeSpanStyle = timeSpanStyles;
return parameterMap;
}
///
/// The to use when type converting.
/// This is used when doing any number conversions.
///
///
public virtual ParameterMap NumberStyles(NumberStyles numberStyle)
{
parameterMap.Data.TypeConverterOptions.NumberStyles = numberStyle;
return parameterMap;
}
///
/// The string format to be used when type converting.
///
/// The format.
public virtual ParameterMap Format(params string[] formats)
{
parameterMap.Data.TypeConverterOptions.Formats = formats;
return parameterMap;
}
///
/// The to use when converting.
/// This is used when doing conversions.
///
/// Kind of the URI.
public virtual ParameterMap UriKind(UriKind uriKind)
{
parameterMap.Data.TypeConverterOptions.UriKind = uriKind;
return parameterMap;
}
///
/// The string values used to represent a boolean when converting.
///
/// A value indicating whether true values or false values are being set.
/// A value indication if the current values should be cleared before adding the new ones.
/// The string boolean values.
public virtual ParameterMap BooleanValues(bool isTrue, bool clearValues = true, params string[] booleanValues)
{
if (isTrue)
{
if (clearValues)
{
parameterMap.Data.TypeConverterOptions.BooleanTrueValues.Clear();
}
parameterMap.Data.TypeConverterOptions.BooleanTrueValues.AddRange(booleanValues);
}
else
{
if (clearValues)
{
parameterMap.Data.TypeConverterOptions.BooleanFalseValues.Clear();
}
parameterMap.Data.TypeConverterOptions.BooleanFalseValues.AddRange(booleanValues);
}
return parameterMap;
}
///
/// The string values used to represent null when converting.
///
/// The values that represent null.
///
public virtual ParameterMap NullValues(params string[] nullValues)
{
return NullValues(true, nullValues);
}
///
/// The string values used to represent null when converting.
///
/// A value indication if the current values should be cleared before adding the new ones.
/// The values that represent null.
///
public virtual ParameterMap NullValues(bool clearValues, params string[] nullValues)
{
if (clearValues)
{
parameterMap.Data.TypeConverterOptions.NullValues.Clear();
}
parameterMap.Data.TypeConverterOptions.NullValues.AddRange(nullValues);
return parameterMap;
}
}
}