diff options
Diffstat (limited to 'ThirdParty/CsvHelper-master/src/CsvHelper/Configuration')
81 files changed, 6732 insertions, 0 deletions
diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/AllowCommentsAttribute.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/AllowCommentsAttribute.cs new file mode 100644 index 0000000..1490cc9 --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/AllowCommentsAttribute.cs @@ -0,0 +1,35 @@ +// 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; + +namespace CsvHelper.Configuration.Attributes +{ + /// <summary> + /// A value indicating if comments are allowed. + /// </summary> + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] + public class AllowCommentsAttribute : Attribute, IClassMapper + { + /// <summary> + /// Gets a value indicating if comments are allowed. + /// </summary> + public bool AllowComments { get; private set; } + + /// <summary> + /// A value indicating if comments are allowed. + /// </summary> + /// <param name="allowComments">The value indicating id comments are allowed.</param> + public AllowCommentsAttribute(bool allowComments) + { + AllowComments = allowComments; + } + + /// <inheritdoc /> + public void ApplyTo(CsvConfiguration configuration) + { + configuration.AllowComments = AllowComments; + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/BooleanFalseValuesAttribute.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/BooleanFalseValuesAttribute.cs new file mode 100644 index 0000000..b26315b --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/BooleanFalseValuesAttribute.cs @@ -0,0 +1,52 @@ +// 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; + +namespace CsvHelper.Configuration.Attributes +{ + /// <summary> + /// The string values used to represent a boolean false when converting. + /// </summary> + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] + public class BooleanFalseValuesAttribute : Attribute, IMemberMapper, IParameterMapper + { + /// <summary> + /// Gets the false values. + /// </summary> + public string[] FalseValues { get; private set; } + + /// <summary> + /// The string values used to represent a boolean false when converting. + /// </summary> + /// <param name="falseValue">The false values.</param> + public BooleanFalseValuesAttribute(string falseValue) + { + FalseValues = new string[] { falseValue }; + } + + /// <summary> + /// The string values used to represent a boolean false when converting. + /// </summary> + /// <param name="falseValues">The false values.</param> + public BooleanFalseValuesAttribute(params string[] falseValues) + { + FalseValues = falseValues; + } + + /// <inheritdoc /> + public void ApplyTo(MemberMap memberMap) + { + memberMap.Data.TypeConverterOptions.BooleanFalseValues.Clear(); + memberMap.Data.TypeConverterOptions.BooleanFalseValues.AddRange(FalseValues); + } + + /// <inheritdoc /> + public void ApplyTo(ParameterMap parameterMap) + { + parameterMap.Data.TypeConverterOptions.BooleanFalseValues.Clear(); + parameterMap.Data.TypeConverterOptions.BooleanFalseValues.AddRange(FalseValues); + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/BooleanTrueValuesAttribute.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/BooleanTrueValuesAttribute.cs new file mode 100644 index 0000000..3a9b591 --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/BooleanTrueValuesAttribute.cs @@ -0,0 +1,52 @@ +// 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; + +namespace CsvHelper.Configuration.Attributes +{ + /// <summary> + /// The string values used to represent a boolean true when converting. + /// </summary> + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] + public class BooleanTrueValuesAttribute : Attribute, IMemberMapper, IParameterMapper + { + /// <summary> + /// Gets the true values. + /// </summary> + public string[] TrueValues { get; private set; } + + /// <summary> + /// The string values used to represent a boolean true when converting. + /// </summary> + /// <param name="trueValue"></param> + public BooleanTrueValuesAttribute(string trueValue) + { + TrueValues = new string[] { trueValue }; + } + + /// <summary> + /// The string values used to represent a boolean true when converting. + /// </summary> + /// <param name="trueValues"></param> + public BooleanTrueValuesAttribute(params string[] trueValues) + { + TrueValues = trueValues; + } + + /// <inheritdoc /> + public void ApplyTo(MemberMap memberMap) + { + memberMap.Data.TypeConverterOptions.BooleanTrueValues.Clear(); + memberMap.Data.TypeConverterOptions.BooleanTrueValues.AddRange(TrueValues); + } + + /// <inheritdoc /> + public void ApplyTo(ParameterMap parameterMap) + { + parameterMap.Data.TypeConverterOptions.BooleanTrueValues.Clear(); + parameterMap.Data.TypeConverterOptions.BooleanTrueValues.AddRange(TrueValues); + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/BufferSizeAttribute.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/BufferSizeAttribute.cs new file mode 100644 index 0000000..f74e98e --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/BufferSizeAttribute.cs @@ -0,0 +1,36 @@ +// 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; + +namespace CsvHelper.Configuration.Attributes +{ + /// <summary> + /// The size of the buffer used for parsing and writing CSV files. + /// Default is 0x1000. + /// </summary> + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] + public class BufferSizeAttribute : Attribute, IClassMapper + { + /// <summary> + /// The buffer size. + /// </summary> + public int BufferSize { get; private set; } + + /// <summary> + /// The size of the buffer used for parsing and writing CSV files. + /// </summary> + /// <param name="bufferSize"></param> + public BufferSizeAttribute(int bufferSize) + { + BufferSize = bufferSize; + } + + /// <inheritdoc /> + public void ApplyTo(CsvConfiguration configuration) + { + configuration.BufferSize = BufferSize; + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/CacheFieldsAttribute.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/CacheFieldsAttribute.cs new file mode 100644 index 0000000..1f6b859 --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/CacheFieldsAttribute.cs @@ -0,0 +1,36 @@ +// 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; + +namespace CsvHelper.Configuration.Attributes +{ + /// <summary> + /// Cache fields that are created when parsing. + /// Default is false. + /// </summary> + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] + public class CacheFieldsAttribute : Attribute, IClassMapper + { + /// <summary> + /// Cache fields that are created when parsing. + /// </summary> + public bool CacheFields { get; private set; } + + /// <summary> + /// Cache fields that are created when parsing. + /// </summary> + /// <param name="cacheFields"></param> + public CacheFieldsAttribute(bool cacheFields) + { + CacheFields = cacheFields; + } + + /// <inheritdoc /> + public void ApplyTo(CsvConfiguration configuration) + { + configuration.CacheFields = CacheFields; + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/CommentAttribute.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/CommentAttribute.cs new file mode 100644 index 0000000..c0c6124 --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/CommentAttribute.cs @@ -0,0 +1,36 @@ +// 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; + +namespace CsvHelper.Configuration.Attributes +{ + /// <summary> + /// The character used to denote a line that is commented out. + /// Default is #. + /// </summary> + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] + public class CommentAttribute : Attribute, IClassMapper + { + /// <summary> + /// Gets the character used to denote a line that is commented out. + /// </summary> + public char Comment { get; private set; } + + /// <summary> + /// The character used to denote a line that is commented out. + /// </summary> + /// <param name="comment">The comment character.</param> + public CommentAttribute(char comment) + { + Comment = comment; + } + + /// <inheritdoc /> + public void ApplyTo(CsvConfiguration configuration) + { + configuration.Comment = Comment; + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/ConstantAttribute.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/ConstantAttribute.cs new file mode 100644 index 0000000..5dd2dc5 --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/ConstantAttribute.cs @@ -0,0 +1,47 @@ +// 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; + +namespace CsvHelper.Configuration.Attributes +{ + /// <summary> + /// The constant value that will be used for every record when + /// reading and writing. This value will always be used no matter + /// what other mapping configurations are specified. + /// </summary> + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] + public class ConstantAttribute : Attribute, IMemberMapper, IParameterMapper + { + /// <summary> + /// Gets the constant. + /// </summary> + public object Constant { get; private set; } + + /// <summary> + /// The constant value that will be used for every record when + /// reading and writing. This value will always be used no matter + /// what other mapping configurations are specified. + /// </summary> + /// <param name="constant">The constant.</param> + public ConstantAttribute(object constant) + { + Constant = constant; + } + + /// <inheritdoc /> + public void ApplyTo(MemberMap memberMap) + { + memberMap.Data.Constant = Constant; + memberMap.Data.IsConstantSet = true; + } + + /// <inheritdoc /> + public void ApplyTo(ParameterMap parameterMap) + { + parameterMap.Data.Constant = Constant; + parameterMap.Data.IsConstantSet = true; + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/CountBytesAttribute.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/CountBytesAttribute.cs new file mode 100644 index 0000000..165784e --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/CountBytesAttribute.cs @@ -0,0 +1,45 @@ +// 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.Text; + +namespace CsvHelper.Configuration.Attributes +{ + /// <summary> + /// A value indicating whether the number of bytes should + /// be counted while parsing. Default is false. This will slow down parsing + /// because it needs to get the byte count of every char for the given encoding. + /// The <see cref="Encoding"/> needs to be set correctly for this to be accurate. + /// </summary> + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] + public class CountBytesAttribute : Attribute, IClassMapper + { + /// <summary> + /// A value indicating whether the number of bytes should + /// be counted while parsing. Default is false. This will slow down parsing + /// because it needs to get the byte count of every char for the given encoding. + /// The <see cref="Encoding"/> needs to be set correctly for this to be accurate. + /// </summary> + public bool CountBytes { get; private set; } + + /// <summary> + /// A value indicating whether the number of bytes should + /// be counted while parsing. Default is false. This will slow down parsing + /// because it needs to get the byte count of every char for the given encoding. + /// The <see cref="Encoding"/> needs to be set correctly for this to be accurate. + /// </summary> + /// <param name="countBytes"></param> + public CountBytesAttribute(bool countBytes) + { + CountBytes = countBytes; + } + + /// <inheritdoc /> + public void ApplyTo(CsvConfiguration configuration) + { + configuration.CountBytes = CountBytes; + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/CultureInfoAttribute.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/CultureInfoAttribute.cs new file mode 100644 index 0000000..47940fb --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/CultureInfoAttribute.cs @@ -0,0 +1,46 @@ +// 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.Globalization; + +namespace CsvHelper.Configuration.Attributes +{ + /// <summary> + /// The <see cref="CultureInfo"/> used when type converting. + /// This will override the global <see cref="CsvConfiguration.CultureInfo"/> + /// setting. Or set the same if the attribute is specified on class level. + /// </summary> + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] + public class CultureInfoAttribute : Attribute, IMemberMapper, IParameterMapper + { + /// <summary> + /// Gets the culture info. + /// </summary> + public CultureInfo CultureInfo { get; private set; } + + /// <summary> + /// The <see cref="CultureInfo"/> used when type converting. + /// This will override the global <see cref="CsvConfiguration.CultureInfo"/> + /// setting. Or set the same if the attribute is specified on class level. + /// </summary> + /// <param name="culture">The culture.</param> + public CultureInfoAttribute(string culture) + { + CultureInfo = CultureInfo.GetCultureInfo(culture); + } + + /// <inheritdoc /> + public void ApplyTo(MemberMap memberMap) + { + memberMap.Data.TypeConverterOptions.CultureInfo = CultureInfo; + } + + /// <inheritdoc /> + public void ApplyTo(ParameterMap parameterMap) + { + parameterMap.Data.TypeConverterOptions.CultureInfo = CultureInfo; + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/DateTimeStylesAttribute.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/DateTimeStylesAttribute.cs new file mode 100644 index 0000000..42fd789 --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/DateTimeStylesAttribute.cs @@ -0,0 +1,44 @@ +// 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.Globalization; + +namespace CsvHelper.Configuration.Attributes +{ + /// <summary> + /// The <see cref="DateTimeStyles"/> to use when type converting. + /// This is used when doing any <see cref="DateTime"/> conversions. + /// </summary> + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] + public class DateTimeStylesAttribute : Attribute, IMemberMapper, IParameterMapper + { + /// <summary> + /// Gets the date time styles. + /// </summary> + public DateTimeStyles DateTimeStyles { get; private set; } + + /// <summary> + /// The <see cref="DateTimeStyles"/> to use when type converting. + /// This is used when doing any <see cref="DateTime"/> conversions. + /// </summary> + /// <param name="dateTimeStyles">The date time styles.</param> + public DateTimeStylesAttribute(DateTimeStyles dateTimeStyles) + { + DateTimeStyles = dateTimeStyles; + } + + /// <inheritdoc /> + public void ApplyTo(MemberMap memberMap) + { + memberMap.Data.TypeConverterOptions.DateTimeStyle = DateTimeStyles; + } + + /// <inheritdoc /> + public void ApplyTo(ParameterMap parameterMap) + { + parameterMap.Data.TypeConverterOptions.DateTimeStyle = DateTimeStyles; + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/DefaultAttribute.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/DefaultAttribute.cs new file mode 100644 index 0000000..f2e4e46 --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/DefaultAttribute.cs @@ -0,0 +1,45 @@ +// 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; + +namespace CsvHelper.Configuration.Attributes +{ + /// <summary> + /// The default value that will be used when reading when + /// the CSV field is empty. + /// </summary> + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] + public class DefaultAttribute : Attribute, IMemberMapper, IParameterMapper + { + /// <summary> + /// Gets the default value. + /// </summary> + public object Default { get; private set; } + + /// <summary> + /// The default value that will be used when reading when + /// the CSV field is empty. + /// </summary> + /// <param name="defaultValue">The default value</param> + public DefaultAttribute(object defaultValue) + { + Default = defaultValue; + } + + /// <inheritdoc /> + public void ApplyTo(MemberMap memberMap) + { + memberMap.Data.Default = Default; + memberMap.Data.IsDefaultSet = true; + } + + /// <inheritdoc /> + public void ApplyTo(ParameterMap parameterMap) + { + parameterMap.Data.Default = Default; + parameterMap.Data.IsDefaultSet = true; + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/DelimiterAttribute.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/DelimiterAttribute.cs new file mode 100644 index 0000000..b8b53f6 --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/DelimiterAttribute.cs @@ -0,0 +1,35 @@ +// 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; + +namespace CsvHelper.Configuration.Attributes +{ + /// <summary> + /// The delimiter used to separate fields. + /// </summary> + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] + public class DelimiterAttribute : Attribute, IClassMapper + { + /// <summary> + /// Gets the delimiter. + /// </summary> + public string Delimiter { get; private set; } + + /// <summary> + /// The delimiter used to separate fields. + /// </summary> + /// <param name="delimiter">The delimiter.</param> + public DelimiterAttribute(string delimiter) + { + Delimiter = delimiter; + } + + /// <inheritdoc /> + public void ApplyTo(CsvConfiguration configuration) + { + configuration.Delimiter = Delimiter; + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/DetectColumnCountChangesAttribute.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/DetectColumnCountChangesAttribute.cs new file mode 100644 index 0000000..f31aaf8 --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/DetectColumnCountChangesAttribute.cs @@ -0,0 +1,40 @@ +// 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; + +namespace CsvHelper.Configuration.Attributes +{ + /// <summary> + /// A value indicating whether changes in the column + /// count should be detected. If true, a <see cref="BadDataException"/> + /// will be thrown if a different column count is detected. + /// </summary> + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] + public class DetectColumnCountChangesAttribute : Attribute, IClassMapper + { + /// <summary> + /// A value indicating whether changes in the column + /// count should be detected. If true, a <see cref="BadDataException"/> + /// will be thrown if a different column count is detected. + /// </summary> + public bool DetectColumnCountChanges { get; private set; } + + /// <summary> + /// A value indicating whether changes in the column + /// count should be detected. If true, a <see cref="BadDataException"/> + /// will be thrown if a different column count is detected. + /// </summary> + public DetectColumnCountChangesAttribute(bool detectColumnCountChanges) + { + DetectColumnCountChanges = detectColumnCountChanges; + } + + /// <inheritdoc /> + public void ApplyTo(CsvConfiguration configuration) + { + configuration.DetectColumnCountChanges = DetectColumnCountChanges; + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/DetectDelimiterAttribute.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/DetectDelimiterAttribute.cs new file mode 100644 index 0000000..2c7da45 --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/DetectDelimiterAttribute.cs @@ -0,0 +1,35 @@ +// 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; + +namespace CsvHelper.Configuration.Attributes +{ + /// <summary> + /// Detect the delimiter instead of using the delimiter from configuration. + /// Default is <c>false</c>. + /// </summary> + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] + public class DetectDelimiterAttribute : Attribute, IClassMapper + { + /// <summary> + /// Detect the delimiter instead of using the delimiter from configuration. + /// </summary> + public bool DetectDelimiter { get; private set; } + + /// <summary> + /// Detect the delimiter instead of using the delimiter from configuration. + /// </summary> + public DetectDelimiterAttribute(bool detectDelimiter) + { + DetectDelimiter = detectDelimiter; + } + + /// <inheritdoc /> + public void ApplyTo(CsvConfiguration configuration) + { + configuration.DetectDelimiter = DetectDelimiter; + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/DetectDelimiterValuesAttribute.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/DetectDelimiterValuesAttribute.cs new file mode 100644 index 0000000..af641df --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/DetectDelimiterValuesAttribute.cs @@ -0,0 +1,37 @@ +// 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.Text.RegularExpressions; + +namespace CsvHelper.Configuration.Attributes +{ + /// <summary> + /// The possible delimiter values used when detecting the delimiter. + /// Default is [",", ";", "|", "\t"]. + /// </summary> + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] + public class DetectDelimiterValuesAttribute : Attribute, IClassMapper + { + /// <summary> + /// The possible delimiter values used when detecting the delimiter. + /// </summary> + public string[] DetectDelimiterValues { get; private set; } + + /// <summary> + /// The possible delimiter values used when detecting the delimiter. + /// </summary> + /// <param name="detectDelimiterValues">Whitespace separated list of values.</param> + public DetectDelimiterValuesAttribute(string detectDelimiterValues) + { + DetectDelimiterValues = Regex.Split(detectDelimiterValues, @"\s+"); + } + + /// <inheritdoc /> + public void ApplyTo(CsvConfiguration configuration) + { + configuration.DetectDelimiterValues = DetectDelimiterValues; + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/EncodingAttribute.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/EncodingAttribute.cs new file mode 100644 index 0000000..ee378ba --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/EncodingAttribute.cs @@ -0,0 +1,36 @@ +// 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.Text; + +namespace CsvHelper.Configuration.Attributes +{ + /// <summary> + /// The encoding used when counting bytes. + /// </summary> + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] + public class EncodingAttribute : Attribute, IClassMapper + { + /// <summary> + /// Gets the encoding used when counting bytes. + /// </summary> + public Encoding Encoding { get; private set; } + + /// <summary> + /// The encoding used when counting bytes. + /// </summary> + /// <param name="encoding">The encoding.</param> + public EncodingAttribute(string encoding) + { + Encoding = Encoding.GetEncoding(encoding); + } + + /// <inheritdoc /> + public void ApplyTo(CsvConfiguration configuration) + { + configuration.Encoding = Encoding; + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/EnumIgnoreCaseAttribute.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/EnumIgnoreCaseAttribute.cs new file mode 100644 index 0000000..c2b25c9 --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/EnumIgnoreCaseAttribute.cs @@ -0,0 +1,41 @@ +// 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.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CsvHelper.Configuration.Attributes +{ + /// <summary> + /// Ignore case when parsing enums. + /// </summary> + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] + public class EnumIgnoreCaseAttribute : Attribute, IMemberMapper, IMemberReferenceMapper, IParameterMapper + { + /// <inheritdoc/> + public void ApplyTo(MemberMap memberMap) + { + memberMap.Data.TypeConverterOptions.EnumIgnoreCase = true; + } + + /// <inheritdoc/> + public void ApplyTo(MemberReferenceMap referenceMap) + { + foreach (var memberMap in referenceMap.Data.Mapping.MemberMaps) + { + ApplyTo(memberMap); + } + } + + /// <inheritdoc/> + public void ApplyTo(ParameterMap parameterMap) + { + parameterMap.Data.TypeConverterOptions.EnumIgnoreCase = true; + } + + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/EscapeAttribute.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/EscapeAttribute.cs new file mode 100644 index 0000000..0d20d50 --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/EscapeAttribute.cs @@ -0,0 +1,35 @@ +// 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; + +namespace CsvHelper.Configuration.Attributes +{ + /// <summary> + /// The escape character used to escape a quote inside a field. + /// </summary> + [AttributeUsage( AttributeTargets.Class, AllowMultiple = false, Inherited = true )] + public class EscapeAttribute : Attribute, IClassMapper + { + /// <summary> + /// Gets the escape character used to escape a quote inside a field. + /// </summary> + public char Escape { get; private set; } + + /// <summary> + /// The escape character used to escape a quote inside a field. + /// </summary> + /// <param name="escape">The escape character.</param> + public EscapeAttribute( char escape ) + { + Escape = escape; + } + + /// <inheritdoc /> + public void ApplyTo(CsvConfiguration configuration) + { + configuration.Escape = Escape; + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/ExceptionMessagesContainRawDataAttribute.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/ExceptionMessagesContainRawDataAttribute.cs new file mode 100644 index 0000000..2cb9608 --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/ExceptionMessagesContainRawDataAttribute.cs @@ -0,0 +1,39 @@ +// 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; + +namespace CsvHelper.Configuration.Attributes +{ + /// <summary> + /// A value indicating if exception messages contain raw CSV data. + /// <c>true</c> if exception contain raw CSV data, otherwise <c>false</c>. + /// Default is <c>true</c>. + /// </summary> + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] + public class ExceptionMessagesContainRawDataAttribute : Attribute, IClassMapper + { + /// <summary> + /// A value indicating if exception messages contain raw CSV data. + /// <c>true</c> if exception contain raw CSV data, otherwise <c>false</c>. + /// </summary> + public bool ExceptionMessagesContainRawData { get; private set; } + + /// <summary> + /// A value indicating if exception messages contain raw CSV data. + /// <c>true</c> if exception contain raw CSV data, otherwise <c>false</c>. + /// </summary> + /// <param name="exceptionMessagesContainRawData"></param> + public ExceptionMessagesContainRawDataAttribute(bool exceptionMessagesContainRawData) + { + ExceptionMessagesContainRawData = exceptionMessagesContainRawData; + } + + /// <inheritdoc /> + public void ApplyTo(CsvConfiguration configuration) + { + configuration.ExceptionMessagesContainRawData = ExceptionMessagesContainRawData; + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/FormatAttribute.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/FormatAttribute.cs new file mode 100644 index 0000000..b42d8ed --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/FormatAttribute.cs @@ -0,0 +1,50 @@ +// 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; + +namespace CsvHelper.Configuration.Attributes +{ + /// <summary> + /// The string format to be used when type converting. + /// </summary> + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] + public class FormatAttribute : Attribute, IMemberMapper, IParameterMapper + { + /// <summary> + /// Gets the formats. + /// </summary> + public string[] Formats { get; private set; } + + /// <summary> + /// The string format to be used when type converting. + /// </summary> + /// <param name="format">The format.</param> + public FormatAttribute(string format) + { + Formats = new string[] { format }; + } + + /// <summary> + /// The string format to be used when type converting. + /// </summary> + /// <param name="formats">The formats.</param> + public FormatAttribute(params string[] formats) + { + Formats = formats; + } + + /// <inheritdoc /> + public void ApplyTo(MemberMap memberMap) + { + memberMap.Data.TypeConverterOptions.Formats = Formats; + } + + /// <inheritdoc /> + public void ApplyTo(ParameterMap parameterMap) + { + parameterMap.Data.TypeConverterOptions.Formats = Formats; + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/HasHeaderRecordAttribute.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/HasHeaderRecordAttribute.cs new file mode 100644 index 0000000..b0d93ae --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/HasHeaderRecordAttribute.cs @@ -0,0 +1,35 @@ +// 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; + +namespace CsvHelper.Configuration.Attributes +{ + /// <summary> + /// A value indicating if the CSV file has a header record. + /// </summary> + [AttributeUsage( AttributeTargets.Class, AllowMultiple = false, Inherited = true )] + public class HasHeaderRecordAttribute : Attribute, IClassMapper + { + /// <summary> + /// Gets a value indicating if the CSV file has a header record. + /// </summary> + public bool HasHeaderRecord { get; private set; } + + /// <summary> + /// A value indicating if the CSV file has a header record. + /// </summary> + /// <param name="hasHeaderRecord">A value indicating if the CSV file has a header record.</param> + public HasHeaderRecordAttribute( bool hasHeaderRecord ) + { + HasHeaderRecord = hasHeaderRecord; + } + + /// <inheritdoc /> + public void ApplyTo(CsvConfiguration configuration) + { + configuration.HasHeaderRecord = HasHeaderRecord; + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/HeaderPrefixAttribute.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/HeaderPrefixAttribute.cs new file mode 100644 index 0000000..4ae8227 --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/HeaderPrefixAttribute.cs @@ -0,0 +1,73 @@ +// 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; + +namespace CsvHelper.Configuration.Attributes +{ + /// <summary> + /// Appends a prefix to the header of each field of the reference member. + /// </summary> + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] + public class HeaderPrefixAttribute : Attribute, IMemberReferenceMapper, IParameterReferenceMapper + { + /// <summary> + /// Gets the prefix. + /// </summary> + public string? Prefix { get; private set; } + + /// <summary> + /// Gets a value indicating if the prefix should inherit parent prefixes. + /// </summary> + public bool Inherit { get; private set; } + + /// <summary> + /// Appends a prefix to the header of each field of the reference member. + /// </summary> + public HeaderPrefixAttribute() { } + + /// <summary> + /// Appends a prefix to the header of each field of the reference member. + /// </summary> + /// <param name="prefix">The prefix.</param> + public HeaderPrefixAttribute(string prefix) + { + Prefix = prefix; + } + + /// <summary> + /// Appends a prefix to the header of each field of the reference member. + /// </summary> + /// <param name="inherit">Inherits parent object prefixes.</param> + public HeaderPrefixAttribute(bool inherit) + { + Inherit = inherit; + } + + /// <summary> + /// Appends a prefix to the header of each field of the reference member. + /// </summary> + /// <param name="prefix">The prefix.</param> + /// <param name="inherit">Inherits parent object prefixes.</param> + public HeaderPrefixAttribute(string prefix, bool inherit) + { + Prefix = prefix; + Inherit = inherit; + } + + /// <inheritdoc /> + public void ApplyTo(MemberReferenceMap referenceMap) + { + referenceMap.Data.Inherit = Inherit; + referenceMap.Data.Prefix = Prefix ?? referenceMap.Data.Member.Name + "."; + } + + /// <inheritdoc /> + public void ApplyTo(ParameterReferenceMap referenceMap) + { + referenceMap.Data.Inherit = Inherit; + referenceMap.Data.Prefix = Prefix ?? referenceMap.Data.Parameter.Name + "."; + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/IClassMapper.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/IClassMapper.cs new file mode 100644 index 0000000..d395ac9 --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/IClassMapper.cs @@ -0,0 +1,19 @@ +// 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 + +namespace CsvHelper.Configuration.Attributes +{ + /// <summary> + /// Defines methods to enable pluggable configuration. + /// </summary> + public interface IClassMapper + { + /// <summary> + /// Applies configuration. + /// </summary> + /// <param name="configuration">The configuration to apply to.</param> + void ApplyTo(CsvConfiguration configuration); + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/IMemberMapper.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/IMemberMapper.cs new file mode 100644 index 0000000..b8701f1 --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/IMemberMapper.cs @@ -0,0 +1,20 @@ +// 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; + +namespace CsvHelper.Configuration.Attributes +{ + /// <summary> + /// Defines methods to enable pluggable configuration of member mapping. + /// </summary> + public interface IMemberMapper + { + /// <summary> + /// Applies configuration to the given <see cref="MemberMap"/>. + /// </summary> + /// <param name="memberMap">The member map.</param> + void ApplyTo(MemberMap memberMap); + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/IMemberReferenceMapper.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/IMemberReferenceMapper.cs new file mode 100644 index 0000000..c9c4d32 --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/IMemberReferenceMapper.cs @@ -0,0 +1,20 @@ +// 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; + +namespace CsvHelper.Configuration.Attributes +{ + /// <summary> + /// Defines methods to enable pluggable configuration of member reference mapping. + /// </summary> + public interface IMemberReferenceMapper + { + /// <summary> + /// Applies configuration to the given <see cref="MemberReferenceMap" />. + /// </summary> + /// <param name="referenceMap">The reference map.</param> + void ApplyTo(MemberReferenceMap referenceMap); + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/IParameterMapper.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/IParameterMapper.cs new file mode 100644 index 0000000..0b5c289 --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/IParameterMapper.cs @@ -0,0 +1,24 @@ +// 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.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CsvHelper.Configuration.Attributes +{ + /// <summary> + /// Defines methods to enable pluggable configuration of parameter mapping. + /// </summary> + public interface IParameterMapper + { + /// <summary> + /// Applies configuration to the given <see cref="ParameterMap"/>. + /// </summary> + /// <param name="parameterMap">The parameter map.</param> + void ApplyTo(ParameterMap parameterMap); + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/IParameterReferenceMapper.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/IParameterReferenceMapper.cs new file mode 100644 index 0000000..ea4fc50 --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/IParameterReferenceMapper.cs @@ -0,0 +1,24 @@ +// 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.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CsvHelper.Configuration.Attributes +{ + /// <summary> + /// Defines methods to enable pluggable configuration of parameter reference mapping. + /// </summary> + public interface IParameterReferenceMapper + { + /// <summary> + /// Applies configuration to the given <see cref="ParameterReferenceMap" />. + /// </summary> + /// <param name="referenceMap">The reference map.</param> + void ApplyTo(ParameterReferenceMap referenceMap); + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/IgnoreAttribute.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/IgnoreAttribute.cs new file mode 100644 index 0000000..41a199a --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/IgnoreAttribute.cs @@ -0,0 +1,41 @@ +// 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.Reflection; + +namespace CsvHelper.Configuration.Attributes +{ + /// <summary> + /// Ignore the member when reading and writing. + /// If this member has already been mapped as a reference + /// member, either by a class map, or by automapping, calling + /// this method will not ignore all the child members down the + /// tree that have already been mapped. + /// </summary> + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] + public class IgnoreAttribute : Attribute, IMemberMapper, IMemberReferenceMapper, IParameterMapper + { + /// <inheritdoc /> + public void ApplyTo(MemberMap memberMap) + { + memberMap.Data.Ignore = true; + } + + /// <inheritdoc /> + public void ApplyTo(MemberReferenceMap referenceMap) + { + foreach (var memberMap in referenceMap.Data.Mapping.MemberMaps) + { + ApplyTo(memberMap); + } + } + + /// <inheritdoc /> + public void ApplyTo(ParameterMap parameterMap) + { + parameterMap.Data.Ignore = true; + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/IgnoreBaseAttribute.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/IgnoreBaseAttribute.cs new file mode 100644 index 0000000..066be2e --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/IgnoreBaseAttribute.cs @@ -0,0 +1,20 @@ +// 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.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CsvHelper.Configuration.Attributes +{ + /// <summary> + /// Ignores base classes when auto mapping. + /// </summary> + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] + public class IgnoreBaseAttribute : Attribute + { + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/IgnoreBlankLinesAttribute.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/IgnoreBlankLinesAttribute.cs new file mode 100644 index 0000000..c270568 --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/IgnoreBlankLinesAttribute.cs @@ -0,0 +1,35 @@ +// 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; + +namespace CsvHelper.Configuration.Attributes +{ + /// <summary> + /// A value indicating if blank lines should be ignored when reading. + /// </summary> + [AttributeUsage( AttributeTargets.Class, AllowMultiple = false, Inherited = true )] + public class IgnoreBlankLinesAttribute : Attribute, IClassMapper + { + /// <summary> + /// Gets a value indicating if blank lines should be ignored when reading. + /// </summary> + public bool IgnoreBlankLines { get; private set; } + + /// <summary> + /// A value indicating if blank lines should be ignored when reading. + /// </summary> + /// <param name="ignoreBlankLines">The Ignore Blank Lines Flag.</param> + public IgnoreBlankLinesAttribute( bool ignoreBlankLines ) + { + IgnoreBlankLines = ignoreBlankLines; + } + + /// <inheritdoc /> + public void ApplyTo(CsvConfiguration configuration) + { + configuration.IgnoreBlankLines = IgnoreBlankLines; + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/IgnoreReferencesAttribute.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/IgnoreReferencesAttribute.cs new file mode 100644 index 0000000..05e7b0e --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/IgnoreReferencesAttribute.cs @@ -0,0 +1,41 @@ +// 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; + +namespace CsvHelper.Configuration.Attributes +{ + /// <summary> + /// Gets a value indicating whether references + /// should be ignored when auto mapping. <c>true</c> to ignore + /// references, otherwise <c>false</c>. Default is false. + /// </summary> + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] + public class IgnoreReferencesAttribute : Attribute, IClassMapper + { + /// <summary> + /// Gets a value indicating whether references + /// should be ignored when auto mapping. <c>true</c> to ignore + /// references, otherwise <c>false</c>. Default is false. + /// </summary> + public bool IgnoreReferences { get; private set; } + + /// <summary> + /// Gets a value indicating whether references + /// should be ignored when auto mapping. <c>true</c> to ignore + /// references, otherwise <c>false</c>. Default is false. + /// </summary> + /// <param name="ignoreReferences">Ignore references value.</param> + public IgnoreReferencesAttribute(bool ignoreReferences) + { + IgnoreReferences = ignoreReferences; + } + + /// <inheritdoc /> + public void ApplyTo(CsvConfiguration configuration) + { + configuration.IgnoreReferences = IgnoreReferences; + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/IncludePrivateMembersAttribute.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/IncludePrivateMembersAttribute.cs new file mode 100644 index 0000000..92c7c1b --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/IncludePrivateMembersAttribute.cs @@ -0,0 +1,35 @@ +// 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; + +namespace CsvHelper.Configuration.Attributes +{ + /// <summary> + /// A value indicating if private member should be read from and written to. + /// </summary> + [AttributeUsage( AttributeTargets.Class, AllowMultiple = false, Inherited = true )] + public class IncludePrivateMembersAttribute : Attribute, IClassMapper + { + /// <summary> + /// Gets a value indicating if private member should be read from and written to. + /// </summary> + public bool IncludePrivateMembers { get; private set; } + + /// <summary> + /// A value indicating if private member should be read from and written to. + /// </summary> + /// <param name="includePrivateMembers">The Include Private Members Flag.</param> + public IncludePrivateMembersAttribute( bool includePrivateMembers ) + { + IncludePrivateMembers = includePrivateMembers; + } + + /// <inheritdoc /> + public void ApplyTo(CsvConfiguration configuration) + { + configuration.IncludePrivateMembers = IncludePrivateMembers; + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/IndexAttribute.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/IndexAttribute.cs new file mode 100644 index 0000000..e469741 --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/IndexAttribute.cs @@ -0,0 +1,57 @@ +// 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; + +namespace CsvHelper.Configuration.Attributes +{ + /// <summary> + /// When reading, is used to get the field at + /// the given index. When writing, the fields + /// will be written in the order of the field + /// indexes. + /// </summary> + [AttributeUsage( AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true )] + public class IndexAttribute : Attribute, IMemberMapper, IParameterMapper + { + /// <summary> + /// Gets the index. + /// </summary> + public int Index { get; private set; } + + /// <summary> + /// Gets the index end. + /// </summary> + public int IndexEnd { get; private set; } + + /// <summary> + /// When reading, is used to get the field at + /// the given index. When writing, the fields + /// will be written in the order of the field + /// indexes. + /// </summary> + /// <param name="index">The index.</param> + /// <param name="indexEnd">The index end.</param> + public IndexAttribute( int index, int indexEnd = -1 ) + { + Index = index; + IndexEnd = indexEnd; + } + + /// <inheritdoc /> + public void ApplyTo(MemberMap memberMap) + { + memberMap.Data.Index = Index; + memberMap.Data.IndexEnd = IndexEnd; + memberMap.Data.IsIndexSet = true; + } + + /// <inheritdoc /> + public void ApplyTo(ParameterMap parameterMap) + { + parameterMap.Data.Index = Index; + parameterMap.Data.IsIndexSet = true; + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/InjectionCharactersAttribute.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/InjectionCharactersAttribute.cs new file mode 100644 index 0000000..66f6964 --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/InjectionCharactersAttribute.cs @@ -0,0 +1,37 @@ +// 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.Linq; +using System.Text.RegularExpressions; + +namespace CsvHelper.Configuration.Attributes +{ + /// <summary> + /// Gets the characters that are used for injection attacks. + /// </summary> + public class InjectionCharactersAttribute : Attribute, IClassMapper + { + /// <summary> + /// Gets the characters that are used for injection attacks. + /// Default is '=', '@', '+', '-', '\t', '\r'. + /// </summary> + public char[] InjectionCharacters { get; private set; } + + /// <summary> + /// Gets the characters that are used for injection attacks. + /// </summary> + /// <param name="injectionCharacters"></param> + public InjectionCharactersAttribute(string injectionCharacters) + { + InjectionCharacters = Regex.Split(injectionCharacters, @"\s+").Select(s => s[0]).ToArray(); + } + + /// <inheritdoc /> + public void ApplyTo(CsvConfiguration configuration) + { + configuration.InjectionCharacters = InjectionCharacters; + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/InjectionEscapeCharacterAttribute.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/InjectionEscapeCharacterAttribute.cs new file mode 100644 index 0000000..1db163d --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/InjectionEscapeCharacterAttribute.cs @@ -0,0 +1,35 @@ +// 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; + +namespace CsvHelper.Configuration.Attributes +{ + /// <summary> + /// The character used to escape a detected injection. + /// </summary> + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] + public class InjectionEscapeCharacterAttribute : Attribute, IClassMapper + { + /// <summary> + /// The character used to escape a detected injection. + /// </summary> + public char InjectionEscapeCharacter { get; private set; } + + /// <summary> + /// The character used to escape a detected injection. + /// </summary> + /// <param name="injectionEscapeCharacter"></param> + public InjectionEscapeCharacterAttribute(char injectionEscapeCharacter) + { + InjectionEscapeCharacter = injectionEscapeCharacter; + } + + /// <inheritdoc /> + public void ApplyTo(CsvConfiguration configuration) + { + configuration.InjectionEscapeCharacter = InjectionEscapeCharacter; + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/InjectionOptionsAttribute.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/InjectionOptionsAttribute.cs new file mode 100644 index 0000000..db97300 --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/InjectionOptionsAttribute.cs @@ -0,0 +1,35 @@ +// 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; + +namespace CsvHelper.Configuration.Attributes +{ + /// <summary> + /// The injection options. + /// </summary> + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] + public class InjectionOptionsAttribute : Attribute, IClassMapper + { + /// <summary> + /// The injection options. + /// </summary> + public InjectionOptions InjectionOptions { get; private set; } + + /// <summary> + /// The injection options. + /// </summary> + /// <param name="injectionOptions"></param> + public InjectionOptionsAttribute(InjectionOptions injectionOptions) + { + InjectionOptions = injectionOptions; + } + + /// <inheritdoc /> + public void ApplyTo(CsvConfiguration configuration) + { + configuration.InjectionOptions = InjectionOptions; + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/LineBreakInQuotedFieldIsBadDataAttribute.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/LineBreakInQuotedFieldIsBadDataAttribute.cs new file mode 100644 index 0000000..db95cbc --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/LineBreakInQuotedFieldIsBadDataAttribute.cs @@ -0,0 +1,39 @@ +// 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; + +namespace CsvHelper.Configuration.Attributes +{ + /// <summary> + /// A value indicating if a line break found in a quote field should + /// be considered bad data. <c>true</c> to consider a line break bad data, otherwise <c>false</c>. + /// Defaults to false. + /// </summary> + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] + public class LineBreakInQuotedFieldIsBadDataAttribute : Attribute, IClassMapper + { + /// <summary> + /// A value indicating if a line break found in a quote field should + /// be considered bad data. <c>true</c> to consider a line break bad data, otherwise <c>false</c>. + /// </summary> + public bool LineBreakInQuotedFieldIsBadData { get; private set; } + + /// <summary> + /// A value indicating if a line break found in a quote field should + /// be considered bad data. <c>true</c> to consider a line break bad data, otherwise <c>false</c>. + /// </summary> + /// <param name="lineBreakInQuotedFieldIsBadData"></param> + public LineBreakInQuotedFieldIsBadDataAttribute(bool lineBreakInQuotedFieldIsBadData) + { + LineBreakInQuotedFieldIsBadData = lineBreakInQuotedFieldIsBadData; + } + + /// <inheritdoc /> + public void ApplyTo(CsvConfiguration configuration) + { + configuration.LineBreakInQuotedFieldIsBadData = LineBreakInQuotedFieldIsBadData; + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/MaxFieldSizeAttribute.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/MaxFieldSizeAttribute.cs new file mode 100644 index 0000000..1d5c837 --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/MaxFieldSizeAttribute.cs @@ -0,0 +1,40 @@ +// 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.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CsvHelper.Configuration.Attributes +{ + /// <summary> + /// Gets or sets the maximum size of a field. + /// Defaults to 0, indicating maximum field size is not checked. + /// </summary> + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] + public class MaxFieldSizeAttribute : Attribute, IClassMapper + { + /// <summary> + /// Gets or sets the maximum size of a field. + /// </summary> + public double MaxFieldSize { get; private set; } + + /// <summary> + /// Gets or sets the maximum size of a field. + /// </summary> + /// <param name="maxFieldSize"></param> + public MaxFieldSizeAttribute(double maxFieldSize) + { + MaxFieldSize = maxFieldSize; + } + + /// <inheritdoc /> + public void ApplyTo(CsvConfiguration configuration) + { + configuration.MaxFieldSize = MaxFieldSize; + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/MemberTypesAttribute.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/MemberTypesAttribute.cs new file mode 100644 index 0000000..e07e86f --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/MemberTypesAttribute.cs @@ -0,0 +1,40 @@ +// 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; + +namespace CsvHelper.Configuration.Attributes +{ + /// <summary> + /// The member types that are used when auto mapping. + /// MemberTypes are flags, so you can choose more than one. + /// Default is Properties. + /// </summary> + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] + public class MemberTypesAttribute : Attribute, IClassMapper + { + /// <summary> + /// The member types that are used when auto mapping. + /// MemberTypes are flags, so you can choose more than one. + /// Default is Properties. + /// </summary> + public MemberTypes MemberTypes { get; private set; } + + /// <summary> + /// The member types that are used when auto mapping. + /// MemberTypes are flags, so you can choose more than one. + /// Default is Properties. + /// </summary> + public MemberTypesAttribute(MemberTypes memberTypes) + { + MemberTypes = memberTypes; + } + + /// <inheritdoc /> + public void ApplyTo(CsvConfiguration configuration) + { + configuration.MemberTypes = MemberTypes; + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/ModeAttribute.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/ModeAttribute.cs new file mode 100644 index 0000000..448a543 --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/ModeAttribute.cs @@ -0,0 +1,38 @@ +// 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; + +namespace CsvHelper.Configuration.Attributes +{ + /// <summary> + /// The mode. + /// See <see cref="CsvMode"/> for more details. + /// </summary> + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] + public class ModeAttribute : Attribute, IClassMapper + { + /// <summary> + /// The mode. + /// See <see cref="CsvMode"/> for more details. + /// </summary> + public CsvMode Mode { get; private set; } + + /// <summary> + /// The mode. + /// See <see cref="CsvMode"/> for more details. + /// </summary> + /// <param name="mode"></param> + public ModeAttribute(CsvMode mode) + { + Mode = mode; + } + + /// <inheritdoc /> + public void ApplyTo(CsvConfiguration configuration) + { + configuration.Mode = Mode; + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/NameAttribute.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/NameAttribute.cs new file mode 100644 index 0000000..f1220e4 --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/NameAttribute.cs @@ -0,0 +1,77 @@ +// 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; + +namespace CsvHelper.Configuration.Attributes +{ + /// <summary> + /// When reading, is used to get the field + /// at the index of the name if there was a + /// header specified. It will look for the + /// first name match in the order listed. + /// When writing, sets the name of the + /// field in the header record. + /// The first name will be used. + /// </summary> + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] + public class NameAttribute : Attribute, IMemberMapper, IParameterMapper + { + /// <summary> + /// Gets the names. + /// </summary> + public string[] Names { get; private set; } + + /// <summary> + /// When reading, is used to get the field + /// at the index of the name if there was a + /// header specified. It will look for the + /// first name match in the order listed. + /// When writing, sets the name of the + /// field in the header record. + /// The first name will be used. + /// </summary> + /// <param name="name">The name</param> + public NameAttribute(string name) + { + Names = new string[] { name }; + } + + /// <summary> + /// When reading, is used to get the field + /// at the index of the name if there was a + /// header specified. It will look for the + /// first name match in the order listed. + /// When writing, sets the name of the + /// field in the header record. + /// The first name will be used. + /// </summary> + /// <param name="names">The names.</param> + public NameAttribute(params string[] names) + { + if (names == null || names.Length == 0) + { + throw new ArgumentNullException(nameof(names)); + } + + Names = names; + } + + /// <inheritdoc /> + public void ApplyTo(MemberMap memberMap) + { + memberMap.Data.Names.Clear(); + memberMap.Data.Names.AddRange(Names); + memberMap.Data.IsNameSet = true; + } + + /// <inheritdoc /> + public void ApplyTo(ParameterMap parameterMap) + { + parameterMap.Data.Names.Clear(); + parameterMap.Data.Names.AddRange(Names); + parameterMap.Data.IsNameSet = true; + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/NameIndexAttribute.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/NameIndexAttribute.cs new file mode 100644 index 0000000..e3d1dfa --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/NameIndexAttribute.cs @@ -0,0 +1,45 @@ +// 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; + +namespace CsvHelper.Configuration.Attributes +{ + /// <summary> + /// When reading, is used to get the + /// index of the name used when there + /// are multiple names that are the same. + /// </summary> + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] + public class NameIndexAttribute : Attribute, IMemberMapper, IParameterMapper + { + /// <summary> + /// The name index. + /// </summary> + public int NameIndex { get; private set; } + + /// <summary> + /// When reading, is used to get the + /// index of the name used when there + /// are multiple names that are the same. + /// </summary> + /// <param name="nameIndex">The name index.</param> + public NameIndexAttribute(int nameIndex) + { + NameIndex = nameIndex; + } + + /// <inheritdoc /> + public void ApplyTo(MemberMap memberMap) + { + memberMap.Data.NameIndex = NameIndex; + } + + /// <inheritdoc /> + public void ApplyTo(ParameterMap parameterMap) + { + parameterMap.Data.NameIndex = NameIndex; + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/NewLineAttribute.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/NewLineAttribute.cs new file mode 100644 index 0000000..a2bdbd2 --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/NewLineAttribute.cs @@ -0,0 +1,39 @@ +// 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; + +namespace CsvHelper.Configuration.Attributes +{ + /// <summary> + /// The newline string to use. Default is \r\n (CRLF). + /// When writing, this value is always used. + /// When reading, this value is only used if explicitly set. + /// If not set, the parser uses one of \r\n, \r, or \n. + /// </summary> + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] + public class NewLineAttribute : Attribute, IClassMapper + { + /// The newline string to use. Default is \r\n (CRLF). + /// When writing, this value is always used. + /// When reading, this value is only used if explicitly set. + /// If not set, the parser uses one of \r\n, \r, or \n. + public string NewLine { get; private set; } + + /// The newline string to use. Default is \r\n (CRLF). + /// When writing, this value is always used. + /// When reading, this value is only used if explicitly set. + /// If not set, the parser uses one of \r\n, \r, or \n. + public NewLineAttribute(string newLine) + { + NewLine = newLine; + } + + /// <inheritdoc /> + public void ApplyTo(CsvConfiguration configuration) + { + configuration.NewLine = NewLine; + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/NullValuesAttribute.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/NullValuesAttribute.cs new file mode 100644 index 0000000..8c87e28 --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/NullValuesAttribute.cs @@ -0,0 +1,52 @@ +// 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; + +namespace CsvHelper.Configuration.Attributes +{ + /// <summary> + /// The string values used to represent null when converting. + /// </summary> + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] + public class NullValuesAttribute : Attribute, IMemberMapper, IParameterMapper + { + /// <summary> + /// Gets the null values. + /// </summary> + public string[] NullValues { get; private set; } + + /// <summary> + /// The string values used to represent null when converting. + /// </summary> + /// <param name="nullValue">The null values.</param> + public NullValuesAttribute(string nullValue) + { + NullValues = new string[] { nullValue }; + } + + /// <summary> + /// The string values used to represent null when converting. + /// </summary> + /// <param name="nullValues">The null values.</param> + public NullValuesAttribute(params string[] nullValues) + { + NullValues = nullValues; + } + + /// <inheritdoc /> + public void ApplyTo(MemberMap memberMap) + { + memberMap.Data.TypeConverterOptions.NullValues.Clear(); + memberMap.Data.TypeConverterOptions.NullValues.AddRange(NullValues); + } + + /// <inheritdoc /> + public void ApplyTo(ParameterMap parameterMap) + { + parameterMap.Data.TypeConverterOptions.NullValues.Clear(); + parameterMap.Data.TypeConverterOptions.NullValues.AddRange(NullValues); + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/NumberStylesAttribute.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/NumberStylesAttribute.cs new file mode 100644 index 0000000..1cd37fb --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/NumberStylesAttribute.cs @@ -0,0 +1,44 @@ +// 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.Globalization; + +namespace CsvHelper.Configuration.Attributes +{ + /// <summary> + /// The <see cref="NumberStyles"/> to use when type converting. + /// This is used when doing any number conversions. + /// </summary> + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] + public class NumberStylesAttribute : Attribute, IMemberMapper, IParameterMapper + { + /// <summary> + /// Gets the number styles. + /// </summary> + public NumberStyles NumberStyles { get; private set; } + + /// <summary> + /// The <see cref="NumberStyles"/> to use when type converting. + /// This is used when doing any number conversions. + /// </summary> + /// <param name="numberStyles">The number styles.</param> + public NumberStylesAttribute(NumberStyles numberStyles) + { + NumberStyles = numberStyles; + } + + /// <inheritdoc /> + public void ApplyTo(MemberMap memberMap) + { + memberMap.Data.TypeConverterOptions.NumberStyles = NumberStyles; + } + + /// <inheritdoc /> + public void ApplyTo(ParameterMap parameterMap) + { + parameterMap.Data.TypeConverterOptions.NumberStyles = NumberStyles; + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/OptionalAttribute.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/OptionalAttribute.cs new file mode 100644 index 0000000..5348c85 --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/OptionalAttribute.cs @@ -0,0 +1,27 @@ +// 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; + +namespace CsvHelper.Configuration.Attributes +{ + /// <summary> + /// Ignore the member when reading if no matching field name can be found. + /// </summary> + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] + public class OptionalAttribute : Attribute, IMemberMapper, IParameterMapper + { + /// <inheritdoc /> + public void ApplyTo(MemberMap memberMap) + { + memberMap.Data.IsOptional = true; + } + + /// <inheritdoc /> + public void ApplyTo(ParameterMap parameterMap) + { + parameterMap.Data.IsOptional = true; + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/ProcessFieldBufferSizeAttribute.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/ProcessFieldBufferSizeAttribute.cs new file mode 100644 index 0000000..81f6178 --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/ProcessFieldBufferSizeAttribute.cs @@ -0,0 +1,36 @@ +// 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; + +namespace CsvHelper.Configuration.Attributes +{ + /// <summary> + /// The size of the buffer used when processing fields. + /// Default is 1024. + /// </summary> + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] + public class ProcessFieldBufferSizeAttribute : Attribute, IClassMapper + { + /// <summary> + /// The size of the buffer used when processing fields. + /// </summary> + public int ProcessFieldBufferSize { get; private set; } + + /// <summary> + /// The size of the buffer used when processing fields. + /// </summary> + /// <param name="processFieldBufferSize"></param> + public ProcessFieldBufferSizeAttribute(int processFieldBufferSize) + { + ProcessFieldBufferSize = processFieldBufferSize; + } + + /// <inheritdoc /> + public void ApplyTo(CsvConfiguration configuration) + { + configuration.ProcessFieldBufferSize = ProcessFieldBufferSize; + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/QuoteAttribute.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/QuoteAttribute.cs new file mode 100644 index 0000000..93b5887 --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/QuoteAttribute.cs @@ -0,0 +1,35 @@ +// 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; + +namespace CsvHelper.Configuration.Attributes +{ + /// <summary> + /// The character used to quote fields. + /// </summary> + [AttributeUsage( AttributeTargets.Class, AllowMultiple = false, Inherited = true )] + public class QuoteAttribute : Attribute, IClassMapper + { + /// <summary> + /// Gets the character used to quote fields. + /// </summary> + public char Quote { get; private set; } + + /// <summary> + /// The character used to quote fields. + /// </summary> + /// <param name="quote">The quote character.</param> + public QuoteAttribute( char quote ) + { + Quote = quote; + } + + /// <inheritdoc /> + public void ApplyTo(CsvConfiguration configuration) + { + configuration.Quote = Quote; + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/TrimOptionsAttribute.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/TrimOptionsAttribute.cs new file mode 100644 index 0000000..1b2f645 --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/TrimOptionsAttribute.cs @@ -0,0 +1,35 @@ +// 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; + +namespace CsvHelper.Configuration.Attributes +{ + /// <summary> + /// The fields trimming options. + /// </summary> + [AttributeUsage( AttributeTargets.Class, AllowMultiple = false, Inherited = true )] + public class TrimOptionsAttribute : Attribute, IClassMapper + { + /// <summary> + /// Gets the fields trimming options. + /// </summary> + public TrimOptions TrimOptions { get; private set; } + + /// <summary> + /// The fields trimming options. + /// </summary> + /// <param name="trimOptions">The TrimOptions.</param> + public TrimOptionsAttribute( TrimOptions trimOptions ) + { + TrimOptions = trimOptions; + } + + /// <inheritdoc /> + public void ApplyTo(CsvConfiguration configuration) + { + configuration.TrimOptions = TrimOptions; + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/TypeConverterAttribute.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/TypeConverterAttribute.cs new file mode 100644 index 0000000..f3900ec --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/TypeConverterAttribute.cs @@ -0,0 +1,57 @@ +// 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 CsvHelper.TypeConversion; +using System; + +namespace CsvHelper.Configuration.Attributes +{ + /// <summary> + /// Specifies the <see cref="TypeConverter"/> to use + /// when converting the member to and from a CSV field. + /// </summary> + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] + public class TypeConverterAttribute : Attribute, IMemberMapper, IParameterMapper + { + /// <summary> + /// Gets the type converter. + /// </summary> + public ITypeConverter TypeConverter { get; private set; } + + /// <summary> + /// Specifies the <see cref="TypeConverter"/> to use + /// when converting the member to and from a CSV field. + /// </summary> + /// <param name="typeConverterType">The type of the <see cref="ITypeConverter"/>.</param> + public TypeConverterAttribute(Type typeConverterType) : this(typeConverterType, new object[0]) { } + + /// <summary> + /// Specifies the <see cref="TypeConverter"/> to use + /// when converting the member to and from a CSV field. + /// </summary> + /// <param name="typeConverterType">The type of the <see cref="ITypeConverter"/>.</param> + /// <param name="constructorArgs">Type constructor arguments for the type converter.</param> + public TypeConverterAttribute(Type typeConverterType, params object[] constructorArgs) + { + if (typeConverterType == null) + { + throw new ArgumentNullException(nameof(typeConverterType)); + } + + TypeConverter = ObjectResolver.Current.Resolve(typeConverterType, constructorArgs) as ITypeConverter ?? throw new ArgumentException($"Type '{typeConverterType.FullName}' does not implement {nameof(ITypeConverter)}"); + } + + /// <inheritdoc /> + public void ApplyTo(MemberMap memberMap) + { + memberMap.Data.TypeConverter = TypeConverter; + } + + /// <inheritdoc /> + public void ApplyTo(ParameterMap parameterMap) + { + parameterMap.Data.TypeConverter = TypeConverter; + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/UseNewObjectForNullReferenceMembersAttribute.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/UseNewObjectForNullReferenceMembersAttribute.cs new file mode 100644 index 0000000..6bfbf37 --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/UseNewObjectForNullReferenceMembersAttribute.cs @@ -0,0 +1,47 @@ +// 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; + +namespace CsvHelper.Configuration.Attributes +{ + /// <summary> + /// Gets a value indicating that during writing if a new + /// object should be created when a reference member is null. + /// True to create a new object and use it's defaults for the + /// fields, or false to leave the fields empty for all the + /// reference member's member. + /// </summary> + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] + public class UseNewObjectForNullReferenceMembersAttribute : Attribute, IClassMapper + { + /// <summary> + /// Gets a value indicating that during writing if a new + /// object should be created when a reference member is null. + /// True to create a new object and use it's defaults for the + /// fields, or false to leave the fields empty for all the + /// reference member's member. + /// </summary> + public bool UseNewObjectForNullReferenceMembers { get; private set; } + + /// <summary> + /// Gets a value indicating that during writing if a new + /// object should be created when a reference member is null. + /// True to create a new object and use it's defaults for the + /// fields, or false to leave the fields empty for all the + /// reference member's member. + /// </summary> + /// <param name="useNewObjectForNullReferenceMembers">The value.</param> + public UseNewObjectForNullReferenceMembersAttribute(bool useNewObjectForNullReferenceMembers) + { + UseNewObjectForNullReferenceMembers = useNewObjectForNullReferenceMembers; + } + + /// <inheritdoc /> + public void ApplyTo(CsvConfiguration configuration) + { + configuration.UseNewObjectForNullReferenceMembers = UseNewObjectForNullReferenceMembers; + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/WhiteSpaceCharsAttribute.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/WhiteSpaceCharsAttribute.cs new file mode 100644 index 0000000..ef8f7cb --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/WhiteSpaceCharsAttribute.cs @@ -0,0 +1,41 @@ +// 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.Linq; +using System.Text.RegularExpressions; + +namespace CsvHelper.Configuration.Attributes +{ + /// <summary> + /// Characters considered whitespace. + /// Used when trimming fields. + /// Default is [' ']. + /// </summary> + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] + public class WhiteSpaceCharsAttribute : Attribute, IClassMapper + { + /// <summary> + /// Characters considered whitespace. + /// Used when trimming fields. + /// </summary> + public char[] WhiteSpaceChars { get; private set; } + + /// <summary> + /// Characters considered whitespace. + /// Used when trimming fields. + /// </summary> + /// <param name="whiteSpaceChars"></param> + public WhiteSpaceCharsAttribute(string whiteSpaceChars) + { + WhiteSpaceChars = Regex.Split(whiteSpaceChars, @"\s").Select(s => s[0]).ToArray(); + } + + /// <inheritdoc /> + public void ApplyTo(CsvConfiguration configuration) + { + configuration.WhiteSpaceChars = WhiteSpaceChars; + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/ClassMap.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/ClassMap.cs new file mode 100644 index 0000000..b000693 --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/ClassMap.cs @@ -0,0 +1,648 @@ +// 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 CsvHelper.Configuration.Attributes; +using CsvHelper.TypeConversion; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Reflection; +using System.Runtime.CompilerServices; + +namespace CsvHelper.Configuration +{ + ///<summary> + /// Maps class members to CSV fields. + ///</summary> + public abstract class ClassMap + { + private static readonly List<Type> enumerableConverters = new List<Type> + { + typeof(ArrayConverter), + typeof(CollectionGenericConverter), + typeof(EnumerableConverter), + typeof(IDictionaryConverter), + typeof(IDictionaryGenericConverter), + typeof(IEnumerableConverter), + typeof(IEnumerableGenericConverter) + }; + + /// <summary> + /// The type of the class this map is for. + /// </summary> + public virtual Type ClassType { get; private set; } + + /// <summary> + /// The class constructor parameter mappings. + /// </summary> + public virtual List<ParameterMap> ParameterMaps { get; } = new List<ParameterMap>(); + + /// <summary> + /// The class member mappings. + /// </summary> + public virtual MemberMapCollection MemberMaps { get; } = new MemberMapCollection(); + + /// <summary> + /// The class member reference mappings. + /// </summary> + public virtual MemberReferenceMapCollection ReferenceMaps { get; } = new MemberReferenceMapCollection(); + + /// <summary> + /// Allow only internal creation of CsvClassMap. + /// </summary> + /// <param name="classType">The type of the class this map is for.</param> + internal ClassMap(Type classType) + { + ClassType = classType; + } + + /// <summary> + /// Maps a member to a CSV field. + /// </summary> + /// <param name="classType">The type of the class this map is for. This may not be the same type + /// as the member.DeclaringType or the current ClassType due to nested member mappings.</param> + /// <param name="member">The member to map.</param> + /// <param name="useExistingMap">If true, an existing map will be used if available. + /// If false, a new map is created for the same member.</param> + /// <returns>The member mapping.</returns> + public MemberMap Map(Type classType, MemberInfo member, bool useExistingMap = true) + { + if (useExistingMap) + { + var existingMap = MemberMaps.Find(member); + if (existingMap != null) + { + return existingMap; + } + } + + var memberMap = MemberMap.CreateGeneric(classType, member); + memberMap.Data.Index = GetMaxIndex() + 1; + MemberMaps.Add(memberMap); + + return memberMap; + } + + /// <summary> + /// Maps a non-member to a CSV field. This allows for writing + /// data that isn't mapped to a class member. + /// </summary> + /// <returns>The member mapping.</returns> + public virtual MemberMap<object, object> Map() + { + var memberMap = new MemberMap<object, object>(null); + memberMap.Data.Index = GetMaxIndex() + 1; + MemberMaps.Add(memberMap); + + return memberMap; + } + + /// <summary> + /// Maps a member to another class map. + /// </summary> + /// <param name="classMapType">The type of the class map.</param> + /// <param name="member">The member.</param> + /// <param name="constructorArgs">Constructor arguments used to create the reference map.</param> + /// <returns>The reference mapping for the member.</returns> + public virtual MemberReferenceMap References(Type classMapType, MemberInfo member, params object[] constructorArgs) + { + if (!typeof(ClassMap).IsAssignableFrom(classMapType)) + { + throw new InvalidOperationException($"Argument {nameof(classMapType)} is not a CsvClassMap."); + } + + var existingMap = ReferenceMaps.Find(member); + + if (existingMap != null) + { + return existingMap; + } + + var map = (ClassMap)ObjectResolver.Current.Resolve(classMapType, constructorArgs); + map.ReIndex(GetMaxIndex() + 1); + var reference = new MemberReferenceMap(member, map); + ReferenceMaps.Add(reference); + + return reference; + } + + /// <summary> + /// Maps a constructor parameter to a CSV field. + /// </summary> + /// <param name="name">The name of the constructor parameter.</param> + public virtual ParameterMap Parameter(string name) + { + if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name)); + + var args = new GetConstructorArgs(ClassType); + + return Parameter(() => ConfigurationFunctions.GetConstructor(args), name); + } + + /// <summary> + /// Maps a constructor parameter to a CSV field. + /// </summary> + /// <param name="getConstructor">A function that returns the <see cref="ConstructorInfo"/> for the constructor.</param> + /// <param name="name">The name of the constructor parameter.</param> + public virtual ParameterMap Parameter(Func<ConstructorInfo> getConstructor, string name) + { + if (getConstructor == null) throw new ArgumentNullException(nameof(getConstructor)); + if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullException(nameof(name)); + + var constructor = getConstructor(); + var parameters = constructor.GetParameters(); + var parameter = parameters.SingleOrDefault(p => p.Name == name); + if (parameter == null) + { + throw new ConfigurationException($"Constructor {constructor.GetDefinition()} doesn't contain a paramter with name '{name}'."); + } + + return Parameter(constructor, parameter); + } + + /// <summary> + /// Maps a constructor parameter to a CSV field. + /// </summary> + /// <param name="constructor">The <see cref="ConstructorInfo"/> for the constructor.</param> + /// <param name="parameter">The <see cref="ParameterInfo"/> for the constructor parameter.</param> + public virtual ParameterMap Parameter(ConstructorInfo constructor, ParameterInfo parameter) + { + if (constructor == null) throw new ArgumentNullException(nameof(constructor)); + if (parameter == null) throw new ArgumentNullException(nameof(parameter)); + + if (!constructor.GetParameters().Contains(parameter)) + { + throw new ConfigurationException($"Constructor {constructor.GetDefinition()} doesn't contain parameter '{parameter.GetDefinition()}'."); + } + + var parameterMap = new ParameterMap(parameter); + parameterMap.Data.Index = GetMaxIndex(isParameter: true) + 1; + ParameterMaps.Add(parameterMap); + + return parameterMap; + } + + /// <summary> + /// Auto maps all members for the given type. If a member + /// is mapped again it will override the existing map. + /// </summary> + /// <param name="culture">The culture.</param> + public virtual void AutoMap(CultureInfo culture) + { + AutoMap(new CsvConfiguration(culture)); + } + + /// <summary> + /// Auto maps all members for the given type. If a member + /// is mapped again it will override the existing map. + /// </summary> + /// <param name="configuration">The configuration.</param> + public virtual void AutoMap(CsvConfiguration configuration) + { + AutoMap(new CsvContext(configuration)); + } + + /// <summary> + /// Auto maps all members for the given type. If a member + /// is mapped again it will override the existing map. + /// </summary> + /// <param name="context">The context.</param> + public virtual void AutoMap(CsvContext context) + { + var type = GetGenericType(); + if (typeof(IEnumerable).IsAssignableFrom(type)) + { + throw new ConfigurationException("Types that inherit IEnumerable cannot be auto mapped. " + + "Did you accidentally call GetRecord or WriteRecord which " + + "acts on a single record instead of calling GetRecords or " + + "WriteRecords which acts on a list of records?"); + } + + var mapParents = new LinkedList<Type>(); + var args = new ShouldUseConstructorParametersArgs(type); + if (context.Configuration.ShouldUseConstructorParameters(args)) + { + // This type doesn't have a parameterless constructor so we can't create an + // instance and set it's member. Constructor parameters need to be created + // instead. Writing only uses getters, so members will also be mapped + // for writing purposes. + AutoMapConstructorParameters(this, context, mapParents); + } + + AutoMapMembers(this, context, mapParents); + } + + /// <summary> + /// Get the largest index for the + /// members and references. + /// </summary> + /// <returns>The max index.</returns> + public virtual int GetMaxIndex(bool isParameter = false) + { + if (isParameter) + { + return ParameterMaps.Select(parameterMap => parameterMap.GetMaxIndex()).DefaultIfEmpty(-1).Max(); + } + + if (MemberMaps.Count == 0 && ReferenceMaps.Count == 0) + { + return -1; + } + + var indexes = new List<int>(); + if (MemberMaps.Count > 0) + { + indexes.Add(MemberMaps.Max(pm => pm.Data.Index)); + } + + if (ReferenceMaps.Count > 0) + { + indexes.AddRange(ReferenceMaps.Select(referenceMap => referenceMap.GetMaxIndex())); + } + + return indexes.Max(); + } + + /// <summary> + /// Resets the indexes based on the given start index. + /// </summary> + /// <param name="indexStart">The index start.</param> + /// <returns>The last index + 1.</returns> + public virtual int ReIndex(int indexStart = 0) + { + foreach (var parameterMap in ParameterMaps) + { + parameterMap.Data.Index = indexStart + parameterMap.Data.Index; + } + + foreach (var memberMap in MemberMaps) + { + if (!memberMap.Data.IsIndexSet) + { + memberMap.Data.Index = indexStart + memberMap.Data.Index; + } + } + + foreach (var referenceMap in ReferenceMaps) + { + indexStart = referenceMap.Data.Mapping.ReIndex(indexStart); + } + + return indexStart; + } + + /// <summary> + /// Auto maps the given map and checks for circular references as it goes. + /// </summary> + /// <param name="map">The map to auto map.</param> + /// <param name="context">The context.</param> + /// <param name="mapParents">The list of parents for the map.</param> + /// <param name="indexStart">The index starting point.</param> + protected virtual void AutoMapMembers(ClassMap map, CsvContext context, LinkedList<Type> mapParents, int indexStart = 0) + { + var type = map.GetGenericType(); + + var flags = BindingFlags.Instance | BindingFlags.Public; + if (context.Configuration.IncludePrivateMembers) + { + flags = flags | BindingFlags.NonPublic; + } + + var members = new List<MemberInfo>(); + if ((context.Configuration.MemberTypes & MemberTypes.Properties) == MemberTypes.Properties) + { + // We need to go up the declaration tree and find the actual type the property + // exists on and use that PropertyInfo instead. This is so we can get the private + // set method for the property. + var properties = new List<PropertyInfo>(); + foreach (var property in ReflectionHelper.GetUniqueProperties(type, flags)) + { + if (properties.Any(p => p.Name == property.Name)) + { + // Multiple properties could have the same name if a child class property + // is hiding a parent class property by using `new`. It's possible that + // the order of the properties returned + continue; + } + + properties.Add(ReflectionHelper.GetDeclaringProperty(type, property, flags)); + } + + members.AddRange(properties); + } + + if ((context.Configuration.MemberTypes & MemberTypes.Fields) == MemberTypes.Fields) + { + // We need to go up the declaration tree and find the actual type the field + // exists on and use that FieldInfo instead. + var fields = new List<MemberInfo>(); + foreach (var field in ReflectionHelper.GetUniqueFields(type, flags)) + { + if (fields.Any(p => p.Name == field.Name)) + { + // Multiple fields could have the same name if a child class field + // is hiding a parent class field by using `new`. It's possible that + // the order of the fields returned + continue; + } + + if (!field.GetCustomAttributes(typeof(CompilerGeneratedAttribute), false).Any()) + { + fields.Add(ReflectionHelper.GetDeclaringField(type, field, flags)); + } + } + + members.AddRange(fields); + } + + foreach (var member in members) + { + if (member.GetCustomAttribute<IgnoreAttribute>() != null) + { + // Ignore this member including its tree if it's a reference. + continue; + } + + var typeConverterType = context.TypeConverterCache.GetConverter(member).GetType(); + + if (context.Configuration.HasHeaderRecord && enumerableConverters.Contains(typeConverterType)) + { + // Enumerable converters can't write the header properly, so skip it. + continue; + } + + var memberTypeInfo = member.MemberType().GetTypeInfo(); + var isDefaultConverter = typeConverterType == typeof(DefaultTypeConverter); + if (isDefaultConverter) + { + // If the type is not one covered by our type converters + // and it has a parameterless constructor, create a + // reference map for it. + + if (context.Configuration.IgnoreReferences) + { + continue; + } + + if (CheckForCircularReference(member.MemberType(), mapParents)) + { + continue; + } + + mapParents.AddLast(type); + var refMapType = typeof(DefaultClassMap<>).MakeGenericType(member.MemberType()); + var refMap = (ClassMap)ObjectResolver.Current.Resolve(refMapType); + + if (memberTypeInfo.HasConstructor() && !memberTypeInfo.HasParameterlessConstructor() && !memberTypeInfo.IsUserDefinedStruct()) + { + AutoMapConstructorParameters(refMap, context, mapParents, Math.Max(map.GetMaxIndex() + 1, indexStart)); + } + + // Need to use Max here for nested types. + AutoMapMembers(refMap, context, mapParents, Math.Max(map.GetMaxIndex() + 1, indexStart)); + mapParents.Drop(mapParents.Find(type)); + + if (refMap.MemberMaps.Count > 0 || refMap.ReferenceMaps.Count > 0) + { + var referenceMap = new MemberReferenceMap(member, refMap); + if (context.Configuration.ReferenceHeaderPrefix != null) + { + var args = new ReferenceHeaderPrefixArgs(member.MemberType(), member.Name); + referenceMap.Data.Prefix = context.Configuration.ReferenceHeaderPrefix(args); + } + + ApplyAttributes(referenceMap); + + map.ReferenceMaps.Add(referenceMap); + } + } + else + { + // Only add the member map if it can be converted later on. + // If the member will use the default converter, don't add it because + // we don't want the .ToString() value to be used when auto mapping. + + // Use the top of the map tree. This will maps that have been auto mapped + // to later on get a reference to a map by doing map.Map( m => m.A.B.C.Id ) + // and it will return the correct parent map type of A instead of C. + var classType = mapParents.First?.Value ?? map.ClassType; + var memberMap = MemberMap.CreateGeneric(classType, member); + + // Use global values as the starting point. + memberMap.Data.TypeConverterOptions = TypeConverterOptions.Merge(new TypeConverterOptions(), context.TypeConverterOptionsCache.GetOptions(member.MemberType()), memberMap.Data.TypeConverterOptions); + memberMap.Data.Index = map.GetMaxIndex() + 1; + + ApplyAttributes(memberMap); + + map.MemberMaps.Add(memberMap); + } + } + + map.ReIndex(indexStart); + } + + /// <summary> + /// Auto maps the given map using constructor parameters. + /// </summary> + /// <param name="map">The map.</param> + /// <param name="context">The context.</param> + /// <param name="mapParents">The list of parents for the map.</param> + /// <param name="indexStart">The index starting point.</param> + protected virtual void AutoMapConstructorParameters(ClassMap map, CsvContext context, LinkedList<Type> mapParents, int indexStart = 0) + { + var type = map.GetGenericType(); + var args = new GetConstructorArgs(map.ClassType); + var constructor = context.Configuration.GetConstructor(args); + var parameters = constructor.GetParameters(); + + foreach (var parameter in parameters) + { + var parameterMap = new ParameterMap(parameter); + + if (parameter.GetCustomAttributes<IgnoreAttribute>(true).Any() || parameter.GetCustomAttributes<ConstantAttribute>(true).Any()) + { + // If there is an IgnoreAttribute or ConstantAttribute, we still need to add a map because a constructor requires + // all parameters to be present. A default value will be used later on. + + ApplyAttributes(parameterMap); + map.ParameterMaps.Add(parameterMap); + continue; + } + + var typeConverterType = context.TypeConverterCache.GetConverter(parameter.ParameterType).GetType(); + var memberTypeInfo = parameter.ParameterType.GetTypeInfo(); + var isDefaultConverter = typeConverterType == typeof(DefaultTypeConverter); + if (isDefaultConverter && (memberTypeInfo.HasParameterlessConstructor() || memberTypeInfo.IsUserDefinedStruct())) + { + // If the type is not one covered by our type converters + // and it has a parameterless constructor, create a + // reference map for it. + + if (context.Configuration.IgnoreReferences) + { + throw new InvalidOperationException($"Configuration '{nameof(CsvConfiguration.IgnoreReferences)}' can't be true " + + "when using types without a default constructor. Constructor parameters " + + "are used and all members including references must be used."); + } + + if (CheckForCircularReference(parameter.ParameterType, mapParents)) + { + throw new InvalidOperationException($"A circular reference was detected in constructor paramter '{parameter.Name}'." + + "Since all parameters must be supplied for a constructor, this parameter can't be skipped."); + } + + mapParents.AddLast(type); + var refMapType = typeof(DefaultClassMap<>).MakeGenericType(parameter.ParameterType); + var refMap = (ClassMap)ObjectResolver.Current.Resolve(refMapType); + AutoMapMembers(refMap, context, mapParents, Math.Max(map.GetMaxIndex(isParameter: true) + 1, indexStart)); + mapParents.Drop(mapParents.Find(type)); + + var referenceMap = new ParameterReferenceMap(parameter, refMap); + if (context.Configuration.ReferenceHeaderPrefix != null) + { + var referenceHeaderPrefix = new ReferenceHeaderPrefixArgs(memberTypeInfo.MemberType(), memberTypeInfo.Name); + referenceMap.Data.Prefix = context.Configuration.ReferenceHeaderPrefix(referenceHeaderPrefix); + } + + ApplyAttributes(referenceMap); + + parameterMap.ReferenceMap = referenceMap; + } + else if (isDefaultConverter && context.Configuration.ShouldUseConstructorParameters(new ShouldUseConstructorParametersArgs(parameter.ParameterType))) + { + // If the type is not one covered by our type converters + // and it should use contructor parameters, create a + // constructor map for it. + + mapParents.AddLast(type); + var constructorMapType = typeof(DefaultClassMap<>).MakeGenericType(parameter.ParameterType); + var constructorMap = (ClassMap)ObjectResolver.Current.Resolve(constructorMapType); + // Need to use Max here for nested types. + AutoMapConstructorParameters(constructorMap, context, mapParents, Math.Max(map.GetMaxIndex(isParameter: true) + 1, indexStart)); + mapParents.Drop(mapParents.Find(type)); + + parameterMap.ConstructorTypeMap = constructorMap; + } + else + { + parameterMap.Data.TypeConverterOptions = TypeConverterOptions.Merge(new TypeConverterOptions(), context.TypeConverterOptionsCache.GetOptions(parameter.ParameterType), parameterMap.Data.TypeConverterOptions); + parameterMap.Data.Index = map.GetMaxIndex(isParameter: true) + 1; + + ApplyAttributes(parameterMap); + } + + map.ParameterMaps.Add(parameterMap); + } + + map.ReIndex(indexStart); + } + + /// <summary> + /// Checks for circular references. + /// </summary> + /// <param name="type">The type to check for.</param> + /// <param name="mapParents">The list of parents to check against.</param> + /// <returns>A value indicating if a circular reference was found. + /// True if a circular reference was found, otherwise false.</returns> + protected virtual bool CheckForCircularReference(Type type, LinkedList<Type> mapParents) + { + if (mapParents.Count == 0) + { + return false; + } + + var node = mapParents.Last; + while (true) + { + if (node?.Value == type) + { + return true; + } + + node = node?.Previous; + if (node == null) + { + break; + } + } + + return false; + } + + /// <summary> + /// Gets the generic type for this class map. + /// </summary> + protected virtual Type GetGenericType() + { + return GetType().GetTypeInfo().BaseType?.GetGenericArguments()[0] ?? throw new ConfigurationException(); + } + + /// <summary> + /// Applies attribute configurations to the map. + /// </summary> + /// <param name="parameterMap">The parameter map.</param> + protected virtual void ApplyAttributes(ParameterMap parameterMap) + { + var parameter = parameterMap.Data.Parameter; + var attributes = parameter.GetCustomAttributes().OfType<IParameterMapper>(); + + foreach (var attribute in attributes) + { + attribute.ApplyTo(parameterMap); + } + } + + /// <summary> + /// Applies attribute configurations to the map. + /// </summary> + /// <param name="referenceMap">The parameter reference map.</param> + protected virtual void ApplyAttributes(ParameterReferenceMap referenceMap) + { + var parameter = referenceMap.Data.Parameter; + var attributes = parameter.GetCustomAttributes().OfType<IParameterReferenceMapper>(); + + foreach (var attribute in attributes) + { + attribute.ApplyTo(referenceMap); + } + } + + /// <summary> + /// Applies attribute configurations to the map. + /// </summary> + /// <param name="memberMap">The member map.</param> + protected virtual void ApplyAttributes(MemberMap memberMap) + { + if (memberMap.Data.Member == null) + { + return; + } + + var member = memberMap.Data.Member; + var attributes = member.GetCustomAttributes().OfType<IMemberMapper>(); + + foreach (var attribute in attributes) + { + attribute.ApplyTo(memberMap); + } + } + + /// <summary> + /// Applies attribute configurations to the map. + /// </summary> + /// <param name="referenceMap">The member reference map.</param> + protected virtual void ApplyAttributes(MemberReferenceMap referenceMap) + { + var member = referenceMap.Data.Member; + var attributes = member.GetCustomAttributes().OfType<IMemberReferenceMapper>(); + + foreach (var attribute in attributes) + { + attribute.ApplyTo(referenceMap); + } + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/ClassMapBuilder.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/ClassMapBuilder.cs new file mode 100644 index 0000000..fbe2e6a --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/ClassMapBuilder.cs @@ -0,0 +1,432 @@ +// 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.Linq.Expressions; +using CsvHelper.TypeConversion; +using System.Collections; + +namespace CsvHelper.Configuration +{ + /// <summary> + /// Has mapping capabilities. + /// </summary> + /// <typeparam name="TClass">The class type.</typeparam> + public interface IHasMap<TClass> : IBuildableClass<TClass> + { + /// <summary> + /// Maps a member to a CSV field. + /// </summary> + /// <param name="expression">The member to map.</param> + /// <param name="useExistingMap">If true, an existing map will be used if available. + /// If false, a new map is created for the same member.</param> + /// <returns>The member mapping.</returns> + IHasMapOptions<TClass, TMember> Map<TMember>(Expression<Func<TClass, TMember>> expression, bool useExistingMap = true); + } + + /// <summary> + /// Options after a mapping call. + /// </summary> + /// <typeparam name="TClass">The class type.</typeparam> + /// <typeparam name="TMember">The member type.</typeparam> + public interface IHasMapOptions<TClass, TMember> : + IHasMap<TClass>, + IHasTypeConverter<TClass, TMember>, + IHasIndex<TClass, TMember>, + IHasName<TClass, TMember>, + IHasOptional<TClass, TMember>, + IHasConvertUsing<TClass, TMember>, + IHasDefault<TClass, TMember>, + IHasConstant<TClass, TMember>, + IHasValidate<TClass, TMember> + { } + + /// <summary> + /// Has type converter capabilities. + /// </summary> + /// <typeparam name="TClass">The class type.</typeparam> + /// <typeparam name="TMember">The member type.</typeparam> + public interface IHasTypeConverter<TClass, TMember> : IBuildableClass<TClass> + { + /// <summary> + /// Specifies the <see cref="TypeConverter"/> to use + /// when converting the member to and from a CSV field. + /// </summary> + /// <param name="typeConverter">The TypeConverter to use.</param> + IHasTypeConverterOptions<TClass, TMember> TypeConverter(ITypeConverter typeConverter); + + /// <summary> + /// Specifies the <see cref="TypeConverter"/> to use + /// when converting the member to and from a CSV field. + /// </summary> + /// <typeparam name="TConverter">The <see cref="System.Type"/> of the + /// <see cref="TypeConverter"/> to use.</typeparam> + IHasTypeConverterOptions<TClass, TMember> TypeConverter<TConverter>() where TConverter : ITypeConverter; + } + + /// <summary> + /// Options after a type converter call. + /// </summary> + /// <typeparam name="TClass">The class type.</typeparam> + /// <typeparam name="TMember">The member type.</typeparam> + public interface IHasTypeConverterOptions<TClass, TMember> : + IHasMap<TClass>, + IHasDefault<TClass, TMember>, + IHasValidate<TClass, TMember> + { } + + /// <summary> + /// Has index capabilities. + /// </summary> + /// <typeparam name="TClass">The class type.</typeparam> + /// <typeparam name="TMember">The member type.</typeparam> + public interface IHasIndex<TClass, TMember> : IBuildableClass<TClass> + { + /// <summary> + /// When reading, is used to get the field at + /// the given index. When writing, the fields + /// will be written in the order of the field + /// indexes. + /// </summary> + /// <param name="index">The index of the CSV field.</param> + /// <param name="indexEnd">The end index used when mapping to an <see cref="IEnumerable"/> member.</param> + IHasIndexOptions<TClass, TMember> Index(int index, int indexEnd = -1); + } + + /// <summary> + /// Options after an index call. + /// </summary> + /// <typeparam name="TClass">The class type.</typeparam> + /// <typeparam name="TMember">The member type.</typeparam> + public interface IHasIndexOptions<TClass, TMember> : + IHasMap<TClass>, + IHasTypeConverter<TClass, TMember>, + IHasName<TClass, TMember>, + IHasDefault<TClass, TMember>, + IHasValidate<TClass, TMember> + { } + + /// <summary> + /// Has optional capabilities. + /// </summary> + /// <typeparam name="TClass">The class type.</typeparam> + /// <typeparam name="TMember">The member type.</typeparam> + public interface IHasOptional<TClass, TMember> : IBuildableClass<TClass> + { + /// <summary> + /// Ignore the member when reading if no matching field name can be found. + /// </summary> + IHasOptionalOptions<TClass, TMember> Optional(); + } + + /// <summary> + /// Options after an optional call. + /// </summary> + /// <typeparam name="TClass">The class type.</typeparam> + /// <typeparam name="TMember">The member type.</typeparam> + public interface IHasOptionalOptions<TClass, TMember> : + IHasMap<TClass>, + IHasTypeConverter<TClass, TMember>, + IHasName<TClass, TMember>, + IHasDefault<TClass, TMember>, + IHasValidate<TClass, TMember> + { } + + /// <summary> + /// Has name capabilities. + /// </summary> + /// <typeparam name="TClass">The class type.</typeparam> + /// <typeparam name="TMember">The member type.</typeparam> + public interface IHasName<TClass, TMember> : IBuildableClass<TClass> + { + /// <summary> + /// When reading, is used to get the field + /// at the index of the name if there was a + /// header specified. It will look for the + /// first name match in the order listed. + /// When writing, sets the name of the + /// field in the header record. + /// The first name will be used. + /// </summary> + /// <param name="names">The possible names of the CSV field.</param> + IHasNameOptions<TClass, TMember> Name(params string[] names); + } + + /// <summary> + /// Options after a name call. + /// </summary> + /// <typeparam name="TClass">The class type.</typeparam> + /// <typeparam name="TMember">The member type.</typeparam> + public interface IHasNameOptions<TClass, TMember> : + IHasMap<TClass>, + IHasTypeConverter<TClass, TMember>, + IHasNameIndex<TClass, TMember>, + IHasDefault<TClass, TMember>, + IHasValidate<TClass, TMember> + { } + + /// <summary> + /// Has name index capabilities. + /// </summary> + /// <typeparam name="TClass">The class type.</typeparam> + /// <typeparam name="TMember">The member type.</typeparam> + public interface IHasNameIndex<TClass, TMember> : IBuildableClass<TClass> + { + /// <summary> + /// When reading, is used to get the + /// index of the name used when there + /// are multiple names that are the same. + /// </summary> + /// <param name="index">The index of the name.</param> + IHasNameIndexOptions<TClass, TMember> NameIndex(int index); + } + + /// <summary> + /// Options after a name index call. + /// </summary> + /// <typeparam name="TClass">The class type.</typeparam> + /// <typeparam name="TMember">The member type.</typeparam> + public interface IHasNameIndexOptions<TClass, TMember> : + IHasMap<TClass>, + IHasTypeConverter<TClass, TMember>, + IHasDefault<TClass, TMember>, + IHasValidate<TClass, TMember> + { } + + /// <summary> + /// Has convert using capabilities. + /// </summary> + /// <typeparam name="TClass">The class type.</typeparam> + /// <typeparam name="TMember">The member type.</typeparam> + public interface IHasConvertUsing<TClass, TMember> : IBuildableClass<TClass> + { + /// <summary> + /// Specifies an expression to be used to convert data in the + /// row to the member. + /// </summary> + /// <param name="convertExpression">The convert expression.</param> + IHasMap<TClass> ConvertUsing(ConvertFromString<TMember> convertExpression); + + /// <summary> + /// Specifies an expression to be used to convert the object + /// to a field. + /// </summary> + /// <param name="convertExpression">The convert expression.</param> + IHasMap<TClass> ConvertUsing(ConvertToString<TClass> convertExpression); + } + + /// <summary> + /// Has default capabilities. + /// </summary> + /// <typeparam name="TClass">The class type.</typeparam> + /// <typeparam name="TMember">The member type.</typeparam> + public interface IHasDefault<TClass, TMember> : IBuildableClass<TClass> + { + /// <summary> + /// The default value that will be used when reading when + /// the CSV field is empty. + /// </summary> + /// <param name="defaultValue">The default value.</param> + IHasDefaultOptions<TClass, TMember> Default(TMember defaultValue); + + /// <summary> + /// The default value that will be used when reading when + /// the CSV field is empty. This value is not type checked + /// and will use a <see cref="ITypeConverter"/> to convert + /// the field. This could potentially have runtime errors. + /// </summary> + /// <param name="defaultValue">The default value.</param> + IHasDefaultOptions<TClass, TMember> Default(string defaultValue); + } + + /// <summary> + /// Options after a default call. + /// </summary> + /// <typeparam name="TClass">The class type.</typeparam> + /// <typeparam name="TMember">The member type.</typeparam> + public interface IHasDefaultOptions<TClass, TMember> : + IHasMap<TClass>, + IHasValidate<TClass, TMember> + { } + + /// <summary> + /// Has constant capabilities. + /// </summary> + /// <typeparam name="TClass">The class type.</typeparam> + /// <typeparam name="TMember">The member type.</typeparam> + public interface IHasConstant<TClass, TMember> : IBuildableClass<TClass> + { + /// <summary> + /// The constant value that will be used for every record when + /// reading and writing. This value will always be used no matter + /// what other mapping configurations are specified. + /// </summary> + /// <param name="value">The constant value.</param> + IHasMap<TClass> Constant(TMember value); + } + + /// <summary> + /// Has validate capabilities. + /// </summary> + /// <typeparam name="TClass">The class type.</typeparam> + /// <typeparam name="TMember">The member type.</typeparam> + public interface IHasValidate<TClass, TMember> : IBuildableClass<TClass> + { + /// <summary> + /// The validate expression that will be called on every field when reading. + /// The expression should return true if the field is valid. + /// If false is returned, a <see cref="ValidationException"/> + /// will be thrown. + /// </summary> + /// <param name="validateExpression">The validation expression.</param> + IHasMap<TClass> Validate(Validate validateExpression); + } + + /// <summary> + /// Has build capabilities. + /// </summary> + /// <typeparam name="TClass">The class type.</typeparam> + public interface IBuildableClass<TClass> + { + /// <summary> + /// Builds the <see cref="ClassMap{TClass}"/>. + /// </summary> + ClassMap<TClass> Build(); + } + + internal class ClassMapBuilder<TClass> : IHasMap<TClass> + { + private readonly ClassMap<TClass> map; + + public ClassMapBuilder() + { + map = new BuilderClassMap<TClass>(); + } + + public IHasMapOptions<TClass, TMember> Map<TMember>(Expression<Func<TClass, TMember>> expression, bool useExistingMap = true) + { + return new MemberMapBuilder<TClass, TMember>(map, map.Map(expression, useExistingMap)); + } + + public ClassMap<TClass> Build() + { + return map; + } + + private class BuilderClassMap<T> : ClassMap<T> { } + } + + internal class MemberMapBuilder<TClass, TMember> : + IHasMap<TClass>, + IHasMapOptions<TClass, TMember>, + IHasTypeConverter<TClass, TMember>, + IHasTypeConverterOptions<TClass, TMember>, + IHasIndex<TClass, TMember>, + IHasIndexOptions<TClass, TMember>, + IHasName<TClass, TMember>, + IHasNameOptions<TClass, TMember>, + IHasNameIndex<TClass, TMember>, + IHasNameIndexOptions<TClass, TMember>, + IHasOptional<TClass, TMember>, + IHasOptionalOptions<TClass, TMember>, + IHasConvertUsing<TClass, TMember>, + IHasDefault<TClass, TMember>, + IHasDefaultOptions<TClass, TMember>, + IHasConstant<TClass, TMember>, + IHasValidate<TClass, TMember> + { + private readonly ClassMap<TClass> classMap; + private readonly MemberMap<TClass, TMember> memberMap; + + public MemberMapBuilder(ClassMap<TClass> classMap, MemberMap<TClass, TMember> memberMap) + { + this.classMap = classMap; + this.memberMap = memberMap; + } + +#pragma warning disable CS0693 // Type parameter has the same name as the type parameter from outer type + public IHasMapOptions<TClass, TMember> Map<TMember>(Expression<Func<TClass, TMember>> expression, bool useExistingMap = true) + { + return new MemberMapBuilder<TClass, TMember>(classMap, classMap.Map(expression, useExistingMap)); + } +#pragma warning restore CS0693 // Type parameter has the same name as the type parameter from outer type + + public IHasMap<TClass> ConvertUsing(ConvertFromString<TMember> convertExpression) + { + memberMap.Convert(convertExpression); + return this; + } + + public IHasMap<TClass> ConvertUsing(ConvertToString<TClass> convertExpression) + { + memberMap.Convert(convertExpression); + return this; + } + + public IHasDefaultOptions<TClass, TMember> Default(TMember defaultValue) + { + memberMap.Default(defaultValue); + return this; + } + + public IHasDefaultOptions<TClass, TMember> Default(string defaultValue) + { + memberMap.Default(defaultValue); + return this; + } + + public IHasIndexOptions<TClass, TMember> Index(int index, int indexEnd = -1) + { + memberMap.Index(index, indexEnd); + return this; + } + + public IHasNameOptions<TClass, TMember> Name(params string[] names) + { + memberMap.Name(names); + return this; + } + + public IHasNameIndexOptions<TClass, TMember> NameIndex(int index) + { + memberMap.NameIndex(index); + return this; + } + + public IHasOptionalOptions<TClass, TMember> Optional() + { + memberMap.Optional(); + return this; + } + + public IHasTypeConverterOptions<TClass, TMember> TypeConverter(ITypeConverter typeConverter) + { + memberMap.TypeConverter(typeConverter); + return this; + } + + public IHasTypeConverterOptions<TClass, TMember> TypeConverter<TConverter>() where TConverter : ITypeConverter + { + memberMap.TypeConverter<TConverter>(); + return this; + } + + public IHasMap<TClass> Constant(TMember value) + { + memberMap.Constant(value); + return this; + } + + public IHasMap<TClass> Validate(Validate validateExpression) + { + memberMap.Validate(validateExpression); + return this; + } + + public ClassMap<TClass> Build() + { + return classMap; + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/ClassMapCollection.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/ClassMapCollection.cs new file mode 100644 index 0000000..f66a284 --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/ClassMapCollection.cs @@ -0,0 +1,188 @@ +// 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.Linq; +using System.Reflection; + +namespace CsvHelper.Configuration +{ + /// <summary> + /// Collection that holds CsvClassMaps for record types. + /// </summary> + public class ClassMapCollection + { + private readonly Dictionary<Type, ClassMap> data = new Dictionary<Type, ClassMap>(); + private readonly CsvContext context; + + /// <summary> + /// Gets the <see cref="ClassMap"/> for the specified record type. + /// </summary> + /// <value> + /// The <see cref="ClassMap"/>. + /// </value> + /// <param name="type">The record type.</param> + /// <returns>The <see cref="ClassMap"/> for the specified record type.</returns> + public virtual ClassMap? this[Type type] + { + get + { + // Go up the inheritance tree to find the matching type. + // We can't use IsAssignableFrom because both a child + // and it's parent/grandparent/etc could be mapped. + var currentType = type; + while (true) + { + if (data.TryGetValue(currentType, out var map)) + { + return map; + } + + currentType = currentType.GetTypeInfo().BaseType; + if (currentType == null) + { + return null; + } + } + } + } + + /// <summary> + /// Creates a new instance using the given configuration. + /// </summary> + /// <param name="context">The context.</param> + public ClassMapCollection(CsvContext context) + { + this.context = context; + } + + /// <summary> + /// Finds the <see cref="ClassMap"/> for the specified record type. + /// </summary> + /// <typeparam name="T">The record type.</typeparam> + /// <returns>The <see cref="ClassMap"/> for the specified record type.</returns> + public virtual ClassMap<T>? Find<T>() + { + return (ClassMap<T>?)this[typeof(T)]; + } + + /// <summary> + /// Adds the specified map for it's record type. If a map + /// already exists for the record type, the specified + /// map will replace it. + /// </summary> + /// <param name="map">The map.</param> + internal virtual void Add(ClassMap map) + { + SetMapDefaults(map); + + var type = GetGenericCsvClassMapType(map.GetType()).GetGenericArguments().First(); + + data[type] = map; + } + + /// <summary> + /// Removes the class map. + /// </summary> + /// <param name="classMapType">The class map type.</param> + internal virtual void Remove(Type classMapType) + { + if (!typeof(ClassMap).IsAssignableFrom(classMapType)) + { + throw new ArgumentException("The class map type must inherit from CsvClassMap."); + } + + var type = GetGenericCsvClassMapType(classMapType).GetGenericArguments().First(); + + data.Remove(type); + } + + /// <summary> + /// Removes all maps. + /// </summary> + internal virtual void Clear() + { + data.Clear(); + } + + /// <summary> + /// Goes up the inheritance tree to find the type instance of CsvClassMap{}. + /// </summary> + /// <param name="type">The type to traverse.</param> + /// <returns>The type that is CsvClassMap{}.</returns> + private Type GetGenericCsvClassMapType(Type type) + { + if (type.GetTypeInfo().IsGenericType && type.GetGenericTypeDefinition() == typeof(ClassMap<>)) + { + return type; + } + + return GetGenericCsvClassMapType(type.GetTypeInfo().BaseType); + } + + /// <summary> + /// Sets defaults for the mapping tree. The defaults used + /// to be set inside the classes, but this didn't allow for + /// the TypeConverter to be created from the Configuration's + /// TypeConverterFactory. + /// </summary> + /// <param name="map">The map to set defaults on.</param> + private void SetMapDefaults(ClassMap map) + { + foreach (var parameterMap in map.ParameterMaps) + { + if (parameterMap.ConstructorTypeMap != null) + { + SetMapDefaults(parameterMap.ConstructorTypeMap); + } + else if (parameterMap.ReferenceMap != null) + { + SetMapDefaults(parameterMap.ReferenceMap.Data.Mapping); + } + else + { + if (parameterMap.Data.TypeConverter == null) + { + parameterMap.Data.TypeConverter = context.TypeConverterCache.GetConverter(parameterMap.Data.Parameter.ParameterType); + } + + if (parameterMap.Data.Names.Count == 0) + { + parameterMap.Data.Names.Add(parameterMap.Data.Parameter.Name); + } + } + } + + foreach (var memberMap in map.MemberMaps) + { + if (memberMap.Data.Member == null) + { + continue; + } + + if (memberMap.Data.TypeConverter == null && memberMap.Data.ReadingConvertExpression == null && memberMap.Data.WritingConvertExpression == null) + { + memberMap.Data.TypeConverter = context.TypeConverterCache.GetConverter(memberMap.Data.Member.MemberType()); + } + + if (memberMap.Data.Names.Count == 0) + { + memberMap.Data.Names.Add(memberMap.Data.Member.Name); + } + } + + foreach (var referenceMap in map.ReferenceMaps) + { + SetMapDefaults(referenceMap.Data.Mapping); + + if (context.Configuration.ReferenceHeaderPrefix != null) + { + var args = new ReferenceHeaderPrefixArgs(referenceMap.Data.Member.MemberType(), referenceMap.Data.Member.Name); + referenceMap.Data.Prefix = context.Configuration.ReferenceHeaderPrefix(args); + } + } + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/ClassMap`1.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/ClassMap`1.cs new file mode 100644 index 0000000..d14c317 --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/ClassMap`1.cs @@ -0,0 +1,112 @@ +// 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.Linq.Expressions; +using System.Reflection; + +namespace CsvHelper.Configuration +{ + /// <summary> + /// Maps class members to CSV fields. + /// </summary> + /// <typeparam name="TClass">The <see cref="System.Type"/> of class to map.</typeparam> + public abstract class ClassMap<TClass> : ClassMap + { + /// <summary> + /// Creates an instance of <see cref="ClassMap{TClass}"/>. + /// </summary> + public ClassMap() : base(typeof(TClass)) { } + + /// <summary> + /// Maps a member to a CSV field. + /// </summary> + /// <param name="expression">The member to map.</param> + /// <param name="useExistingMap">If true, an existing map will be used if available. + /// If false, a new map is created for the same member.</param> + /// <returns>The member mapping.</returns> + public virtual MemberMap<TClass, TMember> Map<TMember>(Expression<Func<TClass, TMember>> expression, bool useExistingMap = true) + { + var (classMap, member) = GetMemberMap(expression); + var memberMap = classMap.Map(typeof(TClass), member, useExistingMap); ; + + return (MemberMap<TClass, TMember>)memberMap; + } + + /// <summary> + /// Maps a member to a CSV field. + /// </summary> + /// <param name="expression">The member to map.</param> + /// <param name="useExistingMap">If true, an existing map will be used if available. + /// If false, a new map is created for the same member.</param> + /// <returns>The member mapping.</returns> + public virtual MemberMap Map<T>(Expression<Func<T, object>> expression, bool useExistingMap = true) + { + var (classMap, member) = GetMemberMap(expression); + var memberMap = classMap.Map(typeof(TClass), member, useExistingMap); + + return memberMap; + } + + /// <summary> + /// Meant for internal use only. + /// Maps a member to another class map. When this is used, accessing a property through + /// sub-property mapping later won't work. You can only use one or the other. When using + /// this, ConvertUsing will also not work. + /// </summary> + /// <typeparam name="TClassMap">The type of the class map.</typeparam> + /// <param name="expression">The expression.</param> + /// <param name="constructorArgs">Constructor arguments used to create the reference map.</param> + /// <returns>The reference mapping for the member.</returns> + public virtual MemberReferenceMap References<TClassMap>(Expression<Func<TClass, object>> expression, params object[] constructorArgs) where TClassMap : ClassMap + { + var member = ReflectionHelper.GetMember(expression); + return References(typeof(TClassMap), member, constructorArgs); + } + + private (ClassMap, MemberInfo) GetMemberMap<TModel, TProperty>(Expression<Func<TModel, TProperty>> expression) + { + var stack = ReflectionHelper.GetMembers(expression); + if (stack.Count == 0) + { + throw new InvalidOperationException($"No members were found in expression '{expression}'."); + } + + ClassMap currentClassMap = this; + MemberInfo member; + + if (stack.Count > 1) + { + // We need to add a reference map for every sub member. + while (stack.Count > 1) + { + member = stack.Pop(); + Type mapType; + var property = member as PropertyInfo; + var field = member as FieldInfo; + if (property != null) + { + mapType = typeof(DefaultClassMap<>).MakeGenericType(property.PropertyType); + } + else if (field != null) + { + mapType = typeof(DefaultClassMap<>).MakeGenericType(field.FieldType); + } + else + { + throw new InvalidOperationException("The given expression was not a property or a field."); + } + + var referenceMap = currentClassMap.References(mapType, member); + currentClassMap = referenceMap.Data.Mapping; + } + } + + // Add the member map to the last reference map. + member = stack.Pop(); + + return (currentClassMap, member); + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/ConfigurationException.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/ConfigurationException.cs new file mode 100644 index 0000000..8a9bba1 --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/ConfigurationException.cs @@ -0,0 +1,36 @@ +// 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; + +namespace CsvHelper.Configuration +{ + /// <summary> + /// Represents configuration errors that occur. + /// </summary> + [Serializable] + public class ConfigurationException : CsvHelperException + { + /// <summary> + /// Initializes a new instance of the <see cref="ConfigurationException"/> class. + /// </summary> + public ConfigurationException() { } + + /// <summary> + /// Initializes a new instance of the <see cref="ConfigurationException"/> class + /// with a specified error message. + /// </summary> + /// <param name="message">The message that describes the error.</param> + public ConfigurationException( string message ) : base( message ) { } + + /// <summary> + /// Initializes a new instance of the <see cref="ConfigurationException"/> class + /// with a specified error message and a reference to the inner exception that + /// is the cause of this exception. + /// </summary> + /// <param name="message">The error message that explains the reason for the exception.</param> + /// <param name="innerException">The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner exception is specified.</param> + public ConfigurationException( string message, Exception innerException ) : base( message, innerException ) { } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/ConfigurationFunctions.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/ConfigurationFunctions.cs new file mode 100644 index 0000000..0cf7259 --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/ConfigurationFunctions.cs @@ -0,0 +1,267 @@ +// 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 CsvHelper.Delegates; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Text.RegularExpressions; + +namespace CsvHelper.Configuration +{ + /// <summary>Holds the default callback methods for delegate members of <c>CsvHelper.Configuration.Configuration</c>.</summary> + public static class ConfigurationFunctions + { + private static readonly char[] lineEndingChars = new char[] { '\r', '\n' }; + + /// <summary> + /// Throws a <see cref="ValidationException"/> if <see name="HeaderValidatedArgs.InvalidHeaders"/> is not empty. + /// </summary> + public static void HeaderValidated(HeaderValidatedArgs args) + { + if (args.InvalidHeaders.Count() == 0) + { + return; + } + + var errorMessage = new StringBuilder(); + foreach (var invalidHeader in args.InvalidHeaders) + { + errorMessage.AppendLine($"Header with name '{string.Join("' or '", invalidHeader.Names)}'[{invalidHeader.Index}] was not found."); + } + + if (args.Context.Reader.HeaderRecord != null) + { + foreach (var header in args.Context.Reader.HeaderRecord) + { + errorMessage.AppendLine($"Headers: '{string.Join("', '", args.Context.Reader.HeaderRecord)}'"); + } + } + + var messagePostfix = + $"If you are expecting some headers to be missing and want to ignore this validation, " + + $"set the configuration {nameof(HeaderValidated)} to null. You can also change the " + + $"functionality to do something else, like logging the issue."; + errorMessage.AppendLine(messagePostfix); + + throw new HeaderValidationException(args.Context, args.InvalidHeaders, errorMessage.ToString()); + } + + /// <summary> + /// Throws a <c>MissingFieldException</c>. + /// </summary> + public static void MissingFieldFound(MissingFieldFoundArgs args) + { + var messagePostfix = $"You can ignore missing fields by setting {nameof(MissingFieldFound)} to null."; + + // Get by index. + + if (args.HeaderNames == null || args.HeaderNames.Length == 0) + { + throw new MissingFieldException(args.Context, $"Field at index '{args.Index}' does not exist. {messagePostfix}"); + } + + // Get by name. + + var indexText = args.Index > 0 ? $" at field index '{args.Index}'" : string.Empty; + + if (args.HeaderNames.Length == 1) + { + throw new MissingFieldException(args.Context, $"Field with name '{args.HeaderNames[0]}'{indexText} does not exist. {messagePostfix}"); + } + + throw new MissingFieldException(args.Context, $"Field containing names '{string.Join("' or '", args.HeaderNames)}'{indexText} does not exist. {messagePostfix}"); + } + + /// <summary> + /// Throws a <see cref="BadDataException"/>. + /// </summary> + public static void BadDataFound(BadDataFoundArgs args) + { + throw new BadDataException(args.Field, args.RawRecord, args.Context, $"You can ignore bad data by setting {nameof(BadDataFound)} to null."); + } + + /// <summary> + /// Throws the given <see name="ReadingExceptionOccurredArgs.Exception"/>. + /// </summary> + public static bool ReadingExceptionOccurred(ReadingExceptionOccurredArgs args) + { + return true; + } + + /// <summary> + /// Returns true if the field contains a <see cref="IWriterConfiguration.Quote"/>, + /// starts with a space, ends with a space, contains \r or \n, or contains + /// the <see cref="IWriterConfiguration.Delimiter"/>. + /// </summary> + /// <param name="args">The args.</param> + /// <returns><c>true</c> if the field should be quoted, otherwise <c>false</c>.</returns> + public static bool ShouldQuote(ShouldQuoteArgs args) + { + var config = args.Row.Configuration; + + var shouldQuote = !string.IsNullOrEmpty(args.Field) && + ( + args.Field.Contains(config.Quote) // Contains quote + || args.Field[0] == ' ' // Starts with a space + || args.Field[args.Field.Length - 1] == ' ' // Ends with a space + || (config.Delimiter.Length > 0 && args.Field.Contains(config.Delimiter)) // Contains delimiter + || !config.IsNewLineSet && args.Field.IndexOfAny(lineEndingChars) > -1 // Contains line ending characters + || config.IsNewLineSet && args.Field.Contains(config.NewLine) // Contains newline + ); + + return shouldQuote; + } + + /// <summary> + /// Returns the <see name="PrepareHeaderForMatchArgs.Header"/> as given. + /// </summary> + public static string PrepareHeaderForMatch(PrepareHeaderForMatchArgs args) + { + return args.Header; + } + + /// <summary> + /// Returns <c>true</c> if <paramref name="args.ParameterType"/>: + /// 1. does not have a parameterless constructor + /// 2. has a constructor + /// 3. is not a value type + /// 4. is not a primitive + /// 5. is not an enum + /// 6. is not an interface + /// 7. TypeCode is an Object. + /// </summary> + public static bool ShouldUseConstructorParameters(ShouldUseConstructorParametersArgs args) + { + return !args.ParameterType.HasParameterlessConstructor() + && args.ParameterType.HasConstructor() + && !args.ParameterType.IsValueType + && !args.ParameterType.IsPrimitive + && !args.ParameterType.IsEnum + && !args.ParameterType.IsInterface + && Type.GetTypeCode(args.ParameterType) == TypeCode.Object; + } + + /// <summary> + /// Returns the type's constructor with the most parameters. + /// If two constructors have the same number of parameters, then + /// there is no guarantee which one will be returned. If you have + /// that situation, you should probably implement this function yourself. + /// </summary> + public static ConstructorInfo GetConstructor(GetConstructorArgs args) + { + return args.ClassType.GetConstructorWithMostParameters(); + } + + /// <summary> + /// Returns the header name ran through <see cref="PrepareHeaderForMatch(PrepareHeaderForMatchArgs)"/>. + /// If no header exists, property names will be Field1, Field2, Field3, etc. + /// </summary> + /// <param name="args">The args.</param> + public static string GetDynamicPropertyName(GetDynamicPropertyNameArgs args) + { + if (args.Context.Reader.HeaderRecord == null) + { + return $"Field{args.FieldIndex + 1}"; + } + + var header = args.Context.Reader.HeaderRecord[args.FieldIndex]; + var prepareHeaderForMatchArgs = new PrepareHeaderForMatchArgs(header, args.FieldIndex); + header = args.Context.Reader.Configuration.PrepareHeaderForMatch(prepareHeaderForMatchArgs); + + return header; + } + + /// <summary> + /// Detects the delimiter based on the given text. + /// Return the detected delimiter or null if one wasn't found. + /// </summary> + /// <param name="args">The args.</param> + public static string? GetDelimiter(GetDelimiterArgs args) + { + var text = args.Text; + var config = args.Configuration; + + if (config.Mode == CsvMode.RFC4180) + { + // Remove text in between pairs of quotes. + text = Regex.Replace(text, $"{config.Quote}.*?{config.Quote}", string.Empty, RegexOptions.Singleline); + } + else if (config.Mode == CsvMode.Escape) + { + // Remove escaped characters. + text = Regex.Replace(text, $"({config.Escape}.)", string.Empty, RegexOptions.Singleline); + } + + var newLine = config.NewLine; + if ((new[] { "\r\n", "\r", "\n" }).Contains(newLine)) + { + newLine = "\r\n|\r|\n"; + } + + var lineDelimiterCounts = new List<Dictionary<string, int>>(); + while (text.Length > 0) + { + // Since all escaped text has been removed, we can reliably read line by line. + var match = Regex.Match(text, newLine); + var line = match.Success ? text.Substring(0, match.Index + match.Length) : text; + + var delimiterCounts = new Dictionary<string, int>(); + foreach (var delimiter in config.DetectDelimiterValues) + { + // Escape regex special chars to use as regex pattern. + var pattern = Regex.Replace(delimiter, @"([.$^{\[(|)*+?\\])", "\\$1"); + delimiterCounts[delimiter] = Regex.Matches(line, pattern).Count; + } + + lineDelimiterCounts.Add(delimiterCounts); + + text = match.Success ? text.Substring(match.Index + match.Length) : string.Empty; + } + + if (lineDelimiterCounts.Count > 1) + { + // The last line isn't complete and can't be used to reliably detect a delimiter. + lineDelimiterCounts.Remove(lineDelimiterCounts.Last()); + } + + // Rank only the delimiters that appear on every line. + var delimiters = + ( + from counts in lineDelimiterCounts + from count in counts + group count by count.Key into g + where g.All(x => x.Value > 0) + let sum = g.Sum(x => x.Value) + orderby sum descending + select new + { + Delimiter = g.Key, + Count = sum + } + ).ToList(); + + string? newDelimiter = null; + if (delimiters.Any(x => x.Delimiter == config.CultureInfo.TextInfo.ListSeparator) && lineDelimiterCounts.Count > 1) + { + // The culture's separator is on every line. Assume this is the delimiter. + newDelimiter = config.CultureInfo.TextInfo.ListSeparator; + } + else + { + // Choose the highest ranked delimiter. + newDelimiter = delimiters.Select(x => x.Delimiter).FirstOrDefault(); + } + + if (newDelimiter != null) + { + config.Validate(); + } + + return newDelimiter ?? config.Delimiter; + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/CsvConfiguration.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/CsvConfiguration.cs new file mode 100644 index 0000000..51636a2 --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/CsvConfiguration.cs @@ -0,0 +1,240 @@ +// 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.IO; +using System.Linq; +using System.Reflection; +using System.Text; +using CsvHelper.Configuration.Attributes; +using CsvHelper.Delegates; +using CsvHelper.TypeConversion; + +namespace CsvHelper.Configuration +{ + /// <summary> + /// Configuration used for reading and writing CSV data. + /// </summary> + public record CsvConfiguration : IReaderConfiguration, IWriterConfiguration + { + private string newLine = "\r\n"; + + /// <inheritdoc/> + public virtual bool AllowComments { get; set; } + + /// <inheritdoc/> + public virtual BadDataFound BadDataFound { get; set; } = ConfigurationFunctions.BadDataFound; + + /// <inheritdoc/> + public virtual int BufferSize { get; set; } = 0x1000; + + /// <inheritdoc/> + public virtual bool CacheFields { get; set; } + + /// <inheritdoc/> + public virtual char Comment { get; set; } = '#'; + + /// <inheritdoc/> + public virtual bool CountBytes { get; set; } + + /// <inheritdoc/> + public virtual CultureInfo CultureInfo { get; protected set; } + + /// <inheritdoc/> + public virtual string Delimiter { get; set; } + + /// <inheritdoc/> + public virtual bool DetectDelimiter { get; set; } + + /// <inheritdoc/> + public virtual GetDelimiter GetDelimiter { get; set; } = ConfigurationFunctions.GetDelimiter; + + /// <inheritdoc/> + public virtual string[] DetectDelimiterValues { get; set; } = new[] { ",", ";", "|", "\t" }; + + /// <inheritdoc/> + public virtual bool DetectColumnCountChanges { get; set; } + + /// <inheritdoc/> + public virtual IComparer<string>? DynamicPropertySort { get; set; } + + /// <inheritdoc/> + public virtual Encoding Encoding { get; set; } = Encoding.UTF8; + + /// <inheritdoc/> + public virtual char Escape { get; set; } = '"'; + + /// <inheritdoc/> + public virtual bool ExceptionMessagesContainRawData { get; set; } = true; + + /// <inheritdoc/> + public virtual GetConstructor GetConstructor { get; set; } = ConfigurationFunctions.GetConstructor; + + /// <inheritdoc/> + public virtual GetDynamicPropertyName GetDynamicPropertyName { get; set; } = ConfigurationFunctions.GetDynamicPropertyName; + + /// <inheritdoc/> + public virtual bool HasHeaderRecord { get; set; } = true; + + /// <inheritdoc/> + public virtual HeaderValidated HeaderValidated { get; set; } = ConfigurationFunctions.HeaderValidated; + + /// <inheritdoc/> + public virtual bool IgnoreBlankLines { get; set; } = true; + + /// <inheritdoc/> + public virtual bool IgnoreReferences { get; set; } + + /// <inheritdoc/> + public virtual bool IncludePrivateMembers { get; set; } + + /// <inheritdoc/> + public virtual char[] InjectionCharacters { get; set; } = new[] { '=', '@', '+', '-', '\t', '\r' }; + + /// <inheritdoc/> + public virtual char InjectionEscapeCharacter { get; set; } = '\''; + + /// <inheritdoc /> + public virtual InjectionOptions InjectionOptions { get; set; } + + /// <inheritdoc/> + public bool IsNewLineSet { get; private set; } + + /// <inheritdoc/> + public virtual bool LineBreakInQuotedFieldIsBadData { get; set; } + + /// <inheritdoc/> + public double MaxFieldSize { get; set; } + + /// <inheritdoc/> + public virtual MemberTypes MemberTypes { get; set; } = MemberTypes.Properties; + + /// <inheritdoc/> + public virtual MissingFieldFound MissingFieldFound { get; set; } = ConfigurationFunctions.MissingFieldFound; + + /// <inheritdoc/> + public virtual CsvMode Mode { get; set; } + + /// <inheritdoc/> + public virtual string NewLine + { + get => newLine; + set + { + IsNewLineSet = true; + newLine = value; + } + } + + /// <inheritdoc/> + public virtual PrepareHeaderForMatch PrepareHeaderForMatch { get; set; } = ConfigurationFunctions.PrepareHeaderForMatch; + + /// <inheritdoc/> + public virtual int ProcessFieldBufferSize { get; set; } = 1024; + + /// <inheritdoc/> + public virtual char Quote { get; set; } = '"'; + + /// <inheritdoc/> + public virtual ReadingExceptionOccurred ReadingExceptionOccurred { get; set; } = ConfigurationFunctions.ReadingExceptionOccurred; + + /// <inheritdoc/> + public virtual ReferenceHeaderPrefix? ReferenceHeaderPrefix { get; set; } + + /// <inheritdoc/> + public ShouldQuote ShouldQuote { get; set; } = ConfigurationFunctions.ShouldQuote; + + /// <inheritdoc/> + public virtual ShouldSkipRecord? ShouldSkipRecord { get; set; } + + /// <inheritdoc/> + public virtual ShouldUseConstructorParameters ShouldUseConstructorParameters { get; set; } = ConfigurationFunctions.ShouldUseConstructorParameters; + + /// <inheritdoc/> + public virtual TrimOptions TrimOptions { get; set; } + + /// <inheritdoc/> + public virtual bool UseNewObjectForNullReferenceMembers { get; set; } = true; + + /// <inheritdoc/> + public virtual char[] WhiteSpaceChars { get; set; } = new char[] { ' ' }; + + /// <summary> + /// Initializes a new instance of the <see cref="CsvConfiguration"/> class + /// using the given <see cref="System.Globalization.CultureInfo"/>. Since <see cref="Delimiter"/> + /// uses <see cref="CultureInfo"/> for it's default, the given <see cref="System.Globalization.CultureInfo"/> + /// will be used instead. + /// </summary> + /// <param name="cultureInfo">The culture information.</param> + /// <param name="attributesType">The type that contains the configuration attributes. + /// This will call <see cref="ApplyAttributes(Type)"/> automatically.</param> + public CsvConfiguration(CultureInfo cultureInfo, Type? attributesType = null) + { + CultureInfo = cultureInfo; + Delimiter = cultureInfo.TextInfo.ListSeparator; + + if (attributesType != null) + { + ApplyAttributes(attributesType); + } + } + + /// <summary> + /// Validates the configuration. + /// </summary> + public void Validate() + { + var escape = Escape.ToString(); + var quote = Quote.ToString(); + var lineEndings = new[] { "\r", "\n", "\r\n" }; + var whiteSpaceChars = WhiteSpaceChars.Select(c => c.ToString()).ToArray(); + + // Escape + if (escape == Delimiter) throw new ConfigurationException($"The escape character '{Escape}' and delimiter '{Delimiter}' cannot be the same."); + if (escape == NewLine && IsNewLineSet) throw new ConfigurationException($"The escape character '{Escape}' and new line '{NewLine}' cannot be the same."); + if (lineEndings.Contains(Escape.ToString()) && !IsNewLineSet) throw new ConfigurationException($"The escape character '{Escape}' cannot be a line ending. ('\\r', '\\n', '\\r\\n')"); + if (whiteSpaceChars.Contains(escape)) throw new ConfigurationException($"The escape character '{Escape}' cannot be a WhiteSpaceChar."); + + // Quote + if (quote == Delimiter) throw new ConfigurationException($"The quote character '{Quote}' and the delimiter '{Delimiter}' cannot be the same."); + if (quote == NewLine && IsNewLineSet) throw new ConfigurationException($"The quote character '{Quote}' and new line '{NewLine}' cannot be the same."); + if (lineEndings.Contains(quote)) throw new ConfigurationException($"The quote character '{Quote}' cannot be a line ending. ('\\r', '\\n', '\\r\\n')"); + if (whiteSpaceChars.Contains(quote)) throw new ConfigurationException($"The quote character '{Quote}' cannot be a WhiteSpaceChar."); + + // Delimiter + if (Delimiter == NewLine && IsNewLineSet) throw new ConfigurationException($"The delimiter '{Delimiter}' and new line '{NewLine}' cannot be the same."); + if (lineEndings.Contains(Delimiter)) throw new ConfigurationException($"The delimiter '{Delimiter}' cannot be a line ending. ('\\r', '\\n', '\\r\\n')"); + if (whiteSpaceChars.Contains(Delimiter)) throw new ConfigurationException($"The delimiter '{Delimiter}' cannot be a WhiteSpaceChar."); + + // Detect Delimiter + if (DetectDelimiter && DetectDelimiterValues.Length == 0) throw new ConfigurationException($"At least one value is required for {nameof(DetectDelimiterValues)} when {nameof(DetectDelimiter)} is enabled."); + } + + /// <summary> + /// Applies class level attribute to configuration. + /// </summary> + /// <typeparam name="T">Type with attributes.</typeparam> + public CsvConfiguration ApplyAttributes<T>() + { + return ApplyAttributes(typeof(T)); + } + + /// <summary> + /// Applies class level attribute to configuration. + /// </summary> + /// <param name="type">Type with attributes.</param> + public CsvConfiguration ApplyAttributes(Type type) + { + var attributes = type.GetCustomAttributes().OfType<IClassMapper>(); + foreach (var attribute in attributes) + { + attribute.ApplyTo(this); + } + + return this; + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/DefaultClassMap`1.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/DefaultClassMap`1.cs new file mode 100644 index 0000000..2e1b88b --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/DefaultClassMap`1.cs @@ -0,0 +1,15 @@ +// 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 +namespace CsvHelper.Configuration +{ + /// <summary> + /// A default <see cref="ClassMap{T}"/> that can be used + /// to create a class map dynamically. + /// </summary> + /// <typeparam name="T"></typeparam> + public class DefaultClassMap<T> : ClassMap<T> + { + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/IParserConfiguration.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/IParserConfiguration.cs new file mode 100644 index 0000000..dec8594 --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/IParserConfiguration.cs @@ -0,0 +1,176 @@ +// 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 CsvHelper.Delegates; +using System.Collections.Generic; +using System.Globalization; +using System.IO; +using System.Text; + +namespace CsvHelper.Configuration +{ + /// <summary> + /// Configuration used for the <see cref="IParser"/>. + /// </summary> + public interface IParserConfiguration + { + /// <summary> + /// Gets the culture info used to read an write CSV files. + /// </summary> + CultureInfo CultureInfo { get; } + + /// <summary> + /// Cache fields that are created when parsing. + /// Default is false. + /// </summary> + bool CacheFields { get; } + + /// <summary> + /// The newline string to use. Default is \r\n (CRLF). + /// When writing, this value is always used. + /// When reading, this value is only used if explicitly set. + /// If not set, the parser uses one of \r\n, \r, or \n. + /// </summary> + string NewLine { get; } + + /// <summary> + /// A value indicating if <see cref="NewLine"/> was set. + /// </summary> + /// <value> + /// <c>true</c> if <see cref="NewLine"/> was set. <c>false</c> if <see cref="NewLine"/> is the default. + /// </value> + bool IsNewLineSet { get; } + + /// <summary> + /// The mode. + /// See <see cref="CsvMode"/> for more details. + /// </summary> + CsvMode Mode { get; } + + /// <summary> + /// Gets the size of the buffer + /// used for parsing and writing CSV files. + /// Default is 0x1000. + /// </summary> + int BufferSize { get; } + + /// <summary> + /// The size of the buffer used when processing fields. + /// Default is 1024. + /// </summary> + int ProcessFieldBufferSize { get; } + + /// <summary> + /// Gets a value indicating whether the number of bytes should + /// be counted while parsing. Default is false. This will slow down parsing + /// because it needs to get the byte count of every char for the given encoding. + /// The <see cref="Encoding"/> needs to be set correctly for this to be accurate. + /// </summary> + bool CountBytes { get; } + + /// <summary> + /// Gets the encoding used when counting bytes. + /// </summary> + Encoding Encoding { get; } + + /// <summary> + /// Gets the function that is called when bad field data is found. A field + /// has bad data if it contains a quote and the field is not quoted (escaped). + /// You can supply your own function to do other things like logging the issue + /// instead of throwing an exception. + /// </summary> + BadDataFound BadDataFound { get; } + + /// <summary> + /// Gets or sets the maximum size of a field. + /// Defaults to 0, indicating maximum field size is not checked. + /// </summary> + double MaxFieldSize { get; } + + /// <summary> + /// Gets a value indicating if a line break found in a quote field should + /// be considered bad data. <c>true</c> to consider a line break bad data, otherwise <c>false</c>. + /// Defaults to false. + /// </summary> + bool LineBreakInQuotedFieldIsBadData { get; } + + /// <summary> + /// Gets the character used to denote + /// a line that is commented out. Default is '#'. + /// </summary> + char Comment { get; } + + /// <summary> + /// Gets a value indicating if comments are allowed. + /// <c>true</c> to allow commented out lines, otherwise <c>false</c>. + /// </summary> + bool AllowComments { get; } + + /// <summary> + /// Gets a value indicating if blank lines + /// should be ignored when reading. + /// <c>true</c> to ignore, otherwise <c>false</c>. Default is true. + /// </summary> + bool IgnoreBlankLines { get; } + + /// <summary> + /// Gets the character used to quote fields. + /// Default is '"'. + /// </summary> + char Quote { get; } + + /// <summary> + /// The delimiter used to separate fields. + /// Default is <see cref="TextInfo.ListSeparator"/>. + /// </summary> + string Delimiter { get; } + + /// <summary> + /// Detect the delimiter instead of using the delimiter from configuration. + /// Default is <c>false</c>. + /// </summary> + bool DetectDelimiter { get; } + + /// <summary> + /// Gets the function that is called when <see cref="DetectDelimiter"/> is enabled. + /// </summary> + GetDelimiter GetDelimiter { get; } + + /// <summary> + /// The possible delimiter values used when detecting the delimiter. + /// Default is [",", ";", "|", "\t"]. + /// </summary> + string[] DetectDelimiterValues { get; } + + /// <summary> + /// The character used to escape characters. + /// Default is '"'. + /// </summary> + char Escape { get; } + + /// <summary> + /// Gets the field trimming options. + /// </summary> + TrimOptions TrimOptions { get; } + + /// <summary> + /// Characters considered whitespace. + /// Used when trimming fields. + /// Default is [' ']. + /// </summary> + char[] WhiteSpaceChars { get; } + + /// <summary> + /// A value indicating if exception messages contain raw CSV data. + /// <c>true</c> if exception contain raw CSV data, otherwise <c>false</c>. + /// Default is <c>true</c>. + /// </summary> + bool ExceptionMessagesContainRawData { get; } + + /// <summary> + /// Validates the configuration. + /// </summary> + void Validate(); + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/IReaderConfiguration.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/IReaderConfiguration.cs new file mode 100644 index 0000000..a1250e6 --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/IReaderConfiguration.cs @@ -0,0 +1,111 @@ +// 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.Globalization; +using CsvHelper.TypeConversion; +using System.Reflection; +using System.Collections.Generic; +using System.IO; + +namespace CsvHelper.Configuration +{ + /// <summary> + /// Configuration used for the <see cref="IReader"/>. + /// </summary> + public interface IReaderConfiguration : IParserConfiguration + { + /// <summary> + /// Gets a value indicating if the + /// CSV file has a header record. + /// Default is true. + /// </summary> + bool HasHeaderRecord { get; } + + /// <summary> + /// Gets the function that is called when a header validation check is ran. The default function + /// will throw a <see cref="ValidationException"/> if there is no header for a given member mapping. + /// You can supply your own function to do other things like logging the issue instead of throwing an exception. + /// </summary> + HeaderValidated HeaderValidated { get; } + + /// <summary> + /// Gets the function that is called when a missing field is found. The default function will + /// throw a <see cref="MissingFieldException"/>. You can supply your own function to do other things + /// like logging the issue instead of throwing an exception. + /// </summary> + MissingFieldFound MissingFieldFound { get; } + + /// <summary> + /// Gets the function that is called when a reading exception occurs. + /// The default function will re-throw the given exception. If you want to ignore + /// reading exceptions, you can supply your own function to do other things like + /// logging the issue. + /// </summary> + ReadingExceptionOccurred ReadingExceptionOccurred { get; } + + /// <summary> + /// Prepares the header field for matching against a member name. + /// The header field and the member name are both ran through this function. + /// You should do things like trimming, removing whitespace, removing underscores, + /// and making casing changes to ignore case. + /// </summary> + PrepareHeaderForMatch PrepareHeaderForMatch { get; } + + /// <summary> + /// Determines if constructor parameters should be used to create + /// the class instead of the default constructor and members. + /// </summary> + ShouldUseConstructorParameters ShouldUseConstructorParameters { get; } + + /// <summary> + /// Chooses the constructor to use for constructor mapping. + /// </summary> + GetConstructor GetConstructor { get; } + + /// <summary> + /// Gets the name to use for the property of the dynamic object. + /// </summary> + GetDynamicPropertyName GetDynamicPropertyName { get; } + + /// <summary> + /// Gets a value indicating whether references + /// should be ignored when auto mapping. <c>true</c> to ignore + /// references, otherwise <c>false</c>. Default is false. + /// </summary> + bool IgnoreReferences { get; } + + /// <summary> + /// Gets the callback that will be called to + /// determine whether to skip the given record or not. + /// </summary> + ShouldSkipRecord? ShouldSkipRecord { get; } + + /// <summary> + /// Gets a value indicating if private + /// member should be read from and written to. + /// <c>true</c> to include private member, otherwise <c>false</c>. Default is false. + /// </summary> + bool IncludePrivateMembers { get; } + + /// <summary> + /// Gets a callback that will return the prefix for a reference header. + /// </summary> + ReferenceHeaderPrefix ReferenceHeaderPrefix { get; } + + /// <summary> + /// Gets a value indicating whether changes in the column + /// count should be detected. If true, a <see cref="BadDataException"/> + /// will be thrown if a different column count is detected. + /// </summary> + bool DetectColumnCountChanges { get; } + + /// <summary> + /// Gets the member types that are used when auto mapping. + /// MemberTypes are flags, so you can choose more than one. + /// Default is Properties. + /// </summary> + MemberTypes MemberTypes { get; } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/IWriterConfiguration.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/IWriterConfiguration.cs new file mode 100644 index 0000000..349c493 --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/IWriterConfiguration.cs @@ -0,0 +1,168 @@ +// 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.Globalization; +using System.Collections.Generic; +using System.IO; + +namespace CsvHelper.Configuration +{ + /// <summary> + /// Configuration used for the <see cref="IWriter"/>. + /// </summary> + public interface IWriterConfiguration + { + /// <summary> + /// Gets the size of the buffer + /// used for parsing and writing CSV files. + /// Default is 0x1000. + /// </summary> + int BufferSize { get; } + + /// <summary> + /// The mode. + /// See <see cref="CsvMode"/> for more details. + /// </summary> + CsvMode Mode { get; } + + /// <summary> + /// Gets the delimiter used to separate fields. + /// Default is ','; + /// </summary> + string Delimiter { get; } + + /// <summary> + /// Gets the character used to quote fields. + /// Default is '"'. + /// </summary> + char Quote { get; } + + /// <summary> + /// The character used to escape characters. + /// Default is '"'. + /// </summary> + char Escape { get; } + + /// <summary> + /// Gets the field trimming options. + /// </summary> + TrimOptions TrimOptions { get; } + + /// <summary> + /// Gets the injection options. + /// </summary> + InjectionOptions InjectionOptions { get; } + + /// <summary> + /// Gets the characters that are used for injection attacks. + /// </summary> + char[] InjectionCharacters { get; } + + /// <summary> + /// Gets the character used to escape a detected injection. + /// </summary> + char InjectionEscapeCharacter { get; } + + /// <summary> + /// The newline string to use. Default is \r\n (CRLF). + /// When writing, this value is always used. + /// When reading, this value is only used if explicitly set. If not set, + /// the parser uses one of \r\n, \r, or \n. + /// </summary> + string NewLine { get; } + + /// <summary> + /// A value indicating if <see cref="NewLine"/> was set. + /// </summary> + /// <value> + /// <c>true</c> if <see cref="NewLine"/> was set. <c>false</c> if <see cref="NewLine"/> is the default. + /// </value> + bool IsNewLineSet { get; } + + /// <summary> + /// Gets a function that is used to determine if a field should get quoted + /// when writing. + /// </summary> + ShouldQuote ShouldQuote { get; } + + /// <summary> + /// Gets the culture info used to read and write CSV files. + /// </summary> + CultureInfo CultureInfo { get; } + + /// <summary> + /// Gets a value indicating if comments are allowed. + /// True to allow commented out lines, otherwise false. + /// </summary> + bool AllowComments { get; } + + /// <summary> + /// Gets the character used to denote + /// a line that is commented out. Default is '#'. + /// </summary> + char Comment { get; } + + /// <summary> + /// Gets a value indicating if the + /// CSV file has a header record. + /// Default is true. + /// </summary> + bool HasHeaderRecord { get; } + + /// <summary> + /// Gets a value indicating whether references + /// should be ignored when auto mapping. True to ignore + /// references, otherwise false. Default is false. + /// </summary> + bool IgnoreReferences { get; } + + /// <summary> + /// Gets a value indicating if private + /// member should be read from and written to. + /// True to include private member, otherwise false. Default is false. + /// </summary> + bool IncludePrivateMembers { get; } + + /// <summary> + /// Gets a callback that will return the prefix for a reference header. + /// </summary> + ReferenceHeaderPrefix ReferenceHeaderPrefix { get; } + + /// <summary> + /// Gets the member types that are used when auto mapping. + /// MemberTypes are flags, so you can choose more than one. + /// Default is Properties. + /// </summary> + MemberTypes MemberTypes { get; } + + /// <summary> + /// Gets a value indicating that during writing if a new + /// object should be created when a reference member is null. + /// True to create a new object and use it's defaults for the + /// fields, or false to leave the fields empty for all the + /// reference member's member. + /// </summary> + bool UseNewObjectForNullReferenceMembers { get; } + + /// <summary> + /// Gets the comparer used to order the properties + /// of dynamic objects when writing. The default is null, + /// which will preserve the order the object properties + /// were created with. + /// </summary> + IComparer<string> DynamicPropertySort { get; } + + /// <summary> + /// A value indicating if exception messages contain raw CSV data. + /// <c>true</c> if exception contain raw CSV data, otherwise <c>false</c>. + /// Default is <c>true</c>. + /// </summary> + bool ExceptionMessagesContainRawData { get; } + + /// <summary> + /// Validates the configuration. + /// </summary> + void Validate(); + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/InjectionOptions.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/InjectionOptions.cs new file mode 100644 index 0000000..a7dc20e --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/InjectionOptions.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CsvHelper.Configuration +{ + /// <summary> + /// Options for handling injection attacks. + /// </summary> + public enum InjectionOptions + { + /// <summary> + /// No injection protection. + /// </summary> + None = 0, + /// <summary> + /// Escape injection characters. + /// </summary> + Escape, + /// <summary> + /// Strip injection characters. + /// </summary> + Strip, + /// <summary> + /// Throw an exception if injection characters are detected. + /// </summary> + Exception, + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/MemberMap.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/MemberMap.cs new file mode 100644 index 0000000..006595d --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/MemberMap.cs @@ -0,0 +1,244 @@ +// 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 CsvHelper.TypeConversion; +using System; +using System.Collections; +using System.Diagnostics; +using System.Linq.Expressions; +using System.Reflection; + +namespace CsvHelper.Configuration +{ + /// <summary> + /// Mapping info for a member to a CSV field. + /// </summary> + [DebuggerDisplay("Member = {Data.Member}, Names = {string.Join(\",\", Data.Names)}, Index = {Data.Index}, Ignore = {Data.Ignore}, Member = {Data.Member}, TypeConverter = {Data.TypeConverter}")] + public abstract class MemberMap + { + /// <summary> + /// Gets the member map data. + /// </summary> + public virtual MemberMapData Data { get; protected set; } + + /// <summary> + /// Type converter options. + /// </summary> + public virtual MemberMapTypeConverterOption TypeConverterOption { get; protected set; } + + /// <summary> + /// Creates an instance of <see cref="MemberMap"/> using the given Type and <see cref="MemberInfo"/>. + /// </summary> + /// <param name="classType">Type of the class the member being mapped belongs to.</param> + /// <param name="member">The member being mapped.</param> + public static MemberMap CreateGeneric(Type classType, MemberInfo member) + { + var memberMapType = typeof(MemberMap<,>).MakeGenericType(classType, member.MemberType()); + var memberMap = (MemberMap)ObjectResolver.Current.Resolve(memberMapType, member); + + return memberMap; + } + + /// <summary> + /// When reading, is used to get the field + /// at the index of the name if there was a + /// header specified. It will look for the + /// first name match in the order listed. + /// When writing, sets the name of the + /// field in the header record. + /// The first name will be used. + /// </summary> + /// <param name="names">The possible names of the CSV field.</param> + public virtual MemberMap Name(params string[] names) + { + if (names == null || names.Length == 0) + { + throw new ArgumentNullException(nameof(names)); + } + + Data.Names.Clear(); + Data.Names.AddRange(names); + Data.IsNameSet = true; + + return this; + } + + /// <summary> + /// When reading, is used to get the + /// index of the name used when there + /// are multiple names that are the same. + /// </summary> + /// <param name="index">The index of the name.</param> + public virtual MemberMap NameIndex(int index) + { + Data.NameIndex = index; + + return this; + } + + /// <summary> + /// When reading, is used to get the field at + /// the given index. When writing, the fields + /// will be written in the order of the field + /// indexes. + /// </summary> + /// <param name="index">The index of the CSV field.</param> + /// <param name="indexEnd">The end index used when mapping to an <see cref="IEnumerable"/> member.</param> + public virtual MemberMap Index(int index, int indexEnd = -1) + { + Data.Index = index; + Data.IsIndexSet = true; + Data.IndexEnd = indexEnd; + + return this; + } + + /// <summary> + /// Ignore the member when reading and writing. + /// If this member has already been mapped as a reference + /// member, either by a class map, or by automapping, calling + /// this method will not ignore all the child members down the + /// tree that have already been mapped. + /// </summary> + public virtual MemberMap Ignore() + { + Data.Ignore = true; + + return this; + } + + /// <summary> + /// Ignore the member when reading and writing. + /// If this member has already been mapped as a reference + /// member, either by a class map, or by automapping, calling + /// this method will not ignore all the child members down the + /// tree that have already been mapped. + /// </summary> + /// <param name="ignore">True to ignore, otherwise false.</param> + public virtual MemberMap Ignore(bool ignore) + { + Data.Ignore = ignore; + + return this; + } + + /// <summary> + /// The default value that will be used when reading when + /// the CSV field is empty. + /// </summary> + /// <param name="defaultValue">The default value.</param> + /// <param name="useOnConversionFailure">Use default on conversion failure.</param> + public virtual MemberMap Default(object? defaultValue, bool useOnConversionFailure = false) + { + if (defaultValue == null && Data.Member.MemberType().IsValueType) + { + throw new ArgumentException($"Member of type '{Data.Member.MemberType().FullName}' can't have a default value of null."); + } + + if (defaultValue != null && !Data.Member.MemberType().IsAssignableFrom(defaultValue.GetType())) + { + throw new ArgumentException($"Default of type '{defaultValue.GetType().FullName}' is not assignable to '{Data.Member.MemberType().FullName}'."); + } + + Data.Default = defaultValue; + Data.IsDefaultSet = true; + Data.UseDefaultOnConversionFailure = useOnConversionFailure; + + return this; + } + + /// <summary> + /// The constant value that will be used for every record when + /// reading and writing. This value will always be used no matter + /// what other mapping configurations are specified. + /// </summary> + /// <param name="constantValue">The constant value.</param> + public virtual MemberMap Constant(object constantValue) + { + if (constantValue == null && Data.Member.MemberType().IsValueType) + { + throw new ArgumentException($"Member of type '{Data.Member.MemberType().FullName}' can't have a constant value of null."); + } + + if (constantValue != null && !Data.Member.MemberType().IsAssignableFrom(constantValue.GetType())) + { + throw new ArgumentException($"Constant of type '{constantValue.GetType().FullName}' is not assignable to '{Data.Member.MemberType().FullName}'."); + } + + Data.Constant = constantValue; + Data.IsConstantSet = true; + + return this; + } + + /// <summary> + /// Specifies the <see cref="TypeConverter"/> to use + /// when converting the member to and from a CSV field. + /// </summary> + /// <param name="typeConverter">The TypeConverter to use.</param> + public virtual MemberMap TypeConverter(ITypeConverter typeConverter) + { + Data.TypeConverter = typeConverter; + + return this; + } + + /// <summary> + /// Specifies the <see cref="TypeConverter"/> to use + /// when converting the member to and from a CSV field. + /// </summary> + /// <typeparam name="TConverter">The <see cref="System.Type"/> of the + /// <see cref="TypeConverter"/> to use.</typeparam> + public virtual MemberMap TypeConverter<TConverter>() where TConverter : ITypeConverter + { + TypeConverter(ObjectResolver.Current.Resolve<TConverter>()); + + return this; + } + + /// <summary> + /// Ignore the member when reading if no matching field name can be found. + /// </summary> + public virtual MemberMap Optional() + { + Data.IsOptional = true; + + return this; + } + + /// <summary> + /// Specifies an expression to be used to validate a field when reading. + /// </summary> + /// <param name="validateExpression"></param> + public virtual MemberMap Validate(Validate validateExpression) + { + return Validate(validateExpression, args => $"Field '{args.Field}' is not valid."); + } + + /// <summary> + /// Specifies an expression to be used to validate a field when reading along with specified exception message. + /// </summary> + /// <param name="validateExpression"></param> + /// <param name="validateMessageExpression"></param> + public virtual MemberMap Validate(Validate validateExpression, ValidateMessage validateMessageExpression) + { + var fieldParameter = Expression.Parameter(typeof(ValidateArgs), "field"); + var validateCallExpression = Expression.Call( + Expression.Constant(validateExpression.Target), + validateExpression.Method, + fieldParameter + ); + var messageCallExpression = Expression.Call( + Expression.Constant(validateMessageExpression.Target), + validateMessageExpression.Method, + fieldParameter + ); + + Data.ValidateExpression = Expression.Lambda<Validate>(validateCallExpression, fieldParameter); + Data.ValidateMessageExpression = Expression.Lambda<ValidateMessage>(messageCallExpression, fieldParameter); + + return this; + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/MemberMapCollection.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/MemberMapCollection.cs new file mode 100644 index 0000000..0532544 --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/MemberMapCollection.cs @@ -0,0 +1,247 @@ +// 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; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Linq.Expressions; +using System.Reflection; + +namespace CsvHelper.Configuration +{ + /// <summary> + /// A collection that holds <see cref="MemberMap"/>'s. + /// </summary> + [DebuggerDisplay("Count = {list.Count}")] + public class MemberMapCollection : IList<MemberMap> + { + private readonly List<MemberMap> list = new List<MemberMap>(); + private readonly IComparer<MemberMap> comparer; + + /// <summary> + /// Gets the number of elements contained in the <see cref="T:System.Collections.Generic.ICollection`1"/>. + /// </summary> + /// <returns> + /// The number of elements contained in the <see cref="T:System.Collections.Generic.ICollection`1"/>. + /// </returns> + public virtual int Count => list.Count; + + /// <summary> + /// Gets a value indicating whether the <see cref="T:System.Collections.Generic.ICollection`1"/> is read-only. + /// </summary> + /// <returns> + /// true if the <see cref="T:System.Collections.Generic.ICollection`1"/> is read-only; otherwise, false. + /// </returns> + public virtual bool IsReadOnly => false; + + /// <summary> + /// Initializes a new instance of the <see cref="MemberMapCollection"/> class. + /// </summary> + public MemberMapCollection() : this(new MemberMapComparer()) { } + + /// <summary> + /// Initializes a new instance of the <see cref="MemberMapCollection"/> class. + /// </summary> + /// <param name="comparer">The comparer to use when sorting the member maps.</param> + public MemberMapCollection(IComparer<MemberMap> comparer) + { + this.comparer = comparer; + } + + /// <summary> + /// Returns an enumerator that iterates through the collection. + /// </summary> + /// <returns> + /// A <see cref="T:System.Collections.Generic.IEnumerator`1"/> that can be used to iterate through the collection. + /// </returns> + /// <filterpriority>1</filterpriority> + public virtual IEnumerator<MemberMap> GetEnumerator() + { + return list.GetEnumerator(); + } + + /// <summary> + /// Returns an enumerator that iterates through a collection. + /// </summary> + /// <returns> + /// An <see cref="T:System.Collections.IEnumerator"/> object that can be used to iterate through the collection. + /// </returns> + /// <filterpriority>2</filterpriority> + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + /// <summary> + /// Adds an item to the <see cref="T:System.Collections.Generic.ICollection`1"/>. + /// </summary> + /// <param name="item">The object to add to the <see cref="T:System.Collections.Generic.ICollection`1"/>. + /// </param><exception cref="T:System.NotSupportedException">The <see cref="T:System.Collections.Generic.ICollection`1"/> is read-only. + /// </exception> + public virtual void Add(MemberMap item) + { + list.Add(item); + list.Sort(comparer); + } + + /// <summary> + /// Adds a range of items to the <see cref="T:System.Collections.Generic.ICollection`1"/>. + /// </summary> + /// <param name="collection">The collection to add.</param> + public virtual void AddRange(ICollection<MemberMap> collection) + { + list.AddRange(collection); + list.Sort(comparer); + } + + /// <summary> + /// Removes all items from the <see cref="T:System.Collections.Generic.ICollection`1"/>. + /// </summary> + /// <exception cref="T:System.NotSupportedException">The <see cref="T:System.Collections.Generic.ICollection`1"/> is read-only. + /// </exception> + public virtual void Clear() + { + list.Clear(); + } + + /// <summary> + /// Determines whether the <see cref="T:System.Collections.Generic.ICollection`1"/> contains a specific value. + /// </summary> + /// <returns> + /// true if <paramref name="item"/> is found in the <see cref="T:System.Collections.Generic.ICollection`1"/>; otherwise, false. + /// </returns> + /// <param name="item">The object to locate in the <see cref="T:System.Collections.Generic.ICollection`1"/>. + /// </param> + public virtual bool Contains(MemberMap item) + { + return list.Contains(item); + } + + /// <summary> + /// Copies the elements of the <see cref="T:System.Collections.Generic.ICollection`1"/> to an <see cref="T:System.Array"/>, starting at a particular <see cref="T:System.Array"/> index. + /// </summary> + /// <param name="array">The one-dimensional <see cref="T:System.Array"/> that is the destination of the elements copied from <see cref="T:System.Collections.Generic.ICollection`1"/>. The <see cref="T:System.Array"/> must have zero-based indexing.</param><param name="arrayIndex">The zero-based index in <paramref name="array"/> at which copying begins.</param><exception cref="T:System.ArgumentNullException"><paramref name="array"/> is null.</exception><exception cref="T:System.ArgumentOutOfRangeException"><paramref name="arrayIndex"/> is less than 0.</exception><exception cref="T:System.ArgumentException">The number of elements in the source <see cref="T:System.Collections.Generic.ICollection`1"/> is greater than the available space from <paramref name="arrayIndex"/> to the end of the destination <paramref name="array"/>.</exception> + public virtual void CopyTo(MemberMap[] array, int arrayIndex) + { + list.CopyTo(array, arrayIndex); + } + + /// <summary> + /// Removes the first occurrence of a specific object from the <see cref="T:System.Collections.Generic.ICollection`1"/>. + /// </summary> + /// <returns> + /// true if <paramref name="item"/> was successfully removed from the <see cref="T:System.Collections.Generic.ICollection`1"/>; otherwise, false. This method also returns false if <paramref name="item"/> is not found in the original <see cref="T:System.Collections.Generic.ICollection`1"/>. + /// </returns> + /// <param name="item">The object to remove from the <see cref="T:System.Collections.Generic.ICollection`1"/>. + /// </param><exception cref="T:System.NotSupportedException">The <see cref="T:System.Collections.Generic.ICollection`1"/> is read-only. + /// </exception> + public virtual bool Remove(MemberMap item) + { + return list.Remove(item); + } + + /// <summary> + /// Determines the index of a specific item in the <see cref="T:System.Collections.Generic.IList`1"/>. + /// </summary> + /// <returns> + /// The index of <paramref name="item"/> if found in the list; otherwise, -1. + /// </returns> + /// <param name="item">The object to locate in the <see cref="T:System.Collections.Generic.IList`1"/>. + /// </param> + public virtual int IndexOf(MemberMap item) + { + return list.IndexOf(item); + } + + /// <summary> + /// Inserts an item to the <see cref="T:System.Collections.Generic.IList`1"/> at the specified index. + /// </summary> + /// <param name="index">The zero-based index at which <paramref name="item"/> should be inserted. + /// </param><param name="item">The object to insert into the <see cref="T:System.Collections.Generic.IList`1"/>. + /// </param><exception cref="T:System.ArgumentOutOfRangeException"><paramref name="index"/> is not a valid index in the <see cref="T:System.Collections.Generic.IList`1"/>. + /// </exception><exception cref="T:System.NotSupportedException">The <see cref="T:System.Collections.Generic.IList`1"/> is read-only. + /// </exception> + public virtual void Insert(int index, MemberMap item) + { + list.Insert(index, item); + } + + /// <summary> + /// Removes the <see cref="T:System.Collections.Generic.IList`1"/> item at the specified index. + /// </summary> + /// <param name="index">The zero-based index of the item to remove. + /// </param><exception cref="T:System.ArgumentOutOfRangeException"><paramref name="index"/> is not a valid index in the <see cref="T:System.Collections.Generic.IList`1"/>. + /// </exception><exception cref="T:System.NotSupportedException">The <see cref="T:System.Collections.Generic.IList`1"/> is read-only. + /// </exception> + public virtual void RemoveAt(int index) + { + list.RemoveAt(index); + } + + /// <summary> + /// Gets or sets the element at the specified index. + /// </summary> + /// <returns> + /// The element at the specified index. + /// </returns> + /// <param name="index">The zero-based index of the element to get or set. + /// </param><exception cref="T:System.ArgumentOutOfRangeException"><paramref name="index"/> is not a valid index in the <see cref="T:System.Collections.Generic.IList`1"/>. + /// </exception><exception cref="T:System.NotSupportedException">The member is set and the <see cref="T:System.Collections.Generic.IList`1"/> is read-only. + /// </exception> + public virtual MemberMap this[int index] + { + get { return list[index]; } + set { list[index] = value; } + } + + /// <summary> + /// Finds the <see cref="MemberMap"/> using the given member expression. + /// </summary> + /// <typeparam name="T">The <see cref="System.Type"/> the member is on.</typeparam> + /// <param name="expression">The member expression.</param> + /// <returns>The <see cref="MemberMap"/> for the given expression, or null if not found.</returns> + public virtual MemberMap? Find<T>(Expression<Func<T, object>> expression) + { + var member = ReflectionHelper.GetMember(expression); + return Find(member); + } + + /// <summary> + /// Finds the <see cref="MemberMap"/> using the given member. + /// </summary> + /// <param name="member">The member.</param> + /// <returns>The <see cref="MemberMap"/> for the given expression, or null if not found.</returns> + public virtual MemberMap? Find(MemberInfo member) + { + var existingMap = list.SingleOrDefault(m => + m.Data.Member == member || + m.Data.Member != null && + m.Data.Member.Name == member.Name && + ( + m.Data.Member.DeclaringType.IsAssignableFrom(member.DeclaringType) || + member.DeclaringType.IsAssignableFrom(m.Data.Member.DeclaringType) + ) + ); + + return existingMap; + } + + /// <summary> + /// Adds the members from the mapping. This will recursively + /// traverse the mapping tree and add all members for + /// reference maps. + /// </summary> + /// <param name="mapping">The mapping where the members are added from.</param> + public virtual void AddMembers(ClassMap mapping) + { + AddRange(mapping.MemberMaps); + foreach (var refmap in mapping.ReferenceMaps) + { + AddMembers(refmap.Data.Mapping); + } + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/MemberMapComparer.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/MemberMapComparer.cs new file mode 100644 index 0000000..84cdf6c --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/MemberMapComparer.cs @@ -0,0 +1,74 @@ +// 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; + +namespace CsvHelper.Configuration +{ + /// <summary> + /// Used to compare <see cref="MemberMap"/>s. + /// The order is by field index ascending. Any + /// fields that don't have an index are pushed + /// to the bottom. + /// </summary> + internal class MemberMapComparer : IComparer<MemberMap> + { + /// <summary> + /// Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other. + /// </summary> + /// <returns> + /// Value + /// Condition + /// Less than zero + /// <paramref name="x"/> is less than <paramref name="y"/>. + /// Zero + /// <paramref name="x"/> equals <paramref name="y"/>. + /// Greater than zero + /// <paramref name="x"/> is greater than <paramref name="y"/>. + /// </returns> + /// <param name="x">The first object to compare. + /// </param><param name="y">The second object to compare. + /// </param><exception cref="T:System.ArgumentException">Neither <paramref name="x"/> nor <paramref name="y"/> implements the <see cref="T:System.IComparable"/> interface. + /// -or- + /// <paramref name="x"/> and <paramref name="y"/> are of different types and neither one can handle comparisons with the other. + /// </exception><filterpriority>2</filterpriority> + public virtual int Compare( object x, object y ) + { + var xMember = x as MemberMap; + var yMember = y as MemberMap; + return Compare( xMember, yMember ); + } + + /// <summary> + /// Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other. + /// </summary> + /// <returns> + /// Value + /// Condition + /// Less than zero + /// <paramref name="x"/> is less than <paramref name="y"/>. + /// Zero + /// <paramref name="x"/> equals <paramref name="y"/>. + /// Greater than zero + /// <paramref name="x"/> is greater than <paramref name="y"/>. + /// </returns> + /// <param name="x">The first object to compare. + /// </param><param name="y">The second object to compare. + /// </param> + public virtual int Compare( MemberMap x, MemberMap y ) + { + if( x == null ) + { + throw new ArgumentNullException( nameof( x ) ); + } + if( y == null ) + { + throw new ArgumentNullException( nameof( y ) ); + } + + return x.Data.Index.CompareTo( y.Data.Index ); + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/MemberMapData.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/MemberMapData.cs new file mode 100644 index 0000000..07d696a --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/MemberMapData.cs @@ -0,0 +1,167 @@ +// 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.Reflection; +using CsvHelper.TypeConversion; +using System.Linq.Expressions; +using System; + +namespace CsvHelper.Configuration +{ + /// <summary> + /// The configured data for the member map. + /// </summary> + public class MemberMapData + { + /// <summary> + /// Gets the member type. + /// </summary> + public virtual Type Type + { + get + { + if (Member != null) + { + return Member.MemberType(); + } + + if (IsConstantSet) + { + return Constant?.GetType() ?? typeof(string); + } + + if (IsDefaultSet) + { + return Default?.GetType() ?? typeof(string); + } + + return typeof(string); + } + } + + /// <summary> + /// Gets the <see cref="MemberInfo"/> that the data + /// is associated with. + /// </summary> + public virtual MemberInfo? Member { get; private set; } + + /// <summary> + /// Gets the list of column names. + /// </summary> + public virtual MemberNameCollection Names { get; } = new MemberNameCollection(); + + /// <summary> + /// Gets or sets the index of the name. + /// This is used if there are multiple + /// columns with the same names. + /// </summary> + public virtual int NameIndex { get; set; } + + /// <summary> + /// Gets or sets a value indicating if the name was + /// explicitly set. True if it was explicitly set, + /// otherwise false. + /// </summary> + public virtual bool IsNameSet { get; set; } + + /// <summary> + /// Gets or sets the column index. + /// </summary> + public virtual int Index { get; set; } = -1; + + /// <summary> + /// Gets or sets the index end. The Index end is used to specify a range for use + /// with a collection member. Index is used as the start of the range, and IndexEnd + /// is the end of the range. + /// </summary> + public virtual int IndexEnd { get; set; } = -1; + + /// <summary> + /// Gets or sets a value indicating if the index was + /// explicitly set. True if it was explicitly set, + /// otherwise false. + /// </summary> + public virtual bool IsIndexSet { get; set; } + + /// <summary> + /// Gets or sets the type converter. + /// </summary> + public virtual ITypeConverter? TypeConverter { get; set; } + + /// <summary> + /// Gets or sets the type converter options. + /// </summary> + public virtual TypeConverterOptions TypeConverterOptions { get; set; } = new TypeConverterOptions(); + + /// <summary> + /// Gets or sets a value indicating whether the field should be ignored. + /// </summary> + public virtual bool Ignore { get; set; } + + /// <summary> + /// Gets or sets the default value used when a CSV field is empty. + /// </summary> + public virtual object? Default { get; set; } + + /// <summary> + /// Gets or sets a value indicating whether this instance is default value set. + /// the default value was explicitly set. True if it was + /// explicitly set, otherwise false. + /// </summary> + public virtual bool IsDefaultSet { get; set; } + + /// <summary> + /// Gets or setse a value indicating if the default value should be used when + /// a type conversion failure happens. <c>true</c> to use the default, otherwise + /// <c>false</c>. + /// </summary> + public virtual bool UseDefaultOnConversionFailure { get; set; } + + /// <summary> + /// Gets or sets the constant value used for every record. + /// </summary> + public virtual object? Constant { get; set; } + + /// <summary> + /// Gets or sets a value indicating if a constant was explicitly set. + /// </summary> + public virtual bool IsConstantSet { get; set; } + + /// <summary> + /// Gets or sets the expression used to convert data in the + /// row to the member. + /// </summary> + public virtual Expression ReadingConvertExpression { get; set; } + + /// <summary> + /// Gets or sets the expression to be used to convert the object + /// to a field. + /// </summary> + public virtual Expression WritingConvertExpression { get; set; } + + /// <summary> + /// Gets or sets the expression use to validate a field. + /// </summary> + public virtual Expression ValidateExpression { get; set; } + + /// <summary> + /// Gets or sets the expression used to get the validation message when validation fails. + /// </summary> + public virtual Expression ValidateMessageExpression { get; set; } + + /// <summary> + /// Gets or sets a value indicating if a field is optional. + /// </summary> + public virtual bool IsOptional { get; set; } + + /// <summary> + /// Initializes a new instance of the <see cref="MemberMapData"/> class. + /// </summary> + /// <param name="member">The member.</param> + public MemberMapData(MemberInfo? member) + { + Member = member; + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/MemberMapTypeConverterOption.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/MemberMapTypeConverterOption.cs new file mode 100644 index 0000000..bafad45 --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/MemberMapTypeConverterOption.cs @@ -0,0 +1,167 @@ +// 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.Globalization; + +namespace CsvHelper.Configuration +{ + /// <summary> + /// Sets type converter options on a member map. + /// </summary> + public class MemberMapTypeConverterOption + { + private readonly MemberMap memberMap; + + /// <summary> + /// Creates a new instance using the given <see cref="MemberMap"/>. + /// </summary> + /// <param name="memberMap">The member map the options are being applied to.</param> + public MemberMapTypeConverterOption(MemberMap memberMap) + { + this.memberMap = memberMap; + } + + /// <summary> + /// The <see cref="CultureInfo"/> used when type converting. + /// This will override the global <see cref="CsvConfiguration.CultureInfo"/> + /// setting. + /// </summary> + /// <param name="cultureInfo">The culture info.</param> + public virtual MemberMap CultureInfo(CultureInfo cultureInfo) + { + memberMap.Data.TypeConverterOptions.CultureInfo = cultureInfo; + + return memberMap; + } + + /// <summary> + /// The <see cref="DateTimeStyles"/> to use when type converting. + /// This is used when doing any <see cref="DateTime"/> conversions. + /// </summary> + /// <param name="dateTimeStyle">The date time style.</param> + public virtual MemberMap DateTimeStyles(DateTimeStyles dateTimeStyle) + { + memberMap.Data.TypeConverterOptions.DateTimeStyle = dateTimeStyle; + + return memberMap; + } + + /// <summary> + /// The <see cref="TimeSpanStyles"/> to use when type converting. + /// This is used when doing <see cref="TimeSpan"/> converting. + /// </summary> + /// <param name="timeSpanStyles">The time span styles.</param> + public virtual MemberMap TimespanStyles(TimeSpanStyles timeSpanStyles) + { + memberMap.Data.TypeConverterOptions.TimeSpanStyle = timeSpanStyles; + + return memberMap; + } + + /// <summary> + /// The <see cref="NumberStyles"/> to use when type converting. + /// This is used when doing any number conversions. + /// </summary> + /// <param name="numberStyle"></param> + public virtual MemberMap NumberStyles(NumberStyles numberStyle) + { + memberMap.Data.TypeConverterOptions.NumberStyles = numberStyle; + + return memberMap; + } + + /// <summary> + /// The string format to be used when type converting. + /// </summary> + /// <param name="formats">The format.</param> + public virtual MemberMap Format(params string[] formats) + { + memberMap.Data.TypeConverterOptions.Formats = formats; + + return memberMap; + } + + /// <summary> + /// The <see cref="UriKind"/> to use when converting. + /// This is used when doing <see cref="Uri"/> conversions. + /// </summary> + /// <param name="uriKind">Kind of the URI.</param> + public virtual MemberMap UriKind(UriKind uriKind) + { + memberMap.Data.TypeConverterOptions.UriKind = uriKind; + + return memberMap; + } + + /// <summary> + /// The string values used to represent a boolean when converting. + /// </summary> + /// <param name="isTrue">A value indicating whether true values or false values are being set.</param> + /// <param name="clearValues">A value indication if the current values should be cleared before adding the new ones.</param> + /// <param name="booleanValues">The string boolean values.</param> + public virtual MemberMap BooleanValues(bool isTrue, bool clearValues = true, params string[] booleanValues) + { + if (isTrue) + { + if (clearValues) + { + memberMap.Data.TypeConverterOptions.BooleanTrueValues.Clear(); + } + + memberMap.Data.TypeConverterOptions.BooleanTrueValues.AddRange(booleanValues); + } + else + { + if (clearValues) + { + memberMap.Data.TypeConverterOptions.BooleanFalseValues.Clear(); + } + + memberMap.Data.TypeConverterOptions.BooleanFalseValues.AddRange(booleanValues); + } + + return memberMap; + } + + /// <summary> + /// The string values used to represent null when converting. + /// </summary> + /// <param name="nullValues">The values that represent null.</param> + /// <returns></returns> + public virtual MemberMap NullValues(params string[] nullValues) + { + return NullValues(true, nullValues); + } + + /// <summary> + /// The string values used to represent null when converting. + /// </summary> + /// <param name="clearValues">A value indication if the current values should be cleared before adding the new ones.</param> + /// <param name="nullValues">The values that represent null.</param> + /// <returns></returns> + public virtual MemberMap NullValues(bool clearValues, params string[] nullValues) + { + if (clearValues) + { + memberMap.Data.TypeConverterOptions.NullValues.Clear(); + } + + memberMap.Data.TypeConverterOptions.NullValues.AddRange(nullValues); + + return memberMap; + } + + /// <summary> + /// Ignore case when parsing enums. + /// </summary> + /// <param name="ignoreCase"><c>true</c> to ignore case, otherwise <c>false</c>.</param> + public virtual MemberMap EnumIgnoreCase(bool ignoreCase = true) + { + memberMap.Data.TypeConverterOptions.EnumIgnoreCase = ignoreCase; + + return memberMap; + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/MemberMap`1.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/MemberMap`1.cs new file mode 100644 index 0000000..590f05a --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/MemberMap`1.cs @@ -0,0 +1,270 @@ +// 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 CsvHelper.TypeConversion; +using System; +using System.Collections; +using System.Linq.Expressions; +using System.Reflection; + +namespace CsvHelper.Configuration +{ + /// <summary> + /// Mapping info for a member to a CSV field. + /// </summary> + public class MemberMap<TClass, TMember> : MemberMap + { + /// <summary> + /// Creates a new <see cref="MemberMap"/> instance using the specified member. + /// </summary> + public MemberMap(MemberInfo? member) + { + TypeConverterOption = new MemberMapTypeConverterOption(this); + + Data = new MemberMapData(member); + } + + /// <summary> + /// When reading, is used to get the field + /// at the index of the name if there was a + /// header specified. It will look for the + /// first name match in the order listed. + /// When writing, sets the name of the + /// field in the header record. + /// The first name will be used. + /// </summary> + /// <param name="names">The possible names of the CSV field.</param> + public new virtual MemberMap<TClass, TMember> Name(params string[] names) + { + if (names == null || names.Length == 0) + { + throw new ArgumentNullException(nameof(names)); + } + + Data.Names.Clear(); + Data.Names.AddRange(names); + Data.IsNameSet = true; + + return this; + } + + /// <summary> + /// When reading, is used to get the + /// index of the name used when there + /// are multiple names that are the same. + /// </summary> + /// <param name="index">The index of the name.</param> + public new virtual MemberMap<TClass, TMember> NameIndex(int index) + { + Data.NameIndex = index; + + return this; + } + + /// <summary> + /// When reading, is used to get the field at + /// the given index. When writing, the fields + /// will be written in the order of the field + /// indexes. + /// </summary> + /// <param name="index">The index of the CSV field.</param> + /// <param name="indexEnd">The end index used when mapping to an <see cref="IEnumerable"/> member.</param> + public new virtual MemberMap<TClass, TMember> Index(int index, int indexEnd = -1) + { + Data.Index = index; + Data.IsIndexSet = true; + Data.IndexEnd = indexEnd; + + return this; + } + + /// <summary> + /// Ignore the member when reading and writing. + /// If this member has already been mapped as a reference + /// member, either by a class map, or by automapping, calling + /// this method will not ignore all the child members down the + /// tree that have already been mapped. + /// </summary> + public new virtual MemberMap<TClass, TMember> Ignore() + { + Data.Ignore = true; + + return this; + } + + /// <summary> + /// Ignore the member when reading and writing. + /// If this member has already been mapped as a reference + /// member, either by a class map, or by automapping, calling + /// this method will not ignore all the child members down the + /// tree that have already been mapped. + /// </summary> + /// <param name="ignore">True to ignore, otherwise false.</param> + public new virtual MemberMap<TClass, TMember> Ignore(bool ignore) + { + Data.Ignore = ignore; + + return this; + } + + /// <summary> + /// The default value that will be used when reading when + /// the CSV field is empty. + /// </summary> + /// <param name="defaultValue">The default value.</param> + /// <param name="useOnConversionFailure">Use default on conversion failure.</param> + public virtual MemberMap<TClass, TMember> Default(TMember defaultValue, bool useOnConversionFailure = false) + { + Data.Default = defaultValue; + Data.IsDefaultSet = true; + Data.UseDefaultOnConversionFailure = useOnConversionFailure; + + return this; + } + + /// <summary> + /// The default value that will be used when reading when + /// the CSV field is empty. This value is not type checked + /// and will use a <see cref="ITypeConverter"/> to convert + /// the field. This could potentially have runtime errors. + /// </summary> + /// <param name="defaultValue">The default value.</param> + /// <param name="useOnConversionFailure">Use default on conversion failure.</param> + public virtual MemberMap<TClass, TMember> Default(string defaultValue, bool useOnConversionFailure = false) + { + Data.Default = defaultValue; + Data.IsDefaultSet = true; + Data.UseDefaultOnConversionFailure = useOnConversionFailure; + + return this; + } + + /// <summary> + /// The constant value that will be used for every record when + /// reading and writing. This value will always be used no matter + /// what other mapping configurations are specified. + /// </summary> + /// <param name="constantValue">The constant value.</param> + public virtual MemberMap<TClass, TMember> Constant(TMember? constantValue) + { + Data.Constant = constantValue; + Data.IsConstantSet = true; + + return this; + } + + /// <summary> + /// Specifies the <see cref="TypeConverter"/> to use + /// when converting the member to and from a CSV field. + /// </summary> + /// <param name="typeConverter">The TypeConverter to use.</param> + public new virtual MemberMap<TClass, TMember> TypeConverter(ITypeConverter typeConverter) + { + Data.TypeConverter = typeConverter; + + return this; + } + + /// <summary> + /// Specifies the <see cref="TypeConverter"/> to use + /// when converting the member to and from a CSV field. + /// </summary> + /// <typeparam name="TConverter">The <see cref="System.Type"/> of the + /// <see cref="TypeConverter"/> to use.</typeparam> + public new virtual MemberMap<TClass, TMember> TypeConverter<TConverter>() where TConverter : ITypeConverter + { + TypeConverter(ObjectResolver.Current.Resolve<TConverter>()); + + return this; + } + + /// <summary> + /// Specifies an expression to be used to convert data in the + /// row to the member. + /// </summary> + /// <param name="convertFromStringFunction">The convert expression.</param> + public virtual MemberMap<TClass, TMember> Convert(ConvertFromString<TMember> convertFromStringFunction) + { + var instance = convertFromStringFunction.Target != null ? Expression.Constant(convertFromStringFunction.Target) : null; + var fieldParameter = Expression.Parameter(typeof(ConvertFromStringArgs), "args"); + var methodExpression = Expression.Call + ( + instance, + convertFromStringFunction.Method, + fieldParameter + ); + var lambdaExpression = Expression.Lambda<ConvertFromString<TMember>>(methodExpression, fieldParameter); + + Data.ReadingConvertExpression = lambdaExpression; + + return this; + } + + /// <summary> + /// Specifies an expression to be used to convert the object + /// to a field. + /// </summary> + /// <param name="convertToStringFunction">The convert expression.</param> + public virtual MemberMap<TClass, TMember> Convert(ConvertToString<TClass> convertToStringFunction) + { + var instance = convertToStringFunction.Target != null ? Expression.Constant(convertToStringFunction.Target) : null; + var fieldParameter = Expression.Parameter(typeof(ConvertToStringArgs<TClass>), "args"); + var methodExpression = Expression.Call + ( + instance, + convertToStringFunction.Method, + fieldParameter + ); + var lambdaExpression = Expression.Lambda<ConvertToString<TClass>>(methodExpression, fieldParameter); + + Data.WritingConvertExpression = lambdaExpression; + + return this; + } + + /// <summary> + /// Ignore the member when reading if no matching field name can be found. + /// </summary> + public new virtual MemberMap<TClass, TMember> Optional() + { + Data.IsOptional = true; + + return this; + } + + /// <summary> + /// Specifies an expression to be used to validate a field when reading. + /// </summary> + /// <param name="validateExpression"></param> + public new virtual MemberMap<TClass, TMember> Validate(Validate validateExpression) + { + return Validate(validateExpression, args => $"Field '{args.Field}' is not valid."); + } + + /// <summary> + /// Specifies an expression to be used to validate a field when reading along with specified exception message. + /// </summary> + /// <param name="validateExpression"></param> + /// <param name="validateMessageExpression"></param> + public new virtual MemberMap<TClass, TMember> Validate(Validate validateExpression, ValidateMessage validateMessageExpression) + { + var fieldParameter = Expression.Parameter(typeof(ValidateArgs), "args"); + var validateCallExpression = Expression.Call( + Expression.Constant(validateExpression.Target), + validateExpression.Method, + fieldParameter + ); + var messageCallExpression = Expression.Call( + Expression.Constant(validateMessageExpression.Target), + validateMessageExpression.Method, + fieldParameter + ); + + Data.ValidateExpression = Expression.Lambda<Validate>(validateCallExpression, fieldParameter); + Data.ValidateMessageExpression = Expression.Lambda<ValidateMessage>(messageCallExpression, fieldParameter); + + return this; + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/MemberNameCollection.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/MemberNameCollection.cs new file mode 100644 index 0000000..fb9db4a --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/MemberNameCollection.cs @@ -0,0 +1,98 @@ +// 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.Collections; +using System.Collections.Generic; + +namespace CsvHelper.Configuration +{ + /// <summary> + /// A collection that holds member names. + /// </summary> + public class MemberNameCollection : IEnumerable<string> + { + private readonly List<string> names = new List<string>(); + + /// <summary> + /// Gets the name at the given index. If a prefix is set, + /// it will be prepended to the name. + /// </summary> + /// <param name="index"></param> + /// <returns></returns> + public string this[int index] + { + get { return Prefix + names[index]; } + set { names[index] = value; } + } + + /// <summary> + /// Gets the prefix to use for each name. + /// </summary> + public string Prefix { get; set; } + + /// <summary> + /// Gets the raw list of names without + /// the prefix being prepended. + /// </summary> + public List<string> Names => names; + + /// <summary> + /// Gets the count. + /// </summary> + public int Count => names.Count; + + /// <summary> + /// Adds the given name to the collection. + /// </summary> + /// <param name="name">The name to add.</param> + public void Add(string name) + { + names.Add(name); + } + + /// <summary> + /// Clears all names from the collection. + /// </summary> + public void Clear() + { + names.Clear(); + } + + /// <summary> + /// Adds a range of names to the collection. + /// </summary> + /// <param name="names">The range to add.</param> + public void AddRange(IEnumerable<string> names) + { + this.names.AddRange(names); + } + + /// <summary> + /// Returns an enumerator that iterates through the collection. + /// </summary> + /// <returns> + /// A <see cref="T:System.Collections.Generic.IEnumerator`1"/> that can be used to iterate through the collection. + /// </returns> + /// <filterpriority>1</filterpriority> + public IEnumerator<string> GetEnumerator() + { + for (var i = 0; i < names.Count; i++) + { + yield return this[i]; + } + } + + /// <summary> + /// Returns an enumerator that iterates through a collection. + /// </summary> + /// <returns> + /// An <see cref="T:System.Collections.IEnumerator"/> object that can be used to iterate through the collection. + /// </returns> + /// <filterpriority>2</filterpriority> + IEnumerator IEnumerable.GetEnumerator() + { + return names.GetEnumerator(); + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/MemberReferenceMap.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/MemberReferenceMap.cs new file mode 100644 index 0000000..66dca90 --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/MemberReferenceMap.cs @@ -0,0 +1,68 @@ +// 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.Diagnostics; +using System.Reflection; + +namespace CsvHelper.Configuration +{ + /// <summary> + /// Mapping info for a reference member mapping to a class. + /// </summary> + [DebuggerDisplay("Member = {Data.Member}, Prefix = {Data.Prefix}")] + public class MemberReferenceMap + { + private readonly MemberReferenceMapData data; + + /// <summary> + /// Gets the member reference map data. + /// </summary> + public MemberReferenceMapData Data => data; + + /// <summary> + /// Initializes a new instance of the <see cref="MemberReferenceMap"/> class. + /// </summary> + /// <param name="member">The member.</param> + /// <param name="mapping">The <see cref="ClassMap"/> to use for the reference map.</param> + public MemberReferenceMap(MemberInfo member, ClassMap mapping) + { + if (mapping == null) + { + throw new ArgumentNullException(nameof(mapping)); + } + + data = new MemberReferenceMapData(member, mapping); + } + + /// <summary> + /// Appends a prefix to the header of each field of the reference member. + /// </summary> + /// <param name="prefix">The prefix to be prepended to headers of each reference member.</param> + /// <param name="inherit">Inherit parent prefixes.</param> + /// <returns>The current <see cref="MemberReferenceMap" /></returns> + public MemberReferenceMap Prefix(string? prefix = null, bool inherit = false) + { + if (string.IsNullOrEmpty(prefix)) + { + prefix = data.Member.Name + "."; + } + + data.Inherit = inherit; + data.Prefix = prefix; + + return this; + } + + /// <summary> + /// Get the largest index for the + /// members and references. + /// </summary> + /// <returns>The max index.</returns> + internal int GetMaxIndex() + { + return data.Mapping.GetMaxIndex(); + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/MemberReferenceMapCollection.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/MemberReferenceMapCollection.cs new file mode 100644 index 0000000..c8745ed --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/MemberReferenceMapCollection.cs @@ -0,0 +1,164 @@ +// 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; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Linq.Expressions; +using System.Reflection; + +namespace CsvHelper.Configuration +{ + /// <summary> + /// A collection that holds <see cref="MemberReferenceMap"/>'s. + /// </summary> + [DebuggerDisplay("Count = {list.Count}")] + public class MemberReferenceMapCollection : IList<MemberReferenceMap> + { + private readonly List<MemberReferenceMap> list = new List<MemberReferenceMap>(); + + /// <summary>Gets the number of elements contained in the <see cref="T:System.Collections.Generic.ICollection`1" />.</summary> + /// <returns>The number of elements contained in the <see cref="T:System.Collections.Generic.ICollection`1" />.</returns> + public virtual int Count => list.Count; + + /// <summary>Gets a value indicating whether the <see cref="T:System.Collections.Generic.ICollection`1" /> is read-only.</summary> + /// <returns>true if the <see cref="T:System.Collections.Generic.ICollection`1" /> is read-only; otherwise, false.</returns> + public virtual bool IsReadOnly => false; + + /// <summary>Gets or sets the element at the specified index.</summary> + /// <returns>The element at the specified index.</returns> + /// <param name="index">The zero-based index of the element to get or set.</param> + /// <exception cref="T:System.ArgumentOutOfRangeException"> + /// <paramref name="index" /> is not a valid index in the <see cref="T:System.Collections.Generic.IList`1" />.</exception> + /// <exception cref="T:System.NotSupportedException">The member is set and the <see cref="T:System.Collections.Generic.IList`1" /> is read-only.</exception> + public virtual MemberReferenceMap this[int index] + { + get => list[index]; + set => list[index] = value; + } + + /// <summary>Returns an enumerator that iterates through the collection.</summary> + /// <returns>A <see cref="T:System.Collections.Generic.IEnumerator`1" /> that can be used to iterate through the collection.</returns> + /// <filterpriority>1</filterpriority> + public virtual IEnumerator<MemberReferenceMap> GetEnumerator() + { + return list.GetEnumerator(); + } + + /// <summary>Returns an enumerator that iterates through a collection.</summary> + /// <returns>An <see cref="T:System.Collections.IEnumerator" /> object that can be used to iterate through the collection.</returns> + /// <filterpriority>2</filterpriority> + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + /// <summary>Adds an item to the <see cref="T:System.Collections.Generic.ICollection`1" />.</summary> + /// <param name="item">The object to add to the <see cref="T:System.Collections.Generic.ICollection`1" />.</param> + /// <exception cref="T:System.NotSupportedException">The <see cref="T:System.Collections.Generic.ICollection`1" /> is read-only.</exception> + public virtual void Add(MemberReferenceMap item) + { + list.Add(item); + } + + /// <summary>Removes all items from the <see cref="T:System.Collections.Generic.ICollection`1" />.</summary> + /// <exception cref="T:System.NotSupportedException">The <see cref="T:System.Collections.Generic.ICollection`1" /> is read-only. </exception> + public virtual void Clear() + { + list.Clear(); + } + + /// <summary>Determines whether the <see cref="T:System.Collections.Generic.ICollection`1" /> contains a specific value.</summary> + /// <returns>true if <paramref name="item" /> is found in the <see cref="T:System.Collections.Generic.ICollection`1" />; otherwise, false.</returns> + /// <param name="item">The object to locate in the <see cref="T:System.Collections.Generic.ICollection`1" />.</param> + public virtual bool Contains(MemberReferenceMap item) + { + return list.Contains(item); + } + + /// <summary>Copies the elements of the <see cref="T:System.Collections.Generic.ICollection`1" /> to an <see cref="T:System.Array" />, starting at a particular <see cref="T:System.Array" /> index.</summary> + /// <param name="array">The one-dimensional <see cref="T:System.Array" /> that is the destination of the elements copied from <see cref="T:System.Collections.Generic.ICollection`1" />. The <see cref="T:System.Array" /> must have zero-based indexing.</param> + /// <param name="arrayIndex">The zero-based index in <paramref name="array" /> at which copying begins.</param> + /// <exception cref="T:System.ArgumentNullException"> + /// <paramref name="array" /> is null.</exception> + /// <exception cref="T:System.ArgumentOutOfRangeException"> + /// <paramref name="arrayIndex" /> is less than 0.</exception> + /// <exception cref="T:System.ArgumentException">The number of elements in the source <see cref="T:System.Collections.Generic.ICollection`1" /> is greater than the available space from <paramref name="arrayIndex" /> to the end of the destination <paramref name="array" />.</exception> + public virtual void CopyTo(MemberReferenceMap[] array, int arrayIndex) + { + list.CopyTo(array, arrayIndex); + } + + /// <summary>Removes the first occurrence of a specific object from the <see cref="T:System.Collections.Generic.ICollection`1" />.</summary> + /// <returns>true if <paramref name="item" /> was successfully removed from the <see cref="T:System.Collections.Generic.ICollection`1" />; otherwise, false. This method also returns false if <paramref name="item" /> is not found in the original <see cref="T:System.Collections.Generic.ICollection`1" />.</returns> + /// <param name="item">The object to remove from the <see cref="T:System.Collections.Generic.ICollection`1" />.</param> + /// <exception cref="T:System.NotSupportedException">The <see cref="T:System.Collections.Generic.ICollection`1" /> is read-only.</exception> + public virtual bool Remove(MemberReferenceMap item) + { + return list.Remove(item); + } + + /// <summary>Determines the index of a specific item in the <see cref="T:System.Collections.Generic.IList`1" />.</summary> + /// <returns>The index of <paramref name="item" /> if found in the list; otherwise, -1.</returns> + /// <param name="item">The object to locate in the <see cref="T:System.Collections.Generic.IList`1" />.</param> + public virtual int IndexOf(MemberReferenceMap item) + { + return list.IndexOf(item); + } + + /// <summary>Inserts an item to the <see cref="T:System.Collections.Generic.IList`1" /> at the specified index.</summary> + /// <param name="index">The zero-based index at which <paramref name="item" /> should be inserted.</param> + /// <param name="item">The object to insert into the <see cref="T:System.Collections.Generic.IList`1" />.</param> + /// <exception cref="T:System.ArgumentOutOfRangeException"> + /// <paramref name="index" /> is not a valid index in the <see cref="T:System.Collections.Generic.IList`1" />.</exception> + /// <exception cref="T:System.NotSupportedException">The <see cref="T:System.Collections.Generic.IList`1" /> is read-only.</exception> + public virtual void Insert(int index, MemberReferenceMap item) + { + list.Insert(index, item); + } + + /// <summary>Removes the <see cref="T:System.Collections.Generic.IList`1" /> item at the specified index.</summary> + /// <param name="index">The zero-based index of the item to remove.</param> + /// <exception cref="T:System.ArgumentOutOfRangeException"> + /// <paramref name="index" /> is not a valid index in the <see cref="T:System.Collections.Generic.IList`1" />.</exception> + /// <exception cref="T:System.NotSupportedException">The <see cref="T:System.Collections.Generic.IList`1" /> is read-only.</exception> + public virtual void RemoveAt(int index) + { + list.RemoveAt(index); + } + + /// <summary> + /// Finds the <see cref="MemberReferenceMap"/> using the given member expression. + /// </summary> + /// <typeparam name="T">The <see cref="System.Type"/> the member is on.</typeparam> + /// <param name="expression">The member expression.</param> + /// <returns>The <see cref="MemberReferenceMap"/> for the given expression, or null if not found.</returns> + public virtual MemberReferenceMap? Find<T>(Expression<Func<T, object>> expression) + { + var member = ReflectionHelper.GetMember(expression); + return Find(member); + } + + /// <summary> + /// Finds the <see cref="MemberReferenceMap"/> using the given member. + /// </summary> + /// <param name="member">The member.</param> + /// <returns>The <see cref="MemberReferenceMap"/> for the given expression, or null if not found.</returns> + public virtual MemberReferenceMap? Find(MemberInfo member) + { + var existingMap = list.SingleOrDefault(m => + m.Data.Member == member || + m.Data.Member.Name == member.Name && + ( + m.Data.Member.DeclaringType.IsAssignableFrom(member.DeclaringType) || + member.DeclaringType.IsAssignableFrom(m.Data.Member.DeclaringType) + ) + ); + + return existingMap; + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/MemberReferenceMapData.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/MemberReferenceMapData.cs new file mode 100644 index 0000000..0726a35 --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/MemberReferenceMapData.cs @@ -0,0 +1,68 @@ +// 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.Reflection; + +namespace CsvHelper.Configuration +{ + /// <summary> + /// The configuration data for the reference map. + /// </summary> + public class MemberReferenceMapData + { + private string prefix; + + /// <summary> + /// Gets or sets the header prefix to use. + /// </summary> + public virtual string Prefix + { + get { return prefix; } + set + { + prefix = value; + foreach (var memberMap in Mapping.MemberMaps) + { + memberMap.Data.Names.Prefix = value; + } + + if (Inherit) + { + foreach (var memberRef in Mapping.ReferenceMaps) + { + memberRef.Data.Prefix = memberRef.Data.Prefix == null ? value : string.Concat(value, memberRef.Data.Prefix); + } + } + } + } + + /// <summary> + /// Gets or sets a value indicating if a prefix should inherit its parent. + /// <c>true</c> to inherit, otherwise <c>false</c>. + /// </summary> + public virtual bool Inherit { get; set; } + + /// <summary> + /// Gets the <see cref="MemberInfo"/> that the data + /// is associated with. + /// </summary> + public virtual MemberInfo Member { get; private set; } + + /// <summary> + /// Gets the mapping this is a reference for. + /// </summary> + public ClassMap Mapping { get; private set; } + + /// <summary> + /// Initializes a new instance of the <see cref="MemberReferenceMapData"/> class. + /// </summary> + /// <param name="member">The member.</param> + /// <param name="mapping">The mapping this is a reference for.</param> + public MemberReferenceMapData(MemberInfo member, ClassMap mapping) + { + Member = member; + Mapping = mapping; + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/MemberTypes.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/MemberTypes.cs new file mode 100644 index 0000000..378524f --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/MemberTypes.cs @@ -0,0 +1,32 @@ +// 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; + +namespace CsvHelper.Configuration +{ + /// <summary> + /// Flags for the type of members that + /// can be used for auto mapping. + /// </summary> + [Flags] + public enum MemberTypes + { + /// <summary> + /// No members. This is not a valid value + /// and will cause an exception if used. + /// </summary> + None = 0, + + /// <summary> + /// Properties on a class. + /// </summary> + Properties = 1, + + /// <summary> + /// Fields on a class. + /// </summary> + Fields = 2 + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/ParameterMap.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/ParameterMap.cs new file mode 100644 index 0000000..991cc8b --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/ParameterMap.cs @@ -0,0 +1,212 @@ +// 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 CsvHelper.TypeConversion; +using System; +using System.Diagnostics; +using System.Reflection; + +namespace CsvHelper.Configuration +{ + /// <summary> + /// Mapping for a constructor parameter. + /// This may contain value type data, a constructor type map, + /// or a reference map, depending on the type of the parameter. + /// </summary> + [DebuggerDisplay("Data = {Data}")] + public class ParameterMap + { + /// <summary> + /// Gets the parameter map data. + /// </summary> + public virtual ParameterMapData Data { get; protected set; } + + /// <summary> + /// Type converter options. + /// </summary> + public virtual ParameterMapTypeConverterOption TypeConverterOption { get; protected set; } + + /// <summary> + /// Gets or sets the map for a constructor type. + /// </summary> + public virtual ClassMap ConstructorTypeMap { get; set; } + + /// <summary> + /// Gets or sets the map for a reference type. + /// </summary> + public virtual ParameterReferenceMap ReferenceMap { get; set; } + + /// <summary> + /// Creates an instance of <see cref="ParameterMap"/> using + /// the given information. + /// </summary> + /// <param name="parameter">The parameter being mapped.</param> + public ParameterMap(ParameterInfo parameter) + { + TypeConverterOption = new ParameterMapTypeConverterOption(this); + + Data = new ParameterMapData(parameter); + } + + /// <summary> + /// When reading, is used to get the field + /// at the index of the name if there was a + /// header specified. It will look for the + /// first name match in the order listed. + /// When writing, sets the name of the + /// field in the header record. + /// The first name will be used. + /// </summary> + /// <param name="names">The possible names of the CSV field.</param> + public virtual ParameterMap Name(params string[] names) + { + if (names == null || names.Length == 0) + { + throw new ArgumentNullException(nameof(names)); + } + + Data.Names.Clear(); + Data.Names.AddRange(names); + Data.IsNameSet = true; + + return this; + } + + /// <summary> + /// When reading, is used to get the + /// index of the name used when there + /// are multiple names that are the same. + /// </summary> + /// <param name="index">The index of the name.</param> + public virtual ParameterMap NameIndex(int index) + { + Data.NameIndex = index; + + return this; + } + + /// <summary> + /// When reading, is used to get the field at + /// the given index. When writing, the fields + /// will be written in the order of the field + /// indexes. + /// </summary> + /// <param name="index">The index of the CSV field.</param> + public virtual ParameterMap Index(int index) + { + Data.Index = index; + Data.IsIndexSet = true; + + return this; + } + + /// <summary> + /// Ignore the parameter when reading and writing. + /// </summary> + public virtual ParameterMap Ignore() + { + Data.Ignore = true; + + return this; + } + + /// <summary> + /// Ignore the parameter when reading and writing. + /// </summary> + /// <param name="ignore">True to ignore, otherwise false.</param> + public virtual ParameterMap Ignore(bool ignore) + { + Data.Ignore = ignore; + + return this; + } + + /// <summary> + /// The default value that will be used when reading when + /// the CSV field is empty. + /// </summary> + /// <param name="defaultValue">The default value.</param> + public virtual ParameterMap Default(object? defaultValue) + { + if (defaultValue == null && Data.Parameter.ParameterType.IsValueType) + { + throw new ArgumentException($"Parameter of type '{Data.Parameter.ParameterType.FullName}' can't have a default value of null."); + } + + if (defaultValue != null && defaultValue.GetType() != Data.Parameter.ParameterType) + { + throw new ArgumentException($"Default of type '{defaultValue.GetType().FullName}' does not match parameter of type '{Data.Parameter.ParameterType.FullName}'."); + } + + Data.Default = defaultValue; + Data.IsDefaultSet = true; + + return this; + } + + /// <summary> + /// The constant value that will be used for every record when + /// reading and writing. This value will always be used no matter + /// what other mapping configurations are specified. + /// </summary> + /// <param name="constantValue">The constant value.</param> + public virtual ParameterMap Constant(object? constantValue) + { + if (constantValue == null && Data.Parameter.ParameterType.IsValueType) + { + throw new ArgumentException($"Parameter of type '{Data.Parameter.ParameterType.FullName}' can't have a constant value of null."); + } + + if (constantValue != null && constantValue.GetType() != Data.Parameter.ParameterType) + { + throw new ArgumentException($"Constant of type '{constantValue.GetType().FullName}' does not match parameter of type '{Data.Parameter.ParameterType.FullName}'."); + } + + Data.Constant = constantValue; + Data.IsConstantSet = true; + + return this; + } + + /// <summary> + /// The field is optional. + /// </summary> + public virtual ParameterMap Optional() + { + Data.IsOptional = true; + + return this; + } + + /// <summary> + /// Specifies the <see cref="TypeConverter"/> to use + /// when converting the parameter to and from a CSV field. + /// </summary> + /// <param name="typeConverter">The TypeConverter to use.</param> + public virtual ParameterMap TypeConverter(ITypeConverter typeConverter) + { + Data.TypeConverter = typeConverter; + + return this; + } + + /// <summary> + /// Specifies the <see cref="TypeConverter"/> to use + /// when converting the parameter to and from a CSV field. + /// </summary> + /// <typeparam name="TConverter">The <see cref="System.Type"/> of the + /// <see cref="TypeConverter"/> to use.</typeparam> + public virtual ParameterMap TypeConverter<TConverter>() where TConverter : ITypeConverter + { + TypeConverter(ObjectResolver.Current.Resolve<TConverter>()); + + return this; + } + + internal int GetMaxIndex() + { + return ReferenceMap?.GetMaxIndex() ?? Data.Index; + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/ParameterMapData.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/ParameterMapData.cs new file mode 100644 index 0000000..a83edbe --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/ParameterMapData.cs @@ -0,0 +1,106 @@ +// 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 CsvHelper.TypeConversion; +using System.Collections.Generic; +using System.Diagnostics; +using System.Reflection; + +namespace CsvHelper.Configuration +{ + /// <summary> + /// The constructor parameter data for the map. + /// </summary> + [DebuggerDisplay("Index = {Index}, Names = {string.Join(\", \", Names)}, Parameter = {Parameter}")] + public class ParameterMapData + { + /// <summary> + /// Gets the <see cref="ParameterInfo"/> that the data + /// is associated with. + /// </summary> + public virtual ParameterInfo Parameter { get; private set; } + + /// <summary> + /// Gets the list of column names. + /// </summary> + public virtual MemberNameCollection Names { get; } = new MemberNameCollection(); + + /// <summary> + /// Gets or sets the index of the name. + /// This is used if there are multiple + /// columns with the same names. + /// </summary> + public virtual int NameIndex { get; set; } + + /// <summary> + /// Gets or sets a value indicating if the name was + /// explicitly set. True if it was explicitly set, + /// otherwise false. + /// </summary> + public virtual bool IsNameSet { get; set; } + + /// <summary> + /// Gets or sets the column index. + /// </summary> + public virtual int Index { get; set; } = -1; + + /// <summary> + /// Gets or sets a value indicating if the index was + /// explicitly set. True if it was explicitly set, + /// otherwise false. + /// </summary> + public virtual bool IsIndexSet { get; set; } + + /// <summary> + /// Gets or sets the type converter. + /// </summary> + public virtual ITypeConverter TypeConverter { get; set; } + + /// <summary> + /// Gets or sets the type converter options. + /// </summary> + public virtual TypeConverterOptions TypeConverterOptions { get; set; } = new TypeConverterOptions(); + + /// <summary> + /// Gets or sets a value indicating whether the field should be ignored. + /// </summary> + public virtual bool Ignore { get; set; } + + /// <summary> + /// Gets or sets the default value used when a CSV field is empty. + /// </summary> + public virtual object? Default { get; set; } + + /// <summary> + /// Gets or sets a value indicating whether this instance is default value set. + /// the default value was explicitly set. True if it was + /// explicitly set, otherwise false. + /// </summary> + public virtual bool IsDefaultSet { get; set; } + + /// <summary> + /// Gets or sets the constant value used for every record. + /// </summary> + public virtual object? Constant { get; set; } + + /// <summary> + /// Gets or sets a value indicating if a constant was explicitly set. + /// </summary> + public virtual bool IsConstantSet { get; set; } + + /// <summary> + /// Gets or sets a value indicating if a field is optional. + /// </summary> + public virtual bool IsOptional { get; set; } + + /// <summary> + /// Initializes a new instance of the <see cref="ParameterMapData"/> class. + /// </summary> + /// <param name="parameter">The constructor parameter.</param> + public ParameterMapData(ParameterInfo parameter) + { + Parameter = parameter; + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/ParameterMapTypeConverterOption.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/ParameterMapTypeConverterOption.cs new file mode 100644 index 0000000..4b3d82a --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/ParameterMapTypeConverterOption.cs @@ -0,0 +1,160 @@ +// 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 +{ + /// <summary> + /// Sets type converter options on a parameter map. + /// </summary> + public class ParameterMapTypeConverterOption + { + private readonly ParameterMap parameterMap; + + /// <summary> + /// Creates a new instance using the given <see cref="ParameterMap"/>. + /// </summary> + /// <param name="parameterMap">The member map the options are being applied to.</param> + public ParameterMapTypeConverterOption(ParameterMap parameterMap) + { + this.parameterMap = parameterMap; + } + + /// <summary> + /// The <see cref="CultureInfo"/> used when type converting. + /// This will override the global <see cref="CsvConfiguration.CultureInfo"/> + /// setting. + /// </summary> + /// <param name="cultureInfo">The culture info.</param> + public virtual ParameterMap CultureInfo(CultureInfo cultureInfo) + { + parameterMap.Data.TypeConverterOptions.CultureInfo = cultureInfo; + + return parameterMap; + } + + /// <summary> + /// The <see cref="DateTimeStyles"/> to use when type converting. + /// This is used when doing any <see cref="DateTime"/> conversions. + /// </summary> + /// <param name="dateTimeStyle">The date time style.</param> + public virtual ParameterMap DateTimeStyles(DateTimeStyles dateTimeStyle) + { + parameterMap.Data.TypeConverterOptions.DateTimeStyle = dateTimeStyle; + + return parameterMap; + } + + /// <summary> + /// The <see cref="TimeSpanStyles"/> to use when type converting. + /// This is used when doing <see cref="TimeSpan"/> converting. + /// </summary> + /// <param name="timeSpanStyles">The time span styles.</param> + public virtual ParameterMap TimespanStyles(TimeSpanStyles timeSpanStyles) + { + parameterMap.Data.TypeConverterOptions.TimeSpanStyle = timeSpanStyles; + + return parameterMap; + } + + /// <summary> + /// The <see cref="NumberStyles"/> to use when type converting. + /// This is used when doing any number conversions. + /// </summary> + /// <param name="numberStyle"></param> + public virtual ParameterMap NumberStyles(NumberStyles numberStyle) + { + parameterMap.Data.TypeConverterOptions.NumberStyles = numberStyle; + + return parameterMap; + } + + /// <summary> + /// The string format to be used when type converting. + /// </summary> + /// <param name="formats">The format.</param> + public virtual ParameterMap Format(params string[] formats) + { + parameterMap.Data.TypeConverterOptions.Formats = formats; + + return parameterMap; + } + + /// <summary> + /// The <see cref="UriKind"/> to use when converting. + /// This is used when doing <see cref="Uri"/> conversions. + /// </summary> + /// <param name="uriKind">Kind of the URI.</param> + public virtual ParameterMap UriKind(UriKind uriKind) + { + parameterMap.Data.TypeConverterOptions.UriKind = uriKind; + + return parameterMap; + } + + /// <summary> + /// The string values used to represent a boolean when converting. + /// </summary> + /// <param name="isTrue">A value indicating whether true values or false values are being set.</param> + /// <param name="clearValues">A value indication if the current values should be cleared before adding the new ones.</param> + /// <param name="booleanValues">The string boolean values.</param> + 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; + } + + /// <summary> + /// The string values used to represent null when converting. + /// </summary> + /// <param name="nullValues">The values that represent null.</param> + /// <returns></returns> + public virtual ParameterMap NullValues(params string[] nullValues) + { + return NullValues(true, nullValues); + } + + /// <summary> + /// The string values used to represent null when converting. + /// </summary> + /// <param name="clearValues">A value indication if the current values should be cleared before adding the new ones.</param> + /// <param name="nullValues">The values that represent null.</param> + /// <returns></returns> + public virtual ParameterMap NullValues(bool clearValues, params string[] nullValues) + { + if (clearValues) + { + parameterMap.Data.TypeConverterOptions.NullValues.Clear(); + } + + parameterMap.Data.TypeConverterOptions.NullValues.AddRange(nullValues); + + return parameterMap; + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/ParameterReferenceMap.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/ParameterReferenceMap.cs new file mode 100644 index 0000000..7e9a5f3 --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/ParameterReferenceMap.cs @@ -0,0 +1,66 @@ +// 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.Reflection; + +namespace CsvHelper.Configuration +{ + /// <summary> + /// Mapping info for a reference parameter mapping to a class. + /// </summary> + public class ParameterReferenceMap + { + private readonly ParameterReferenceMapData data; + + /// <summary> + /// Gets the parameter reference map data. + /// </summary> + public ParameterReferenceMapData Data => data; + + /// <summary> + /// Initializes a new instance of the <see cref="ParameterReferenceMap"/> class. + /// </summary> + /// <param name="parameter">The parameter.</param> + /// <param name="mapping">The <see cref="ClassMap"/> to use for the reference map.</param> + public ParameterReferenceMap(ParameterInfo parameter, ClassMap mapping) + { + if (mapping == null) + { + throw new ArgumentNullException(nameof(mapping)); + } + + data = new ParameterReferenceMapData(parameter, mapping); + } + + /// <summary> + /// Appends a prefix to the header of each field of the reference parameter. + /// </summary> + /// <param name="prefix">The prefix to be prepended to headers of each reference parameter.</param> + /// <param name="inherit">Inherit parent prefixes.</param> + /// <returns>The current <see cref="ParameterReferenceMap" /></returns> + public ParameterReferenceMap Prefix(string prefix = null, bool inherit = false) + { + if (string.IsNullOrEmpty(prefix)) + { + prefix = data.Parameter.Name + "."; + } + + data.Inherit = inherit; + data.Prefix = prefix; + + return this; + } + + /// <summary> + /// Get the largest index for the + /// members and references. + /// </summary> + /// <returns>The max index.</returns> + internal int GetMaxIndex() + { + return data.Mapping.GetMaxIndex(); + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/ParameterReferenceMapData.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/ParameterReferenceMapData.cs new file mode 100644 index 0000000..ab2a28d --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/ParameterReferenceMapData.cs @@ -0,0 +1,70 @@ +// 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.Diagnostics; +using System.Reflection; + +namespace CsvHelper.Configuration +{ + /// <summary> + /// The configuration data for the reference map. + /// </summary> + [DebuggerDisplay( "Prefix = {Prefix}, Parameter = {Parameter}" )] + public class ParameterReferenceMapData + { + private string prefix; + + /// <summary> + /// Gets or sets the header prefix to use. + /// </summary> + public virtual string Prefix + { + get { return prefix; } + set + { + prefix = value; + foreach( var memberMap in Mapping.MemberMaps ) + { + memberMap.Data.Names.Prefix = value; + } + + if (Inherit) + { + foreach (var memberRef in Mapping.ReferenceMaps) + { + memberRef.Data.Prefix = memberRef.Data.Prefix == null ? value : string.Concat(value, memberRef.Data.Prefix); + } + } + } + } + + /// <summary> + /// Gets or sets a value indicating if a prefix should inherit its parent. + /// <c>true</c> to inherit, otherwise <c>false</c>. + /// </summary> + public virtual bool Inherit { get; set; } + + /// <summary> + /// Gets the <see cref="ParameterInfo"/> that the data + /// is associated with. + /// </summary> + public virtual ParameterInfo Parameter { get; private set; } + + /// <summary> + /// Gets the mapping this is a reference for. + /// </summary> + public ClassMap Mapping { get; private set; } + + /// <summary> + /// Initializes a new instance of the <see cref="ParameterReferenceMapData"/> class. + /// </summary> + /// <param name="parameter">The parameter.</param> + /// <param name="mapping">The mapping this is a reference for.</param> + public ParameterReferenceMapData( ParameterInfo parameter, ClassMap mapping ) + { + Parameter = parameter; + Mapping = mapping; + } + } +} diff --git a/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/TrimOptions.cs b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/TrimOptions.cs new file mode 100644 index 0000000..5555c92 --- /dev/null +++ b/ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/TrimOptions.cs @@ -0,0 +1,30 @@ +// 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; + +namespace CsvHelper.Configuration +{ + /// <summary> + /// Options for trimming of fields. + /// </summary> + [Flags] + public enum TrimOptions + { + /// <summary> + /// No trimming. + /// </summary> + None = 0, + + /// <summary> + /// Trims the whitespace around a field. + /// </summary> + Trim = 1, + + /// <summary> + /// Trims the whitespace inside of quotes around a field. + /// </summary> + InsideQuotes = 2 + } +} |