From 2a1cd4fda8a4a8e649910d16b4dfa1ce7ae63543 Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Fri, 12 May 2023 09:24:40 +0800 Subject: *misc --- .../Attributes/AllowCommentsAttribute.cs | 35 ++ .../Attributes/BooleanFalseValuesAttribute.cs | 52 ++ .../Attributes/BooleanTrueValuesAttribute.cs | 52 ++ .../Attributes/BufferSizeAttribute.cs | 36 ++ .../Attributes/CacheFieldsAttribute.cs | 36 ++ .../Configuration/Attributes/CommentAttribute.cs | 36 ++ .../Configuration/Attributes/ConstantAttribute.cs | 47 ++ .../Attributes/CountBytesAttribute.cs | 45 ++ .../Attributes/CultureInfoAttribute.cs | 46 ++ .../Attributes/DateTimeStylesAttribute.cs | 44 ++ .../Configuration/Attributes/DefaultAttribute.cs | 45 ++ .../Configuration/Attributes/DelimiterAttribute.cs | 35 ++ .../DetectColumnCountChangesAttribute.cs | 40 ++ .../Attributes/DetectDelimiterAttribute.cs | 35 ++ .../Attributes/DetectDelimiterValuesAttribute.cs | 37 ++ .../Configuration/Attributes/EncodingAttribute.cs | 36 ++ .../Attributes/EnumIgnoreCaseAttribute.cs | 41 ++ .../Configuration/Attributes/EscapeAttribute.cs | 35 ++ .../ExceptionMessagesContainRawDataAttribute.cs | 39 ++ .../Configuration/Attributes/FormatAttribute.cs | 50 ++ .../Attributes/HasHeaderRecordAttribute.cs | 35 ++ .../Attributes/HeaderPrefixAttribute.cs | 73 +++ .../Configuration/Attributes/IClassMapper.cs | 19 + .../Configuration/Attributes/IMemberMapper.cs | 20 + .../Attributes/IMemberReferenceMapper.cs | 20 + .../Configuration/Attributes/IParameterMapper.cs | 24 + .../Attributes/IParameterReferenceMapper.cs | 24 + .../Configuration/Attributes/IgnoreAttribute.cs | 41 ++ .../Attributes/IgnoreBaseAttribute.cs | 20 + .../Attributes/IgnoreBlankLinesAttribute.cs | 35 ++ .../Attributes/IgnoreReferencesAttribute.cs | 41 ++ .../Attributes/IncludePrivateMembersAttribute.cs | 35 ++ .../Configuration/Attributes/IndexAttribute.cs | 57 ++ .../Attributes/InjectionCharactersAttribute.cs | 37 ++ .../InjectionEscapeCharacterAttribute.cs | 35 ++ .../Attributes/InjectionOptionsAttribute.cs | 35 ++ .../LineBreakInQuotedFieldIsBadDataAttribute.cs | 39 ++ .../Attributes/MaxFieldSizeAttribute.cs | 40 ++ .../Attributes/MemberTypesAttribute.cs | 40 ++ .../Configuration/Attributes/ModeAttribute.cs | 38 ++ .../Configuration/Attributes/NameAttribute.cs | 77 +++ .../Configuration/Attributes/NameIndexAttribute.cs | 45 ++ .../Configuration/Attributes/NewLineAttribute.cs | 39 ++ .../Attributes/NullValuesAttribute.cs | 52 ++ .../Attributes/NumberStylesAttribute.cs | 44 ++ .../Configuration/Attributes/OptionalAttribute.cs | 27 + .../Attributes/ProcessFieldBufferSizeAttribute.cs | 36 ++ .../Configuration/Attributes/QuoteAttribute.cs | 35 ++ .../Attributes/TrimOptionsAttribute.cs | 35 ++ .../Attributes/TypeConverterAttribute.cs | 57 ++ ...UseNewObjectForNullReferenceMembersAttribute.cs | 47 ++ .../Attributes/WhiteSpaceCharsAttribute.cs | 41 ++ .../src/CsvHelper/Configuration/ClassMap.cs | 648 +++++++++++++++++++++ .../src/CsvHelper/Configuration/ClassMapBuilder.cs | 432 ++++++++++++++ .../CsvHelper/Configuration/ClassMapCollection.cs | 188 ++++++ .../src/CsvHelper/Configuration/ClassMap`1.cs | 112 ++++ .../Configuration/ConfigurationException.cs | 36 ++ .../Configuration/ConfigurationFunctions.cs | 267 +++++++++ .../CsvHelper/Configuration/CsvConfiguration.cs | 240 ++++++++ .../CsvHelper/Configuration/DefaultClassMap`1.cs | 15 + .../Configuration/IParserConfiguration.cs | 176 ++++++ .../Configuration/IReaderConfiguration.cs | 111 ++++ .../Configuration/IWriterConfiguration.cs | 168 ++++++ .../CsvHelper/Configuration/InjectionOptions.cs | 31 + .../src/CsvHelper/Configuration/MemberMap.cs | 244 ++++++++ .../CsvHelper/Configuration/MemberMapCollection.cs | 247 ++++++++ .../CsvHelper/Configuration/MemberMapComparer.cs | 74 +++ .../src/CsvHelper/Configuration/MemberMapData.cs | 167 ++++++ .../Configuration/MemberMapTypeConverterOption.cs | 167 ++++++ .../src/CsvHelper/Configuration/MemberMap`1.cs | 270 +++++++++ .../Configuration/MemberNameCollection.cs | 98 ++++ .../CsvHelper/Configuration/MemberReferenceMap.cs | 68 +++ .../Configuration/MemberReferenceMapCollection.cs | 164 ++++++ .../Configuration/MemberReferenceMapData.cs | 68 +++ .../src/CsvHelper/Configuration/MemberTypes.cs | 32 + .../src/CsvHelper/Configuration/ParameterMap.cs | 212 +++++++ .../CsvHelper/Configuration/ParameterMapData.cs | 106 ++++ .../ParameterMapTypeConverterOption.cs | 160 +++++ .../Configuration/ParameterReferenceMap.cs | 66 +++ .../Configuration/ParameterReferenceMapData.cs | 70 +++ .../src/CsvHelper/Configuration/TrimOptions.cs | 30 + 81 files changed, 6732 insertions(+) create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/AllowCommentsAttribute.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/BooleanFalseValuesAttribute.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/BooleanTrueValuesAttribute.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/BufferSizeAttribute.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/CacheFieldsAttribute.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/CommentAttribute.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/ConstantAttribute.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/CountBytesAttribute.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/CultureInfoAttribute.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/DateTimeStylesAttribute.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/DefaultAttribute.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/DelimiterAttribute.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/DetectColumnCountChangesAttribute.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/DetectDelimiterAttribute.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/DetectDelimiterValuesAttribute.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/EncodingAttribute.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/EnumIgnoreCaseAttribute.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/EscapeAttribute.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/ExceptionMessagesContainRawDataAttribute.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/FormatAttribute.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/HasHeaderRecordAttribute.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/HeaderPrefixAttribute.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/IClassMapper.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/IMemberMapper.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/IMemberReferenceMapper.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/IParameterMapper.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/IParameterReferenceMapper.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/IgnoreAttribute.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/IgnoreBaseAttribute.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/IgnoreBlankLinesAttribute.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/IgnoreReferencesAttribute.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/IncludePrivateMembersAttribute.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/IndexAttribute.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/InjectionCharactersAttribute.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/InjectionEscapeCharacterAttribute.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/InjectionOptionsAttribute.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/LineBreakInQuotedFieldIsBadDataAttribute.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/MaxFieldSizeAttribute.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/MemberTypesAttribute.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/ModeAttribute.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/NameAttribute.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/NameIndexAttribute.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/NewLineAttribute.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/NullValuesAttribute.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/NumberStylesAttribute.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/OptionalAttribute.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/ProcessFieldBufferSizeAttribute.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/QuoteAttribute.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/TrimOptionsAttribute.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/TypeConverterAttribute.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/UseNewObjectForNullReferenceMembersAttribute.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/Attributes/WhiteSpaceCharsAttribute.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/ClassMap.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/ClassMapBuilder.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/ClassMapCollection.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/ClassMap`1.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/ConfigurationException.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/ConfigurationFunctions.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/CsvConfiguration.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/DefaultClassMap`1.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/IParserConfiguration.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/IReaderConfiguration.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/IWriterConfiguration.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/InjectionOptions.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/MemberMap.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/MemberMapCollection.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/MemberMapComparer.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/MemberMapData.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/MemberMapTypeConverterOption.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/MemberMap`1.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/MemberNameCollection.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/MemberReferenceMap.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/MemberReferenceMapCollection.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/MemberReferenceMapData.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/MemberTypes.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/ParameterMap.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/ParameterMapData.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/ParameterMapTypeConverterOption.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/ParameterReferenceMap.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/ParameterReferenceMapData.cs create mode 100644 ThirdParty/CsvHelper-master/src/CsvHelper/Configuration/TrimOptions.cs (limited to 'ThirdParty/CsvHelper-master/src/CsvHelper/Configuration') 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 +{ + /// + /// A value indicating if comments are allowed. + /// + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] + public class AllowCommentsAttribute : Attribute, IClassMapper + { + /// + /// Gets a value indicating if comments are allowed. + /// + public bool AllowComments { get; private set; } + + /// + /// A value indicating if comments are allowed. + /// + /// The value indicating id comments are allowed. + public AllowCommentsAttribute(bool allowComments) + { + AllowComments = allowComments; + } + + /// + 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 +{ + /// + /// The string values used to represent a boolean false when converting. + /// + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] + public class BooleanFalseValuesAttribute : Attribute, IMemberMapper, IParameterMapper + { + /// + /// Gets the false values. + /// + public string[] FalseValues { get; private set; } + + /// + /// The string values used to represent a boolean false when converting. + /// + /// The false values. + public BooleanFalseValuesAttribute(string falseValue) + { + FalseValues = new string[] { falseValue }; + } + + /// + /// The string values used to represent a boolean false when converting. + /// + /// The false values. + public BooleanFalseValuesAttribute(params string[] falseValues) + { + FalseValues = falseValues; + } + + /// + public void ApplyTo(MemberMap memberMap) + { + memberMap.Data.TypeConverterOptions.BooleanFalseValues.Clear(); + memberMap.Data.TypeConverterOptions.BooleanFalseValues.AddRange(FalseValues); + } + + /// + 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 +{ + /// + /// The string values used to represent a boolean true when converting. + /// + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] + public class BooleanTrueValuesAttribute : Attribute, IMemberMapper, IParameterMapper + { + /// + /// Gets the true values. + /// + public string[] TrueValues { get; private set; } + + /// + /// The string values used to represent a boolean true when converting. + /// + /// + public BooleanTrueValuesAttribute(string trueValue) + { + TrueValues = new string[] { trueValue }; + } + + /// + /// The string values used to represent a boolean true when converting. + /// + /// + public BooleanTrueValuesAttribute(params string[] trueValues) + { + TrueValues = trueValues; + } + + /// + public void ApplyTo(MemberMap memberMap) + { + memberMap.Data.TypeConverterOptions.BooleanTrueValues.Clear(); + memberMap.Data.TypeConverterOptions.BooleanTrueValues.AddRange(TrueValues); + } + + /// + 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 +{ + /// + /// The size of the buffer used for parsing and writing CSV files. + /// Default is 0x1000. + /// + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] + public class BufferSizeAttribute : Attribute, IClassMapper + { + /// + /// The buffer size. + /// + public int BufferSize { get; private set; } + + /// + /// The size of the buffer used for parsing and writing CSV files. + /// + /// + public BufferSizeAttribute(int bufferSize) + { + BufferSize = bufferSize; + } + + /// + 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 +{ + /// + /// Cache fields that are created when parsing. + /// Default is false. + /// + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] + public class CacheFieldsAttribute : Attribute, IClassMapper + { + /// + /// Cache fields that are created when parsing. + /// + public bool CacheFields { get; private set; } + + /// + /// Cache fields that are created when parsing. + /// + /// + public CacheFieldsAttribute(bool cacheFields) + { + CacheFields = cacheFields; + } + + /// + 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 +{ + /// + /// The character used to denote a line that is commented out. + /// Default is #. + /// + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] + public class CommentAttribute : Attribute, IClassMapper + { + /// + /// Gets the character used to denote a line that is commented out. + /// + public char Comment { get; private set; } + + /// + /// The character used to denote a line that is commented out. + /// + /// The comment character. + public CommentAttribute(char comment) + { + Comment = comment; + } + + /// + 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 +{ + /// + /// 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. + /// + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] + public class ConstantAttribute : Attribute, IMemberMapper, IParameterMapper + { + /// + /// Gets the constant. + /// + public object Constant { get; private set; } + + /// + /// 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. + /// + /// The constant. + public ConstantAttribute(object constant) + { + Constant = constant; + } + + /// + public void ApplyTo(MemberMap memberMap) + { + memberMap.Data.Constant = Constant; + memberMap.Data.IsConstantSet = true; + } + + /// + 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 +{ + /// + /// 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 needs to be set correctly for this to be accurate. + /// + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] + public class CountBytesAttribute : Attribute, IClassMapper + { + /// + /// 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 needs to be set correctly for this to be accurate. + /// + public bool CountBytes { get; private set; } + + /// + /// 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 needs to be set correctly for this to be accurate. + /// + /// + public CountBytesAttribute(bool countBytes) + { + CountBytes = countBytes; + } + + /// + 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 +{ + /// + /// The used when type converting. + /// This will override the global + /// setting. Or set the same if the attribute is specified on class level. + /// + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] + public class CultureInfoAttribute : Attribute, IMemberMapper, IParameterMapper + { + /// + /// Gets the culture info. + /// + public CultureInfo CultureInfo { get; private set; } + + /// + /// The used when type converting. + /// This will override the global + /// setting. Or set the same if the attribute is specified on class level. + /// + /// The culture. + public CultureInfoAttribute(string culture) + { + CultureInfo = CultureInfo.GetCultureInfo(culture); + } + + /// + public void ApplyTo(MemberMap memberMap) + { + memberMap.Data.TypeConverterOptions.CultureInfo = CultureInfo; + } + + /// + 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 +{ + /// + /// The to use when type converting. + /// This is used when doing any conversions. + /// + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] + public class DateTimeStylesAttribute : Attribute, IMemberMapper, IParameterMapper + { + /// + /// Gets the date time styles. + /// + public DateTimeStyles DateTimeStyles { get; private set; } + + /// + /// The to use when type converting. + /// This is used when doing any conversions. + /// + /// The date time styles. + public DateTimeStylesAttribute(DateTimeStyles dateTimeStyles) + { + DateTimeStyles = dateTimeStyles; + } + + /// + public void ApplyTo(MemberMap memberMap) + { + memberMap.Data.TypeConverterOptions.DateTimeStyle = DateTimeStyles; + } + + /// + 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 +{ + /// + /// The default value that will be used when reading when + /// the CSV field is empty. + /// + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] + public class DefaultAttribute : Attribute, IMemberMapper, IParameterMapper + { + /// + /// Gets the default value. + /// + public object Default { get; private set; } + + /// + /// The default value that will be used when reading when + /// the CSV field is empty. + /// + /// The default value + public DefaultAttribute(object defaultValue) + { + Default = defaultValue; + } + + /// + public void ApplyTo(MemberMap memberMap) + { + memberMap.Data.Default = Default; + memberMap.Data.IsDefaultSet = true; + } + + /// + 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 +{ + /// + /// The delimiter used to separate fields. + /// + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] + public class DelimiterAttribute : Attribute, IClassMapper + { + /// + /// Gets the delimiter. + /// + public string Delimiter { get; private set; } + + /// + /// The delimiter used to separate fields. + /// + /// The delimiter. + public DelimiterAttribute(string delimiter) + { + Delimiter = delimiter; + } + + /// + 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 +{ + /// + /// A value indicating whether changes in the column + /// count should be detected. If true, a + /// will be thrown if a different column count is detected. + /// + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] + public class DetectColumnCountChangesAttribute : Attribute, IClassMapper + { + /// + /// A value indicating whether changes in the column + /// count should be detected. If true, a + /// will be thrown if a different column count is detected. + /// + public bool DetectColumnCountChanges { get; private set; } + + /// + /// A value indicating whether changes in the column + /// count should be detected. If true, a + /// will be thrown if a different column count is detected. + /// + public DetectColumnCountChangesAttribute(bool detectColumnCountChanges) + { + DetectColumnCountChanges = detectColumnCountChanges; + } + + /// + 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 +{ + /// + /// Detect the delimiter instead of using the delimiter from configuration. + /// Default is false. + /// + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] + public class DetectDelimiterAttribute : Attribute, IClassMapper + { + /// + /// Detect the delimiter instead of using the delimiter from configuration. + /// + public bool DetectDelimiter { get; private set; } + + /// + /// Detect the delimiter instead of using the delimiter from configuration. + /// + public DetectDelimiterAttribute(bool detectDelimiter) + { + DetectDelimiter = detectDelimiter; + } + + /// + 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 +{ + /// + /// The possible delimiter values used when detecting the delimiter. + /// Default is [",", ";", "|", "\t"]. + /// + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] + public class DetectDelimiterValuesAttribute : Attribute, IClassMapper + { + /// + /// The possible delimiter values used when detecting the delimiter. + /// + public string[] DetectDelimiterValues { get; private set; } + + /// + /// The possible delimiter values used when detecting the delimiter. + /// + /// Whitespace separated list of values. + public DetectDelimiterValuesAttribute(string detectDelimiterValues) + { + DetectDelimiterValues = Regex.Split(detectDelimiterValues, @"\s+"); + } + + /// + 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 +{ + /// + /// The encoding used when counting bytes. + /// + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] + public class EncodingAttribute : Attribute, IClassMapper + { + /// + /// Gets the encoding used when counting bytes. + /// + public Encoding Encoding { get; private set; } + + /// + /// The encoding used when counting bytes. + /// + /// The encoding. + public EncodingAttribute(string encoding) + { + Encoding = Encoding.GetEncoding(encoding); + } + + /// + 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 +{ + /// + /// Ignore case when parsing enums. + /// + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] + public class EnumIgnoreCaseAttribute : Attribute, IMemberMapper, IMemberReferenceMapper, IParameterMapper + { + /// + public void ApplyTo(MemberMap memberMap) + { + memberMap.Data.TypeConverterOptions.EnumIgnoreCase = true; + } + + /// + public void ApplyTo(MemberReferenceMap referenceMap) + { + foreach (var memberMap in referenceMap.Data.Mapping.MemberMaps) + { + ApplyTo(memberMap); + } + } + + /// + 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 +{ + /// + /// The escape character used to escape a quote inside a field. + /// + [AttributeUsage( AttributeTargets.Class, AllowMultiple = false, Inherited = true )] + public class EscapeAttribute : Attribute, IClassMapper + { + /// + /// Gets the escape character used to escape a quote inside a field. + /// + public char Escape { get; private set; } + + /// + /// The escape character used to escape a quote inside a field. + /// + /// The escape character. + public EscapeAttribute( char escape ) + { + Escape = escape; + } + + /// + 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 +{ + /// + /// A value indicating if exception messages contain raw CSV data. + /// true if exception contain raw CSV data, otherwise false. + /// Default is true. + /// + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] + public class ExceptionMessagesContainRawDataAttribute : Attribute, IClassMapper + { + /// + /// A value indicating if exception messages contain raw CSV data. + /// true if exception contain raw CSV data, otherwise false. + /// + public bool ExceptionMessagesContainRawData { get; private set; } + + /// + /// A value indicating if exception messages contain raw CSV data. + /// true if exception contain raw CSV data, otherwise false. + /// + /// + public ExceptionMessagesContainRawDataAttribute(bool exceptionMessagesContainRawData) + { + ExceptionMessagesContainRawData = exceptionMessagesContainRawData; + } + + /// + 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 +{ + /// + /// The string format to be used when type converting. + /// + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] + public class FormatAttribute : Attribute, IMemberMapper, IParameterMapper + { + /// + /// Gets the formats. + /// + public string[] Formats { get; private set; } + + /// + /// The string format to be used when type converting. + /// + /// The format. + public FormatAttribute(string format) + { + Formats = new string[] { format }; + } + + /// + /// The string format to be used when type converting. + /// + /// The formats. + public FormatAttribute(params string[] formats) + { + Formats = formats; + } + + /// + public void ApplyTo(MemberMap memberMap) + { + memberMap.Data.TypeConverterOptions.Formats = Formats; + } + + /// + 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 +{ + /// + /// A value indicating if the CSV file has a header record. + /// + [AttributeUsage( AttributeTargets.Class, AllowMultiple = false, Inherited = true )] + public class HasHeaderRecordAttribute : Attribute, IClassMapper + { + /// + /// Gets a value indicating if the CSV file has a header record. + /// + public bool HasHeaderRecord { get; private set; } + + /// + /// A value indicating if the CSV file has a header record. + /// + /// A value indicating if the CSV file has a header record. + public HasHeaderRecordAttribute( bool hasHeaderRecord ) + { + HasHeaderRecord = hasHeaderRecord; + } + + /// + 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 +{ + /// + /// Appends a prefix to the header of each field of the reference member. + /// + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] + public class HeaderPrefixAttribute : Attribute, IMemberReferenceMapper, IParameterReferenceMapper + { + /// + /// Gets the prefix. + /// + public string? Prefix { get; private set; } + + /// + /// Gets a value indicating if the prefix should inherit parent prefixes. + /// + public bool Inherit { get; private set; } + + /// + /// Appends a prefix to the header of each field of the reference member. + /// + public HeaderPrefixAttribute() { } + + /// + /// Appends a prefix to the header of each field of the reference member. + /// + /// The prefix. + public HeaderPrefixAttribute(string prefix) + { + Prefix = prefix; + } + + /// + /// Appends a prefix to the header of each field of the reference member. + /// + /// Inherits parent object prefixes. + public HeaderPrefixAttribute(bool inherit) + { + Inherit = inherit; + } + + /// + /// Appends a prefix to the header of each field of the reference member. + /// + /// The prefix. + /// Inherits parent object prefixes. + public HeaderPrefixAttribute(string prefix, bool inherit) + { + Prefix = prefix; + Inherit = inherit; + } + + /// + public void ApplyTo(MemberReferenceMap referenceMap) + { + referenceMap.Data.Inherit = Inherit; + referenceMap.Data.Prefix = Prefix ?? referenceMap.Data.Member.Name + "."; + } + + /// + 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 +{ + /// + /// Defines methods to enable pluggable configuration. + /// + public interface IClassMapper + { + /// + /// Applies configuration. + /// + /// The configuration to apply to. + 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 +{ + /// + /// Defines methods to enable pluggable configuration of member mapping. + /// + public interface IMemberMapper + { + /// + /// Applies configuration to the given . + /// + /// The member map. + 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 +{ + /// + /// Defines methods to enable pluggable configuration of member reference mapping. + /// + public interface IMemberReferenceMapper + { + /// + /// Applies configuration to the given . + /// + /// The reference map. + 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 +{ + /// + /// Defines methods to enable pluggable configuration of parameter mapping. + /// + public interface IParameterMapper + { + /// + /// Applies configuration to the given . + /// + /// The parameter map. + 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 +{ + /// + /// Defines methods to enable pluggable configuration of parameter reference mapping. + /// + public interface IParameterReferenceMapper + { + /// + /// Applies configuration to the given . + /// + /// The reference map. + 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 +{ + /// + /// 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. + /// + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] + public class IgnoreAttribute : Attribute, IMemberMapper, IMemberReferenceMapper, IParameterMapper + { + /// + public void ApplyTo(MemberMap memberMap) + { + memberMap.Data.Ignore = true; + } + + /// + public void ApplyTo(MemberReferenceMap referenceMap) + { + foreach (var memberMap in referenceMap.Data.Mapping.MemberMaps) + { + ApplyTo(memberMap); + } + } + + /// + 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 +{ + /// + /// Ignores base classes when auto mapping. + /// + [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 +{ + /// + /// A value indicating if blank lines should be ignored when reading. + /// + [AttributeUsage( AttributeTargets.Class, AllowMultiple = false, Inherited = true )] + public class IgnoreBlankLinesAttribute : Attribute, IClassMapper + { + /// + /// Gets a value indicating if blank lines should be ignored when reading. + /// + public bool IgnoreBlankLines { get; private set; } + + /// + /// A value indicating if blank lines should be ignored when reading. + /// + /// The Ignore Blank Lines Flag. + public IgnoreBlankLinesAttribute( bool ignoreBlankLines ) + { + IgnoreBlankLines = ignoreBlankLines; + } + + /// + 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 +{ + /// + /// Gets a value indicating whether references + /// should be ignored when auto mapping. true to ignore + /// references, otherwise false. Default is false. + /// + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] + public class IgnoreReferencesAttribute : Attribute, IClassMapper + { + /// + /// Gets a value indicating whether references + /// should be ignored when auto mapping. true to ignore + /// references, otherwise false. Default is false. + /// + public bool IgnoreReferences { get; private set; } + + /// + /// Gets a value indicating whether references + /// should be ignored when auto mapping. true to ignore + /// references, otherwise false. Default is false. + /// + /// Ignore references value. + public IgnoreReferencesAttribute(bool ignoreReferences) + { + IgnoreReferences = ignoreReferences; + } + + /// + 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 +{ + /// + /// A value indicating if private member should be read from and written to. + /// + [AttributeUsage( AttributeTargets.Class, AllowMultiple = false, Inherited = true )] + public class IncludePrivateMembersAttribute : Attribute, IClassMapper + { + /// + /// Gets a value indicating if private member should be read from and written to. + /// + public bool IncludePrivateMembers { get; private set; } + + /// + /// A value indicating if private member should be read from and written to. + /// + /// The Include Private Members Flag. + public IncludePrivateMembersAttribute( bool includePrivateMembers ) + { + IncludePrivateMembers = includePrivateMembers; + } + + /// + 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 +{ + /// + /// 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. + /// + [AttributeUsage( AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true )] + public class IndexAttribute : Attribute, IMemberMapper, IParameterMapper + { + /// + /// Gets the index. + /// + public int Index { get; private set; } + + /// + /// Gets the index end. + /// + public int IndexEnd { get; private set; } + + /// + /// 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. + /// + /// The index. + /// The index end. + public IndexAttribute( int index, int indexEnd = -1 ) + { + Index = index; + IndexEnd = indexEnd; + } + + /// + public void ApplyTo(MemberMap memberMap) + { + memberMap.Data.Index = Index; + memberMap.Data.IndexEnd = IndexEnd; + memberMap.Data.IsIndexSet = true; + } + + /// + 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 +{ + /// + /// Gets the characters that are used for injection attacks. + /// + public class InjectionCharactersAttribute : Attribute, IClassMapper + { + /// + /// Gets the characters that are used for injection attacks. + /// Default is '=', '@', '+', '-', '\t', '\r'. + /// + public char[] InjectionCharacters { get; private set; } + + /// + /// Gets the characters that are used for injection attacks. + /// + /// + public InjectionCharactersAttribute(string injectionCharacters) + { + InjectionCharacters = Regex.Split(injectionCharacters, @"\s+").Select(s => s[0]).ToArray(); + } + + /// + 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 +{ + /// + /// The character used to escape a detected injection. + /// + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] + public class InjectionEscapeCharacterAttribute : Attribute, IClassMapper + { + /// + /// The character used to escape a detected injection. + /// + public char InjectionEscapeCharacter { get; private set; } + + /// + /// The character used to escape a detected injection. + /// + /// + public InjectionEscapeCharacterAttribute(char injectionEscapeCharacter) + { + InjectionEscapeCharacter = injectionEscapeCharacter; + } + + /// + 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 +{ + /// + /// The injection options. + /// + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] + public class InjectionOptionsAttribute : Attribute, IClassMapper + { + /// + /// The injection options. + /// + public InjectionOptions InjectionOptions { get; private set; } + + /// + /// The injection options. + /// + /// + public InjectionOptionsAttribute(InjectionOptions injectionOptions) + { + InjectionOptions = injectionOptions; + } + + /// + 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 +{ + /// + /// A value indicating if a line break found in a quote field should + /// be considered bad data. true to consider a line break bad data, otherwise false. + /// Defaults to false. + /// + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] + public class LineBreakInQuotedFieldIsBadDataAttribute : Attribute, IClassMapper + { + /// + /// A value indicating if a line break found in a quote field should + /// be considered bad data. true to consider a line break bad data, otherwise false. + /// + public bool LineBreakInQuotedFieldIsBadData { get; private set; } + + /// + /// A value indicating if a line break found in a quote field should + /// be considered bad data. true to consider a line break bad data, otherwise false. + /// + /// + public LineBreakInQuotedFieldIsBadDataAttribute(bool lineBreakInQuotedFieldIsBadData) + { + LineBreakInQuotedFieldIsBadData = lineBreakInQuotedFieldIsBadData; + } + + /// + 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 +{ + /// + /// Gets or sets the maximum size of a field. + /// Defaults to 0, indicating maximum field size is not checked. + /// + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] + public class MaxFieldSizeAttribute : Attribute, IClassMapper + { + /// + /// Gets or sets the maximum size of a field. + /// + public double MaxFieldSize { get; private set; } + + /// + /// Gets or sets the maximum size of a field. + /// + /// + public MaxFieldSizeAttribute(double maxFieldSize) + { + MaxFieldSize = maxFieldSize; + } + + /// + 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 +{ + /// + /// The member types that are used when auto mapping. + /// MemberTypes are flags, so you can choose more than one. + /// Default is Properties. + /// + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] + public class MemberTypesAttribute : Attribute, IClassMapper + { + /// + /// The member types that are used when auto mapping. + /// MemberTypes are flags, so you can choose more than one. + /// Default is Properties. + /// + public MemberTypes MemberTypes { get; private set; } + + /// + /// The member types that are used when auto mapping. + /// MemberTypes are flags, so you can choose more than one. + /// Default is Properties. + /// + public MemberTypesAttribute(MemberTypes memberTypes) + { + MemberTypes = memberTypes; + } + + /// + 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 +{ + /// + /// The mode. + /// See for more details. + /// + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] + public class ModeAttribute : Attribute, IClassMapper + { + /// + /// The mode. + /// See for more details. + /// + public CsvMode Mode { get; private set; } + + /// + /// The mode. + /// See for more details. + /// + /// + public ModeAttribute(CsvMode mode) + { + Mode = mode; + } + + /// + 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 +{ + /// + /// 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. + /// + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] + public class NameAttribute : Attribute, IMemberMapper, IParameterMapper + { + /// + /// Gets the names. + /// + public string[] Names { get; private set; } + + /// + /// 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. + /// + /// The name + public NameAttribute(string name) + { + Names = new string[] { name }; + } + + /// + /// 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. + /// + /// The names. + public NameAttribute(params string[] names) + { + if (names == null || names.Length == 0) + { + throw new ArgumentNullException(nameof(names)); + } + + Names = names; + } + + /// + public void ApplyTo(MemberMap memberMap) + { + memberMap.Data.Names.Clear(); + memberMap.Data.Names.AddRange(Names); + memberMap.Data.IsNameSet = true; + } + + /// + 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 +{ + /// + /// When reading, is used to get the + /// index of the name used when there + /// are multiple names that are the same. + /// + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] + public class NameIndexAttribute : Attribute, IMemberMapper, IParameterMapper + { + /// + /// The name index. + /// + public int NameIndex { get; private set; } + + /// + /// When reading, is used to get the + /// index of the name used when there + /// are multiple names that are the same. + /// + /// The name index. + public NameIndexAttribute(int nameIndex) + { + NameIndex = nameIndex; + } + + /// + public void ApplyTo(MemberMap memberMap) + { + memberMap.Data.NameIndex = NameIndex; + } + + /// + 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 +{ + /// + /// 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. + /// + [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; + } + + /// + 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 +{ + /// + /// The string values used to represent null when converting. + /// + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] + public class NullValuesAttribute : Attribute, IMemberMapper, IParameterMapper + { + /// + /// Gets the null values. + /// + public string[] NullValues { get; private set; } + + /// + /// The string values used to represent null when converting. + /// + /// The null values. + public NullValuesAttribute(string nullValue) + { + NullValues = new string[] { nullValue }; + } + + /// + /// The string values used to represent null when converting. + /// + /// The null values. + public NullValuesAttribute(params string[] nullValues) + { + NullValues = nullValues; + } + + /// + public void ApplyTo(MemberMap memberMap) + { + memberMap.Data.TypeConverterOptions.NullValues.Clear(); + memberMap.Data.TypeConverterOptions.NullValues.AddRange(NullValues); + } + + /// + 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 +{ + /// + /// The to use when type converting. + /// This is used when doing any number conversions. + /// + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] + public class NumberStylesAttribute : Attribute, IMemberMapper, IParameterMapper + { + /// + /// Gets the number styles. + /// + public NumberStyles NumberStyles { get; private set; } + + /// + /// The to use when type converting. + /// This is used when doing any number conversions. + /// + /// The number styles. + public NumberStylesAttribute(NumberStyles numberStyles) + { + NumberStyles = numberStyles; + } + + /// + public void ApplyTo(MemberMap memberMap) + { + memberMap.Data.TypeConverterOptions.NumberStyles = NumberStyles; + } + + /// + 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 +{ + /// + /// Ignore the member when reading if no matching field name can be found. + /// + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] + public class OptionalAttribute : Attribute, IMemberMapper, IParameterMapper + { + /// + public void ApplyTo(MemberMap memberMap) + { + memberMap.Data.IsOptional = true; + } + + /// + 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 +{ + /// + /// The size of the buffer used when processing fields. + /// Default is 1024. + /// + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] + public class ProcessFieldBufferSizeAttribute : Attribute, IClassMapper + { + /// + /// The size of the buffer used when processing fields. + /// + public int ProcessFieldBufferSize { get; private set; } + + /// + /// The size of the buffer used when processing fields. + /// + /// + public ProcessFieldBufferSizeAttribute(int processFieldBufferSize) + { + ProcessFieldBufferSize = processFieldBufferSize; + } + + /// + 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 +{ + /// + /// The character used to quote fields. + /// + [AttributeUsage( AttributeTargets.Class, AllowMultiple = false, Inherited = true )] + public class QuoteAttribute : Attribute, IClassMapper + { + /// + /// Gets the character used to quote fields. + /// + public char Quote { get; private set; } + + /// + /// The character used to quote fields. + /// + /// The quote character. + public QuoteAttribute( char quote ) + { + Quote = quote; + } + + /// + 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 +{ + /// + /// The fields trimming options. + /// + [AttributeUsage( AttributeTargets.Class, AllowMultiple = false, Inherited = true )] + public class TrimOptionsAttribute : Attribute, IClassMapper + { + /// + /// Gets the fields trimming options. + /// + public TrimOptions TrimOptions { get; private set; } + + /// + /// The fields trimming options. + /// + /// The TrimOptions. + public TrimOptionsAttribute( TrimOptions trimOptions ) + { + TrimOptions = trimOptions; + } + + /// + 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 +{ + /// + /// Specifies the to use + /// when converting the member to and from a CSV field. + /// + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)] + public class TypeConverterAttribute : Attribute, IMemberMapper, IParameterMapper + { + /// + /// Gets the type converter. + /// + public ITypeConverter TypeConverter { get; private set; } + + /// + /// Specifies the to use + /// when converting the member to and from a CSV field. + /// + /// The type of the . + public TypeConverterAttribute(Type typeConverterType) : this(typeConverterType, new object[0]) { } + + /// + /// Specifies the to use + /// when converting the member to and from a CSV field. + /// + /// The type of the . + /// Type constructor arguments for the type converter. + 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)}"); + } + + /// + public void ApplyTo(MemberMap memberMap) + { + memberMap.Data.TypeConverter = TypeConverter; + } + + /// + 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 +{ + /// + /// 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. + /// + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] + public class UseNewObjectForNullReferenceMembersAttribute : Attribute, IClassMapper + { + /// + /// 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. + /// + public bool UseNewObjectForNullReferenceMembers { get; private set; } + + /// + /// 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. + /// + /// The value. + public UseNewObjectForNullReferenceMembersAttribute(bool useNewObjectForNullReferenceMembers) + { + UseNewObjectForNullReferenceMembers = useNewObjectForNullReferenceMembers; + } + + /// + 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 +{ + /// + /// Characters considered whitespace. + /// Used when trimming fields. + /// Default is [' ']. + /// + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] + public class WhiteSpaceCharsAttribute : Attribute, IClassMapper + { + /// + /// Characters considered whitespace. + /// Used when trimming fields. + /// + public char[] WhiteSpaceChars { get; private set; } + + /// + /// Characters considered whitespace. + /// Used when trimming fields. + /// + /// + public WhiteSpaceCharsAttribute(string whiteSpaceChars) + { + WhiteSpaceChars = Regex.Split(whiteSpaceChars, @"\s").Select(s => s[0]).ToArray(); + } + + /// + 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 +{ + /// + /// Maps class members to CSV fields. + /// + public abstract class ClassMap + { + private static readonly List enumerableConverters = new List + { + typeof(ArrayConverter), + typeof(CollectionGenericConverter), + typeof(EnumerableConverter), + typeof(IDictionaryConverter), + typeof(IDictionaryGenericConverter), + typeof(IEnumerableConverter), + typeof(IEnumerableGenericConverter) + }; + + /// + /// The type of the class this map is for. + /// + public virtual Type ClassType { get; private set; } + + /// + /// The class constructor parameter mappings. + /// + public virtual List ParameterMaps { get; } = new List(); + + /// + /// The class member mappings. + /// + public virtual MemberMapCollection MemberMaps { get; } = new MemberMapCollection(); + + /// + /// The class member reference mappings. + /// + public virtual MemberReferenceMapCollection ReferenceMaps { get; } = new MemberReferenceMapCollection(); + + /// + /// Allow only internal creation of CsvClassMap. + /// + /// The type of the class this map is for. + internal ClassMap(Type classType) + { + ClassType = classType; + } + + /// + /// Maps a member to a CSV field. + /// + /// 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. + /// The member to map. + /// If true, an existing map will be used if available. + /// If false, a new map is created for the same member. + /// The member mapping. + 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; + } + + /// + /// Maps a non-member to a CSV field. This allows for writing + /// data that isn't mapped to a class member. + /// + /// The member mapping. + public virtual MemberMap Map() + { + var memberMap = new MemberMap(null); + memberMap.Data.Index = GetMaxIndex() + 1; + MemberMaps.Add(memberMap); + + return memberMap; + } + + /// + /// Maps a member to another class map. + /// + /// The type of the class map. + /// The member. + /// Constructor arguments used to create the reference map. + /// The reference mapping for the member. + 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; + } + + /// + /// Maps a constructor parameter to a CSV field. + /// + /// The name of the constructor parameter. + 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); + } + + /// + /// Maps a constructor parameter to a CSV field. + /// + /// A function that returns the for the constructor. + /// The name of the constructor parameter. + public virtual ParameterMap Parameter(Func 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); + } + + /// + /// Maps a constructor parameter to a CSV field. + /// + /// The for the constructor. + /// The for the constructor parameter. + 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; + } + + /// + /// Auto maps all members for the given type. If a member + /// is mapped again it will override the existing map. + /// + /// The culture. + public virtual void AutoMap(CultureInfo culture) + { + AutoMap(new CsvConfiguration(culture)); + } + + /// + /// Auto maps all members for the given type. If a member + /// is mapped again it will override the existing map. + /// + /// The configuration. + public virtual void AutoMap(CsvConfiguration configuration) + { + AutoMap(new CsvContext(configuration)); + } + + /// + /// Auto maps all members for the given type. If a member + /// is mapped again it will override the existing map. + /// + /// The context. + 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(); + 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); + } + + /// + /// Get the largest index for the + /// members and references. + /// + /// The max index. + 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(); + 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(); + } + + /// + /// Resets the indexes based on the given start index. + /// + /// The index start. + /// The last index + 1. + 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; + } + + /// + /// Auto maps the given map and checks for circular references as it goes. + /// + /// The map to auto map. + /// The context. + /// The list of parents for the map. + /// The index starting point. + protected virtual void AutoMapMembers(ClassMap map, CsvContext context, LinkedList 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(); + 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(); + 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(); + 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() != 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); + } + + /// + /// Auto maps the given map using constructor parameters. + /// + /// The map. + /// The context. + /// The list of parents for the map. + /// The index starting point. + protected virtual void AutoMapConstructorParameters(ClassMap map, CsvContext context, LinkedList 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(true).Any() || parameter.GetCustomAttributes(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); + } + + /// + /// Checks for circular references. + /// + /// The type to check for. + /// The list of parents to check against. + /// A value indicating if a circular reference was found. + /// True if a circular reference was found, otherwise false. + protected virtual bool CheckForCircularReference(Type type, LinkedList 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; + } + + /// + /// Gets the generic type for this class map. + /// + protected virtual Type GetGenericType() + { + return GetType().GetTypeInfo().BaseType?.GetGenericArguments()[0] ?? throw new ConfigurationException(); + } + + /// + /// Applies attribute configurations to the map. + /// + /// The parameter map. + protected virtual void ApplyAttributes(ParameterMap parameterMap) + { + var parameter = parameterMap.Data.Parameter; + var attributes = parameter.GetCustomAttributes().OfType(); + + foreach (var attribute in attributes) + { + attribute.ApplyTo(parameterMap); + } + } + + /// + /// Applies attribute configurations to the map. + /// + /// The parameter reference map. + protected virtual void ApplyAttributes(ParameterReferenceMap referenceMap) + { + var parameter = referenceMap.Data.Parameter; + var attributes = parameter.GetCustomAttributes().OfType(); + + foreach (var attribute in attributes) + { + attribute.ApplyTo(referenceMap); + } + } + + /// + /// Applies attribute configurations to the map. + /// + /// The member map. + protected virtual void ApplyAttributes(MemberMap memberMap) + { + if (memberMap.Data.Member == null) + { + return; + } + + var member = memberMap.Data.Member; + var attributes = member.GetCustomAttributes().OfType(); + + foreach (var attribute in attributes) + { + attribute.ApplyTo(memberMap); + } + } + + /// + /// Applies attribute configurations to the map. + /// + /// The member reference map. + protected virtual void ApplyAttributes(MemberReferenceMap referenceMap) + { + var member = referenceMap.Data.Member; + var attributes = member.GetCustomAttributes().OfType(); + + 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 +{ + /// + /// Has mapping capabilities. + /// + /// The class type. + public interface IHasMap : IBuildableClass + { + /// + /// Maps a member to a CSV field. + /// + /// The member to map. + /// If true, an existing map will be used if available. + /// If false, a new map is created for the same member. + /// The member mapping. + IHasMapOptions Map(Expression> expression, bool useExistingMap = true); + } + + /// + /// Options after a mapping call. + /// + /// The class type. + /// The member type. + public interface IHasMapOptions : + IHasMap, + IHasTypeConverter, + IHasIndex, + IHasName, + IHasOptional, + IHasConvertUsing, + IHasDefault, + IHasConstant, + IHasValidate + { } + + /// + /// Has type converter capabilities. + /// + /// The class type. + /// The member type. + public interface IHasTypeConverter : IBuildableClass + { + /// + /// Specifies the to use + /// when converting the member to and from a CSV field. + /// + /// The TypeConverter to use. + IHasTypeConverterOptions TypeConverter(ITypeConverter typeConverter); + + /// + /// Specifies the to use + /// when converting the member to and from a CSV field. + /// + /// The of the + /// to use. + IHasTypeConverterOptions TypeConverter() where TConverter : ITypeConverter; + } + + /// + /// Options after a type converter call. + /// + /// The class type. + /// The member type. + public interface IHasTypeConverterOptions : + IHasMap, + IHasDefault, + IHasValidate + { } + + /// + /// Has index capabilities. + /// + /// The class type. + /// The member type. + public interface IHasIndex : IBuildableClass + { + /// + /// 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. + /// + /// The index of the CSV field. + /// The end index used when mapping to an member. + IHasIndexOptions Index(int index, int indexEnd = -1); + } + + /// + /// Options after an index call. + /// + /// The class type. + /// The member type. + public interface IHasIndexOptions : + IHasMap, + IHasTypeConverter, + IHasName, + IHasDefault, + IHasValidate + { } + + /// + /// Has optional capabilities. + /// + /// The class type. + /// The member type. + public interface IHasOptional : IBuildableClass + { + /// + /// Ignore the member when reading if no matching field name can be found. + /// + IHasOptionalOptions Optional(); + } + + /// + /// Options after an optional call. + /// + /// The class type. + /// The member type. + public interface IHasOptionalOptions : + IHasMap, + IHasTypeConverter, + IHasName, + IHasDefault, + IHasValidate + { } + + /// + /// Has name capabilities. + /// + /// The class type. + /// The member type. + public interface IHasName : IBuildableClass + { + /// + /// 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. + /// + /// The possible names of the CSV field. + IHasNameOptions Name(params string[] names); + } + + /// + /// Options after a name call. + /// + /// The class type. + /// The member type. + public interface IHasNameOptions : + IHasMap, + IHasTypeConverter, + IHasNameIndex, + IHasDefault, + IHasValidate + { } + + /// + /// Has name index capabilities. + /// + /// The class type. + /// The member type. + public interface IHasNameIndex : IBuildableClass + { + /// + /// When reading, is used to get the + /// index of the name used when there + /// are multiple names that are the same. + /// + /// The index of the name. + IHasNameIndexOptions NameIndex(int index); + } + + /// + /// Options after a name index call. + /// + /// The class type. + /// The member type. + public interface IHasNameIndexOptions : + IHasMap, + IHasTypeConverter, + IHasDefault, + IHasValidate + { } + + /// + /// Has convert using capabilities. + /// + /// The class type. + /// The member type. + public interface IHasConvertUsing : IBuildableClass + { + /// + /// Specifies an expression to be used to convert data in the + /// row to the member. + /// + /// The convert expression. + IHasMap ConvertUsing(ConvertFromString convertExpression); + + /// + /// Specifies an expression to be used to convert the object + /// to a field. + /// + /// The convert expression. + IHasMap ConvertUsing(ConvertToString convertExpression); + } + + /// + /// Has default capabilities. + /// + /// The class type. + /// The member type. + public interface IHasDefault : IBuildableClass + { + /// + /// The default value that will be used when reading when + /// the CSV field is empty. + /// + /// The default value. + IHasDefaultOptions Default(TMember defaultValue); + + /// + /// 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 to convert + /// the field. This could potentially have runtime errors. + /// + /// The default value. + IHasDefaultOptions Default(string defaultValue); + } + + /// + /// Options after a default call. + /// + /// The class type. + /// The member type. + public interface IHasDefaultOptions : + IHasMap, + IHasValidate + { } + + /// + /// Has constant capabilities. + /// + /// The class type. + /// The member type. + public interface IHasConstant : IBuildableClass + { + /// + /// 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. + /// + /// The constant value. + IHasMap Constant(TMember value); + } + + /// + /// Has validate capabilities. + /// + /// The class type. + /// The member type. + public interface IHasValidate : IBuildableClass + { + /// + /// 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 + /// will be thrown. + /// + /// The validation expression. + IHasMap Validate(Validate validateExpression); + } + + /// + /// Has build capabilities. + /// + /// The class type. + public interface IBuildableClass + { + /// + /// Builds the . + /// + ClassMap Build(); + } + + internal class ClassMapBuilder : IHasMap + { + private readonly ClassMap map; + + public ClassMapBuilder() + { + map = new BuilderClassMap(); + } + + public IHasMapOptions Map(Expression> expression, bool useExistingMap = true) + { + return new MemberMapBuilder(map, map.Map(expression, useExistingMap)); + } + + public ClassMap Build() + { + return map; + } + + private class BuilderClassMap : ClassMap { } + } + + internal class MemberMapBuilder : + IHasMap, + IHasMapOptions, + IHasTypeConverter, + IHasTypeConverterOptions, + IHasIndex, + IHasIndexOptions, + IHasName, + IHasNameOptions, + IHasNameIndex, + IHasNameIndexOptions, + IHasOptional, + IHasOptionalOptions, + IHasConvertUsing, + IHasDefault, + IHasDefaultOptions, + IHasConstant, + IHasValidate + { + private readonly ClassMap classMap; + private readonly MemberMap memberMap; + + public MemberMapBuilder(ClassMap classMap, MemberMap 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 Map(Expression> expression, bool useExistingMap = true) + { + return new MemberMapBuilder(classMap, classMap.Map(expression, useExistingMap)); + } +#pragma warning restore CS0693 // Type parameter has the same name as the type parameter from outer type + + public IHasMap ConvertUsing(ConvertFromString convertExpression) + { + memberMap.Convert(convertExpression); + return this; + } + + public IHasMap ConvertUsing(ConvertToString convertExpression) + { + memberMap.Convert(convertExpression); + return this; + } + + public IHasDefaultOptions Default(TMember defaultValue) + { + memberMap.Default(defaultValue); + return this; + } + + public IHasDefaultOptions Default(string defaultValue) + { + memberMap.Default(defaultValue); + return this; + } + + public IHasIndexOptions Index(int index, int indexEnd = -1) + { + memberMap.Index(index, indexEnd); + return this; + } + + public IHasNameOptions Name(params string[] names) + { + memberMap.Name(names); + return this; + } + + public IHasNameIndexOptions NameIndex(int index) + { + memberMap.NameIndex(index); + return this; + } + + public IHasOptionalOptions Optional() + { + memberMap.Optional(); + return this; + } + + public IHasTypeConverterOptions TypeConverter(ITypeConverter typeConverter) + { + memberMap.TypeConverter(typeConverter); + return this; + } + + public IHasTypeConverterOptions TypeConverter() where TConverter : ITypeConverter + { + memberMap.TypeConverter(); + return this; + } + + public IHasMap Constant(TMember value) + { + memberMap.Constant(value); + return this; + } + + public IHasMap Validate(Validate validateExpression) + { + memberMap.Validate(validateExpression); + return this; + } + + public ClassMap 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 +{ + /// + /// Collection that holds CsvClassMaps for record types. + /// + public class ClassMapCollection + { + private readonly Dictionary data = new Dictionary(); + private readonly CsvContext context; + + /// + /// Gets the for the specified record type. + /// + /// + /// The . + /// + /// The record type. + /// The for the specified record type. + 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; + } + } + } + } + + /// + /// Creates a new instance using the given configuration. + /// + /// The context. + public ClassMapCollection(CsvContext context) + { + this.context = context; + } + + /// + /// Finds the for the specified record type. + /// + /// The record type. + /// The for the specified record type. + public virtual ClassMap? Find() + { + return (ClassMap?)this[typeof(T)]; + } + + /// + /// Adds the specified map for it's record type. If a map + /// already exists for the record type, the specified + /// map will replace it. + /// + /// The map. + internal virtual void Add(ClassMap map) + { + SetMapDefaults(map); + + var type = GetGenericCsvClassMapType(map.GetType()).GetGenericArguments().First(); + + data[type] = map; + } + + /// + /// Removes the class map. + /// + /// The class map type. + 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); + } + + /// + /// Removes all maps. + /// + internal virtual void Clear() + { + data.Clear(); + } + + /// + /// Goes up the inheritance tree to find the type instance of CsvClassMap{}. + /// + /// The type to traverse. + /// The type that is CsvClassMap{}. + private Type GetGenericCsvClassMapType(Type type) + { + if (type.GetTypeInfo().IsGenericType && type.GetGenericTypeDefinition() == typeof(ClassMap<>)) + { + return type; + } + + return GetGenericCsvClassMapType(type.GetTypeInfo().BaseType); + } + + /// + /// 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. + /// + /// The map to set defaults on. + 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 +{ + /// + /// Maps class members to CSV fields. + /// + /// The of class to map. + public abstract class ClassMap : ClassMap + { + /// + /// Creates an instance of . + /// + public ClassMap() : base(typeof(TClass)) { } + + /// + /// Maps a member to a CSV field. + /// + /// The member to map. + /// If true, an existing map will be used if available. + /// If false, a new map is created for the same member. + /// The member mapping. + public virtual MemberMap Map(Expression> expression, bool useExistingMap = true) + { + var (classMap, member) = GetMemberMap(expression); + var memberMap = classMap.Map(typeof(TClass), member, useExistingMap); ; + + return (MemberMap)memberMap; + } + + /// + /// Maps a member to a CSV field. + /// + /// The member to map. + /// If true, an existing map will be used if available. + /// If false, a new map is created for the same member. + /// The member mapping. + public virtual MemberMap Map(Expression> expression, bool useExistingMap = true) + { + var (classMap, member) = GetMemberMap(expression); + var memberMap = classMap.Map(typeof(TClass), member, useExistingMap); + + return memberMap; + } + + /// + /// 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. + /// + /// The type of the class map. + /// The expression. + /// Constructor arguments used to create the reference map. + /// The reference mapping for the member. + public virtual MemberReferenceMap References(Expression> expression, params object[] constructorArgs) where TClassMap : ClassMap + { + var member = ReflectionHelper.GetMember(expression); + return References(typeof(TClassMap), member, constructorArgs); + } + + private (ClassMap, MemberInfo) GetMemberMap(Expression> 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 +{ + /// + /// Represents configuration errors that occur. + /// + [Serializable] + public class ConfigurationException : CsvHelperException + { + /// + /// Initializes a new instance of the class. + /// + public ConfigurationException() { } + + /// + /// Initializes a new instance of the class + /// with a specified error message. + /// + /// The message that describes the error. + public ConfigurationException( string message ) : base( message ) { } + + /// + /// Initializes a new instance of the class + /// with a specified error message and a reference to the inner exception that + /// is the cause of this exception. + /// + /// The error message that explains the reason for the exception. + /// The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner exception is specified. + 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 +{ + /// Holds the default callback methods for delegate members of CsvHelper.Configuration.Configuration. + public static class ConfigurationFunctions + { + private static readonly char[] lineEndingChars = new char[] { '\r', '\n' }; + + /// + /// Throws a if is not empty. + /// + 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()); + } + + /// + /// Throws a MissingFieldException. + /// + 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}"); + } + + /// + /// Throws a . + /// + 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."); + } + + /// + /// Throws the given . + /// + public static bool ReadingExceptionOccurred(ReadingExceptionOccurredArgs args) + { + return true; + } + + /// + /// Returns true if the field contains a , + /// starts with a space, ends with a space, contains \r or \n, or contains + /// the . + /// + /// The args. + /// true if the field should be quoted, otherwise false. + 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; + } + + /// + /// Returns the as given. + /// + public static string PrepareHeaderForMatch(PrepareHeaderForMatchArgs args) + { + return args.Header; + } + + /// + /// Returns true if : + /// 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. + /// + 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; + } + + /// + /// 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. + /// + public static ConstructorInfo GetConstructor(GetConstructorArgs args) + { + return args.ClassType.GetConstructorWithMostParameters(); + } + + /// + /// Returns the header name ran through . + /// If no header exists, property names will be Field1, Field2, Field3, etc. + /// + /// The args. + 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; + } + + /// + /// Detects the delimiter based on the given text. + /// Return the detected delimiter or null if one wasn't found. + /// + /// The args. + 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>(); + 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(); + 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 +{ + /// + /// Configuration used for reading and writing CSV data. + /// + public record CsvConfiguration : IReaderConfiguration, IWriterConfiguration + { + private string newLine = "\r\n"; + + /// + public virtual bool AllowComments { get; set; } + + /// + public virtual BadDataFound BadDataFound { get; set; } = ConfigurationFunctions.BadDataFound; + + /// + public virtual int BufferSize { get; set; } = 0x1000; + + /// + public virtual bool CacheFields { get; set; } + + /// + public virtual char Comment { get; set; } = '#'; + + /// + public virtual bool CountBytes { get; set; } + + /// + public virtual CultureInfo CultureInfo { get; protected set; } + + /// + public virtual string Delimiter { get; set; } + + /// + public virtual bool DetectDelimiter { get; set; } + + /// + public virtual GetDelimiter GetDelimiter { get; set; } = ConfigurationFunctions.GetDelimiter; + + /// + public virtual string[] DetectDelimiterValues { get; set; } = new[] { ",", ";", "|", "\t" }; + + /// + public virtual bool DetectColumnCountChanges { get; set; } + + /// + public virtual IComparer? DynamicPropertySort { get; set; } + + /// + public virtual Encoding Encoding { get; set; } = Encoding.UTF8; + + /// + public virtual char Escape { get; set; } = '"'; + + /// + public virtual bool ExceptionMessagesContainRawData { get; set; } = true; + + /// + public virtual GetConstructor GetConstructor { get; set; } = ConfigurationFunctions.GetConstructor; + + /// + public virtual GetDynamicPropertyName GetDynamicPropertyName { get; set; } = ConfigurationFunctions.GetDynamicPropertyName; + + /// + public virtual bool HasHeaderRecord { get; set; } = true; + + /// + public virtual HeaderValidated HeaderValidated { get; set; } = ConfigurationFunctions.HeaderValidated; + + /// + public virtual bool IgnoreBlankLines { get; set; } = true; + + /// + public virtual bool IgnoreReferences { get; set; } + + /// + public virtual bool IncludePrivateMembers { get; set; } + + /// + public virtual char[] InjectionCharacters { get; set; } = new[] { '=', '@', '+', '-', '\t', '\r' }; + + /// + public virtual char InjectionEscapeCharacter { get; set; } = '\''; + + /// + public virtual InjectionOptions InjectionOptions { get; set; } + + /// + public bool IsNewLineSet { get; private set; } + + /// + public virtual bool LineBreakInQuotedFieldIsBadData { get; set; } + + /// + public double MaxFieldSize { get; set; } + + /// + public virtual MemberTypes MemberTypes { get; set; } = MemberTypes.Properties; + + /// + public virtual MissingFieldFound MissingFieldFound { get; set; } = ConfigurationFunctions.MissingFieldFound; + + /// + public virtual CsvMode Mode { get; set; } + + /// + public virtual string NewLine + { + get => newLine; + set + { + IsNewLineSet = true; + newLine = value; + } + } + + /// + public virtual PrepareHeaderForMatch PrepareHeaderForMatch { get; set; } = ConfigurationFunctions.PrepareHeaderForMatch; + + /// + public virtual int ProcessFieldBufferSize { get; set; } = 1024; + + /// + public virtual char Quote { get; set; } = '"'; + + /// + public virtual ReadingExceptionOccurred ReadingExceptionOccurred { get; set; } = ConfigurationFunctions.ReadingExceptionOccurred; + + /// + public virtual ReferenceHeaderPrefix? ReferenceHeaderPrefix { get; set; } + + /// + public ShouldQuote ShouldQuote { get; set; } = ConfigurationFunctions.ShouldQuote; + + /// + public virtual ShouldSkipRecord? ShouldSkipRecord { get; set; } + + /// + public virtual ShouldUseConstructorParameters ShouldUseConstructorParameters { get; set; } = ConfigurationFunctions.ShouldUseConstructorParameters; + + /// + public virtual TrimOptions TrimOptions { get; set; } + + /// + public virtual bool UseNewObjectForNullReferenceMembers { get; set; } = true; + + /// + public virtual char[] WhiteSpaceChars { get; set; } = new char[] { ' ' }; + + /// + /// Initializes a new instance of the class + /// using the given . Since + /// uses for it's default, the given + /// will be used instead. + /// + /// The culture information. + /// The type that contains the configuration attributes. + /// This will call automatically. + public CsvConfiguration(CultureInfo cultureInfo, Type? attributesType = null) + { + CultureInfo = cultureInfo; + Delimiter = cultureInfo.TextInfo.ListSeparator; + + if (attributesType != null) + { + ApplyAttributes(attributesType); + } + } + + /// + /// Validates the configuration. + /// + 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."); + } + + /// + /// Applies class level attribute to configuration. + /// + /// Type with attributes. + public CsvConfiguration ApplyAttributes() + { + return ApplyAttributes(typeof(T)); + } + + /// + /// Applies class level attribute to configuration. + /// + /// Type with attributes. + public CsvConfiguration ApplyAttributes(Type type) + { + var attributes = type.GetCustomAttributes().OfType(); + 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 +{ + /// + /// A default that can be used + /// to create a class map dynamically. + /// + /// + public class DefaultClassMap : ClassMap + { + } +} 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 +{ + /// + /// Configuration used for the . + /// + public interface IParserConfiguration + { + /// + /// Gets the culture info used to read an write CSV files. + /// + CultureInfo CultureInfo { get; } + + /// + /// Cache fields that are created when parsing. + /// Default is false. + /// + bool CacheFields { get; } + + /// + /// 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. + /// + string NewLine { get; } + + /// + /// A value indicating if was set. + /// + /// + /// true if was set. false if is the default. + /// + bool IsNewLineSet { get; } + + /// + /// The mode. + /// See for more details. + /// + CsvMode Mode { get; } + + /// + /// Gets the size of the buffer + /// used for parsing and writing CSV files. + /// Default is 0x1000. + /// + int BufferSize { get; } + + /// + /// The size of the buffer used when processing fields. + /// Default is 1024. + /// + int ProcessFieldBufferSize { get; } + + /// + /// 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 needs to be set correctly for this to be accurate. + /// + bool CountBytes { get; } + + /// + /// Gets the encoding used when counting bytes. + /// + Encoding Encoding { get; } + + /// + /// 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. + /// + BadDataFound BadDataFound { get; } + + /// + /// Gets or sets the maximum size of a field. + /// Defaults to 0, indicating maximum field size is not checked. + /// + double MaxFieldSize { get; } + + /// + /// Gets a value indicating if a line break found in a quote field should + /// be considered bad data. true to consider a line break bad data, otherwise false. + /// Defaults to false. + /// + bool LineBreakInQuotedFieldIsBadData { get; } + + /// + /// Gets the character used to denote + /// a line that is commented out. Default is '#'. + /// + char Comment { get; } + + /// + /// Gets a value indicating if comments are allowed. + /// true to allow commented out lines, otherwise false. + /// + bool AllowComments { get; } + + /// + /// Gets a value indicating if blank lines + /// should be ignored when reading. + /// true to ignore, otherwise false. Default is true. + /// + bool IgnoreBlankLines { get; } + + /// + /// Gets the character used to quote fields. + /// Default is '"'. + /// + char Quote { get; } + + /// + /// The delimiter used to separate fields. + /// Default is . + /// + string Delimiter { get; } + + /// + /// Detect the delimiter instead of using the delimiter from configuration. + /// Default is false. + /// + bool DetectDelimiter { get; } + + /// + /// Gets the function that is called when is enabled. + /// + GetDelimiter GetDelimiter { get; } + + /// + /// The possible delimiter values used when detecting the delimiter. + /// Default is [",", ";", "|", "\t"]. + /// + string[] DetectDelimiterValues { get; } + + /// + /// The character used to escape characters. + /// Default is '"'. + /// + char Escape { get; } + + /// + /// Gets the field trimming options. + /// + TrimOptions TrimOptions { get; } + + /// + /// Characters considered whitespace. + /// Used when trimming fields. + /// Default is [' ']. + /// + char[] WhiteSpaceChars { get; } + + /// + /// A value indicating if exception messages contain raw CSV data. + /// true if exception contain raw CSV data, otherwise false. + /// Default is true. + /// + bool ExceptionMessagesContainRawData { get; } + + /// + /// Validates the configuration. + /// + 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 +{ + /// + /// Configuration used for the . + /// + public interface IReaderConfiguration : IParserConfiguration + { + /// + /// Gets a value indicating if the + /// CSV file has a header record. + /// Default is true. + /// + bool HasHeaderRecord { get; } + + /// + /// Gets the function that is called when a header validation check is ran. The default function + /// will throw a 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. + /// + HeaderValidated HeaderValidated { get; } + + /// + /// Gets the function that is called when a missing field is found. The default function will + /// throw a . You can supply your own function to do other things + /// like logging the issue instead of throwing an exception. + /// + MissingFieldFound MissingFieldFound { get; } + + /// + /// 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. + /// + ReadingExceptionOccurred ReadingExceptionOccurred { get; } + + /// + /// 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. + /// + PrepareHeaderForMatch PrepareHeaderForMatch { get; } + + /// + /// Determines if constructor parameters should be used to create + /// the class instead of the default constructor and members. + /// + ShouldUseConstructorParameters ShouldUseConstructorParameters { get; } + + /// + /// Chooses the constructor to use for constructor mapping. + /// + GetConstructor GetConstructor { get; } + + /// + /// Gets the name to use for the property of the dynamic object. + /// + GetDynamicPropertyName GetDynamicPropertyName { get; } + + /// + /// Gets a value indicating whether references + /// should be ignored when auto mapping. true to ignore + /// references, otherwise false. Default is false. + /// + bool IgnoreReferences { get; } + + /// + /// Gets the callback that will be called to + /// determine whether to skip the given record or not. + /// + ShouldSkipRecord? ShouldSkipRecord { get; } + + /// + /// Gets a value indicating if private + /// member should be read from and written to. + /// true to include private member, otherwise false. Default is false. + /// + bool IncludePrivateMembers { get; } + + /// + /// Gets a callback that will return the prefix for a reference header. + /// + ReferenceHeaderPrefix ReferenceHeaderPrefix { get; } + + /// + /// Gets a value indicating whether changes in the column + /// count should be detected. If true, a + /// will be thrown if a different column count is detected. + /// + bool DetectColumnCountChanges { get; } + + /// + /// Gets the member types that are used when auto mapping. + /// MemberTypes are flags, so you can choose more than one. + /// Default is Properties. + /// + 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 +{ + /// + /// Configuration used for the . + /// + public interface IWriterConfiguration + { + /// + /// Gets the size of the buffer + /// used for parsing and writing CSV files. + /// Default is 0x1000. + /// + int BufferSize { get; } + + /// + /// The mode. + /// See for more details. + /// + CsvMode Mode { get; } + + /// + /// Gets the delimiter used to separate fields. + /// Default is ','; + /// + string Delimiter { get; } + + /// + /// Gets the character used to quote fields. + /// Default is '"'. + /// + char Quote { get; } + + /// + /// The character used to escape characters. + /// Default is '"'. + /// + char Escape { get; } + + /// + /// Gets the field trimming options. + /// + TrimOptions TrimOptions { get; } + + /// + /// Gets the injection options. + /// + InjectionOptions InjectionOptions { get; } + + /// + /// Gets the characters that are used for injection attacks. + /// + char[] InjectionCharacters { get; } + + /// + /// Gets the character used to escape a detected injection. + /// + char InjectionEscapeCharacter { get; } + + /// + /// 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. + /// + string NewLine { get; } + + /// + /// A value indicating if was set. + /// + /// + /// true if was set. false if is the default. + /// + bool IsNewLineSet { get; } + + /// + /// Gets a function that is used to determine if a field should get quoted + /// when writing. + /// + ShouldQuote ShouldQuote { get; } + + /// + /// Gets the culture info used to read and write CSV files. + /// + CultureInfo CultureInfo { get; } + + /// + /// Gets a value indicating if comments are allowed. + /// True to allow commented out lines, otherwise false. + /// + bool AllowComments { get; } + + /// + /// Gets the character used to denote + /// a line that is commented out. Default is '#'. + /// + char Comment { get; } + + /// + /// Gets a value indicating if the + /// CSV file has a header record. + /// Default is true. + /// + bool HasHeaderRecord { get; } + + /// + /// Gets a value indicating whether references + /// should be ignored when auto mapping. True to ignore + /// references, otherwise false. Default is false. + /// + bool IgnoreReferences { get; } + + /// + /// Gets a value indicating if private + /// member should be read from and written to. + /// True to include private member, otherwise false. Default is false. + /// + bool IncludePrivateMembers { get; } + + /// + /// Gets a callback that will return the prefix for a reference header. + /// + ReferenceHeaderPrefix ReferenceHeaderPrefix { get; } + + /// + /// Gets the member types that are used when auto mapping. + /// MemberTypes are flags, so you can choose more than one. + /// Default is Properties. + /// + MemberTypes MemberTypes { get; } + + /// + /// 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. + /// + bool UseNewObjectForNullReferenceMembers { get; } + + /// + /// 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. + /// + IComparer DynamicPropertySort { get; } + + /// + /// A value indicating if exception messages contain raw CSV data. + /// true if exception contain raw CSV data, otherwise false. + /// Default is true. + /// + bool ExceptionMessagesContainRawData { get; } + + /// + /// Validates the configuration. + /// + 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 +{ + /// + /// Options for handling injection attacks. + /// + public enum InjectionOptions + { + /// + /// No injection protection. + /// + None = 0, + /// + /// Escape injection characters. + /// + Escape, + /// + /// Strip injection characters. + /// + Strip, + /// + /// Throw an exception if injection characters are detected. + /// + 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 +{ + /// + /// Mapping info for a member to a CSV field. + /// + [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 + { + /// + /// Gets the member map data. + /// + public virtual MemberMapData Data { get; protected set; } + + /// + /// Type converter options. + /// + public virtual MemberMapTypeConverterOption TypeConverterOption { get; protected set; } + + /// + /// Creates an instance of using the given Type and . + /// + /// Type of the class the member being mapped belongs to. + /// The member being mapped. + 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; + } + + /// + /// 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. + /// + /// The possible names of the CSV field. + 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; + } + + /// + /// When reading, is used to get the + /// index of the name used when there + /// are multiple names that are the same. + /// + /// The index of the name. + public virtual MemberMap NameIndex(int index) + { + Data.NameIndex = index; + + return this; + } + + /// + /// 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. + /// + /// The index of the CSV field. + /// The end index used when mapping to an member. + public virtual MemberMap Index(int index, int indexEnd = -1) + { + Data.Index = index; + Data.IsIndexSet = true; + Data.IndexEnd = indexEnd; + + return this; + } + + /// + /// 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. + /// + public virtual MemberMap Ignore() + { + Data.Ignore = true; + + return this; + } + + /// + /// 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. + /// + /// True to ignore, otherwise false. + public virtual MemberMap Ignore(bool ignore) + { + Data.Ignore = ignore; + + return this; + } + + /// + /// The default value that will be used when reading when + /// the CSV field is empty. + /// + /// The default value. + /// Use default on conversion failure. + 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; + } + + /// + /// 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. + /// + /// The constant value. + 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; + } + + /// + /// Specifies the to use + /// when converting the member to and from a CSV field. + /// + /// The TypeConverter to use. + public virtual MemberMap TypeConverter(ITypeConverter typeConverter) + { + Data.TypeConverter = typeConverter; + + return this; + } + + /// + /// Specifies the to use + /// when converting the member to and from a CSV field. + /// + /// The of the + /// to use. + public virtual MemberMap TypeConverter() where TConverter : ITypeConverter + { + TypeConverter(ObjectResolver.Current.Resolve()); + + return this; + } + + /// + /// Ignore the member when reading if no matching field name can be found. + /// + public virtual MemberMap Optional() + { + Data.IsOptional = true; + + return this; + } + + /// + /// Specifies an expression to be used to validate a field when reading. + /// + /// + public virtual MemberMap Validate(Validate validateExpression) + { + return Validate(validateExpression, args => $"Field '{args.Field}' is not valid."); + } + + /// + /// Specifies an expression to be used to validate a field when reading along with specified exception message. + /// + /// + /// + 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(validateCallExpression, fieldParameter); + Data.ValidateMessageExpression = Expression.Lambda(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 +{ + /// + /// A collection that holds 's. + /// + [DebuggerDisplay("Count = {list.Count}")] + public class MemberMapCollection : IList + { + private readonly List list = new List(); + private readonly IComparer comparer; + + /// + /// Gets the number of elements contained in the . + /// + /// + /// The number of elements contained in the . + /// + public virtual int Count => list.Count; + + /// + /// Gets a value indicating whether the is read-only. + /// + /// + /// true if the is read-only; otherwise, false. + /// + public virtual bool IsReadOnly => false; + + /// + /// Initializes a new instance of the class. + /// + public MemberMapCollection() : this(new MemberMapComparer()) { } + + /// + /// Initializes a new instance of the class. + /// + /// The comparer to use when sorting the member maps. + public MemberMapCollection(IComparer comparer) + { + this.comparer = comparer; + } + + /// + /// Returns an enumerator that iterates through the collection. + /// + /// + /// A that can be used to iterate through the collection. + /// + /// 1 + public virtual IEnumerator GetEnumerator() + { + return list.GetEnumerator(); + } + + /// + /// Returns an enumerator that iterates through a collection. + /// + /// + /// An object that can be used to iterate through the collection. + /// + /// 2 + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + /// + /// Adds an item to the . + /// + /// The object to add to the . + /// The is read-only. + /// + public virtual void Add(MemberMap item) + { + list.Add(item); + list.Sort(comparer); + } + + /// + /// Adds a range of items to the . + /// + /// The collection to add. + public virtual void AddRange(ICollection collection) + { + list.AddRange(collection); + list.Sort(comparer); + } + + /// + /// Removes all items from the . + /// + /// The is read-only. + /// + public virtual void Clear() + { + list.Clear(); + } + + /// + /// Determines whether the contains a specific value. + /// + /// + /// true if is found in the ; otherwise, false. + /// + /// The object to locate in the . + /// + public virtual bool Contains(MemberMap item) + { + return list.Contains(item); + } + + /// + /// Copies the elements of the to an , starting at a particular index. + /// + /// The one-dimensional that is the destination of the elements copied from . The must have zero-based indexing.The zero-based index in at which copying begins. is null. is less than 0.The number of elements in the source is greater than the available space from to the end of the destination . + public virtual void CopyTo(MemberMap[] array, int arrayIndex) + { + list.CopyTo(array, arrayIndex); + } + + /// + /// Removes the first occurrence of a specific object from the . + /// + /// + /// true if was successfully removed from the ; otherwise, false. This method also returns false if is not found in the original . + /// + /// The object to remove from the . + /// The is read-only. + /// + public virtual bool Remove(MemberMap item) + { + return list.Remove(item); + } + + /// + /// Determines the index of a specific item in the . + /// + /// + /// The index of if found in the list; otherwise, -1. + /// + /// The object to locate in the . + /// + public virtual int IndexOf(MemberMap item) + { + return list.IndexOf(item); + } + + /// + /// Inserts an item to the at the specified index. + /// + /// The zero-based index at which should be inserted. + /// The object to insert into the . + /// is not a valid index in the . + /// The is read-only. + /// + public virtual void Insert(int index, MemberMap item) + { + list.Insert(index, item); + } + + /// + /// Removes the item at the specified index. + /// + /// The zero-based index of the item to remove. + /// is not a valid index in the . + /// The is read-only. + /// + public virtual void RemoveAt(int index) + { + list.RemoveAt(index); + } + + /// + /// Gets or sets the element at the specified index. + /// + /// + /// The element at the specified index. + /// + /// The zero-based index of the element to get or set. + /// is not a valid index in the . + /// The member is set and the is read-only. + /// + public virtual MemberMap this[int index] + { + get { return list[index]; } + set { list[index] = value; } + } + + /// + /// Finds the using the given member expression. + /// + /// The the member is on. + /// The member expression. + /// The for the given expression, or null if not found. + public virtual MemberMap? Find(Expression> expression) + { + var member = ReflectionHelper.GetMember(expression); + return Find(member); + } + + /// + /// Finds the using the given member. + /// + /// The member. + /// The for the given expression, or null if not found. + 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; + } + + /// + /// Adds the members from the mapping. This will recursively + /// traverse the mapping tree and add all members for + /// reference maps. + /// + /// The mapping where the members are added from. + 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 +{ + /// + /// Used to compare s. + /// The order is by field index ascending. Any + /// fields that don't have an index are pushed + /// to the bottom. + /// + internal class MemberMapComparer : IComparer + { + /// + /// Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other. + /// + /// + /// Value + /// Condition + /// Less than zero + /// is less than . + /// Zero + /// equals . + /// Greater than zero + /// is greater than . + /// + /// The first object to compare. + /// The second object to compare. + /// Neither nor implements the interface. + /// -or- + /// and are of different types and neither one can handle comparisons with the other. + /// 2 + public virtual int Compare( object x, object y ) + { + var xMember = x as MemberMap; + var yMember = y as MemberMap; + return Compare( xMember, yMember ); + } + + /// + /// Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other. + /// + /// + /// Value + /// Condition + /// Less than zero + /// is less than . + /// Zero + /// equals . + /// Greater than zero + /// is greater than . + /// + /// The first object to compare. + /// The second object to compare. + /// + 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 +{ + /// + /// The configured data for the member map. + /// + public class MemberMapData + { + /// + /// Gets the member type. + /// + 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); + } + } + + /// + /// Gets the that the data + /// is associated with. + /// + public virtual MemberInfo? Member { get; private set; } + + /// + /// Gets the list of column names. + /// + public virtual MemberNameCollection Names { get; } = new MemberNameCollection(); + + /// + /// Gets or sets the index of the name. + /// This is used if there are multiple + /// columns with the same names. + /// + public virtual int NameIndex { get; set; } + + /// + /// Gets or sets a value indicating if the name was + /// explicitly set. True if it was explicitly set, + /// otherwise false. + /// + public virtual bool IsNameSet { get; set; } + + /// + /// Gets or sets the column index. + /// + public virtual int Index { get; set; } = -1; + + /// + /// 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. + /// + public virtual int IndexEnd { get; set; } = -1; + + /// + /// Gets or sets a value indicating if the index was + /// explicitly set. True if it was explicitly set, + /// otherwise false. + /// + public virtual bool IsIndexSet { get; set; } + + /// + /// Gets or sets the type converter. + /// + public virtual ITypeConverter? TypeConverter { get; set; } + + /// + /// Gets or sets the type converter options. + /// + public virtual TypeConverterOptions TypeConverterOptions { get; set; } = new TypeConverterOptions(); + + /// + /// Gets or sets a value indicating whether the field should be ignored. + /// + public virtual bool Ignore { get; set; } + + /// + /// Gets or sets the default value used when a CSV field is empty. + /// + public virtual object? Default { get; set; } + + /// + /// 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. + /// + public virtual bool IsDefaultSet { get; set; } + + /// + /// Gets or setse a value indicating if the default value should be used when + /// a type conversion failure happens. true to use the default, otherwise + /// false. + /// + public virtual bool UseDefaultOnConversionFailure { get; set; } + + /// + /// Gets or sets the constant value used for every record. + /// + public virtual object? Constant { get; set; } + + /// + /// Gets or sets a value indicating if a constant was explicitly set. + /// + public virtual bool IsConstantSet { get; set; } + + /// + /// Gets or sets the expression used to convert data in the + /// row to the member. + /// + public virtual Expression ReadingConvertExpression { get; set; } + + /// + /// Gets or sets the expression to be used to convert the object + /// to a field. + /// + public virtual Expression WritingConvertExpression { get; set; } + + /// + /// Gets or sets the expression use to validate a field. + /// + public virtual Expression ValidateExpression { get; set; } + + /// + /// Gets or sets the expression used to get the validation message when validation fails. + /// + public virtual Expression ValidateMessageExpression { get; set; } + + /// + /// Gets or sets a value indicating if a field is optional. + /// + public virtual bool IsOptional { get; set; } + + /// + /// Initializes a new instance of the class. + /// + /// The member. + 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 +{ + /// + /// Sets type converter options on a member map. + /// + public class MemberMapTypeConverterOption + { + private readonly MemberMap memberMap; + + /// + /// Creates a new instance using the given . + /// + /// The member map the options are being applied to. + public MemberMapTypeConverterOption(MemberMap memberMap) + { + this.memberMap = memberMap; + } + + /// + /// The used when type converting. + /// This will override the global + /// setting. + /// + /// The culture info. + public virtual MemberMap CultureInfo(CultureInfo cultureInfo) + { + memberMap.Data.TypeConverterOptions.CultureInfo = cultureInfo; + + return memberMap; + } + + /// + /// The to use when type converting. + /// This is used when doing any conversions. + /// + /// The date time style. + public virtual MemberMap DateTimeStyles(DateTimeStyles dateTimeStyle) + { + memberMap.Data.TypeConverterOptions.DateTimeStyle = dateTimeStyle; + + return memberMap; + } + + /// + /// The to use when type converting. + /// This is used when doing converting. + /// + /// The time span styles. + public virtual MemberMap TimespanStyles(TimeSpanStyles timeSpanStyles) + { + memberMap.Data.TypeConverterOptions.TimeSpanStyle = timeSpanStyles; + + return memberMap; + } + + /// + /// The to use when type converting. + /// This is used when doing any number conversions. + /// + /// + public virtual MemberMap NumberStyles(NumberStyles numberStyle) + { + memberMap.Data.TypeConverterOptions.NumberStyles = numberStyle; + + return memberMap; + } + + /// + /// The string format to be used when type converting. + /// + /// The format. + public virtual MemberMap Format(params string[] formats) + { + memberMap.Data.TypeConverterOptions.Formats = formats; + + return memberMap; + } + + /// + /// The to use when converting. + /// This is used when doing conversions. + /// + /// Kind of the URI. + public virtual MemberMap UriKind(UriKind uriKind) + { + memberMap.Data.TypeConverterOptions.UriKind = uriKind; + + return memberMap; + } + + /// + /// The string values used to represent a boolean when converting. + /// + /// A value indicating whether true values or false values are being set. + /// A value indication if the current values should be cleared before adding the new ones. + /// The string boolean values. + public virtual 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; + } + + /// + /// The string values used to represent null when converting. + /// + /// The values that represent null. + /// + public virtual MemberMap NullValues(params string[] nullValues) + { + return NullValues(true, nullValues); + } + + /// + /// The string values used to represent null when converting. + /// + /// A value indication if the current values should be cleared before adding the new ones. + /// The values that represent null. + /// + public virtual MemberMap NullValues(bool clearValues, params string[] nullValues) + { + if (clearValues) + { + memberMap.Data.TypeConverterOptions.NullValues.Clear(); + } + + memberMap.Data.TypeConverterOptions.NullValues.AddRange(nullValues); + + return memberMap; + } + + /// + /// Ignore case when parsing enums. + /// + /// true to ignore case, otherwise false. + 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 +{ + /// + /// Mapping info for a member to a CSV field. + /// + public class MemberMap : MemberMap + { + /// + /// Creates a new instance using the specified member. + /// + public MemberMap(MemberInfo? member) + { + TypeConverterOption = new MemberMapTypeConverterOption(this); + + Data = new MemberMapData(member); + } + + /// + /// 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. + /// + /// The possible names of the CSV field. + public new 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; + } + + /// + /// When reading, is used to get the + /// index of the name used when there + /// are multiple names that are the same. + /// + /// The index of the name. + public new virtual MemberMap NameIndex(int index) + { + Data.NameIndex = index; + + return this; + } + + /// + /// 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. + /// + /// The index of the CSV field. + /// The end index used when mapping to an member. + public new virtual MemberMap Index(int index, int indexEnd = -1) + { + Data.Index = index; + Data.IsIndexSet = true; + Data.IndexEnd = indexEnd; + + return this; + } + + /// + /// 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. + /// + public new virtual MemberMap Ignore() + { + Data.Ignore = true; + + return this; + } + + /// + /// 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. + /// + /// True to ignore, otherwise false. + public new virtual MemberMap Ignore(bool ignore) + { + Data.Ignore = ignore; + + return this; + } + + /// + /// The default value that will be used when reading when + /// the CSV field is empty. + /// + /// The default value. + /// Use default on conversion failure. + public virtual MemberMap Default(TMember defaultValue, bool useOnConversionFailure = false) + { + Data.Default = defaultValue; + Data.IsDefaultSet = true; + Data.UseDefaultOnConversionFailure = useOnConversionFailure; + + return this; + } + + /// + /// 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 to convert + /// the field. This could potentially have runtime errors. + /// + /// The default value. + /// Use default on conversion failure. + public virtual MemberMap Default(string defaultValue, bool useOnConversionFailure = false) + { + Data.Default = defaultValue; + Data.IsDefaultSet = true; + Data.UseDefaultOnConversionFailure = useOnConversionFailure; + + return this; + } + + /// + /// 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. + /// + /// The constant value. + public virtual MemberMap Constant(TMember? constantValue) + { + Data.Constant = constantValue; + Data.IsConstantSet = true; + + return this; + } + + /// + /// Specifies the to use + /// when converting the member to and from a CSV field. + /// + /// The TypeConverter to use. + public new virtual MemberMap TypeConverter(ITypeConverter typeConverter) + { + Data.TypeConverter = typeConverter; + + return this; + } + + /// + /// Specifies the to use + /// when converting the member to and from a CSV field. + /// + /// The of the + /// to use. + public new virtual MemberMap TypeConverter() where TConverter : ITypeConverter + { + TypeConverter(ObjectResolver.Current.Resolve()); + + return this; + } + + /// + /// Specifies an expression to be used to convert data in the + /// row to the member. + /// + /// The convert expression. + public virtual MemberMap Convert(ConvertFromString 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>(methodExpression, fieldParameter); + + Data.ReadingConvertExpression = lambdaExpression; + + return this; + } + + /// + /// Specifies an expression to be used to convert the object + /// to a field. + /// + /// The convert expression. + public virtual MemberMap Convert(ConvertToString convertToStringFunction) + { + var instance = convertToStringFunction.Target != null ? Expression.Constant(convertToStringFunction.Target) : null; + var fieldParameter = Expression.Parameter(typeof(ConvertToStringArgs), "args"); + var methodExpression = Expression.Call + ( + instance, + convertToStringFunction.Method, + fieldParameter + ); + var lambdaExpression = Expression.Lambda>(methodExpression, fieldParameter); + + Data.WritingConvertExpression = lambdaExpression; + + return this; + } + + /// + /// Ignore the member when reading if no matching field name can be found. + /// + public new virtual MemberMap Optional() + { + Data.IsOptional = true; + + return this; + } + + /// + /// Specifies an expression to be used to validate a field when reading. + /// + /// + public new virtual MemberMap Validate(Validate validateExpression) + { + return Validate(validateExpression, args => $"Field '{args.Field}' is not valid."); + } + + /// + /// Specifies an expression to be used to validate a field when reading along with specified exception message. + /// + /// + /// + public new virtual MemberMap 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(validateCallExpression, fieldParameter); + Data.ValidateMessageExpression = Expression.Lambda(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 +{ + /// + /// A collection that holds member names. + /// + public class MemberNameCollection : IEnumerable + { + private readonly List names = new List(); + + /// + /// Gets the name at the given index. If a prefix is set, + /// it will be prepended to the name. + /// + /// + /// + public string this[int index] + { + get { return Prefix + names[index]; } + set { names[index] = value; } + } + + /// + /// Gets the prefix to use for each name. + /// + public string Prefix { get; set; } + + /// + /// Gets the raw list of names without + /// the prefix being prepended. + /// + public List Names => names; + + /// + /// Gets the count. + /// + public int Count => names.Count; + + /// + /// Adds the given name to the collection. + /// + /// The name to add. + public void Add(string name) + { + names.Add(name); + } + + /// + /// Clears all names from the collection. + /// + public void Clear() + { + names.Clear(); + } + + /// + /// Adds a range of names to the collection. + /// + /// The range to add. + public void AddRange(IEnumerable names) + { + this.names.AddRange(names); + } + + /// + /// Returns an enumerator that iterates through the collection. + /// + /// + /// A that can be used to iterate through the collection. + /// + /// 1 + public IEnumerator GetEnumerator() + { + for (var i = 0; i < names.Count; i++) + { + yield return this[i]; + } + } + + /// + /// Returns an enumerator that iterates through a collection. + /// + /// + /// An object that can be used to iterate through the collection. + /// + /// 2 + 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 +{ + /// + /// Mapping info for a reference member mapping to a class. + /// + [DebuggerDisplay("Member = {Data.Member}, Prefix = {Data.Prefix}")] + public class MemberReferenceMap + { + private readonly MemberReferenceMapData data; + + /// + /// Gets the member reference map data. + /// + public MemberReferenceMapData Data => data; + + /// + /// Initializes a new instance of the class. + /// + /// The member. + /// The to use for the reference map. + public MemberReferenceMap(MemberInfo member, ClassMap mapping) + { + if (mapping == null) + { + throw new ArgumentNullException(nameof(mapping)); + } + + data = new MemberReferenceMapData(member, mapping); + } + + /// + /// Appends a prefix to the header of each field of the reference member. + /// + /// The prefix to be prepended to headers of each reference member. + /// Inherit parent prefixes. + /// The current + 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; + } + + /// + /// Get the largest index for the + /// members and references. + /// + /// The max index. + 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 +{ + /// + /// A collection that holds 's. + /// + [DebuggerDisplay("Count = {list.Count}")] + public class MemberReferenceMapCollection : IList + { + private readonly List list = new List(); + + /// Gets the number of elements contained in the . + /// The number of elements contained in the . + public virtual int Count => list.Count; + + /// Gets a value indicating whether the is read-only. + /// true if the is read-only; otherwise, false. + public virtual bool IsReadOnly => false; + + /// Gets or sets the element at the specified index. + /// The element at the specified index. + /// The zero-based index of the element to get or set. + /// + /// is not a valid index in the . + /// The member is set and the is read-only. + public virtual MemberReferenceMap this[int index] + { + get => list[index]; + set => list[index] = value; + } + + /// Returns an enumerator that iterates through the collection. + /// A that can be used to iterate through the collection. + /// 1 + public virtual IEnumerator GetEnumerator() + { + return list.GetEnumerator(); + } + + /// Returns an enumerator that iterates through a collection. + /// An object that can be used to iterate through the collection. + /// 2 + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + /// Adds an item to the . + /// The object to add to the . + /// The is read-only. + public virtual void Add(MemberReferenceMap item) + { + list.Add(item); + } + + /// Removes all items from the . + /// The is read-only. + public virtual void Clear() + { + list.Clear(); + } + + /// Determines whether the contains a specific value. + /// true if is found in the ; otherwise, false. + /// The object to locate in the . + public virtual bool Contains(MemberReferenceMap item) + { + return list.Contains(item); + } + + /// Copies the elements of the to an , starting at a particular index. + /// The one-dimensional that is the destination of the elements copied from . The must have zero-based indexing. + /// The zero-based index in at which copying begins. + /// + /// is null. + /// + /// is less than 0. + /// The number of elements in the source is greater than the available space from to the end of the destination . + public virtual void CopyTo(MemberReferenceMap[] array, int arrayIndex) + { + list.CopyTo(array, arrayIndex); + } + + /// Removes the first occurrence of a specific object from the . + /// true if was successfully removed from the ; otherwise, false. This method also returns false if is not found in the original . + /// The object to remove from the . + /// The is read-only. + public virtual bool Remove(MemberReferenceMap item) + { + return list.Remove(item); + } + + /// Determines the index of a specific item in the . + /// The index of if found in the list; otherwise, -1. + /// The object to locate in the . + public virtual int IndexOf(MemberReferenceMap item) + { + return list.IndexOf(item); + } + + /// Inserts an item to the at the specified index. + /// The zero-based index at which should be inserted. + /// The object to insert into the . + /// + /// is not a valid index in the . + /// The is read-only. + public virtual void Insert(int index, MemberReferenceMap item) + { + list.Insert(index, item); + } + + /// Removes the item at the specified index. + /// The zero-based index of the item to remove. + /// + /// is not a valid index in the . + /// The is read-only. + public virtual void RemoveAt(int index) + { + list.RemoveAt(index); + } + + /// + /// Finds the using the given member expression. + /// + /// The the member is on. + /// The member expression. + /// The for the given expression, or null if not found. + public virtual MemberReferenceMap? Find(Expression> expression) + { + var member = ReflectionHelper.GetMember(expression); + return Find(member); + } + + /// + /// Finds the using the given member. + /// + /// The member. + /// The for the given expression, or null if not found. + 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 +{ + /// + /// The configuration data for the reference map. + /// + public class MemberReferenceMapData + { + private string prefix; + + /// + /// Gets or sets the header prefix to use. + /// + 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); + } + } + } + } + + /// + /// Gets or sets a value indicating if a prefix should inherit its parent. + /// true to inherit, otherwise false. + /// + public virtual bool Inherit { get; set; } + + /// + /// Gets the that the data + /// is associated with. + /// + public virtual MemberInfo Member { get; private set; } + + /// + /// Gets the mapping this is a reference for. + /// + public ClassMap Mapping { get; private set; } + + /// + /// Initializes a new instance of the class. + /// + /// The member. + /// The mapping this is a reference for. + 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 +{ + /// + /// Flags for the type of members that + /// can be used for auto mapping. + /// + [Flags] + public enum MemberTypes + { + /// + /// No members. This is not a valid value + /// and will cause an exception if used. + /// + None = 0, + + /// + /// Properties on a class. + /// + Properties = 1, + + /// + /// Fields on a class. + /// + 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 +{ + /// + /// 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. + /// + [DebuggerDisplay("Data = {Data}")] + public class ParameterMap + { + /// + /// Gets the parameter map data. + /// + public virtual ParameterMapData Data { get; protected set; } + + /// + /// Type converter options. + /// + public virtual ParameterMapTypeConverterOption TypeConverterOption { get; protected set; } + + /// + /// Gets or sets the map for a constructor type. + /// + public virtual ClassMap ConstructorTypeMap { get; set; } + + /// + /// Gets or sets the map for a reference type. + /// + public virtual ParameterReferenceMap ReferenceMap { get; set; } + + /// + /// Creates an instance of using + /// the given information. + /// + /// The parameter being mapped. + public ParameterMap(ParameterInfo parameter) + { + TypeConverterOption = new ParameterMapTypeConverterOption(this); + + Data = new ParameterMapData(parameter); + } + + /// + /// 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. + /// + /// The possible names of the CSV field. + 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; + } + + /// + /// When reading, is used to get the + /// index of the name used when there + /// are multiple names that are the same. + /// + /// The index of the name. + public virtual ParameterMap NameIndex(int index) + { + Data.NameIndex = index; + + return this; + } + + /// + /// 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. + /// + /// The index of the CSV field. + public virtual ParameterMap Index(int index) + { + Data.Index = index; + Data.IsIndexSet = true; + + return this; + } + + /// + /// Ignore the parameter when reading and writing. + /// + public virtual ParameterMap Ignore() + { + Data.Ignore = true; + + return this; + } + + /// + /// Ignore the parameter when reading and writing. + /// + /// True to ignore, otherwise false. + public virtual ParameterMap Ignore(bool ignore) + { + Data.Ignore = ignore; + + return this; + } + + /// + /// The default value that will be used when reading when + /// the CSV field is empty. + /// + /// The default value. + 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; + } + + /// + /// 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. + /// + /// The constant value. + 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; + } + + /// + /// The field is optional. + /// + public virtual ParameterMap Optional() + { + Data.IsOptional = true; + + return this; + } + + /// + /// Specifies the to use + /// when converting the parameter to and from a CSV field. + /// + /// The TypeConverter to use. + public virtual ParameterMap TypeConverter(ITypeConverter typeConverter) + { + Data.TypeConverter = typeConverter; + + return this; + } + + /// + /// Specifies the to use + /// when converting the parameter to and from a CSV field. + /// + /// The of the + /// to use. + public virtual ParameterMap TypeConverter() where TConverter : ITypeConverter + { + TypeConverter(ObjectResolver.Current.Resolve()); + + 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 +{ + /// + /// The constructor parameter data for the map. + /// + [DebuggerDisplay("Index = {Index}, Names = {string.Join(\", \", Names)}, Parameter = {Parameter}")] + public class ParameterMapData + { + /// + /// Gets the that the data + /// is associated with. + /// + public virtual ParameterInfo Parameter { get; private set; } + + /// + /// Gets the list of column names. + /// + public virtual MemberNameCollection Names { get; } = new MemberNameCollection(); + + /// + /// Gets or sets the index of the name. + /// This is used if there are multiple + /// columns with the same names. + /// + public virtual int NameIndex { get; set; } + + /// + /// Gets or sets a value indicating if the name was + /// explicitly set. True if it was explicitly set, + /// otherwise false. + /// + public virtual bool IsNameSet { get; set; } + + /// + /// Gets or sets the column index. + /// + public virtual int Index { get; set; } = -1; + + /// + /// Gets or sets a value indicating if the index was + /// explicitly set. True if it was explicitly set, + /// otherwise false. + /// + public virtual bool IsIndexSet { get; set; } + + /// + /// Gets or sets the type converter. + /// + public virtual ITypeConverter TypeConverter { get; set; } + + /// + /// Gets or sets the type converter options. + /// + public virtual TypeConverterOptions TypeConverterOptions { get; set; } = new TypeConverterOptions(); + + /// + /// Gets or sets a value indicating whether the field should be ignored. + /// + public virtual bool Ignore { get; set; } + + /// + /// Gets or sets the default value used when a CSV field is empty. + /// + public virtual object? Default { get; set; } + + /// + /// 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. + /// + public virtual bool IsDefaultSet { get; set; } + + /// + /// Gets or sets the constant value used for every record. + /// + public virtual object? Constant { get; set; } + + /// + /// Gets or sets a value indicating if a constant was explicitly set. + /// + public virtual bool IsConstantSet { get; set; } + + /// + /// Gets or sets a value indicating if a field is optional. + /// + public virtual bool IsOptional { get; set; } + + /// + /// Initializes a new instance of the class. + /// + /// The constructor parameter. + 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 +{ + /// + /// Sets type converter options on a parameter map. + /// + public class ParameterMapTypeConverterOption + { + private readonly ParameterMap parameterMap; + + /// + /// Creates a new instance using the given . + /// + /// The member map the options are being applied to. + public ParameterMapTypeConverterOption(ParameterMap parameterMap) + { + this.parameterMap = parameterMap; + } + + /// + /// The used when type converting. + /// This will override the global + /// setting. + /// + /// The culture info. + public virtual ParameterMap CultureInfo(CultureInfo cultureInfo) + { + parameterMap.Data.TypeConverterOptions.CultureInfo = cultureInfo; + + return parameterMap; + } + + /// + /// The to use when type converting. + /// This is used when doing any conversions. + /// + /// The date time style. + public virtual ParameterMap DateTimeStyles(DateTimeStyles dateTimeStyle) + { + parameterMap.Data.TypeConverterOptions.DateTimeStyle = dateTimeStyle; + + return parameterMap; + } + + /// + /// The to use when type converting. + /// This is used when doing converting. + /// + /// The time span styles. + public virtual ParameterMap TimespanStyles(TimeSpanStyles timeSpanStyles) + { + parameterMap.Data.TypeConverterOptions.TimeSpanStyle = timeSpanStyles; + + return parameterMap; + } + + /// + /// The to use when type converting. + /// This is used when doing any number conversions. + /// + /// + public virtual ParameterMap NumberStyles(NumberStyles numberStyle) + { + parameterMap.Data.TypeConverterOptions.NumberStyles = numberStyle; + + return parameterMap; + } + + /// + /// The string format to be used when type converting. + /// + /// The format. + public virtual ParameterMap Format(params string[] formats) + { + parameterMap.Data.TypeConverterOptions.Formats = formats; + + return parameterMap; + } + + /// + /// The to use when converting. + /// This is used when doing conversions. + /// + /// Kind of the URI. + public virtual ParameterMap UriKind(UriKind uriKind) + { + parameterMap.Data.TypeConverterOptions.UriKind = uriKind; + + return parameterMap; + } + + /// + /// The string values used to represent a boolean when converting. + /// + /// A value indicating whether true values or false values are being set. + /// A value indication if the current values should be cleared before adding the new ones. + /// The string boolean values. + public virtual ParameterMap BooleanValues(bool isTrue, bool clearValues = true, params string[] booleanValues) + { + if (isTrue) + { + if (clearValues) + { + parameterMap.Data.TypeConverterOptions.BooleanTrueValues.Clear(); + } + + parameterMap.Data.TypeConverterOptions.BooleanTrueValues.AddRange(booleanValues); + } + else + { + if (clearValues) + { + parameterMap.Data.TypeConverterOptions.BooleanFalseValues.Clear(); + } + + parameterMap.Data.TypeConverterOptions.BooleanFalseValues.AddRange(booleanValues); + } + + return parameterMap; + } + + /// + /// The string values used to represent null when converting. + /// + /// The values that represent null. + /// + public virtual ParameterMap NullValues(params string[] nullValues) + { + return NullValues(true, nullValues); + } + + /// + /// The string values used to represent null when converting. + /// + /// A value indication if the current values should be cleared before adding the new ones. + /// The values that represent null. + /// + public virtual ParameterMap NullValues(bool clearValues, params string[] nullValues) + { + if (clearValues) + { + parameterMap.Data.TypeConverterOptions.NullValues.Clear(); + } + + parameterMap.Data.TypeConverterOptions.NullValues.AddRange(nullValues); + + return parameterMap; + } + } +} 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 +{ + /// + /// Mapping info for a reference parameter mapping to a class. + /// + public class ParameterReferenceMap + { + private readonly ParameterReferenceMapData data; + + /// + /// Gets the parameter reference map data. + /// + public ParameterReferenceMapData Data => data; + + /// + /// Initializes a new instance of the class. + /// + /// The parameter. + /// The to use for the reference map. + public ParameterReferenceMap(ParameterInfo parameter, ClassMap mapping) + { + if (mapping == null) + { + throw new ArgumentNullException(nameof(mapping)); + } + + data = new ParameterReferenceMapData(parameter, mapping); + } + + /// + /// Appends a prefix to the header of each field of the reference parameter. + /// + /// The prefix to be prepended to headers of each reference parameter. + /// Inherit parent prefixes. + /// The current + 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; + } + + /// + /// Get the largest index for the + /// members and references. + /// + /// The max index. + 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 +{ + /// + /// The configuration data for the reference map. + /// + [DebuggerDisplay( "Prefix = {Prefix}, Parameter = {Parameter}" )] + public class ParameterReferenceMapData + { + private string prefix; + + /// + /// Gets or sets the header prefix to use. + /// + 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); + } + } + } + } + + /// + /// Gets or sets a value indicating if a prefix should inherit its parent. + /// true to inherit, otherwise false. + /// + public virtual bool Inherit { get; set; } + + /// + /// Gets the that the data + /// is associated with. + /// + public virtual ParameterInfo Parameter { get; private set; } + + /// + /// Gets the mapping this is a reference for. + /// + public ClassMap Mapping { get; private set; } + + /// + /// Initializes a new instance of the class. + /// + /// The parameter. + /// The mapping this is a reference for. + 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 +{ + /// + /// Options for trimming of fields. + /// + [Flags] + public enum TrimOptions + { + /// + /// No trimming. + /// + None = 0, + + /// + /// Trims the whitespace around a field. + /// + Trim = 1, + + /// + /// Trims the whitespace inside of quotes around a field. + /// + InsideQuotes = 2 + } +} -- cgit v1.1-26-g67d0