├── .editorconfig
├── .github
├── FUNDING.yml
├── ISSUE_TEMPLATE
│ ├── bug_report.md
│ ├── config.yml
│ ├── documentation.md
│ └── feature_request.md
└── workflows
│ ├── ci.yaml
│ ├── git-version.yaml
│ └── publish.yaml
├── .gitignore
├── .vscode
├── launch.json
├── settings.json
└── tasks.json
├── CsvHelper.sln
├── CsvHelper.sln.licenseheader
├── CsvHelper.v3.ncrunchsolution
├── CsvHelperDependencies.linq
├── GitVersion.yml
├── LICENSE.txt
├── README.markdown
├── Unity Build.bat
├── build-docs.cmd
├── docs-src
└── CsvHelper.DocsGenerator
│ ├── ConsoleHost.cs
│ ├── CsvHelper.DocsGenerator.csproj
│ ├── EncodingType.cs
│ ├── Extensions.cs
│ ├── Formatters
│ ├── HtmlFormatter.cs
│ ├── Symbols.cs
│ └── XmlDocFormatter.cs
│ ├── Generators
│ ├── AssemblyGenerator.cs
│ ├── DocumentGenerator.cs
│ ├── DocumentGeneratorFactory.cs
│ ├── NamespaceGenerator.cs
│ └── TypeGenerator.cs
│ ├── Infos
│ ├── AssemblyInfo.cs
│ ├── ConstructorInfo.cs
│ ├── Info.cs
│ ├── MethodInfo.cs
│ ├── NamespaceInfo.cs
│ ├── PropertyInfo.cs
│ └── TypeInfo.cs
│ ├── LinkGenerator.cs
│ ├── Program.cs
│ ├── Startup.cs
│ └── XmlDocs.cs
├── docs
├── .nojekyll
├── api
│ └── index.html
├── browserconfig.xml
├── change-log
│ └── index.html
├── examples
│ ├── configuration
│ │ ├── attributes
│ │ │ └── index.html
│ │ ├── class-maps
│ │ │ ├── auto-mapping
│ │ │ │ └── index.html
│ │ │ ├── constant-value
│ │ │ │ └── index.html
│ │ │ ├── ignoring-properties
│ │ │ │ └── index.html
│ │ │ ├── index.html
│ │ │ ├── inline-type-conversion
│ │ │ │ └── index.html
│ │ │ ├── mapping-by-alternate-names
│ │ │ │ └── index.html
│ │ │ ├── mapping-by-index
│ │ │ │ └── index.html
│ │ │ ├── mapping-by-name
│ │ │ │ └── index.html
│ │ │ ├── mapping-duplicate-names
│ │ │ │ └── index.html
│ │ │ ├── mapping-properties
│ │ │ │ └── index.html
│ │ │ ├── optional-maps
│ │ │ │ └── index.html
│ │ │ ├── type-conversion
│ │ │ │ └── index.html
│ │ │ └── validation
│ │ │ │ └── index.html
│ │ └── index.html
│ ├── csvdatareader
│ │ └── index.html
│ ├── index.html
│ ├── prerequisites
│ │ ├── index.html
│ │ ├── reading-and-writing-files
│ │ │ └── index.html
│ │ ├── streams
│ │ │ └── index.html
│ │ └── using-and-dispose
│ │ │ └── index.html
│ ├── reading
│ │ ├── enumerate-class-records
│ │ │ └── index.html
│ │ ├── get-anonymous-type-records
│ │ │ └── index.html
│ │ ├── get-class-records
│ │ │ └── index.html
│ │ ├── get-dynamic-records
│ │ │ └── index.html
│ │ ├── index.html
│ │ ├── reading-by-hand
│ │ │ └── index.html
│ │ ├── reading-multiple-data-sets
│ │ │ └── index.html
│ │ └── reading-multiple-record-types
│ │ │ └── index.html
│ ├── type-conversion
│ │ ├── custom-type-converter
│ │ │ └── index.html
│ │ ├── index.html
│ │ └── type-converter-options
│ │ │ └── index.html
│ └── writing
│ │ ├── appending-to-an-existing-file
│ │ └── index.html
│ │ ├── index.html
│ │ ├── write-anonymous-type-objects
│ │ └── index.html
│ │ ├── write-class-objects
│ │ └── index.html
│ │ └── write-dynamic-objects
│ │ └── index.html
├── favicons
│ ├── android-icon-144x144.png
│ ├── android-icon-192x192.png
│ ├── android-icon-36x36.png
│ ├── android-icon-48x48.png
│ ├── android-icon-72x72.png
│ ├── android-icon-96x96.png
│ ├── apple-icon-114x114.png
│ ├── apple-icon-120x120.png
│ ├── apple-icon-144x144.png
│ ├── apple-icon-152x152.png
│ ├── apple-icon-180x180.png
│ ├── apple-icon-57x57.png
│ ├── apple-icon-60x60.png
│ ├── apple-icon-72x72.png
│ ├── apple-icon-76x76.png
│ ├── apple-icon-precomposed.png
│ ├── apple-icon.png
│ ├── favicon-16x16.png
│ ├── favicon-32x32.png
│ ├── favicon-96x96.png
│ ├── favicon.ico
│ ├── ms-icon-144x144.png
│ ├── ms-icon-150x150.png
│ ├── ms-icon-310x310.png
│ └── ms-icon-70x70.png
├── getting-started
│ └── index.html
├── google6ad86f23ff698b61.html
├── images
│ ├── aws.png
│ ├── logo.svg
│ └── microsoft.png
├── index.html
├── manifest.json
├── migration
│ ├── index.html
│ ├── v10
│ │ └── index.html
│ ├── v11
│ │ └── index.html
│ ├── v12
│ │ └── index.html
│ ├── v13
│ │ └── index.html
│ ├── v14
│ │ └── index.html
│ ├── v15
│ │ └── index.html
│ ├── v16
│ │ └── index.html
│ ├── v17
│ │ └── index.html
│ ├── v18
│ │ └── index.html
│ ├── v19
│ │ └── index.html
│ ├── v2
│ │ └── index.html
│ ├── v20
│ │ └── index.html
│ ├── v21
│ │ └── index.html
│ ├── v22
│ │ └── index.html
│ ├── v23
│ │ └── index.html
│ ├── v24
│ │ └── index.html
│ ├── v25
│ │ └── index.html
│ ├── v26
│ │ └── index.html
│ ├── v27
│ │ └── index.html
│ ├── v28
│ │ └── index.html
│ ├── v29
│ │ └── index.html
│ ├── v3
│ │ └── index.html
│ ├── v30
│ │ └── index.html
│ ├── v4
│ │ └── index.html
│ ├── v5
│ │ └── index.html
│ ├── v6
│ │ └── index.html
│ ├── v7
│ │ └── index.html
│ ├── v8
│ │ └── index.html
│ └── v9
│ │ └── index.html
├── robots.txt
├── scripts
│ ├── header.js
│ └── sidebar.js
├── sitemap.xml
└── styles
│ ├── base.css
│ ├── content.css
│ ├── header.css
│ ├── index.css
│ └── sidebar.css
├── logo
├── CSV Helper logo.ai
├── CSV Helper logo.eps
├── CSV Helper logo.png
├── CSV Helper logo.svg
├── CSV-Helper-logo-Web.jpg
├── CSV-Helper-logo-Web.png
├── Comma-Small.jpg
├── Comma-Small.png
├── Comma.ai
├── Comma.eps
├── Comma.svg
├── aws.png
└── microsoft.png
├── performance
└── CsvHelper.Benchmarks
│ ├── BenchmarkEnumerateRecords.cs
│ ├── BenchmarkMain.cs
│ └── CsvHelper.Benchmarks.csproj
├── src
├── CsvHelper.Website
│ ├── .gitignore
│ ├── CsvHelper.Website.csproj
│ ├── CsvHelper.Website.v3.ncrunchproject
│ ├── Program.cs
│ ├── README.md
│ ├── TocItem.cs
│ ├── input
│ │ ├── .nojekyll
│ │ ├── Index.cshtml
│ │ ├── Shared
│ │ │ ├── _Footer.cshtml
│ │ │ ├── _Header.cshtml
│ │ │ ├── _Layout.cshtml
│ │ │ ├── _Metadata.cshtml
│ │ │ ├── _SideBar.cshtml
│ │ │ ├── _TocItem.cshtml
│ │ │ └── _TocItems.cshtml
│ │ ├── _ViewImports.cshtml
│ │ ├── _ViewStart.cshtml
│ │ ├── _manifest.yml
│ │ ├── api
│ │ │ └── Index.md
│ │ ├── browserconfig.xml
│ │ ├── change-log
│ │ │ └── index.md
│ │ ├── examples
│ │ │ ├── _directory.json
│ │ │ ├── configuration
│ │ │ │ ├── attributes
│ │ │ │ │ └── index.md
│ │ │ │ ├── class-maps
│ │ │ │ │ ├── auto-mapping
│ │ │ │ │ │ └── index.md
│ │ │ │ │ ├── constant-value
│ │ │ │ │ │ └── index.md
│ │ │ │ │ ├── ignoring-properties
│ │ │ │ │ │ └── index.md
│ │ │ │ │ ├── index.md
│ │ │ │ │ ├── inline-type-conversion
│ │ │ │ │ │ └── index.md
│ │ │ │ │ ├── mapping-by-alternate-names
│ │ │ │ │ │ └── index.md
│ │ │ │ │ ├── mapping-by-index
│ │ │ │ │ │ └── index.md
│ │ │ │ │ ├── mapping-by-name
│ │ │ │ │ │ └── index.md
│ │ │ │ │ ├── mapping-duplicate-names
│ │ │ │ │ │ └── index.md
│ │ │ │ │ ├── mapping-properties
│ │ │ │ │ │ └── index.md
│ │ │ │ │ ├── optional-maps
│ │ │ │ │ │ └── index.md
│ │ │ │ │ ├── type-conversion
│ │ │ │ │ │ └── index.md
│ │ │ │ │ └── validation
│ │ │ │ │ │ └── index.md
│ │ │ │ └── index.md
│ │ │ ├── csvdatareader
│ │ │ │ └── index.md
│ │ │ ├── index.md
│ │ │ ├── prerequisites
│ │ │ │ ├── index.md
│ │ │ │ ├── reading-and-writing-files
│ │ │ │ │ └── index.md
│ │ │ │ ├── streams
│ │ │ │ │ └── index.md
│ │ │ │ └── using-and-dispose
│ │ │ │ │ └── index.md
│ │ │ ├── reading
│ │ │ │ ├── enumerate-class-records
│ │ │ │ │ └── index.md
│ │ │ │ ├── get-anonymous-type-records
│ │ │ │ │ └── index.md
│ │ │ │ ├── get-class-records
│ │ │ │ │ └── index.md
│ │ │ │ ├── get-dynamic-records
│ │ │ │ │ └── index.md
│ │ │ │ ├── index.md
│ │ │ │ ├── reading-by-hand
│ │ │ │ │ └── index.md
│ │ │ │ ├── reading-multiple-data-sets
│ │ │ │ │ └── index.md
│ │ │ │ └── reading-multiple-record-types
│ │ │ │ │ └── index.md
│ │ │ ├── type-conversion
│ │ │ │ ├── custom-type-converter
│ │ │ │ │ └── index.md
│ │ │ │ ├── index.md
│ │ │ │ └── type-converter-options
│ │ │ │ │ └── index.md
│ │ │ └── writing
│ │ │ │ ├── appending-to-an-existing-file
│ │ │ │ └── index.md
│ │ │ │ ├── index.md
│ │ │ │ ├── write-anonymous-type-objects
│ │ │ │ └── index.md
│ │ │ │ ├── write-class-objects
│ │ │ │ └── index.md
│ │ │ │ └── write-dynamic-objects
│ │ │ │ └── index.md
│ │ ├── favicons
│ │ │ ├── android-icon-144x144.png
│ │ │ ├── android-icon-192x192.png
│ │ │ ├── android-icon-36x36.png
│ │ │ ├── android-icon-48x48.png
│ │ │ ├── android-icon-72x72.png
│ │ │ ├── android-icon-96x96.png
│ │ │ ├── apple-icon-114x114.png
│ │ │ ├── apple-icon-120x120.png
│ │ │ ├── apple-icon-144x144.png
│ │ │ ├── apple-icon-152x152.png
│ │ │ ├── apple-icon-180x180.png
│ │ │ ├── apple-icon-57x57.png
│ │ │ ├── apple-icon-60x60.png
│ │ │ ├── apple-icon-72x72.png
│ │ │ ├── apple-icon-76x76.png
│ │ │ ├── apple-icon-precomposed.png
│ │ │ ├── apple-icon.png
│ │ │ ├── favicon-16x16.png
│ │ │ ├── favicon-32x32.png
│ │ │ ├── favicon-96x96.png
│ │ │ ├── favicon.ico
│ │ │ ├── ms-icon-144x144.png
│ │ │ ├── ms-icon-150x150.png
│ │ │ ├── ms-icon-310x310.png
│ │ │ └── ms-icon-70x70.png
│ │ ├── getting-started
│ │ │ ├── _index.json
│ │ │ └── index.md
│ │ ├── google6ad86f23ff698b61.html
│ │ ├── images
│ │ │ ├── aws.png
│ │ │ ├── logo.svg
│ │ │ └── microsoft.png
│ │ ├── manifest.json
│ │ ├── migration
│ │ │ ├── index.md
│ │ │ ├── v10
│ │ │ │ └── index.md
│ │ │ ├── v11
│ │ │ │ └── index.md
│ │ │ ├── v12
│ │ │ │ └── index.md
│ │ │ ├── v13
│ │ │ │ └── index.md
│ │ │ ├── v14
│ │ │ │ └── index.md
│ │ │ ├── v15
│ │ │ │ └── index.md
│ │ │ ├── v16
│ │ │ │ └── index.md
│ │ │ ├── v17
│ │ │ │ └── index.md
│ │ │ ├── v18
│ │ │ │ └── index.md
│ │ │ ├── v19
│ │ │ │ └── index.md
│ │ │ ├── v2
│ │ │ │ └── index.md
│ │ │ ├── v20
│ │ │ │ └── index.md
│ │ │ ├── v21
│ │ │ │ └── index.md
│ │ │ ├── v22
│ │ │ │ └── index.md
│ │ │ ├── v23
│ │ │ │ └── index.md
│ │ │ ├── v24
│ │ │ │ └── index.md
│ │ │ ├── v25
│ │ │ │ └── index.md
│ │ │ ├── v26
│ │ │ │ └── index.md
│ │ │ ├── v27
│ │ │ │ └── index.md
│ │ │ ├── v28
│ │ │ │ └── index.md
│ │ │ ├── v29
│ │ │ │ └── index.md
│ │ │ ├── v3
│ │ │ │ └── index.md
│ │ │ ├── v30
│ │ │ │ └── index.md
│ │ │ ├── v4
│ │ │ │ └── index.md
│ │ │ ├── v5
│ │ │ │ └── index.md
│ │ │ ├── v6
│ │ │ │ └── index.md
│ │ │ ├── v7
│ │ │ │ └── index.md
│ │ │ ├── v8
│ │ │ │ └── index.md
│ │ │ └── v9
│ │ │ │ └── index.md
│ │ ├── robots.txt
│ │ ├── scripts
│ │ │ ├── header.js
│ │ │ └── sidebar.js
│ │ └── styles
│ │ │ ├── base.scss
│ │ │ ├── bulma.scss
│ │ │ ├── content.scss
│ │ │ ├── header.scss
│ │ │ ├── index.scss
│ │ │ └── sidebar.scss
│ ├── lib
│ │ └── bulma
│ │ │ ├── bulma-rtl.css
│ │ │ ├── bulma-rtl.css.map
│ │ │ ├── bulma-rtl.min.css
│ │ │ ├── bulma.css
│ │ │ ├── bulma.css.map
│ │ │ └── bulma.min.css
│ └── settings.yml
└── CsvHelper
│ ├── ArrayHelper.cs
│ ├── BadDataException.cs
│ ├── Compatibility
│ └── AsyncExtensions.cs
│ ├── Configuration
│ ├── Attributes
│ │ ├── AllowCommentsAttribute.cs
│ │ ├── BooleanFalseValuesAttribute.cs
│ │ ├── BooleanTrueValuesAttribute.cs
│ │ ├── BufferSizeAttribute.cs
│ │ ├── CacheFieldsAttribute.cs
│ │ ├── CommentAttribute.cs
│ │ ├── ConstantAttribute.cs
│ │ ├── CountBytesAttribute.cs
│ │ ├── CultureInfoAttribute.cs
│ │ ├── DateTimeStylesAttribute.cs
│ │ ├── DefaultAttribute.cs
│ │ ├── DelimiterAttribute.cs
│ │ ├── DetectColumnCountChangesAttribute.cs
│ │ ├── DetectDelimiterAttribute.cs
│ │ ├── DetectDelimiterValuesAttribute.cs
│ │ ├── EncodingAttribute.cs
│ │ ├── EnumIgnoreCaseAttribute.cs
│ │ ├── EscapeAttribute.cs
│ │ ├── ExceptionMessagesContainRawDataAttribute.cs
│ │ ├── FormatAttribute.cs
│ │ ├── HasHeaderRecordAttribute.cs
│ │ ├── HeaderPrefixAttribute.cs
│ │ ├── IClassMapper.cs
│ │ ├── IMemberMapper.cs
│ │ ├── IMemberReferenceMapper.cs
│ │ ├── IParameterMapper.cs
│ │ ├── IParameterReferenceMapper.cs
│ │ ├── IgnoreAttribute.cs
│ │ ├── IgnoreBaseAttribute.cs
│ │ ├── IgnoreBlankLinesAttribute.cs
│ │ ├── IgnoreReferencesAttribute.cs
│ │ ├── IncludePrivateMembersAttribute.cs
│ │ ├── IndexAttribute.cs
│ │ ├── InjectionCharactersAttribute.cs
│ │ ├── InjectionEscapeCharacterAttribute.cs
│ │ ├── InjectionOptionsAttribute.cs
│ │ ├── LineBreakInQuotedFieldIsBadDataAttribute.cs
│ │ ├── MaxFieldSizeAttribute.cs
│ │ ├── MemberTypesAttribute.cs
│ │ ├── ModeAttribute.cs
│ │ ├── NameAttribute.cs
│ │ ├── NameIndexAttribute.cs
│ │ ├── NewLineAttribute.cs
│ │ ├── NullValuesAttribute.cs
│ │ ├── NumberStylesAttribute.cs
│ │ ├── OptionalAttribute.cs
│ │ ├── ProcessFieldBufferSizeAttribute.cs
│ │ ├── QuoteAttribute.cs
│ │ ├── TrimOptionsAttribute.cs
│ │ ├── TypeConverterAttribute.cs
│ │ ├── UseNewObjectForNullReferenceMembersAttribute.cs
│ │ └── WhiteSpaceCharsAttribute.cs
│ ├── ClassMap.cs
│ ├── ClassMapBuilder.cs
│ ├── ClassMapCollection.cs
│ ├── ClassMap`1.cs
│ ├── ConfigurationException.cs
│ ├── ConfigurationFunctions.cs
│ ├── CsvConfiguration.cs
│ ├── DefaultClassMap`1.cs
│ ├── IParserConfiguration.cs
│ ├── IReaderConfiguration.cs
│ ├── IWriterConfiguration.cs
│ ├── InjectionOptions.cs
│ ├── MemberMap.cs
│ ├── MemberMapCollection.cs
│ ├── MemberMapComparer.cs
│ ├── MemberMapData.cs
│ ├── MemberMapTypeConverterOption.cs
│ ├── MemberMap`1.cs
│ ├── MemberNameCollection.cs
│ ├── MemberReferenceMap.cs
│ ├── MemberReferenceMapCollection.cs
│ ├── MemberReferenceMapData.cs
│ ├── MemberTypes.cs
│ ├── ParameterMap.cs
│ ├── ParameterMapData.cs
│ ├── ParameterMapTypeConverterOption.cs
│ ├── ParameterReferenceMap.cs
│ ├── ParameterReferenceMapData.cs
│ └── TrimOptions.cs
│ ├── CsvContext.cs
│ ├── CsvDataReader.cs
│ ├── CsvHelper.csproj
│ ├── CsvHelper.net45.v3.ncrunchproject
│ ├── CsvHelper.net462.v3.ncrunchproject
│ ├── CsvHelper.net47.v3.ncrunchproject
│ ├── CsvHelper.net48.v3.ncrunchproject
│ ├── CsvHelper.net5.0.v3.ncrunchproject
│ ├── CsvHelper.net50.v3.ncrunchproject
│ ├── CsvHelper.net6.0.v3.ncrunchproject
│ ├── CsvHelper.net60.v3.ncrunchproject
│ ├── CsvHelper.net7.0.v3.ncrunchproject
│ ├── CsvHelper.net8.0.v3.ncrunchproject
│ ├── CsvHelper.net9.0.v3.ncrunchproject
│ ├── CsvHelper.netstandard2.0.v3.ncrunchproject
│ ├── CsvHelper.netstandard2.1.v3.ncrunchproject
│ ├── CsvHelper.snk
│ ├── CsvHelperException.cs
│ ├── CsvMode.cs
│ ├── CsvParser.cs
│ ├── CsvReader.cs
│ ├── CsvWriter.cs
│ ├── Delegates
│ ├── BadDataFound.cs
│ ├── ConvertFromString.cs
│ ├── ConvertToString.cs
│ ├── GetConstructor.cs
│ ├── GetDelimiter.cs
│ ├── GetDynamicPropertyName.cs
│ ├── HeaderValidated.cs
│ ├── MissingFieldFound.cs
│ ├── PrepareHeaderForMatch.cs
│ ├── ReadingExceptionOccurred.cs
│ ├── ReferenceHeaderPrefix.cs
│ ├── ShouldQuote.cs
│ ├── ShouldSkipRecord.cs
│ ├── ShouldUseConstructorParameters.cs
│ └── Validate.cs
│ ├── Expressions
│ ├── DynamicRecordCreator.cs
│ ├── DynamicRecordWriter.cs
│ ├── ExpandoObjectRecordWriter.cs
│ ├── ExpressionManager.cs
│ ├── ObjectRecordCreator.cs
│ ├── ObjectRecordWriter.cs
│ ├── PrimitiveRecordCreator.cs
│ ├── PrimitiveRecordWriter.cs
│ ├── RecordCreator.cs
│ ├── RecordCreatorFactory.cs
│ ├── RecordHydrator.cs
│ ├── RecordManager.cs
│ ├── RecordWriter.cs
│ └── RecordWriterFactory.cs
│ ├── Factory.cs
│ ├── FastDynamicObject.cs
│ ├── FieldCache.cs
│ ├── FieldValidationException.cs
│ ├── HeaderValidationException.cs
│ ├── IFactory.cs
│ ├── IObjectResolver.cs
│ ├── IParser.cs
│ ├── IReader.cs
│ ├── IReaderRow.cs
│ ├── IWriter.cs
│ ├── IWriterRow.cs
│ ├── Icon.png
│ ├── InvalidHeader.cs
│ ├── LinkedListExtensions.cs
│ ├── MaxFieldSizeException.cs
│ ├── MissingFieldException.cs
│ ├── ObjectCreator.cs
│ ├── ObjectResolver.cs
│ ├── ParserException.cs
│ ├── Properties
│ └── AssemblyInfo.cs
│ ├── ReaderException.cs
│ ├── RecordTypeInfo.cs
│ ├── ReflectionExtensions.cs
│ ├── ReflectionHelper.cs
│ ├── TypeConversion
│ ├── ArrayConverter.cs
│ ├── BigIntegerConverter.cs
│ ├── BooleanConverter.cs
│ ├── ByteArrayConverter.cs
│ ├── ByteArrayConverterOptions.cs
│ ├── ByteConverter.cs
│ ├── CharConverter.cs
│ ├── CollectionConverterFactory.cs
│ ├── CollectionGenericConverter.cs
│ ├── DateOnlyConverter.cs
│ ├── DateTimeConverter.cs
│ ├── DateTimeOffsetConverter.cs
│ ├── DecimalConverter.cs
│ ├── DefaultTypeConverter.cs
│ ├── DoubleConverter.cs
│ ├── EnumConverter.cs
│ ├── EnumConverterFactory.cs
│ ├── EnumerableConverter.cs
│ ├── GuidConverter.cs
│ ├── IDictionaryConverter.cs
│ ├── IDictionaryGenericConverter.cs
│ ├── IEnumerableConverter.cs
│ ├── IEnumerableGenericConverter.cs
│ ├── ITypeConverter.cs
│ ├── ITypeConverterFactory.cs
│ ├── Int16Converter.cs
│ ├── Int32Converter.cs
│ ├── Int64Converter.cs
│ ├── NotSupportedTypeConverter.cs
│ ├── NullableConverter.cs
│ ├── NullableConverterFactory.cs
│ ├── SByteConverter.cs
│ ├── SingleConverter.cs
│ ├── StringConverter.cs
│ ├── TimeOnlyConverter.cs
│ ├── TimeSpanConverter.cs
│ ├── TypeConverter.cs
│ ├── TypeConverterCache.cs
│ ├── TypeConverterException.cs
│ ├── TypeConverterOptions.cs
│ ├── TypeConverterOptionsCache.cs
│ ├── UInt16Converter.cs
│ ├── UInt32Converter.cs
│ ├── UInt64Converter.cs
│ └── UriConverter.cs
│ ├── ValidationException.cs
│ └── WriterException.cs
└── tests
└── CsvHelper.Tests
├── ArrayHelperTests.cs
├── Async
├── ReadingTests.cs
└── WritingTests.cs
├── AutoMapping
├── AutoMappingTests.cs
├── BaseClassTests.cs
├── CircularReferenceTests.cs
├── ContextTests.cs
├── IgnoreReferencesTests.cs
├── MappingTypeOfTypeTest.cs
└── StructTests.cs
├── ClassMapOrderingTests.cs
├── Compatibility
└── IsExternalInit.cs
├── Configuration
├── ClassMapBuilderTests.cs
└── CsvClassMapCollectionTests.cs
├── CsvClassMappingAutoMapTests.cs
├── CsvConfigurationTests.cs
├── CsvHelper.Tests.csproj
├── CsvHelper.Tests.net452.v3.ncrunchproject
├── CsvHelper.Tests.net462.v3.ncrunchproject
├── CsvHelper.Tests.net47.v3.ncrunchproject
├── CsvHelper.Tests.net48.v3.ncrunchproject
├── CsvHelper.Tests.net50.v3.ncrunchproject
├── CsvHelper.Tests.net6.0.v3.ncrunchproject
├── CsvHelper.Tests.net7.0.v3.ncrunchproject
├── CsvHelper.Tests.net8.0.v3.ncrunchproject
├── CsvHelper.Tests.netcoreapp2.1.v3.ncrunchproject
├── CsvHelper.Tests.netcoreapp3.1.v3.ncrunchproject
├── CsvHelper.Tests.v3.ncrunchproject
├── CsvHelper.snk
├── CsvParserConstructorTests.cs
├── CsvParserDelimiterTests.cs
├── CsvParserRawRecordTests.cs
├── CsvParserTests.cs
├── CsvReaderConstructorTests.cs
├── CsvReaderDefaultValueTests.cs
├── CsvReaderDynamicMappingsTests.cs
├── CsvReaderErrorMessageTests.cs
├── CsvReaderMappingTests.cs
├── CsvReaderReferenceMappingPrefixTests.cs
├── CsvReaderReferenceMappingTests.cs
├── CsvReaderSubClassingTests.cs
├── CsvReaderTests.cs
├── CsvWriterBoxedTypesTests.cs
├── CsvWriterConstructorTests.cs
├── CsvWriterFormatTests.cs
├── CsvWriterMappingTests.cs
├── CsvWriterReferenceMappingPrefixTests.cs
├── CsvWriterReferenceMappingTests.cs
├── CsvWriterSubClassingTests.cs
├── CsvWriterTests.cs
├── Culture
└── TypeConverterOptionsFactoryTests.cs
├── DataTableTests
└── CsvDataReaderTests.cs
├── Defaults
└── WritingDefaultsTests.cs
├── DisposeTests.cs
├── Dynamic
└── FastDynamicTests.cs
├── DynamicProxyTests.cs
├── EnumerateRecordsTests.cs
├── Exceptions
├── ExceptionMessageTests.cs
└── ExceptionTests.cs
├── HeaderValidationTests.cs
├── Issues
├── Issue1341.cs
├── Issue1954.cs
├── Issue2060.cs
├── Issue2118.cs
└── Issue920.cs
├── LocalCultureTests.cs
├── MapPropertyMultipleTimesTests.cs
├── MappingInheritedClassTests.cs
├── Mappings
├── Attribute
│ ├── AllowCommentsTests.cs
│ ├── BooleanValuesTests.cs
│ ├── BufferSizeTests.cs
│ ├── CacheFieldsTests.cs
│ ├── CommentTests.cs
│ ├── ConstantTests.cs
│ ├── CountBytesTest.cs
│ ├── DateTimeStylesTests.cs
│ ├── DefaultTests.cs
│ ├── DelimiterTests.cs
│ ├── DetectColumnCountChangesTests.cs
│ ├── DetectDelimiterTests.cs
│ ├── DetectDelimiterValuesTests.cs
│ ├── EncodingTests.cs
│ ├── EnumIgnoreCaseTests.cs
│ ├── EscapeTests.cs
│ ├── ExceptionMessagesContainRawDataTests.cs
│ ├── FormatTests.cs
│ ├── HasHeaderRecordTests.cs
│ ├── HeaderPrefixTests.cs
│ ├── IgnoreBaseTests.cs
│ ├── IgnoreBlankLinesTests.cs
│ ├── IgnoreReferencesTests.cs
│ ├── IgnoreTests.cs
│ ├── IncludePrivateMembersTests.cs
│ ├── IndexTests.cs
│ ├── InjectionCharactersTests.cs
│ ├── InjectionEscapeCharacterTests.cs
│ ├── InjectionOptionsTests.cs
│ ├── LineBreakInQuotedFieldIsBadDataTests.cs
│ ├── MaxFieldSizeTests.cs
│ ├── MemberTypesTests.cs
│ ├── ModeTests.cs
│ ├── NameIndexTests.cs
│ ├── NameTests.cs
│ ├── NewLineTests.cs
│ ├── NullValuesTests.cs
│ ├── NumberStylesTests.cs
│ ├── OptionalTests.cs
│ ├── ProcessFieldBufferSizeTests.cs
│ ├── QuoteTests.cs
│ ├── ReferenceTests.cs
│ ├── TrimOptionsTests.cs
│ ├── TypeConverterTests.cs
│ ├── UseNewObjectForNullReferenceMembersTests.cs
│ └── WhiteSpaceCharsTests.cs
├── ConstructorParameter
│ ├── BooleanFalseValuesAttributeTests.cs
│ ├── BooleanFalseValuesMapTests.cs
│ ├── BooleanTrueValuesAttributeTests.cs
│ ├── BooleanTrueValuesMapTests.cs
│ ├── ConstantAttributeTests.cs
│ ├── ConstantMapTests.cs
│ ├── CultureInfoAttributeTests.cs
│ ├── CultureInfoMapTests.cs
│ ├── DateTimeStylesAttributeTests.cs
│ ├── DateTimeStylesMapTests.cs
│ ├── DefaultAttributeTests.cs
│ ├── DefaultMapTests.cs
│ ├── EnumIgnoreCaseTests.cs
│ ├── FormatAttributeTests.cs
│ ├── FormatMapTests.cs
│ ├── HeaderPrefixAttributeTests.cs
│ ├── HeaderPrefixMapTests.cs
│ ├── IgnoreAttributeTests.cs
│ ├── IgnoreMapTests.cs
│ ├── IndexAttributeTests.cs
│ ├── IndexMapTests.cs
│ ├── NameAttributeTests.cs
│ ├── NameIndexAttributeTests.cs
│ ├── NameIndexMapTests.cs
│ ├── NameMapTests.cs
│ ├── NullValuesAttributeTests.cs
│ ├── NullValuesMapTests.cs
│ ├── NumberStylesAttributeTests.cs
│ ├── NumberStylesMapTests.cs
│ ├── OptionalAttributeTests.cs
│ ├── OptionalMapTests.cs
│ ├── TypeConverterAttributeTests.cs
│ └── TypeConverterMapTests.cs
├── CsvClassMappingTests.cs
├── FieldMappingTests.cs
├── HiddenBaseMembersTests.cs
├── IgnoreHeaderWhiteSpaceTests.cs
├── MapConstructorTests.cs
├── MappingWithNoHeaderTests.cs
├── OptionalTests.cs
├── Property
│ └── ConstantTests.cs
├── ReferenceConstructorArgsTests.cs
├── RuntimeMapping.cs
└── SubPropertyMappingTests.cs
├── Mocks
├── DynamicObjectMock.cs
├── ParserMock.cs
├── ParserMockTests.cs
└── ReaderRowMock.cs
├── ObjectCreatorTests.cs
├── ObjectResolverTests
├── Issue1073.cs
└── ResolveSingleTypeTests.cs
├── Parsing
├── BadDataTests.cs
├── BufferSplittingEscapeAndQuoteTests.cs
├── BufferSplittingLineEndingTests.cs
├── BufferSplittingNewLineEndingTests.cs
├── ByteCountTests.cs
├── CharCountTests.cs
├── CommentTests.cs
├── CrTests.cs
├── CsvModeTests.cs
├── DelimiterTests.cs
├── DetectDelimiterTests.cs
├── EndBufferTests.cs
├── EscapeCharacterTests.cs
├── ExcelCompatibilityTests.cs
├── FieldCacheTests.cs
├── MaxFieldSizeTests.cs
├── NewLineTests.cs
├── RefillingTextReaderTests.cs
└── TrimTests.cs
├── Reading
├── AnonymousTypesTests.cs
├── BadDataTests.cs
├── ConstantTests.cs
├── ConstructorParametersTests.cs
├── DetectColumnCountChangesTests.cs
├── DynamicTests.cs
├── EmptyTextReaderTests.cs
├── MultipleGetRecordsTests.cs
├── MultipleHeadersTests.cs
├── NullableValuesInEmptyColumnsInputTests.cs
├── NumberReadingTests.cs
├── PrivateSettersInParentTests.cs
├── ReadHeaderTests.cs
├── ShouldSkipRecordTests.cs
├── TryGetTests.cs
├── ValidateTests.cs
└── YieldTests.cs
├── ReferenceMappingClassMapTests.cs
├── ReferenceMappingIndexTests.cs
├── Reflection
└── GetMemberExpressionStackTests.cs
├── TestStringBuilder.cs
├── TestStringWriter.cs
├── TypeConversion
├── ArrayConverterTests.cs
├── BigIntegerConverterTests.cs
├── BooleanConverterTests.cs
├── ByteArrayConverterTests.cs
├── ByteConverterTests.cs
├── CharConverterTests.cs
├── CollectionGenericConverterTests.cs
├── DateOnlyConverterTests.cs
├── DateTimeConverterTests.cs
├── DateTimeOffsetConverterTests.cs
├── DefaultConverterTests.cs
├── DefaultValueTests.cs
├── DoubleConverterTests.cs
├── EnumConverterTests.cs
├── EnumerableConverterTests.cs
├── GuidConverterTests.cs
├── IDictionaryConverterTests.cs
├── IDictionaryGenericConverterTests.cs
├── IEnumerableConverterTests.cs
├── IEnumerableGenericConverterTests.cs
├── NullableConverterTests.cs
├── SingleConverterTests.cs
├── TimeOnlyConverterTests.cs
├── TimeSpanConverterTests.cs
├── TypeConverterCacheTests.cs
├── TypeConverterFactoryTests.cs
├── TypeConverterOptionsFactoryTests.cs
├── TypeConverterOptionsTests.cs
├── TypeConverterTests.cs
├── TypeConverter`1Tests.cs
└── UriConverterTests.cs
├── Writing
├── AnonymousTypesTests.cs
├── ConstantTests.cs
├── CsvModeTests.cs
├── DynamicTests.cs
├── EnumerableTests.cs
├── FieldTypeTests.cs
├── IAsyncEnumerableTests.cs
├── IgnoreTests.cs
├── InterfaceTests.cs
├── MultipleFieldsFromOnePropertyTests.cs
├── MultipleHeadersTest.cs
├── NewLineTests.cs
├── NoPropertyMappingTests.cs
├── SanitizationTests.cs
├── ShouldQuoteTests.cs
├── TrimTests.cs
├── WriteBufferTests.cs
├── WriteCustomEscapeTests.cs
└── WriteNullTests.cs
├── XunitException.cs
└── xunit.runner.json
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | github: [JoshClose]
2 | open_collective: [csvhelper]
3 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us improve
4 | title: ''
5 | labels: bug
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Describe the bug**
11 | A clear and concise description of what the bug is.
12 |
13 | **To Reproduce**
14 | Provide a small working example that shows the issue.
15 |
16 | **Expected behavior**
17 | A clear and concise description of what you expected to happen.
18 |
19 | **Screenshots**
20 | If applicable, add screenshots to help explain your problem.
21 |
22 | **Additional context**
23 | Add any other context about the problem here.
24 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/config.yml:
--------------------------------------------------------------------------------
1 | blank_issues_enabled: false
2 | contact_links:
3 | - name: Questions
4 | url: https://stackoverflow.com/questions/tagged/csvhelper
5 | about: All questions should be directed to StackOverflow.
6 | Please only submit a question if no one has been able to answer your question on StackOverflow.
7 | I have very limited time to work on this project, and would prefer to use that time for bugs and features.
8 | Thanks.
9 | - name: Unanswered Questions
10 | url: https://github.com/JoshClose/CsvHelper/discussions?discussions_q=category%3AQ%26A
11 | about: If StackOverflow has failed you, you can ask a question on the disucssions board.
12 | Please add a link to your StackOverflow question so we can answer it in both places.
13 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/documentation.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Documentation
3 | about: Suggest documentation that needs to be added or changed
4 | title: ''
5 | labels: documentation
6 | assignees: ''
7 |
8 | ---
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature request
3 | about: Suggest an idea for this project
4 | title: ''
5 | labels: feature
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Is your feature request related to a problem? Please describe.**
11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12 |
13 | **Describe the solution you'd like**
14 | A clear and concise description of what you want to happen.
15 |
16 | **Describe alternatives you've considered**
17 | A clear and concise description of any alternative solutions or features you've considered.
18 |
19 | **Additional context**
20 | Add any other context or screenshots about the feature request here.
21 |
--------------------------------------------------------------------------------
/.github/workflows/ci.yaml:
--------------------------------------------------------------------------------
1 | name: CI
2 | on: [push, pull_request]
3 | jobs:
4 | ci:
5 | runs-on: windows-latest
6 | steps:
7 | - name: Checkout
8 | uses: actions/checkout@v4
9 | with:
10 | fetch-depth: 0
11 | - name: Setup .NET Core
12 | uses: actions/setup-dotnet@v4
13 | - name: Display .NET Version
14 | run: dotnet --version
15 | - name: Restore
16 | run: dotnet restore
17 | - name: Build
18 | run: dotnet build --configuration Release --no-restore
19 | - name: Test
20 | run: dotnet test --configuration Release --no-restore --no-build
21 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .vs/
2 | bin/
3 | obj/
4 | *NCrunch*/
5 | artifacts/
6 | .tmp/
7 | cache/
8 | .idea/
9 |
10 | *.user
11 | *.psess
12 | *.log
13 |
--------------------------------------------------------------------------------
/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | // Use IntelliSense to find out which attributes exist for C# debugging
3 | // Use hover for the description of the existing attributes
4 | // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
5 | "version": "0.2.0",
6 | "configurations": [
7 | {
8 | "name": ".NET Core Launch (console)",
9 | "type": "coreclr",
10 | "request": "launch",
11 | "preLaunchTask": "build",
12 | // If you have changed target frameworks, make sure to update the program path.
13 | "program": "${workspaceFolder}/src/CsvHelper.Tests/bin/Debug/netcoreapp2.0/CsvHelper.Tests.dll",
14 | "args": [],
15 | "cwd": "${workspaceFolder}/src/CsvHelper.Tests",
16 | // For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window
17 | "console": "internalConsole",
18 | "stopAtEntry": false,
19 | "internalConsoleOptions": "openOnSessionStart"
20 | },
21 | {
22 | "name": ".NET Core Attach",
23 | "type": "coreclr",
24 | "request": "attach",
25 | "processId": "${command:pickProcess}"
26 | }
27 | ,]
28 | }
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "editor.trimAutoWhitespace": false
3 | }
--------------------------------------------------------------------------------
/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "2.0.0",
3 | "tasks": [
4 | {
5 | "label": "build",
6 | "command": "dotnet",
7 | "type": "process",
8 | "args": [
9 | "build",
10 | "${workspaceFolder}/src/CsvHelper.Tests/CsvHelper.Tests.csproj"
11 | ],
12 | "problemMatcher": "$msCompile"
13 | }
14 | ]
15 | }
--------------------------------------------------------------------------------
/CsvHelper.v3.ncrunchsolution:
--------------------------------------------------------------------------------
1 |
2 |
3 | True
4 | Optimised
5 | True
6 | True
7 |
8 |
--------------------------------------------------------------------------------
/CsvHelperDependencies.linq:
--------------------------------------------------------------------------------
1 |
2 |
3 | var el = XElement.Load(@"https://packages.nuget.org/v1/FeedService.svc/Packages?$filter=substringof(%27CsvHelper%27,%20Dependencies)%20eq%20true&$select=Id,Dependencies");
4 | //el.Attributes().Dump();
5 | XNamespace nsm = "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata";
6 | XNamespace nsd = "http://schemas.microsoft.com/ado/2007/08/dataservices";
7 | el.Descendants(nsd + "Id").Select(n => n.Value).Distinct().Dump();
8 | el.Dump();
9 |
--------------------------------------------------------------------------------
/GitVersion.yml:
--------------------------------------------------------------------------------
1 | #next-version: 21.0.5
2 | assembly-versioning-scheme: Major
3 | assembly-file-versioning-format: '{Major}.{Minor}.{Patch}.{env:BUILD_NUMBER ?? 0}'
4 | branches:
5 | configuration-constructor:
6 | regex: configuration-constructor
7 | source-branches: [ 'master' ]
8 | tag: beta
9 | ignore:
10 | sha: []
11 | merge-message-formats: {}
12 |
--------------------------------------------------------------------------------
/Unity Build.bat:
--------------------------------------------------------------------------------
1 | rmdir /S /Q unity\Assets\CsvHelper
2 |
3 | dotnet build src\CsvHelper\CsvHelper.csproj -c release -o ..\..\unity\Assets\CsvHelper
4 |
5 | pause
6 |
--------------------------------------------------------------------------------
/build-docs.cmd:
--------------------------------------------------------------------------------
1 | dotnet run --project src\CsvHelper.Website --configuration Release -- -o ..\..\docs
2 | pause
3 |
--------------------------------------------------------------------------------
/docs-src/CsvHelper.DocsGenerator/CsvHelper.DocsGenerator.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp2.2
6 | latest
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/docs-src/CsvHelper.DocsGenerator/EncodingType.cs:
--------------------------------------------------------------------------------
1 | namespace CsvHelper.DocsGenerator
2 | {
3 | public enum EncodingType
4 | {
5 | // Generic<Parameter>
6 | Html = 0,
7 |
8 | // Generic
9 | Code = 1,
10 |
11 | // Generic{Parameter}
12 | Xml = 2
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/docs-src/CsvHelper.DocsGenerator/Formatters/Symbols.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Linq;
3 |
4 | namespace CsvHelper.DocsGenerator.Formatters
5 | {
6 | public static class Symbols
7 | {
8 | public static readonly Dictionary Html = new Dictionary
9 | {
10 | { "<", "<" },
11 | { ">", ">" },
12 | { "[", "[" },
13 | { "]", "]" }
14 | };
15 |
16 | public static readonly Dictionary Code = new Dictionary(Html.Select(pair => new KeyValuePair(pair.Key, pair.Key)));
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/docs-src/CsvHelper.DocsGenerator/Generators/AssemblyGenerator.cs:
--------------------------------------------------------------------------------
1 | using CsvHelper.DocsGenerator.Infos;
2 |
3 | namespace CsvHelper.DocsGenerator.Generators
4 | {
5 | public class AssemblyGenerator : DocumentGenerator
6 | {
7 | public AssemblyGenerator(AssemblyInfo assemblyInfo) : base(assemblyInfo) { }
8 |
9 | protected override void GenerateContent()
10 | {
11 | content.AppendLine($"# {assemblyInfo.Assembly.GetName().Name} Namespaces");
12 | content.AppendLine();
13 | content.AppendLine("## Namespaces");
14 | content.AppendLine(" | ");
15 | content.AppendLine("- | -");
16 | foreach (var @namespace in assemblyInfo.Namespaces)
17 | {
18 | content.AppendLine($"[{@namespace.Namespace}](/api/{@namespace.Namespace}) | ");
19 | }
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/docs-src/CsvHelper.DocsGenerator/Generators/DocumentGenerator.cs:
--------------------------------------------------------------------------------
1 | using CsvHelper.DocsGenerator.Infos;
2 | using System;
3 | using System.Text;
4 |
5 | namespace CsvHelper.DocsGenerator.Generators
6 | {
7 | public abstract class DocumentGenerator
8 | {
9 | //protected readonly HtmlFormatter htmlFormatter = new HtmlFormatter();
10 | protected readonly LinkGenerator linkGenerator = new LinkGenerator();
11 | protected readonly AssemblyInfo assemblyInfo;
12 | protected readonly NamespaceInfo namespaceInfo;
13 | protected readonly TypeInfo typeInfo;
14 | protected readonly StringBuilder content = new StringBuilder();
15 |
16 | public DocumentGenerator(AssemblyInfo assemblyInfo)
17 | {
18 | this.assemblyInfo = assemblyInfo ?? throw new ArgumentNullException(nameof(assemblyInfo));
19 | }
20 |
21 | public DocumentGenerator(NamespaceInfo namespaceInfo)
22 | {
23 | this.namespaceInfo = namespaceInfo;
24 | }
25 |
26 | public DocumentGenerator(TypeInfo typeInfo)
27 | {
28 | this.typeInfo = typeInfo ?? throw new ArgumentNullException(nameof(typeInfo));
29 | }
30 |
31 | public string Generate()
32 | {
33 | content.Clear();
34 |
35 | GenerateContent();
36 |
37 | return content.ToString();
38 | }
39 |
40 | protected abstract void GenerateContent();
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/docs-src/CsvHelper.DocsGenerator/Generators/DocumentGeneratorFactory.cs:
--------------------------------------------------------------------------------
1 | using CsvHelper.DocsGenerator.Infos;
2 |
3 | namespace CsvHelper.DocsGenerator.Generators
4 | {
5 | public class DocumentGeneratorFactory
6 | {
7 | public DocumentGenerator Create(AssemblyInfo assemblyInfo)
8 | {
9 | return new AssemblyGenerator(assemblyInfo);
10 | }
11 |
12 | public DocumentGenerator Create(NamespaceInfo namespaceInfo)
13 | {
14 | return new NamespaceGenerator(namespaceInfo);
15 | }
16 |
17 | public DocumentGenerator Create(TypeInfo typeInfo)
18 | {
19 | return new TypeGenerator(typeInfo);
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/docs-src/CsvHelper.DocsGenerator/Infos/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Diagnostics;
3 | using System.Linq;
4 | using System.Reflection;
5 | using System.Xml.Linq;
6 |
7 | namespace CsvHelper.DocsGenerator.Infos
8 | {
9 | [DebuggerDisplay("Name = {Name}")]
10 | public class AssemblyInfo : Info
11 | {
12 | public Assembly Assembly { get; protected set; }
13 |
14 | public List Namespaces { get; private set; }
15 |
16 | public AssemblyInfo(Assembly assembly, XElement xmlDocs)
17 | {
18 | Assembly = assembly;
19 |
20 | Namespaces =
21 | (
22 | from type in assembly.GetTypes()
23 | where type.IsPublic
24 | orderby type.Namespace ascending, type.Name ascending
25 | group type by type.Namespace into g
26 | select new NamespaceInfo(this, g.Key, g.ToList(), xmlDocs)
27 | ).ToList();
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/docs-src/CsvHelper.DocsGenerator/Infos/ConstructorInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Linq;
3 | using System.Xml.Linq;
4 |
5 | namespace CsvHelper.DocsGenerator.Infos
6 | {
7 | public class ConstructorInfo : Info
8 | {
9 | public System.Reflection.ConstructorInfo Constructor { get; private set; }
10 |
11 | public List Parameters { get; private set; }
12 |
13 | public ConstructorInfo(System.Reflection.ConstructorInfo constructorInfo, XElement xmlDocs)
14 | {
15 | Constructor = constructorInfo;
16 |
17 | Parameters = constructorInfo.GetParameters().ToList();
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/docs-src/CsvHelper.DocsGenerator/Infos/MethodInfo.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Xml.Linq;
5 |
6 | namespace CsvHelper.DocsGenerator.Infos
7 | {
8 | public class MethodInfo : Info
9 | {
10 | public System.Reflection.MethodInfo Method { get; private set; }
11 |
12 | public List Parameters { get; private set; }
13 |
14 | public List GenericArguments { get; private set; }
15 |
16 | public MethodInfo(System.Reflection.MethodInfo methodInfo, XElement xmlDocs)
17 | {
18 | Method = methodInfo;
19 |
20 | Parameters = methodInfo.GetParameters().ToList();
21 |
22 | GenericArguments = methodInfo.GetGenericArguments().ToList();
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/docs-src/CsvHelper.DocsGenerator/Infos/PropertyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Linq;
3 | using System.Xml.Linq;
4 |
5 | namespace CsvHelper.DocsGenerator.Infos
6 | {
7 | public class PropertyInfo : Info
8 | {
9 | public List IndexParameters { get; protected set; }
10 |
11 | public TypeInfo Type { get; protected set; }
12 |
13 | public System.Reflection.PropertyInfo Property { get; protected set; }
14 |
15 | public PropertyInfo(TypeInfo type, System.Reflection.PropertyInfo propertyInfo, XElement xmlDocs)
16 | {
17 | Type = type;
18 |
19 | Property = propertyInfo;
20 |
21 | IndexParameters = propertyInfo.GetIndexParameters().ToList();
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/docs-src/CsvHelper.DocsGenerator/LinkGenerator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace CsvHelper.DocsGenerator
4 | {
5 | public class LinkGenerator
6 | {
7 | public string GenerateLink(Type type)
8 | {
9 | if (type.Namespace.StartsWith("CsvHelper"))
10 | {
11 | return $"[{type.Name}](/api/{type.Namespace}/{type.Name})";
12 | }
13 |
14 | var fullName = $"{type.Namespace}.{type.Name}";
15 |
16 | return $"[{type.Name}](https://docs.microsoft.com/en-us/dotnet/api/{fullName.ToLower()})";
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/docs-src/CsvHelper.DocsGenerator/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace CsvHelper.DocsGenerator
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | new Startup()
10 | .Configure()
11 | .Run();
12 |
13 | Console.WriteLine();
14 | Console.WriteLine("Press any key to exit.");
15 | Console.ReadKey();
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/docs-src/CsvHelper.DocsGenerator/XmlDocs.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Xml.Linq;
3 |
4 | namespace CsvHelper.DocsGenerator
5 | {
6 | public static class XmlDocs
7 | {
8 | private static readonly Lazy lazy = new Lazy(() => XElement.Load("CsvHelper.xml"));
9 |
10 | public static XElement XElement => lazy.Value;
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/docs/.nojekyll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/docs/.nojekyll
--------------------------------------------------------------------------------
/docs/browserconfig.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | #ffffff
9 |
10 |
11 |
--------------------------------------------------------------------------------
/docs/favicons/android-icon-144x144.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/docs/favicons/android-icon-144x144.png
--------------------------------------------------------------------------------
/docs/favicons/android-icon-192x192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/docs/favicons/android-icon-192x192.png
--------------------------------------------------------------------------------
/docs/favicons/android-icon-36x36.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/docs/favicons/android-icon-36x36.png
--------------------------------------------------------------------------------
/docs/favicons/android-icon-48x48.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/docs/favicons/android-icon-48x48.png
--------------------------------------------------------------------------------
/docs/favicons/android-icon-72x72.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/docs/favicons/android-icon-72x72.png
--------------------------------------------------------------------------------
/docs/favicons/android-icon-96x96.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/docs/favicons/android-icon-96x96.png
--------------------------------------------------------------------------------
/docs/favicons/apple-icon-114x114.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/docs/favicons/apple-icon-114x114.png
--------------------------------------------------------------------------------
/docs/favicons/apple-icon-120x120.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/docs/favicons/apple-icon-120x120.png
--------------------------------------------------------------------------------
/docs/favicons/apple-icon-144x144.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/docs/favicons/apple-icon-144x144.png
--------------------------------------------------------------------------------
/docs/favicons/apple-icon-152x152.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/docs/favicons/apple-icon-152x152.png
--------------------------------------------------------------------------------
/docs/favicons/apple-icon-180x180.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/docs/favicons/apple-icon-180x180.png
--------------------------------------------------------------------------------
/docs/favicons/apple-icon-57x57.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/docs/favicons/apple-icon-57x57.png
--------------------------------------------------------------------------------
/docs/favicons/apple-icon-60x60.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/docs/favicons/apple-icon-60x60.png
--------------------------------------------------------------------------------
/docs/favicons/apple-icon-72x72.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/docs/favicons/apple-icon-72x72.png
--------------------------------------------------------------------------------
/docs/favicons/apple-icon-76x76.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/docs/favicons/apple-icon-76x76.png
--------------------------------------------------------------------------------
/docs/favicons/apple-icon-precomposed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/docs/favicons/apple-icon-precomposed.png
--------------------------------------------------------------------------------
/docs/favicons/apple-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/docs/favicons/apple-icon.png
--------------------------------------------------------------------------------
/docs/favicons/favicon-16x16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/docs/favicons/favicon-16x16.png
--------------------------------------------------------------------------------
/docs/favicons/favicon-32x32.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/docs/favicons/favicon-32x32.png
--------------------------------------------------------------------------------
/docs/favicons/favicon-96x96.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/docs/favicons/favicon-96x96.png
--------------------------------------------------------------------------------
/docs/favicons/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/docs/favicons/favicon.ico
--------------------------------------------------------------------------------
/docs/favicons/ms-icon-144x144.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/docs/favicons/ms-icon-144x144.png
--------------------------------------------------------------------------------
/docs/favicons/ms-icon-150x150.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/docs/favicons/ms-icon-150x150.png
--------------------------------------------------------------------------------
/docs/favicons/ms-icon-310x310.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/docs/favicons/ms-icon-310x310.png
--------------------------------------------------------------------------------
/docs/favicons/ms-icon-70x70.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/docs/favicons/ms-icon-70x70.png
--------------------------------------------------------------------------------
/docs/images/aws.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/docs/images/aws.png
--------------------------------------------------------------------------------
/docs/images/microsoft.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/docs/images/microsoft.png
--------------------------------------------------------------------------------
/docs/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "App",
3 | "icons": [
4 | {
5 | "src": "\/android-icon-36x36.png",
6 | "sizes": "36x36",
7 | "type": "image\/png",
8 | "density": "0.75"
9 | },
10 | {
11 | "src": "\/android-icon-48x48.png",
12 | "sizes": "48x48",
13 | "type": "image\/png",
14 | "density": "1.0"
15 | },
16 | {
17 | "src": "\/android-icon-72x72.png",
18 | "sizes": "72x72",
19 | "type": "image\/png",
20 | "density": "1.5"
21 | },
22 | {
23 | "src": "\/android-icon-96x96.png",
24 | "sizes": "96x96",
25 | "type": "image\/png",
26 | "density": "2.0"
27 | },
28 | {
29 | "src": "\/android-icon-144x144.png",
30 | "sizes": "144x144",
31 | "type": "image\/png",
32 | "density": "3.0"
33 | },
34 | {
35 | "src": "\/android-icon-192x192.png",
36 | "sizes": "192x192",
37 | "type": "image\/png",
38 | "density": "4.0"
39 | }
40 | ]
41 | }
--------------------------------------------------------------------------------
/docs/robots.txt:
--------------------------------------------------------------------------------
1 | User-agent: *
2 |
--------------------------------------------------------------------------------
/docs/scripts/header.js:
--------------------------------------------------------------------------------
1 | (() => {
2 | document.getElementById("navbar-burger").addEventListener("click", () => {
3 | document.getElementById("navbar-burger").classList.toggle("is-active");
4 | document.getElementById("navbar-menu").classList.toggle("is-active");
5 | });
6 | });
7 |
--------------------------------------------------------------------------------
/docs/styles/base.css:
--------------------------------------------------------------------------------
1 | html, body { height: 100vh; }
2 |
3 | body { display: flex; flex-direction: column; }
4 |
--------------------------------------------------------------------------------
/docs/styles/content.css:
--------------------------------------------------------------------------------
1 | pre code.hljs { background-color: transparent; }
2 |
--------------------------------------------------------------------------------
/docs/styles/header.css:
--------------------------------------------------------------------------------
1 | @media screen and (min-width: 769px) { nav { padding: 0 1.5em; } }
2 |
--------------------------------------------------------------------------------
/docs/styles/index.css:
--------------------------------------------------------------------------------
1 | html, body { height: 100vh; }
2 |
3 | body { display: flex; flex-direction: column; }
4 |
5 | @media screen and (min-width: 769px) { nav { padding: 0 1.5em; } }
6 |
7 | pre code.hljs { background-color: transparent; }
8 |
9 | .expander { position: absolute; font-size: 1.5rem; transform: rotate(0deg); top: -3px; left: 0; }
10 |
11 | .expander::before { content: "\203A"; }
12 |
13 | .expander.expanded { left: 4px; top: 2px; transform: rotate(90deg); }
14 |
15 | .sidebar { display: flex; position: fixed; overflow-x: hidden; overflow-y: auto; }
16 |
17 | .sidebar ul li { line-height: 2rem; padding-left: 1em; position: relative; }
18 |
19 | .sidebar ul li a { color: #4a4a4a; }
20 |
21 | .sidebar ul li a:not(.expander):hover { text-decoration: underline; }
22 |
--------------------------------------------------------------------------------
/docs/styles/sidebar.css:
--------------------------------------------------------------------------------
1 | .expander { position: absolute; font-size: 1.5rem; transform: rotate(0deg); top: -3px; left: 0; }
2 |
3 | .expander::before { content: "\203A"; }
4 |
5 | .expander.expanded { left: 4px; top: 2px; transform: rotate(90deg); }
6 |
7 | .sidebar { display: flex; position: fixed; overflow-x: hidden; overflow-y: auto; }
8 |
9 | .sidebar ul li { line-height: 2rem; padding-left: 1em; position: relative; }
10 |
11 | .sidebar ul li a { color: #4a4a4a; }
12 |
13 | .sidebar ul li a:not(.expander):hover { text-decoration: underline; }
14 |
--------------------------------------------------------------------------------
/logo/CSV Helper logo.ai:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/logo/CSV Helper logo.ai
--------------------------------------------------------------------------------
/logo/CSV Helper logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/logo/CSV Helper logo.png
--------------------------------------------------------------------------------
/logo/CSV-Helper-logo-Web.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/logo/CSV-Helper-logo-Web.jpg
--------------------------------------------------------------------------------
/logo/CSV-Helper-logo-Web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/logo/CSV-Helper-logo-Web.png
--------------------------------------------------------------------------------
/logo/Comma-Small.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/logo/Comma-Small.jpg
--------------------------------------------------------------------------------
/logo/Comma-Small.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/logo/Comma-Small.png
--------------------------------------------------------------------------------
/logo/Comma.ai:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/logo/Comma.ai
--------------------------------------------------------------------------------
/logo/aws.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/logo/aws.png
--------------------------------------------------------------------------------
/logo/microsoft.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/logo/microsoft.png
--------------------------------------------------------------------------------
/performance/CsvHelper.Benchmarks/BenchmarkMain.cs:
--------------------------------------------------------------------------------
1 | using BenchmarkDotNet.Running;
2 |
3 | namespace CsvHelper.Benchmarks;
4 |
5 | internal class BenchmarkMain
6 | {
7 | static void Main(string[] args)
8 | {
9 | _ = BenchmarkRunner.Run();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/performance/CsvHelper.Benchmarks/CsvHelper.Benchmarks.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net9.0
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/.gitignore:
--------------------------------------------------------------------------------
1 | output/
--------------------------------------------------------------------------------
/src/CsvHelper.Website/CsvHelper.Website.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net6.0
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/CsvHelper.Website.v3.ncrunchproject:
--------------------------------------------------------------------------------
1 |
2 |
3 | True
4 |
5 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/Program.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using System;
6 | using System.Threading.Tasks;
7 | using Statiq.App;
8 | using Statiq.Common;
9 | using Statiq.Markdown;
10 | using Statiq.Web;
11 |
12 | namespace CsvHelper.Docs
13 | {
14 | class Program
15 | {
16 | static async Task Main(string[] args) => await Bootstrapper
17 | .Factory
18 | .CreateWeb(args)
19 | .RunAsync();
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/README.md:
--------------------------------------------------------------------------------
1 | ## Preview the docs locally
2 |
3 | ```
4 | > dotnet run -- preview --virtual-dir CsvHelper
5 | ```
6 |
7 | Open browser to http://localhost:5080/CsvHelper
8 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/TocItem.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using Statiq.Common;
6 | using System;
7 | using System.Collections.Generic;
8 | using System.Linq;
9 | using System.Text;
10 | using System.Threading.Tasks;
11 |
12 | namespace CsvHelper.Website
13 | {
14 | public class TocItem
15 | {
16 | public string Title { get; set; }
17 |
18 | public string Link { get; set; }
19 |
20 | public List Children { get; set; } = new List();
21 |
22 | public static TocItem Create(IMetadataDictionary data)
23 | {
24 | var tocItem = new TocItem()
25 | {
26 | Title = data.Get("title"),
27 | Link = data.Get("link"),
28 | };
29 |
30 | if (data.ContainsKey("children"))
31 | {
32 | tocItem.Children = Create(data.GetList("children"));
33 | }
34 |
35 | return tocItem;
36 | }
37 |
38 | public static List Create(IEnumerable objects, TocItem parent = null) => objects?.Select(Create).ToList() ?? new List();
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/.nojekyll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/src/CsvHelper.Website/input/.nojekyll
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/Shared/_Footer.cshtml:
--------------------------------------------------------------------------------
1 |
4 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/Shared/_Metadata.cshtml:
--------------------------------------------------------------------------------
1 |
2 |
3 | @foreach (var key in Metadata.Keys)
4 | {
5 |
6 | @key
7 | @Metadata[key]
8 |
9 | }
10 |
11 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/Shared/_SideBar.cshtml:
--------------------------------------------------------------------------------
1 | @{
2 | var items = TocItem.Create(Metadata.GetList("toc"));
3 | items.Add(new TocItem { Title = "Back to top", Link = "#" });
4 | ViewBag.ShowChildren = true;
5 | }
6 |
7 |
10 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/Shared/_TocItem.cshtml:
--------------------------------------------------------------------------------
1 | @inherits StatiqRazorPage
2 |
3 |
4 | @if (Model.Children.Count > 0)
5 | {
6 |
7 | }
8 |
9 | @Model.Title
10 |
11 |
12 | @if (Model.Children.Any())
13 | {
14 |
15 | }
16 |
17 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/Shared/_TocItems.cshtml:
--------------------------------------------------------------------------------
1 | @inherits StatiqRazorPage>
2 | @{
3 | var c = ViewBag.ShowChildren ? string.Empty : "is-hidden";
4 | ViewBag.showChildren = false;
5 | }
6 |
7 | @foreach (var item in Model)
8 | {
9 |
10 | }
11 |
12 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/_ViewImports.cshtml:
--------------------------------------------------------------------------------
1 | @using Statiq.Common
2 | @using Statiq.Razor
3 | @using Statiq.Web
4 | @using Statiq.Web.Pipelines
5 | @using Microsoft.Extensions.Logging
6 | @using CsvHelper.Website;
7 | @using Newtonsoft.Json;
8 |
9 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
10 | @inherits StatiqRazorPage
11 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/_ViewStart.cshtml:
--------------------------------------------------------------------------------
1 | @{
2 | Layout = @"Shared/_Layout.cshtml";
3 | }
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/_manifest.yml:
--------------------------------------------------------------------------------
1 | ContentType: Asset
2 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/api/Index.md:
--------------------------------------------------------------------------------
1 | # Coming soon...
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/browserconfig.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | #ffffff
9 |
10 |
11 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/examples/configuration/class-maps/auto-mapping/index.md:
--------------------------------------------------------------------------------
1 | # Auto Mapping
2 |
3 | If you don't supply a map to the configuration, one is automatically created for you on the fly. You can call auto mapping directly in your class map also. You may want to do this if you have a large number of properties that will be set up correctly by default, and only need to make a couple changes.
4 |
5 | ###### Data
6 |
7 | ```
8 | Id,The Name
9 | 1,one
10 | ```
11 |
12 | ###### Example
13 |
14 | ```cs
15 | void Main()
16 | {
17 | using (var reader = new StreamReader("path\\to\\file.csv"))
18 | using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
19 | {
20 | csv.Context.RegisterClassMap();
21 | var records = csv.GetRecords();
22 | }
23 | }
24 |
25 | public class Foo
26 | {
27 | public int Id { get; set; }
28 | public string Name { get; set; }
29 | }
30 |
31 | public sealed class FooMap : ClassMap
32 | {
33 | public FooMap()
34 | {
35 | AutoMap(CultureInfo.InvariantCulture);
36 | Map(m => m.Name).Name("The Name");
37 | }
38 | }
39 | ```
40 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/examples/configuration/class-maps/constant-value/index.md:
--------------------------------------------------------------------------------
1 | # Constant Value
2 |
3 | You can set a constant value to a property instead of mapping it to a field.
4 |
5 | ###### Data
6 |
7 | ```
8 | Id,Name
9 | 1,one
10 | ```
11 |
12 | ###### Example
13 |
14 | ```cs
15 | void Main()
16 | {
17 | using (var reader = new StreamReader("path\\to\\file.csv"))
18 | using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
19 | {
20 | csv.Context.RegisterClassMap();
21 | var records = csv.GetRecords();
22 | }
23 | }
24 |
25 | public class Foo
26 | {
27 | public int Id { get; set; }
28 | public string Name { get; set; }
29 | public bool IsDirty { get; set; }
30 | }
31 |
32 | public sealed class FooMap : ClassMap
33 | {
34 | public FooMap()
35 | {
36 | Map(m => m.Id);
37 | Map(m => m.Name);
38 | Map(m => m.IsDirty).Constant(true);
39 | }
40 | }
41 | ```
42 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/examples/configuration/class-maps/ignoring-properties/index.md:
--------------------------------------------------------------------------------
1 | # Ignoring Properties
2 |
3 | When you use auto mapping in your class map, every property will get mapped. If there are properties that you don't want mapped, you can ignore them.
4 |
5 | ###### Data
6 |
7 | ```
8 | Id,Name
9 | 1,one
10 | ```
11 |
12 | ###### Example
13 |
14 | ```cs
15 | void Main()
16 | {
17 | using (var reader = new StreamReader("path\\to\\file.csv"))
18 | using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
19 | {
20 | csv.Context.RegisterClassMap();
21 | var records = csv.GetRecords();
22 | }
23 | }
24 |
25 | public class Foo
26 | {
27 | public int Id { get; set; }
28 | public string Name { get; set; }
29 | public bool IsDirty { get; set; }
30 | }
31 |
32 | public sealed class FooMap : ClassMap
33 | {
34 | public FooMap()
35 | {
36 | AutoMap(CultureInfo.InvariantCulture);
37 | Map(m => m.IsDirty).Ignore();
38 | }
39 | }
40 | ```
41 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/examples/configuration/class-maps/mapping-by-alternate-names/index.md:
--------------------------------------------------------------------------------
1 | # Mapping by Alternate Names
2 |
3 | If you have a header name that could vary, you can specify multiple header names.
4 |
5 | ###### Data
6 |
7 | ```
8 | Id,Name
9 | 1,one
10 | ```
11 |
12 | ###### Example
13 |
14 | ```cs
15 | void Main()
16 | {
17 | using (var reader = new StreamReader("path\\to\\file.csv"))
18 | using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
19 | {
20 | csv.Context.RegisterClassMap();
21 | var records = csv.GetRecords();
22 | }
23 | }
24 |
25 | public class Foo
26 | {
27 | public int Id { get; set; }
28 | public string Name { get set; }
29 | }
30 |
31 | public sealed class FooMap : ClassMap
32 | {
33 | public FooMap()
34 | {
35 | Map(m => m.Id).Name("TheId", "Id");
36 | Map(m => m.Name).Name("TheName", "Name");
37 | }
38 | }
39 | ```
40 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/examples/configuration/class-maps/mapping-by-index/index.md:
--------------------------------------------------------------------------------
1 | # Mapping by Index
2 |
3 | If your data doesn't have a header you can map by index instead of name. You can't rely on the order of class properties in .NET, so if you're not mapping by name, make sure you specify an index.
4 |
5 | ###### Data
6 | ```
7 | 1,one
8 | ```
9 |
10 | ###### Example
11 |
12 | ```cs
13 | void Main()
14 | {
15 | var config = new CsvConfiguration(CultureInfo.InvariantCulture)
16 | {
17 | HasHeaderRecord = false,
18 | };
19 | using (var reader = new StreamReader("path\\to\\file.csv"))
20 | using (var csv = new CsvReader(reader, config))
21 | {
22 | csv.Context.RegisterClassMap();
23 | var records = csv.GetRecords();
24 | }
25 | }
26 |
27 | public class Foo
28 | {
29 | public int Id { get; set; }
30 | public string Name { get set; }
31 | }
32 |
33 | public sealed class FooMap : ClassMap
34 | {
35 | public FooMap()
36 | {
37 | Map(m => m.Id).Index(0);
38 | Map(m => m.Name).Index(1);
39 | }
40 | }
41 | ```
42 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/examples/configuration/class-maps/mapping-by-name/index.md:
--------------------------------------------------------------------------------
1 | # Mapping by Name
2 |
3 | If your property names don't match your class names, you can map the property to the column by name.
4 |
5 | ###### Data
6 |
7 | ```
8 | ColumnA,ColumnB
9 | 1,one
10 | ```
11 |
12 | ###### Example
13 |
14 | ```cs
15 | void Main()
16 | {
17 | using (var reader = new StreamReader("path\\to\\file.csv"))
18 | using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
19 | {
20 | csv.Context.RegisterClassMap();
21 | var records = csv.GetRecords();
22 | }
23 | }
24 |
25 | public class Foo
26 | {
27 | public int Id { get; set; }
28 | public string Name { get set; }
29 | }
30 |
31 | public sealed class FooMap : ClassMap
32 | {
33 | public FooMap()
34 | {
35 | Map(m => m.Id).Name("ColumnA");
36 | Map(m => m.Name).Name("ColumnB");
37 | }
38 | }
39 | ```
40 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/examples/configuration/class-maps/mapping-duplicate-names/index.md:
--------------------------------------------------------------------------------
1 | # Mapping Duplicate Names
2 |
3 | Sometimes you have duplicate header names. This is handled through a header name index. The name index is the index of how many occurrences of that header name there are, not the position of the header.
4 |
5 | ###### Data
6 |
7 | ```
8 | Id,Name,Name
9 | 1,first,last
10 | ```
11 |
12 | ###### Example
13 |
14 | ```cs
15 | void Main()
16 | {
17 | using (var reader = new StreamReader("path\\to\\file.csv"))
18 | using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
19 | {
20 | csv.Context.RegisterClassMap();
21 | var records = csv.GetRecords();
22 | }
23 | }
24 |
25 | public class Foo
26 | {
27 | public int Id { get; set; }
28 | public string FirstName { get set; }
29 | public string LastName { get; set; }
30 | }
31 |
32 | public sealed class FooMap : ClassMap
33 | {
34 | public FooMap()
35 | {
36 | Map(m => m.Id);
37 | Map(m => m.FirstName).Name("Name").NameIndex(0);
38 | Map(m => m.LastName).Name("Name").NameIndex(1);
39 | }
40 | }
41 | ```
42 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/examples/configuration/class-maps/mapping-properties/index.md:
--------------------------------------------------------------------------------
1 | # Mapping Properties
2 |
3 | This will map the properties of a class to the header names of the CSV data. The mapping needs to be registered in the context. This example is identical to not using a class mapping at all. The headers match the property names.
4 |
5 | ###### Data
6 |
7 | ```
8 | Id,Name
9 | 1,one
10 | ```
11 |
12 | ###### Example
13 |
14 | ```cs
15 | void Main()
16 | {
17 | using (var reader = new StreamReader("path\\to\\file.csv"))
18 | using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
19 | {
20 | csv.Context.RegisterClassMap();
21 | var records = csv.GetRecords();
22 | }
23 | }
24 |
25 | public class Foo
26 | {
27 | public int Id { get; set; }
28 | public string Name { get; set; }
29 | }
30 |
31 | public sealed class FooMap : ClassMap
32 | {
33 | public FooMap()
34 | {
35 | Map(m => m.Id);
36 | Map(m => m.Name);
37 | }
38 | }
39 | ```
40 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/examples/configuration/class-maps/optional-maps/index.md:
--------------------------------------------------------------------------------
1 | # Optional Maps
2 |
3 | If you have data that may or may not have a header, you can make the mapping optional.
4 |
5 | ###### Data
6 |
7 | ```
8 | Id,Name
9 | 1,one
10 | ```
11 |
12 | ###### Example
13 |
14 | ```cs
15 | void Main()
16 | {
17 | using (var reader = new StreamReader("path\\to\\file.csv"))
18 | using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
19 | {
20 | csv.Context.RegisterClassMap();
21 | csv.GetRecords().ToList().Dump();
22 | }
23 | }
24 |
25 | public class Foo
26 | {
27 | public int Id { get; set; }
28 | public string Name { get; set; }
29 | public DateTimeOffset? Date { get; set; }
30 | }
31 |
32 | public class FooMap : ClassMap
33 | {
34 | public FooMap()
35 | {
36 | Map(m => m.Id);
37 | Map(m => m.Name);
38 | Map(m => m.Date).Optional();
39 | }
40 | }
41 | ```
42 |
43 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/examples/configuration/class-maps/validation/index.md:
--------------------------------------------------------------------------------
1 | # Validation
2 |
3 | If you want to ensure your data conforms to some sort of standard, you can validate it.
4 |
5 | ###### Data
6 |
7 | ```
8 | Id,Name
9 | 1,on-e
10 | ```
11 |
12 | ###### Example
13 |
14 | ```cs
15 | void Main()
16 | {
17 | using (var reader = new StreamReader("path\\to\\file.csv"))
18 | using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
19 | {
20 | csv.Context.RegisterClassMap();
21 | csv.GetRecords().ToList().Dump();
22 | }
23 | }
24 |
25 | public class Foo
26 | {
27 | public int Id { get; set; }
28 | public string Name { get; set; }
29 | public DateTimeOffset? Date { get; set; }
30 | }
31 |
32 | public class FooMap : ClassMap
33 | {
34 | public FooMap()
35 | {
36 | Map(m => m.Id);
37 | Map(m => m.Name).Validate(args => !args.Field.Contains("-"));
38 | }
39 | }
40 | ```
41 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/examples/configuration/index.md:
--------------------------------------------------------------------------------
1 | # Configuration
2 |
3 | ## Topics
4 | |
5 | - | -
6 | [Class Maps](~/examples/configuration/class-maps) | Configure CSV structure with a class map.
7 | [Attributes](~/examples/configuration/attributes) | Configure CSV structure with attributes.
8 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/examples/index.md:
--------------------------------------------------------------------------------
1 | # Examples
2 |
3 | Sections |
4 | - | -
5 | [Prerequisites](~/examples/prerequisites) | Implied knowledge when using CsvHelper.
6 | [Reading](~/examples/reading) | Reading CSV data.
7 | [Writing](~/examples/writing) | Writing CSV data.
8 | [Configuration](~/examples/configuration) | Configuring the behavior of CsvHelper to work with your CSV data or custom class structures.
9 | [Type Conversion](~/examples/type-conversion) | Using type conversion to convert CSV fields to and from .NET types.
10 | [DataReader](~/examples/csvdatareader) | Using a DataTable to read CSV data.
11 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/examples/prerequisites/index.md:
--------------------------------------------------------------------------------
1 | # Prerequisites
2 |
3 | Here are some prerequisites that are needed for using CsvHelper. These are .NET basics that are implied knowledge when using CsvHelper. [Microsoft has excellent documentation](https://docs.microsoft.com/dotnet/){target=_blank} that can you can use to learn more.
4 |
5 | Topics |
6 | - | -
7 | [Using and Dispose](~/examples/prerequisites/using-and-dispose) |
8 | [Reading and Writing Files](~/examples/prerequisites/reading-and-writing-files) |
9 | [Streams](~/examples/prerequisites/streams) |
10 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/examples/prerequisites/streams/index.md:
--------------------------------------------------------------------------------
1 | # Streams
2 |
3 | When reading from a stream, if you need to go back to the beginning of the stream, you can use the `Stream.Position` property.
4 |
5 | ```cs
6 | using (var stream = new File.OpenRead("path\\to\\file"))
7 | using (var reader = new StreamReader(stream))
8 | {
9 | // Read file content.
10 | var content = reader.ReadToEnd();
11 |
12 | // Go back to beginning of the stream.
13 | stream.Position = 0;
14 |
15 | // Read file content again.
16 | content = reader.ReadToEnd();
17 | }
18 | ```
19 |
20 | When writing to a file, you need to flush the writer for the data to be written to the stream. `StreamWriter` contains an internal buffer and the data is only written to the stream when the buffer is full, or `Flush` is called. `Flush` is automatically called when a `using` block exits.
21 |
22 | ```cs
23 | using (var stream = new File.OpenWrite("path\\to\\file"))
24 | using (var writer = new StreamWriter(stream))
25 | {
26 | writer.WriteLine("Foo");
27 | writer.Flush(); // Data is written from the writer buffer to the stream.
28 | } // Flush is also called here.
29 | ```
30 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/examples/prerequisites/using-and-dispose/index.md:
--------------------------------------------------------------------------------
1 | # Using and Dispose
2 |
3 | Whenever you have an object that implements `IDisposable`, you need to dispose of the resource when you're done with it. Most classes that use unmanaged resources will implement `IDisposable`. This means a lot of classes in the `System.IO` namespace will need to be disposed of.
4 |
5 | The best practice to dispose of an object when you're done with it is to wrap the code in a `using` block. When the `using` block exits, the resource will automatically be disposed of as soon as possible.
6 |
7 | ```cs
8 | using (var stream = new MemoryStream())
9 | {
10 | // Use the stream.
11 | }
12 | // The stream will be disposed of as soon as possible.
13 | ```
14 |
15 | If you need to keep it around for a while and dispose of it later, `using` does some error handling for you, so it's still a good idea to use it instead of calling `Dispose` directly. There is some debate on whether this is a good idea because it doesn't show intent.
16 |
17 | ```cs
18 | var stream = new MemoryStream();
19 | // Later in a different part of your code.
20 | using (stream) { }
21 | ```
22 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/examples/reading/enumerate-class-records/index.md:
--------------------------------------------------------------------------------
1 | # Enumerate Class Records
2 |
3 | Convert CSV rows into a class object that is re-used on every iteration of the enumerable. Each enumeration will hydrate the given record, but only the mapped members. If you supplied a map and didn't map one of the members, that member will not get hydrated with the current row's data. Be careful. Any methods that you call on the projection that force the evaluation of the `IEnumerable`, such as `ToList()`, you will get a list where all the records are the same instance you provided that is hydrated with the last record in the CSV file.
4 |
5 | ###### Data
6 |
7 | ```
8 | Id,Name
9 | 1,one
10 | ```
11 |
12 | ###### Example
13 |
14 | ```cs
15 | void Main()
16 | {
17 | using (var reader = new StreamReader("path\\to\\file.csv"))
18 | using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
19 | {
20 | var record = new Foo();
21 | var records = csv.EnumerateRecords(record);
22 | foreach (var r in records)
23 | {
24 | // r is the same instance as record.
25 | }
26 | }
27 | }
28 |
29 | public class Foo
30 | {
31 | public int Id { get; set; }
32 | public string Name { get; set; }
33 | }
34 | ```
35 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/examples/reading/get-anonymous-type-records/index.md:
--------------------------------------------------------------------------------
1 | # Get Anonymous Type Records
2 |
3 | Convert CSV rows into anonymous type objects. You just need to supply the anonymous type definition.
4 |
5 | ###### Data
6 |
7 | ```
8 | Id,Name
9 | 1,one
10 | ```
11 |
12 | ###### Example
13 |
14 | ```cs
15 | void Main()
16 | {
17 | using (var reader = new StreamReader("path\\to\\file.csv"))
18 | using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
19 | {
20 | var anonymousTypeDefinition = new
21 | {
22 | Id = default(int),
23 | Name = string.Empty
24 | };
25 | var records = csv.GetRecords(anonymousTypeDefinition);
26 | }
27 | }
28 | ```
29 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/examples/reading/get-class-records/index.md:
--------------------------------------------------------------------------------
1 | # Get Class Records
2 |
3 | Convert CSV rows into class objects.
4 |
5 | ###### Data
6 | ```
7 | Id,Name
8 | 1,one
9 | ```
10 |
11 | ###### Example
12 | ```cs
13 | void Main()
14 | {
15 | using (var reader = new StreamReader("path\\to\\file.csv"))
16 | using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
17 | {
18 | var records = csv.GetRecords();
19 | }
20 | }
21 |
22 | public class Foo
23 | {
24 | public int Id { get; set; }
25 | public string Name { get; set; }
26 | }
27 | ```
28 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/examples/reading/get-dynamic-records/index.md:
--------------------------------------------------------------------------------
1 | # Get Dynamic Records
2 |
3 | Convert CSV rows into `dynamic` objects. Since there is no way to tell what type the properties should be, all the properties on the dynamic object are strings.
4 |
5 | ###### Data
6 |
7 | ```
8 | Id,Name
9 | 1,one
10 | ```
11 |
12 | ###### Example
13 |
14 | ```cs
15 | void Main()
16 | {
17 | using (var reader = new StreamReader("path\\to\\file.csv"))
18 | using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
19 | {
20 | var records = csv.GetRecords();
21 | }
22 | }
23 | ```
24 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/examples/reading/index.md:
--------------------------------------------------------------------------------
1 | # Reading
2 |
3 | Topics |
4 | - | -
5 | [Get Class Records](~/examples/reading/get-class-records) |
6 | [Get Dynamic Records](~/examples/reading/get-dynamic-records) |
7 | [Get Anonymous Type Records](~/examples/reading/get-anonymous-type-records) |
8 | [Enumerate Class Records](~/examples/reading/enumerate-class-records) |
9 | [Reading by Hand](~/examples/reading/reading-by-hand) |
10 | [Reading Multiple Data Sets](~/examples/reading/reading-multiple-data-sets) |
11 | [Reading Multiple Record Types](~/examples/reading/reading-multiple-record-types) |
12 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/examples/reading/reading-by-hand/index.md:
--------------------------------------------------------------------------------
1 | # Reading by Hand
2 |
3 | Sometimes it's easier to not try and configure a mapping to match your class definition for various reasons. It's usually only a few more lines of code to just read the rows by hand instead.
4 |
5 | ###### Data
6 |
7 | ```
8 | Id,Name
9 | 1,one
10 | ```
11 |
12 | ###### Example
13 |
14 | ```cs
15 | void Main()
16 | {
17 | using (var reader = new StreamReader("path\\to\\file.csv"))
18 | using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
19 | {
20 | var records = new List();
21 | csv.Read();
22 | csv.ReadHeader();
23 | while (csv.Read())
24 | {
25 | var record = new Foo
26 | {
27 | Id = csv.GetField("Id"),
28 | Name = csv.GetField("Name")
29 | };
30 | records.Add(record);
31 | }
32 | }
33 | }
34 |
35 | public class Foo
36 | {
37 | public int Id { get; set; }
38 | public string Name { get; set; }
39 | }
40 | ```
41 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/examples/type-conversion/type-converter-options/index.md:
--------------------------------------------------------------------------------
1 | # Type Converter Options
2 |
3 | Options can be passed to the type converters.
4 | Most type converters use `IFormattable.ToString` to write and `TryParse` to read.
5 | Any option for these methods should be available through configuration.
6 |
7 | ###### Mapping Example
8 |
9 | ```cs
10 | public sealed class FooMap : ClassMap
11 | {
12 | public FooMap()
13 | {
14 | Map(m => m.DateTimeProps).TypeConverterOption.DateTimeStyles(DateTimeStyles.AllowInnerWhite | DateTimeStyles.RoundtripKind);
15 | }
16 | }
17 | ```
18 |
19 | ###### Attributes Example
20 |
21 | ```cs
22 | public class Foo
23 | {
24 | [DateTimeStyles(DateTimeStyles.AllowInnerWhite | DateTimeStyles.RoundtripKind)]
25 | public DateTime DateTimeProp { get; set; }
26 | }
27 | ```
28 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/examples/writing/appending-to-an-existing-file/index.md:
--------------------------------------------------------------------------------
1 | # Appending to an Existing CSV File
2 |
3 | ###### Example
4 |
5 | ```cs
6 | void Main()
7 | {
8 | var records = new List
9 | {
10 | new Foo { Id = 1, Name = "one" },
11 | };
12 |
13 | // Write to a file.
14 | using (var writer = new StreamWriter("path\\to\\file.csv"))
15 | using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture))
16 | {
17 | csv.WriteRecords(records);
18 | }
19 |
20 | records = new List
21 | {
22 | new Foo { Id = 2, Name = "two" },
23 | };
24 |
25 | // Append to the file.
26 | var config = new CsvConfiguration(CultureInfo.InvariantCulture)
27 | {
28 | // Don't write the header again.
29 | HasHeaderRecord = false,
30 | };
31 | using (var stream = File.Open("path\\to\\file.csv", FileMode.Append))
32 | using (var writer = new StreamWriter(stream))
33 | using (var csv = new CsvWriter(writer, config))
34 | {
35 | csv.WriteRecords(records);
36 | }
37 | }
38 |
39 | public class Foo
40 | {
41 | public int Id { get; set; }
42 | public string Name { get; set; }
43 | }
44 | ```
45 |
46 | ###### Output
47 |
48 | ```
49 | Id,Name
50 | 1,one
51 | 2,two
52 | ```
53 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/examples/writing/write-anonymous-type-objects/index.md:
--------------------------------------------------------------------------------
1 | # Write Anonymous Type Objects
2 |
3 | ###### Example
4 |
5 | ```cs
6 | void Main()
7 | {
8 | var records = new List
9 | {
10 | new { Id = 1, Name = "one" },
11 | };
12 |
13 | using (var writer = new StreamWriter("path\\to\\file.csv"))
14 | using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture))
15 | {
16 | csv.WriteRecords(records);
17 | }
18 | }
19 | ```
20 |
21 | ###### Output
22 |
23 | ```
24 | Id,Name
25 | 1,one
26 | ```
27 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/examples/writing/write-class-objects/index.md:
--------------------------------------------------------------------------------
1 | # Write Class Objects
2 |
3 | ###### Example
4 |
5 | ```cs
6 | void Main()
7 | {
8 | var records = new List
9 | {
10 | new Foo { Id = 1, Name = "one" },
11 | };
12 |
13 | using (var writer = new StreamWriter("path\\to\\file.csv"))
14 | using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture))
15 | {
16 | csv.WriteRecords(records);
17 | }
18 | }
19 |
20 | public class Foo
21 | {
22 | public int Id { get; set; }
23 | public string Name { get; set; }
24 | }
25 | ```
26 |
27 | ###### Output
28 |
29 | ```
30 | Id,Name
31 | 1,one
32 | ```
33 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/examples/writing/write-dynamic-objects/index.md:
--------------------------------------------------------------------------------
1 | # Write Dynamic Objects
2 |
3 | ###### Example
4 |
5 | ```cs
6 | void Main()
7 | {
8 | var records = new List();
9 |
10 | dynamic record = new ExpandoObject();
11 | record.Id = 1;
12 | record.Name = "one";
13 | records.Add(record);
14 |
15 | using (var writer = new StringWriter())
16 | using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture))
17 | {
18 | csv.WriteRecords(records);
19 |
20 | writer.ToString().Dump();
21 | }
22 | }
23 | ```
24 |
25 | ###### Output
26 |
27 | ```
28 | Id,Name
29 | 1,one
30 | ```
31 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/favicons/android-icon-144x144.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/src/CsvHelper.Website/input/favicons/android-icon-144x144.png
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/favicons/android-icon-192x192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/src/CsvHelper.Website/input/favicons/android-icon-192x192.png
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/favicons/android-icon-36x36.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/src/CsvHelper.Website/input/favicons/android-icon-36x36.png
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/favicons/android-icon-48x48.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/src/CsvHelper.Website/input/favicons/android-icon-48x48.png
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/favicons/android-icon-72x72.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/src/CsvHelper.Website/input/favicons/android-icon-72x72.png
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/favicons/android-icon-96x96.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/src/CsvHelper.Website/input/favicons/android-icon-96x96.png
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/favicons/apple-icon-114x114.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/src/CsvHelper.Website/input/favicons/apple-icon-114x114.png
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/favicons/apple-icon-120x120.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/src/CsvHelper.Website/input/favicons/apple-icon-120x120.png
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/favicons/apple-icon-144x144.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/src/CsvHelper.Website/input/favicons/apple-icon-144x144.png
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/favicons/apple-icon-152x152.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/src/CsvHelper.Website/input/favicons/apple-icon-152x152.png
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/favicons/apple-icon-180x180.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/src/CsvHelper.Website/input/favicons/apple-icon-180x180.png
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/favicons/apple-icon-57x57.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/src/CsvHelper.Website/input/favicons/apple-icon-57x57.png
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/favicons/apple-icon-60x60.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/src/CsvHelper.Website/input/favicons/apple-icon-60x60.png
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/favicons/apple-icon-72x72.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/src/CsvHelper.Website/input/favicons/apple-icon-72x72.png
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/favicons/apple-icon-76x76.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/src/CsvHelper.Website/input/favicons/apple-icon-76x76.png
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/favicons/apple-icon-precomposed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/src/CsvHelper.Website/input/favicons/apple-icon-precomposed.png
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/favicons/apple-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/src/CsvHelper.Website/input/favicons/apple-icon.png
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/favicons/favicon-16x16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/src/CsvHelper.Website/input/favicons/favicon-16x16.png
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/favicons/favicon-32x32.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/src/CsvHelper.Website/input/favicons/favicon-32x32.png
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/favicons/favicon-96x96.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/src/CsvHelper.Website/input/favicons/favicon-96x96.png
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/favicons/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/src/CsvHelper.Website/input/favicons/favicon.ico
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/favicons/ms-icon-144x144.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/src/CsvHelper.Website/input/favicons/ms-icon-144x144.png
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/favicons/ms-icon-150x150.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/src/CsvHelper.Website/input/favicons/ms-icon-150x150.png
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/favicons/ms-icon-310x310.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/src/CsvHelper.Website/input/favicons/ms-icon-310x310.png
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/favicons/ms-icon-70x70.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/src/CsvHelper.Website/input/favicons/ms-icon-70x70.png
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/getting-started/_index.json:
--------------------------------------------------------------------------------
1 | {
2 | "toc": [
3 | {
4 | "title": "Installation",
5 | "link": "#installation"
6 | },
7 | {
8 | "title": "CultureInfo",
9 | "link": "#cultureinfo"
10 | },
11 | {
12 | "title": "Newlines",
13 | "link": "#newlines"
14 | },
15 | {
16 | "title": "Reading a CSV file",
17 | "link": "#reading-a-csv-file"
18 | },
19 | {
20 | "title": "Writing a CSV file",
21 | "link": "#writing-a-csv-file"
22 | }
23 | ]
24 | }
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/google6ad86f23ff698b61.html:
--------------------------------------------------------------------------------
1 | google-site-verification: google6ad86f23ff698b61.html
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/images/aws.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/src/CsvHelper.Website/input/images/aws.png
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/images/microsoft.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/src/CsvHelper.Website/input/images/microsoft.png
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "App",
3 | "icons": [
4 | {
5 | "src": "\/android-icon-36x36.png",
6 | "sizes": "36x36",
7 | "type": "image\/png",
8 | "density": "0.75"
9 | },
10 | {
11 | "src": "\/android-icon-48x48.png",
12 | "sizes": "48x48",
13 | "type": "image\/png",
14 | "density": "1.0"
15 | },
16 | {
17 | "src": "\/android-icon-72x72.png",
18 | "sizes": "72x72",
19 | "type": "image\/png",
20 | "density": "1.5"
21 | },
22 | {
23 | "src": "\/android-icon-96x96.png",
24 | "sizes": "96x96",
25 | "type": "image\/png",
26 | "density": "2.0"
27 | },
28 | {
29 | "src": "\/android-icon-144x144.png",
30 | "sizes": "144x144",
31 | "type": "image\/png",
32 | "density": "3.0"
33 | },
34 | {
35 | "src": "\/android-icon-192x192.png",
36 | "sizes": "192x192",
37 | "type": "image\/png",
38 | "density": "4.0"
39 | }
40 | ]
41 | }
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/migration/index.md:
--------------------------------------------------------------------------------
1 | # Migration
2 |
3 | Migration steps for major version bumps.
4 |
5 | - [29 to 30](~/migration/v30)
6 | - [28 to 29](~/migration/v29)
7 | - [27 to 28](~/migration/v28)
8 | - [26 to 27](~/migration/v27)
9 | - [25 to 26](~/migration/v26)
10 | - [24 to 25](~/migration/v25)
11 | - [23 to 24](~/migration/v24)
12 | - [22 to 23](~/migration/v23)
13 | - [21 to 22](~/migration/v22)
14 | - [20 to 21](~/migration/v21)
15 | - [19 to 20](~/migration/v20)
16 | - [18 to 19](~/migration/v19)
17 | - [17 to 18](~/migration/v18)
18 | - [16 to 17](~/migration/v17)
19 | - [15 to 16](~/migration/v16)
20 | - [14 to 15](~/migration/v15)
21 | - [13 to 14](~/migration/v14)
22 | - [12 to 13](~/migration/v13)
23 | - [11 to 12](~/migration/v12)
24 | - [10 to 11](~/migration/v11)
25 | - [9 to 10](~/migration/v10)
26 | - [8 to 9](~/migration/v9)
27 | - [7 to 8](~/migration/v8)
28 | - [6 to 7](~/migration/v7)
29 | - [5 to 6](~/migration/v6)
30 | - [4 to 5](~/migration/v5)
31 | - [3 to 4](~/migration/v4)
32 | - [2 to 3](~/migration/v3)
33 | - [1 to 2](~/migration/v2)
34 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/migration/v10/index.md:
--------------------------------------------------------------------------------
1 | # Coming Soon
2 |
3 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/migration/v11/index.md:
--------------------------------------------------------------------------------
1 | # Coming Soon
2 |
3 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/migration/v12/index.md:
--------------------------------------------------------------------------------
1 | # Coming Soon
2 |
3 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/migration/v13/index.md:
--------------------------------------------------------------------------------
1 | # Coming Soon
2 |
3 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/migration/v14/index.md:
--------------------------------------------------------------------------------
1 | # Coming Soon
2 |
3 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/migration/v15/index.md:
--------------------------------------------------------------------------------
1 | # Coming Soon
2 |
3 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/migration/v16/index.md:
--------------------------------------------------------------------------------
1 | # Coming Soon
2 |
3 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/migration/v17/index.md:
--------------------------------------------------------------------------------
1 | # Coming Soon
2 |
3 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/migration/v18/index.md:
--------------------------------------------------------------------------------
1 | # Coming Soon
2 |
3 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/migration/v19/index.md:
--------------------------------------------------------------------------------
1 | # Coming Soon
2 |
3 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/migration/v2/index.md:
--------------------------------------------------------------------------------
1 | # Coming Soon
2 |
3 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/migration/v21/index.md:
--------------------------------------------------------------------------------
1 | # Migrating from version 20 to 21
2 |
3 | ## CsvConfiguration
4 |
5 | Property `char? NewLine` changed to `string NewLine`.
6 |
7 | ```cs
8 | // v20
9 | var config = new CsvConfiguration(CultureInfo.InvariantCulture)
10 | {
11 | NewLine = '\r',
12 | };
13 |
14 | // v21
15 | var config = new CsvConfiguration(CultureInfo.InvariantCulture)
16 | {
17 | NewLine = "\r",
18 | };
19 | ```
20 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/migration/v22/index.md:
--------------------------------------------------------------------------------
1 | # Migrating from version 21 to 22
2 |
3 | ## ParserMode
4 |
5 | Name change to `CsvMode`.
6 |
7 | ```cs
8 | // v21
9 | ParserMode.RFC4180
10 |
11 | //v22
12 | CsvMode.RFC4180
13 | ```
14 |
15 | ## ShouldQuote
16 |
17 | ```cs
18 | // v21
19 | var config = new CsvConfiguration(CultureInfo.InvariantCulture)
20 | {
21 | ShouldQuote = (field, context) => true,
22 | };
23 |
24 | // v22
25 | var config = new CsvConfiguration(CultureInfo.InvariantCulture)
26 | {
27 | ShouldQuote = (field, context, row) => true,
28 | };
29 | ```
30 |
31 | ## EnumConverter
32 |
33 | `EnumConverter` was changed to case sensitive by default.
34 |
35 | If you want Enums to ignore case, you need to set a type converter option.
36 |
37 | ```cs
38 | Map(m => m.Property).TypeConverterOption.EnumIgnoreCase();
39 | ```
40 |
41 | ## IParserConfiguration
42 |
43 | - Added `ProcessFieldBufferSizse`.
44 |
45 | Any class that implements `IParserConfiguration` will need these changes applied to it.
46 |
47 | ## IWriterConfiguration
48 |
49 | - Added `Mode`.
50 |
51 | Any class that implements `IWriterConfiguration` will need these changes applied to it.
52 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/migration/v24/index.md:
--------------------------------------------------------------------------------
1 | # Migrating from version 23 to 24
2 |
3 | ## IWriterRow
4 |
5 | ```cs
6 | // v23
7 | WriteConvertedField(field);
8 |
9 | // v24
10 | WriteConvertedField(field, fieldType);
11 | ```
12 |
13 | ## CsvWriter
14 |
15 | ```cs
16 | // v23
17 | WriteConvertedField(field);
18 |
19 | // v24
20 | WriteConvertedField(field, fieldType);
21 | ```
22 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/migration/v27/index.md:
--------------------------------------------------------------------------------
1 | # Migrating from version 26 to 27
2 |
3 | ## CsvConfiguration.WhiteSpaceChars
4 |
5 | - Removed `\t` from the array of default characters.
6 |
7 | If you are expecting `\t` to be trimmed, you will need to add this to the
8 | whitespace characters.
9 |
10 | ```cs
11 | var config = new CsvConfiguration(CultureInfo.InvariantCulture)
12 | {
13 | WhiteSpaceChars = new[] { ' ', '\t' },
14 | };
15 | ```
16 |
17 | ## IParserConfiguration
18 |
19 | - Added property `bool DetectDelimiter { get; }`.
20 | - Added property `string[] DetectDelimiterValues { get; }`.
21 |
22 | Any class that implements `IParserConfiguration` will need these changes
23 | applied to it.
24 |
25 | ## IWriter
26 |
27 | - Added method `Task WriteRecordsAsync(IAsyncEnumerable records, CancellationToken cancellationToken = default)`.
28 | This does not apply to projects that reference the `net45` version of CsvHelper.
29 |
30 | Any class that implements `IWriter` will need these changes applied to it.
31 |
32 | ## IParser
33 |
34 | - Added property `string Delimiter { get; }`.
35 |
36 | Any class that implements `IParser` will need these changes applied to it.
37 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/migration/v28/index.md:
--------------------------------------------------------------------------------
1 | # Migrating from version 27 to 28
2 |
3 | ## ShouldSkipRecordArgs
4 |
5 | - `string[] ShouldSkipRecordArgs.Record` changed to `IReaderRow ShouldSkipRecordArgs.Row`.
6 |
7 | ```cs
8 | // 27
9 | var config = new CsvConfiguration(CultureInfo.InvariantCulture)
10 | {
11 | ShouldSkipRecord = args => args.Record.Length < 10;
12 | };
13 |
14 | // 28
15 |
16 | var config = new CsvConfiguration(CultureInfo.InvariantCulture)
17 | {
18 | ShouldSkipRecord = args => args.Row.Parser.Record.Length < 10;
19 | };
20 | ```
21 |
22 | ## ConfigurationFunctions.ShouldSkipRecord
23 |
24 | - Removed `ConfigurationFunctions.ShouldSkipRecord`.
25 |
26 | `null` can be used in place of this now, and is the default.
27 |
28 | ```cs
29 | var config = new CsvConfiguration(CultureInfo.InvariantCulture)
30 | {
31 | ShouldSkipRecord = null
32 | };
33 | ```
34 |
35 |
36 | ## IParserConfiguration.Validate
37 |
38 | Implement the `Validate` method.
39 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/migration/v29/index.md:
--------------------------------------------------------------------------------
1 | # Migrating from version 28 to 29
2 |
3 | ## CsvConfiguration.SanitizeForInjection
4 |
5 | `bool CsvConfiguration.SanitizeInjection` changed to `InjectionOptions CsvConfiguration.InjectionOptions`.
6 |
7 | ```cs
8 | // 28
9 | var config = new CsvConfiguration(CultureInfo.InvariantCulture)
10 | {
11 | SanitizeForInjection = true,
12 | }
13 |
14 | // 29
15 | var config = new CsvConfiguration(CultureInfo.InvariantCulture)
16 | {
17 | InjectionOptions = InjectionOptions.Escape,
18 | }
19 | ```
20 |
21 | ## IWriterConfiguration.SanitizeForInjection
22 |
23 | `bool IWriterConfiguration.SanitizeInjection` changed to `InjectionOptions IWriterConfiguration.InjectionOptions`.
24 | Any class that implements `IWriterConfiguration` will need this changed.
25 |
26 | ## IParserConfiguration.GetDelimiter
27 |
28 | `GetDelimiter IParserConfiguration.GetDelimiter` was added.
29 | Any class that implements `IParserConfiguration` will need to add this.
30 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/migration/v3/index.md:
--------------------------------------------------------------------------------
1 | # Coming Soon
2 |
3 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/migration/v30/index.md:
--------------------------------------------------------------------------------
1 | # Migrating from version 29 to 30
2 |
3 | ## BadDataException constructor
4 |
5 | ```cs
6 | // 29
7 | throw new BadDataException(context);
8 |
9 | // 30
10 | throw new BadDataException(field, rawRecord, context);
11 | ```
12 |
13 | ## IParserConfiguration
14 |
15 | Any class that implements `IParserConfiguration` will need to add property `double MaxFixFieldSize { get; }`.
16 | Any class that implements `IParserConfiguration` will need to add property `bool LeaveOpen { get; }`.
17 |
18 | ## IWriterConfiguration
19 |
20 | ixFieldSize { get; }`.
21 | Any class that implements `IWriterConfiguration` will need to add property `bool LeaveO
22 |
23 | ## ValidateArgs
24 |
25 | ```cs
26 | // 29
27 | var args = new ValidateArgs(field);
28 |
29 | // 30
30 | var args = new ValidateArgs(field, row);
31 | ```
32 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/migration/v4/index.md:
--------------------------------------------------------------------------------
1 | # Coming Soon
2 |
3 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/migration/v5/index.md:
--------------------------------------------------------------------------------
1 | # Coming Soon
2 |
3 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/migration/v6/index.md:
--------------------------------------------------------------------------------
1 | # Coming Soon
2 |
3 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/migration/v7/index.md:
--------------------------------------------------------------------------------
1 | # Coming Soon
2 |
3 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/migration/v8/index.md:
--------------------------------------------------------------------------------
1 | # Coming Soon
2 |
3 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/migration/v9/index.md:
--------------------------------------------------------------------------------
1 | # Coming Soon
2 |
3 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/robots.txt:
--------------------------------------------------------------------------------
1 | User-agent: *
2 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/scripts/header.js:
--------------------------------------------------------------------------------
1 | (() => {
2 | document.getElementById("navbar-burger").addEventListener("click", () => {
3 | document.getElementById("navbar-burger").classList.toggle("is-active");
4 | document.getElementById("navbar-menu").classList.toggle("is-active");
5 | });
6 | });
7 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/styles/base.scss:
--------------------------------------------------------------------------------
1 | html, body
2 | {
3 | height: 100vh;
4 | }
5 |
6 | body
7 | {
8 | display: flex;
9 | flex-direction: column;
10 | }
11 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/styles/content.scss:
--------------------------------------------------------------------------------
1 | pre code.hljs
2 | {
3 | background-color: transparent;
4 | }
5 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/styles/header.scss:
--------------------------------------------------------------------------------
1 | @import "bulma";
2 |
3 | @media screen and (min-width: $tablet)
4 | {
5 | nav
6 | {
7 | padding: 0 1.5em;
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/styles/index.scss:
--------------------------------------------------------------------------------
1 | @charset "utf-8";
2 |
3 | @import "bulma";
4 |
5 | @import "base";
6 | @import "header";
7 | @import "content";
8 | @import "sidebar";
9 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/input/styles/sidebar.scss:
--------------------------------------------------------------------------------
1 | @import "bulma";
2 |
3 | .expander
4 | {
5 | position: absolute;
6 | font-size: 1.5rem;
7 | transform: rotate(0deg);
8 | top: -3px;
9 | left: 0;
10 |
11 | &::before
12 | {
13 | content: "\203A";
14 | }
15 |
16 | &.expanded
17 | {
18 | left: 4px;
19 | top: 2px;
20 | transform: rotate(90deg);
21 | }
22 | }
23 |
24 | .sidebar
25 | {
26 | display: flex;
27 | position: fixed;
28 | overflow-x: hidden;
29 | overflow-y: auto;
30 |
31 | ul
32 | {
33 | li
34 | {
35 | line-height: 2rem;
36 | padding-left: 1em;
37 | position: relative;
38 |
39 | a
40 | {
41 | color: $text;
42 |
43 | &:not(.expander)
44 | {
45 | &:hover
46 | {
47 | text-decoration: underline;
48 | }
49 | }
50 | }
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/CsvHelper.Website/settings.yml:
--------------------------------------------------------------------------------
1 | LinkRoot: /CsvHelper
2 |
--------------------------------------------------------------------------------
/src/CsvHelper/Compatibility/AsyncExtensions.cs:
--------------------------------------------------------------------------------
1 | namespace CsvHelper;
2 |
3 | internal static class AsyncExtensions
4 | {
5 | #if !(NETSTANDARD2_1_OR_GREATER || NET)
6 | public static ValueTask DisposeAsync(this TextWriter textWriter)
7 | {
8 | if (textWriter != null)
9 | {
10 | textWriter.Dispose();
11 | }
12 |
13 | return default;
14 | }
15 | #endif
16 | }
17 |
--------------------------------------------------------------------------------
/src/CsvHelper/Configuration/Attributes/AllowCommentsAttribute.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | namespace CsvHelper.Configuration.Attributes;
6 |
7 | ///
8 | /// A value indicating whether comments are allowed.
9 | ///
10 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
11 | public class AllowCommentsAttribute : Attribute, IClassMapper
12 | {
13 | ///
14 | /// Gets a value indicating whether comments are allowed.
15 | ///
16 | public bool AllowComments { get; private set; }
17 |
18 | ///
19 | /// A value indicating whether comments are allowed.
20 | ///
21 | /// The value indicating whether comments are allowed.
22 | public AllowCommentsAttribute(bool allowComments = true)
23 | {
24 | AllowComments = allowComments;
25 | }
26 |
27 | ///
28 | public void ApplyTo(CsvConfiguration configuration)
29 | {
30 | configuration.AllowComments = AllowComments;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/CsvHelper/Configuration/Attributes/BufferSizeAttribute.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | namespace CsvHelper.Configuration.Attributes;
6 |
7 | ///
8 | /// The size of the buffer used for parsing and writing CSV files.
9 | /// Default is 0x1000.
10 | ///
11 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
12 | public class BufferSizeAttribute : Attribute, IClassMapper
13 | {
14 | ///
15 | /// The buffer size.
16 | ///
17 | public int BufferSize { get; private set; }
18 |
19 | ///
20 | /// The size of the buffer used for parsing and writing CSV files.
21 | ///
22 | ///
23 | public BufferSizeAttribute(int bufferSize)
24 | {
25 | BufferSize = bufferSize;
26 | }
27 |
28 | ///
29 | public void ApplyTo(CsvConfiguration configuration)
30 | {
31 | configuration.BufferSize = BufferSize;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/CsvHelper/Configuration/Attributes/CacheFieldsAttribute.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | namespace CsvHelper.Configuration.Attributes;
6 |
7 | ///
8 | /// Cache fields that are created when parsing.
9 | ///
10 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
11 | public class CacheFieldsAttribute : Attribute, IClassMapper
12 | {
13 | ///
14 | /// Cache fields that are created when parsing.
15 | ///
16 | public bool CacheFields { get; private set; }
17 |
18 | ///
19 | /// Cache fields that are created when parsing.
20 | ///
21 | ///
22 | public CacheFieldsAttribute(bool cacheFields = true)
23 | {
24 | CacheFields = cacheFields;
25 | }
26 |
27 | ///
28 | public void ApplyTo(CsvConfiguration configuration)
29 | {
30 | configuration.CacheFields = CacheFields;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/CsvHelper/Configuration/Attributes/CommentAttribute.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | namespace CsvHelper.Configuration.Attributes;
6 |
7 | ///
8 | /// The character used to denote a line that is commented out.
9 | /// Default is #.
10 | ///
11 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
12 | public class CommentAttribute : Attribute, IClassMapper
13 | {
14 | ///
15 | /// Gets the character used to denote a line that is commented out.
16 | ///
17 | public char Comment { get; private set; }
18 |
19 | ///
20 | /// The character used to denote a line that is commented out.
21 | ///
22 | /// The comment character.
23 | public CommentAttribute(char comment)
24 | {
25 | Comment = comment;
26 | }
27 |
28 | ///
29 | public void ApplyTo(CsvConfiguration configuration)
30 | {
31 | configuration.Comment = Comment;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/CsvHelper/Configuration/Attributes/DelimiterAttribute.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | namespace CsvHelper.Configuration.Attributes;
6 |
7 | ///
8 | /// The delimiter used to separate fields.
9 | ///
10 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
11 | public class DelimiterAttribute : Attribute, IClassMapper
12 | {
13 | ///
14 | /// Gets the delimiter.
15 | ///
16 | public string Delimiter { get; private set; }
17 |
18 | ///
19 | /// The delimiter used to separate fields.
20 | ///
21 | /// The delimiter.
22 | public DelimiterAttribute(string delimiter)
23 | {
24 | Delimiter = delimiter;
25 | }
26 |
27 | ///
28 | public void ApplyTo(CsvConfiguration configuration)
29 | {
30 | configuration.Delimiter = Delimiter;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/CsvHelper/Configuration/Attributes/DetectDelimiterAttribute.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | namespace CsvHelper.Configuration.Attributes;
6 |
7 | ///
8 | /// Detect the delimiter instead of using the delimiter from configuration.
9 | ///
10 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
11 | public class DetectDelimiterAttribute : Attribute, IClassMapper
12 | {
13 | ///
14 | /// Detect the delimiter instead of using the delimiter from configuration.
15 | ///
16 | public bool DetectDelimiter { get; private set; }
17 |
18 | ///
19 | /// Detect the delimiter instead of using the delimiter from configuration.
20 | ///
21 | public DetectDelimiterAttribute(bool detectDelimiter = true)
22 | {
23 | DetectDelimiter = detectDelimiter;
24 | }
25 |
26 | ///
27 | public void ApplyTo(CsvConfiguration configuration)
28 | {
29 | configuration.DetectDelimiter = DetectDelimiter;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/CsvHelper/Configuration/Attributes/EnumIgnoreCaseAttribute.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | namespace CsvHelper.Configuration.Attributes;
6 |
7 | ///
8 | /// Ignore case when parsing enums.
9 | ///
10 | [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)]
11 | public class EnumIgnoreCaseAttribute : Attribute, IMemberMapper, IMemberReferenceMapper, IParameterMapper
12 | {
13 | ///
14 | public void ApplyTo(MemberMap memberMap)
15 | {
16 | memberMap.Data.TypeConverterOptions.EnumIgnoreCase = true;
17 | }
18 |
19 | ///
20 | public void ApplyTo(MemberReferenceMap referenceMap)
21 | {
22 | foreach (var memberMap in referenceMap.Data.Mapping.MemberMaps)
23 | {
24 | ApplyTo(memberMap);
25 | }
26 | }
27 |
28 | ///
29 | public void ApplyTo(ParameterMap parameterMap)
30 | {
31 | parameterMap.Data.TypeConverterOptions.EnumIgnoreCase = true;
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/src/CsvHelper/Configuration/Attributes/EscapeAttribute.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | namespace CsvHelper.Configuration.Attributes;
6 |
7 | ///
8 | /// The escape character used to escape a quote inside a field.
9 | ///
10 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
11 | public class EscapeAttribute : Attribute, IClassMapper
12 | {
13 | ///
14 | /// Gets the escape character used to escape a quote inside a field.
15 | ///
16 | public char Escape { get; private set; }
17 |
18 | ///
19 | /// The escape character used to escape a quote inside a field.
20 | ///
21 | /// The escape character.
22 | public EscapeAttribute(char escape)
23 | {
24 | Escape = escape;
25 | }
26 |
27 | ///
28 | public void ApplyTo(CsvConfiguration configuration)
29 | {
30 | configuration.Escape = Escape;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/CsvHelper/Configuration/Attributes/IClassMapper.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | namespace CsvHelper.Configuration.Attributes;
6 |
7 | ///
8 | /// Defines methods to enable pluggable configuration.
9 | ///
10 | public interface IClassMapper
11 | {
12 | ///
13 | /// Applies configuration.
14 | ///
15 | /// The configuration to apply to.
16 | void ApplyTo(CsvConfiguration configuration);
17 | }
18 |
--------------------------------------------------------------------------------
/src/CsvHelper/Configuration/Attributes/IMemberMapper.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | namespace CsvHelper.Configuration.Attributes;
6 |
7 | ///
8 | /// Defines methods to enable pluggable configuration of member mapping.
9 | ///
10 | public interface IMemberMapper
11 | {
12 | ///
13 | /// Applies configuration to the given .
14 | ///
15 | /// The member map.
16 | void ApplyTo(MemberMap memberMap);
17 | }
18 |
--------------------------------------------------------------------------------
/src/CsvHelper/Configuration/Attributes/IMemberReferenceMapper.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | namespace CsvHelper.Configuration.Attributes;
6 |
7 | ///
8 | /// Defines methods to enable pluggable configuration of member reference mapping.
9 | ///
10 | public interface IMemberReferenceMapper
11 | {
12 | ///
13 | /// Applies configuration to the given .
14 | ///
15 | /// The reference map.
16 | void ApplyTo(MemberReferenceMap referenceMap);
17 | }
18 |
--------------------------------------------------------------------------------
/src/CsvHelper/Configuration/Attributes/IParameterMapper.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | namespace CsvHelper.Configuration.Attributes;
6 |
7 | ///
8 | /// Defines methods to enable pluggable configuration of parameter mapping.
9 | ///
10 | public interface IParameterMapper
11 | {
12 | ///
13 | /// Applies configuration to the given .
14 | ///
15 | /// The parameter map.
16 | void ApplyTo(ParameterMap parameterMap);
17 | }
18 |
--------------------------------------------------------------------------------
/src/CsvHelper/Configuration/Attributes/IParameterReferenceMapper.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | namespace CsvHelper.Configuration.Attributes;
6 |
7 | ///
8 | /// Defines methods to enable pluggable configuration of parameter reference mapping.
9 | ///
10 | public interface IParameterReferenceMapper
11 | {
12 | ///
13 | /// Applies configuration to the given .
14 | ///
15 | /// The reference map.
16 | void ApplyTo(ParameterReferenceMap referenceMap);
17 | }
18 |
--------------------------------------------------------------------------------
/src/CsvHelper/Configuration/Attributes/IgnoreBaseAttribute.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | namespace CsvHelper.Configuration.Attributes;
6 |
7 | ///
8 | /// Ignores base classes when auto mapping.
9 | ///
10 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
11 | public class IgnoreBaseAttribute : Attribute
12 | {
13 | }
14 |
--------------------------------------------------------------------------------
/src/CsvHelper/Configuration/Attributes/IgnoreBlankLinesAttribute.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | namespace CsvHelper.Configuration.Attributes;
6 |
7 | ///
8 | /// A value indicating whether blank lines should be ignored when reading.
9 | ///
10 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
11 | public class IgnoreBlankLinesAttribute : Attribute, IClassMapper
12 | {
13 | ///
14 | /// Gets a value indicating whether blank lines should be ignored when reading.
15 | ///
16 | public bool IgnoreBlankLines { get; private set; }
17 |
18 | ///
19 | /// A value indicating whether blank lines should be ignored when reading.
20 | ///
21 | public IgnoreBlankLinesAttribute(bool ignoreBlankLines = true)
22 | {
23 | IgnoreBlankLines = ignoreBlankLines;
24 | }
25 |
26 | ///
27 | public void ApplyTo(CsvConfiguration configuration)
28 | {
29 | configuration.IgnoreBlankLines = IgnoreBlankLines;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/CsvHelper/Configuration/Attributes/InjectionOptionsAttribute.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | namespace CsvHelper.Configuration.Attributes;
6 |
7 | ///
8 | /// The injection options.
9 | ///
10 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
11 | public class InjectionOptionsAttribute : Attribute, IClassMapper
12 | {
13 | ///
14 | /// The injection options.
15 | ///
16 | public InjectionOptions InjectionOptions { get; private set; }
17 |
18 | ///
19 | /// The injection options.
20 | ///
21 | ///
22 | public InjectionOptionsAttribute(InjectionOptions injectionOptions)
23 | {
24 | InjectionOptions = injectionOptions;
25 | }
26 |
27 | ///
28 | public void ApplyTo(CsvConfiguration configuration)
29 | {
30 | configuration.InjectionOptions = InjectionOptions;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/CsvHelper/Configuration/Attributes/MaxFieldSizeAttribute.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | namespace CsvHelper.Configuration.Attributes;
6 |
7 | ///
8 | /// Gets or sets the maximum size of a field.
9 | /// Defaults to 0, indicating maximum field size is not checked.
10 | ///
11 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
12 | public class MaxFieldSizeAttribute : Attribute, IClassMapper
13 | {
14 | ///
15 | /// Gets or sets the maximum size of a field.
16 | ///
17 | public double MaxFieldSize { get; private set; }
18 |
19 | ///
20 | /// Gets or sets the maximum size of a field.
21 | ///
22 | ///
23 | public MaxFieldSizeAttribute(double maxFieldSize)
24 | {
25 | MaxFieldSize = maxFieldSize;
26 | }
27 |
28 | ///
29 | public void ApplyTo(CsvConfiguration configuration)
30 | {
31 | configuration.MaxFieldSize = MaxFieldSize;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/CsvHelper/Configuration/Attributes/ModeAttribute.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | namespace CsvHelper.Configuration.Attributes;
6 |
7 | ///
8 | /// The mode.
9 | /// See for more details.
10 | ///
11 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
12 | public class ModeAttribute : Attribute, IClassMapper
13 | {
14 | ///
15 | /// The mode.
16 | /// See for more details.
17 | ///
18 | public CsvMode Mode { get; private set; }
19 |
20 | ///
21 | /// The mode.
22 | /// See for more details.
23 | ///
24 | ///
25 | public ModeAttribute(CsvMode mode)
26 | {
27 | Mode = mode;
28 | }
29 |
30 | ///
31 | public void ApplyTo(CsvConfiguration configuration)
32 | {
33 | configuration.Mode = Mode;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/CsvHelper/Configuration/Attributes/OptionalAttribute.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | namespace CsvHelper.Configuration.Attributes;
6 |
7 | ///
8 | /// Ignore the member when reading if no matching field name can be found.
9 | ///
10 | [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)]
11 | public class OptionalAttribute : Attribute, IMemberMapper, IParameterMapper
12 | {
13 | ///
14 | public void ApplyTo(MemberMap memberMap)
15 | {
16 | memberMap.Data.IsOptional = true;
17 | }
18 |
19 | ///
20 | public void ApplyTo(ParameterMap parameterMap)
21 | {
22 | parameterMap.Data.IsOptional = true;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/CsvHelper/Configuration/Attributes/QuoteAttribute.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | namespace CsvHelper.Configuration.Attributes;
6 |
7 | ///
8 | /// The character used to quote fields.
9 | ///
10 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
11 | public class QuoteAttribute : Attribute, IClassMapper
12 | {
13 | ///
14 | /// Gets the character used to quote fields.
15 | ///
16 | public char Quote { get; private set; }
17 |
18 | ///
19 | /// The character used to quote fields.
20 | ///
21 | /// The quote character.
22 | public QuoteAttribute(char quote)
23 | {
24 | Quote = quote;
25 | }
26 |
27 | ///
28 | public void ApplyTo(CsvConfiguration configuration)
29 | {
30 | configuration.Quote = Quote;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/CsvHelper/Configuration/Attributes/TrimOptionsAttribute.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | namespace CsvHelper.Configuration.Attributes;
6 |
7 | ///
8 | /// The fields trimming options.
9 | ///
10 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
11 | public class TrimOptionsAttribute : Attribute, IClassMapper
12 | {
13 | ///
14 | /// Gets the fields trimming options.
15 | ///
16 | public TrimOptions TrimOptions { get; private set; }
17 |
18 | ///
19 | /// The fields trimming options.
20 | ///
21 | /// The TrimOptions.
22 | public TrimOptionsAttribute(TrimOptions trimOptions)
23 | {
24 | TrimOptions = trimOptions;
25 | }
26 |
27 | ///
28 | public void ApplyTo(CsvConfiguration configuration)
29 | {
30 | configuration.TrimOptions = TrimOptions;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/CsvHelper/Configuration/DefaultClassMap`1.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | namespace CsvHelper.Configuration;
6 |
7 | ///
8 | /// A default that can be used
9 | /// to create a class map dynamically.
10 | ///
11 | ///
12 | public class DefaultClassMap : ClassMap
13 | {
14 | }
15 |
--------------------------------------------------------------------------------
/src/CsvHelper/Configuration/InjectionOptions.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | namespace CsvHelper.Configuration;
6 |
7 | ///
8 | /// Options for handling injection attacks.
9 | ///
10 | public enum InjectionOptions
11 | {
12 | ///
13 | /// No injection protection.
14 | ///
15 | None = 0,
16 | ///
17 | /// Escape injection characters.
18 | ///
19 | Escape,
20 | ///
21 | /// Strip injection characters.
22 | ///
23 | Strip,
24 | ///
25 | /// Throw an exception if injection characters are detected.
26 | ///
27 | Exception,
28 | }
29 |
--------------------------------------------------------------------------------
/src/CsvHelper/Configuration/MemberTypes.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using System;
6 |
7 | namespace CsvHelper.Configuration;
8 |
9 | ///
10 | /// Flags for the type of members that
11 | /// can be used for auto mapping.
12 | ///
13 | [Flags]
14 | public enum MemberTypes
15 | {
16 | ///
17 | /// No members. This is not a valid value
18 | /// and will cause an exception if used.
19 | ///
20 | None = 0,
21 |
22 | ///
23 | /// Properties on a class.
24 | ///
25 | Properties = 1,
26 |
27 | ///
28 | /// Fields on a class.
29 | ///
30 | Fields = 2
31 | }
32 |
--------------------------------------------------------------------------------
/src/CsvHelper/Configuration/TrimOptions.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | namespace CsvHelper.Configuration;
6 |
7 | ///
8 | /// Options for trimming of fields.
9 | ///
10 | [Flags]
11 | public enum TrimOptions
12 | {
13 | ///
14 | /// No trimming.
15 | ///
16 | None = 0,
17 |
18 | ///
19 | /// Trims the whitespace around a field.
20 | ///
21 | Trim = 1,
22 |
23 | ///
24 | /// Trims the whitespace inside of quotes around a field.
25 | ///
26 | InsideQuotes = 2
27 | }
28 |
--------------------------------------------------------------------------------
/src/CsvHelper/CsvHelper.net45.v3.ncrunchproject:
--------------------------------------------------------------------------------
1 |
2 |
3 | True
4 |
5 |
--------------------------------------------------------------------------------
/src/CsvHelper/CsvHelper.net462.v3.ncrunchproject:
--------------------------------------------------------------------------------
1 |
2 |
3 | True
4 |
5 |
--------------------------------------------------------------------------------
/src/CsvHelper/CsvHelper.net47.v3.ncrunchproject:
--------------------------------------------------------------------------------
1 |
2 |
3 | True
4 |
5 |
--------------------------------------------------------------------------------
/src/CsvHelper/CsvHelper.net48.v3.ncrunchproject:
--------------------------------------------------------------------------------
1 |
2 |
3 | True
4 |
5 |
--------------------------------------------------------------------------------
/src/CsvHelper/CsvHelper.net5.0.v3.ncrunchproject:
--------------------------------------------------------------------------------
1 |
2 |
3 | True
4 |
5 |
--------------------------------------------------------------------------------
/src/CsvHelper/CsvHelper.net50.v3.ncrunchproject:
--------------------------------------------------------------------------------
1 |
2 |
3 | True
4 |
5 |
--------------------------------------------------------------------------------
/src/CsvHelper/CsvHelper.net6.0.v3.ncrunchproject:
--------------------------------------------------------------------------------
1 |
2 |
3 | True
4 |
5 |
--------------------------------------------------------------------------------
/src/CsvHelper/CsvHelper.net60.v3.ncrunchproject:
--------------------------------------------------------------------------------
1 |
2 |
3 | True
4 |
5 |
--------------------------------------------------------------------------------
/src/CsvHelper/CsvHelper.net7.0.v3.ncrunchproject:
--------------------------------------------------------------------------------
1 |
2 |
3 | True
4 |
5 |
--------------------------------------------------------------------------------
/src/CsvHelper/CsvHelper.net8.0.v3.ncrunchproject:
--------------------------------------------------------------------------------
1 |
2 |
3 | True
4 |
5 |
--------------------------------------------------------------------------------
/src/CsvHelper/CsvHelper.net9.0.v3.ncrunchproject:
--------------------------------------------------------------------------------
1 |
2 |
3 | True
4 |
5 |
--------------------------------------------------------------------------------
/src/CsvHelper/CsvHelper.netstandard2.0.v3.ncrunchproject:
--------------------------------------------------------------------------------
1 |
2 |
3 | True
4 |
5 |
--------------------------------------------------------------------------------
/src/CsvHelper/CsvHelper.netstandard2.1.v3.ncrunchproject:
--------------------------------------------------------------------------------
1 |
2 |
3 | True
4 |
5 |
--------------------------------------------------------------------------------
/src/CsvHelper/CsvHelper.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/src/CsvHelper/CsvHelper.snk
--------------------------------------------------------------------------------
/src/CsvHelper/Delegates/ConvertFromString.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | namespace CsvHelper;
6 |
7 | ///
8 | /// Function that converts a string into an object.
9 | ///
10 | /// The type of the member.
11 | /// The args.
12 | /// The class object.
13 | public delegate TMember? ConvertFromString(ConvertFromStringArgs args);
14 |
15 | ///
16 | /// args.
17 | ///
18 | public readonly struct ConvertFromStringArgs
19 | {
20 | ///
21 | /// The row.
22 | ///
23 | public readonly IReaderRow Row;
24 |
25 | ///
26 | /// Creates a new instance of ConvertFromStringArgs.
27 | ///
28 | /// The row.
29 | public ConvertFromStringArgs(IReaderRow row)
30 | {
31 | Row = row;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/CsvHelper/Delegates/ConvertToString.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | namespace CsvHelper;
6 |
7 | ///
8 | /// Function that converts an object into a string.
9 | ///
10 | /// The type of the class.
11 | /// The args.
12 | /// The string.
13 | public delegate string? ConvertToString(ConvertToStringArgs args);
14 |
15 | ///
16 | /// args.
17 | ///
18 | /// The value to convert.
19 | public readonly struct ConvertToStringArgs
20 | {
21 | ///
22 | /// The value to convert.
23 | ///
24 | public readonly TClass Value;
25 |
26 | ///
27 | /// Creates a new instance of ConvertToStringArgs{TClass}.
28 | ///
29 | /// The value to convert.
30 | public ConvertToStringArgs(TClass value)
31 | {
32 | Value = value;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/CsvHelper/Delegates/GetConstructor.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using System.Reflection;
6 |
7 | namespace CsvHelper;
8 |
9 | ///
10 | /// Function that chooses the constructor to use for constructor mapping.
11 | ///
12 | public delegate ConstructorInfo GetConstructor(GetConstructorArgs args);
13 |
14 | ///
15 | /// GetConstructor args.
16 | ///
17 | public readonly struct GetConstructorArgs
18 | {
19 | ///
20 | /// The class type.
21 | ///
22 | public readonly Type ClassType;
23 |
24 | ///
25 | /// Creates a new instance of GetConstructorArgs.
26 | ///
27 | /// The class type.
28 | public GetConstructorArgs(Type classType)
29 | {
30 | ClassType = classType;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/CsvHelper/Delegates/GetDynamicPropertyName.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | namespace CsvHelper;
6 |
7 | ///
8 | /// Function that gets the name to use for the property of the dynamic object.
9 | ///
10 | public delegate string GetDynamicPropertyName(GetDynamicPropertyNameArgs args);
11 |
12 | ///
13 | /// GetDynamicPropertyName args.
14 | ///
15 | public readonly struct GetDynamicPropertyNameArgs
16 | {
17 | ///
18 | /// The field index.
19 | ///
20 | public readonly int FieldIndex;
21 |
22 | ///
23 | /// The context.
24 | ///
25 | public readonly CsvContext Context;
26 |
27 | ///
28 | /// Creates a new instance of GetDynamicPropertyNameArgs.
29 | ///
30 | /// The field index.
31 | /// The context.
32 | public GetDynamicPropertyNameArgs(int fieldIndex, CsvContext context)
33 | {
34 | FieldIndex = fieldIndex;
35 | Context = context;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/CsvHelper/Delegates/ReferenceHeaderPrefix.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | namespace CsvHelper;
6 |
7 | ///
8 | /// Function that will return the prefix for a reference header.
9 | ///
10 | public delegate string ReferenceHeaderPrefix(ReferenceHeaderPrefixArgs args);
11 |
12 | ///
13 | /// ReferenceHeaderPrefix args.
14 | ///
15 | public readonly struct ReferenceHeaderPrefixArgs
16 | {
17 | ///
18 | /// The member type.
19 | ///
20 | public readonly Type MemberType;
21 |
22 | ///
23 | /// The member name.
24 | ///
25 | public readonly string MemberName;
26 |
27 | ///
28 | /// Creates a new instance of ReferenceHeaderPrefixArgs.
29 | ///
30 | /// The member type.
31 | /// The member name.
32 | public ReferenceHeaderPrefixArgs(Type memberType, string memberName)
33 | {
34 | MemberType = memberType;
35 | MemberName = memberName;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/CsvHelper/Delegates/ShouldSkipRecord.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | namespace CsvHelper;
6 |
7 | ///
8 | /// Function that determines whether to skip the given record or not.
9 | ///
10 | public delegate bool ShouldSkipRecord(ShouldSkipRecordArgs args);
11 |
12 | ///
13 | /// ShouldSkipRecord args.
14 | ///
15 | public readonly struct ShouldSkipRecordArgs
16 | {
17 | ///
18 | /// The record.
19 | ///
20 | public readonly IReaderRow Row;
21 |
22 | ///
23 | /// Creates a new instance of ShouldSkipRecordArgs.
24 | ///
25 | /// The row.
26 | public ShouldSkipRecordArgs(IReaderRow row)
27 | {
28 | Row = row;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/CsvHelper/Delegates/ShouldUseConstructorParameters.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | namespace CsvHelper;
6 |
7 | ///
8 | /// Function that determines if constructor parameters should be used to create
9 | /// the class instead of the default constructor and members.
10 | ///
11 | public delegate bool ShouldUseConstructorParameters(ShouldUseConstructorParametersArgs args);
12 |
13 | ///
14 | /// ShouldUseConstructorParameters args.
15 | ///
16 | public readonly struct ShouldUseConstructorParametersArgs
17 | {
18 | ///
19 | /// The parameter type.
20 | ///
21 | public readonly Type ParameterType;
22 |
23 | ///
24 | /// Creates a new instance of ShouldUseConstructorParametersArgs.
25 | ///
26 | /// The parameter type.
27 | public ShouldUseConstructorParametersArgs(Type parameterType)
28 | {
29 | ParameterType = parameterType;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/CsvHelper/Icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/src/CsvHelper/Icon.png
--------------------------------------------------------------------------------
/src/CsvHelper/InvalidHeader.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | namespace CsvHelper;
6 |
7 | ///
8 | /// Invalid header information.
9 | ///
10 | public class InvalidHeader
11 | {
12 | ///
13 | /// Header names mapped to a CSV field that couldn't be found.
14 | ///
15 | public List Names { get; set; } = new List();
16 |
17 | ///
18 | /// Header name index maped to a CSV field that couldn't be found.
19 | ///
20 | public int Index { get; set; }
21 | }
22 |
--------------------------------------------------------------------------------
/src/CsvHelper/LinkedListExtensions.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | namespace CsvHelper;
6 |
7 | internal static class LinkedListExtensions
8 | {
9 | public static void Drop(this LinkedList list, LinkedListNode? node)
10 | {
11 | if (list.Count == 0 || node == null)
12 | {
13 | return;
14 | }
15 |
16 | while (list.Count > 0)
17 | {
18 | var nodeToRemove = list.Last;
19 | list.RemoveLast();
20 | if (nodeToRemove == node)
21 | {
22 | break;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/CsvHelper/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using System;
6 | using System.Runtime.CompilerServices;
7 |
8 | [assembly: CLSCompliant(true)]
9 | #if NCRUNCH
10 | [assembly: InternalsVisibleTo("CsvHelper.Tests, PublicKeyToken=null")]
11 | #else
12 | [assembly: InternalsVisibleTo("CsvHelper.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001000db97564beef98ad18a76ba31f769fab92b14341c9c37ed12f8004bb2a1a7fe42ad829b0e285915a816f05a32325c5e0ba83bd69d8f4d26a0785ccf446749842ad038f7325601a99c59a323dfa7ecf210139159da0aad1822b5d9c9be6d914ecbaa8b8c908c4af798a89b8777010971d81975079a49662ced398c742ff186a94")]
13 | #endif
14 |
--------------------------------------------------------------------------------
/src/CsvHelper/TypeConversion/ByteArrayConverterOptions.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | namespace CsvHelper.TypeConversion;
6 |
7 | ///
8 | /// Options for converting byte arrays.
9 | ///
10 | [Flags]
11 | public enum ByteArrayConverterOptions
12 | {
13 | ///
14 | /// No options.
15 | ///
16 | None = 0,
17 |
18 | // TypeOptions
19 |
20 | ///
21 | /// Hexadecimal encoding.
22 | ///
23 | Hexadecimal = 1,
24 |
25 | ///
26 | /// Base64 encoding.
27 | ///
28 | Base64 = 2,
29 |
30 | // HexFormattingOptions
31 |
32 | ///
33 | /// Use dashes in between hex values.
34 | ///
35 | HexDashes = 4,
36 |
37 | ///
38 | /// Prefix hex number with 0x.
39 | ///
40 | HexInclude0x = 8,
41 | }
42 |
--------------------------------------------------------------------------------
/src/CsvHelper/TypeConversion/EnumConverterFactory.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | namespace CsvHelper.TypeConversion;
6 |
7 | ///
8 | public class EnumConverterFactory : ITypeConverterFactory
9 | {
10 | ///
11 | public bool CanCreate(Type type)
12 | {
13 | return typeof(Enum).IsAssignableFrom(type);
14 | }
15 |
16 | ///
17 | public bool Create(Type type, TypeConverterCache cache, out ITypeConverter typeConverter)
18 | {
19 | if (cache.Contains(typeof(Enum)))
20 | {
21 | // If the user has registered a converter for the generic Enum type,
22 | // that converter will be used as a default for all enums.
23 | typeConverter = cache.GetConverter();
24 |
25 | return false;
26 | }
27 |
28 | typeConverter = new EnumConverter(type);
29 |
30 | return true;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/CsvHelper/TypeConversion/GuidConverter.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using CsvHelper.Configuration;
6 |
7 | namespace CsvHelper.TypeConversion;
8 |
9 | ///
10 | /// Converts a to and from a .
11 | ///
12 | public class GuidConverter : DefaultTypeConverter
13 | {
14 | ///
15 | /// Converts the string to an object.
16 | ///
17 | /// The string to convert to an object.
18 | /// The for the current record.
19 | /// The for the member being created.
20 | /// The object created from the string.
21 | public override object? ConvertFromString(string? text, IReaderRow row, MemberMapData memberMapData)
22 | {
23 | if (Guid.TryParse(text, out var g))
24 | {
25 | return g;
26 | }
27 |
28 | return base.ConvertFromString(text, row, memberMapData);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/CsvHelper/TypeConversion/NullableConverterFactory.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | namespace CsvHelper.TypeConversion;
6 |
7 | ///
8 | public class NullableConverterFactory : ITypeConverterFactory
9 | {
10 | ///
11 | public bool CanCreate(Type type)
12 | {
13 | return (type.IsGenericType && type.GetGenericTypeDefinition().Equals(typeof(Nullable<>)));
14 | }
15 |
16 | ///
17 | public bool Create(Type type, TypeConverterCache cache, out ITypeConverter typeConverter)
18 | {
19 | typeConverter = new NullableConverter(type, cache);
20 |
21 | return true;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/AutoMapping/ContextTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using CsvHelper.Configuration;
6 | using Xunit;
7 | using System;
8 | using System.Collections.Generic;
9 | using System.Globalization;
10 | using System.Linq;
11 | using System.Text;
12 | using System.Threading.Tasks;
13 |
14 | namespace CsvHelper.Tests.AutoMapping
15 | {
16 |
17 | public class ContextTests
18 | {
19 | [Fact]
20 | public void AutoMap_UsesContext()
21 | {
22 | var context = new CsvContext(new CsvConfiguration(CultureInfo.InvariantCulture));
23 | context.TypeConverterOptionsCache.GetOptions().NullValues.Add("Bar");
24 |
25 | var map = context.AutoMap();
26 |
27 | Assert.Contains("Bar", map.MemberMaps.Find(x => x.Name)?.Data.TypeConverterOptions.NullValues);
28 | }
29 |
30 | private class Foo
31 | {
32 | public int Id { get; set; }
33 | public string Name { get; set; } = string.Empty;
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/AutoMapping/MappingTypeOfTypeTest.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using CsvHelper.Tests.Mocks;
6 | using Xunit;
7 | using System;
8 | using System.Collections.Generic;
9 | using System.Linq;
10 |
11 | namespace CsvHelper.Tests.AutoMapping
12 | {
13 |
14 | public class MappingTypeOfTypeTest
15 | {
16 | [Fact]
17 | public void ClassWithPropertyOfTypeTypeShouldNotCauseStackOverflowExceptionTest()
18 | {
19 | var parser = new ParserMock
20 | {
21 | { "Id" },
22 | { "1" },
23 | };
24 |
25 | using (var csv = new CsvReader(parser))
26 | {
27 | var records = csv.GetRecords().ToList();
28 | Assert.Single(records);
29 | Assert.Equal(1, records[0].Id);
30 | }
31 | }
32 |
33 | public class EquipmentDataPoint
34 | {
35 | public int Id { get; set; }
36 |
37 | [CsvHelper.Configuration.Attributes.Ignore]
38 | public Type? ValueType { get; set; }
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/Compatibility/IsExternalInit.cs:
--------------------------------------------------------------------------------
1 | #if NETFRAMEWORK
2 | namespace System.Runtime.CompilerServices
3 | {
4 | internal static class IsExternalInit { }
5 | }
6 | #endif
7 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/CsvHelper.Tests.net452.v3.ncrunchproject:
--------------------------------------------------------------------------------
1 |
2 |
3 | True
4 |
5 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/CsvHelper.Tests.net462.v3.ncrunchproject:
--------------------------------------------------------------------------------
1 |
2 |
3 | True
4 |
5 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/CsvHelper.Tests.net47.v3.ncrunchproject:
--------------------------------------------------------------------------------
1 |
2 |
3 | True
4 |
5 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/CsvHelper.Tests.net48.v3.ncrunchproject:
--------------------------------------------------------------------------------
1 |
2 |
3 | True
4 |
5 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/CsvHelper.Tests.net50.v3.ncrunchproject:
--------------------------------------------------------------------------------
1 |
2 |
3 | True
4 |
5 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/CsvHelper.Tests.net6.0.v3.ncrunchproject:
--------------------------------------------------------------------------------
1 |
2 |
3 | True
4 |
5 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/CsvHelper.Tests.net7.0.v3.ncrunchproject:
--------------------------------------------------------------------------------
1 |
2 |
3 | True
4 |
5 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/CsvHelper.Tests.net8.0.v3.ncrunchproject:
--------------------------------------------------------------------------------
1 |
2 |
3 | True
4 |
5 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/CsvHelper.Tests.netcoreapp2.1.v3.ncrunchproject:
--------------------------------------------------------------------------------
1 |
2 |
3 | True
4 |
5 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/CsvHelper.Tests.netcoreapp3.1.v3.ncrunchproject:
--------------------------------------------------------------------------------
1 |
2 |
3 | True
4 |
5 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/CsvHelper.Tests.v3.ncrunchproject:
--------------------------------------------------------------------------------
1 |
2 |
3 | False
4 |
5 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/CsvHelper.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JoshClose/CsvHelper/33970e5183383bdac1fbce3b3fbcdf46b318ca52/tests/CsvHelper.Tests/CsvHelper.snk
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/CsvParserConstructorTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using System.Globalization;
6 | using System.IO;
7 | using Xunit;
8 |
9 | namespace CsvHelper.Tests
10 | {
11 |
12 | public class CsvParserConstructorTests
13 | {
14 | [Fact]
15 | public void EnsureInternalsAreSetupWhenPassingReaderAndConfigTest()
16 | {
17 | using( var stream = new MemoryStream() )
18 | using( var reader = new StreamReader( stream ) )
19 | {
20 | var config = new CsvHelper.Configuration.CsvConfiguration(CultureInfo.InvariantCulture);
21 | using( var parser = new CsvParser( reader, config ) )
22 | {
23 | Assert.Same( config, parser.Configuration );
24 | }
25 | }
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/CsvReaderSubClassingTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using System.Collections.Generic;
6 | using System.Linq;
7 | using CsvHelper.Tests.Mocks;
8 | using Xunit;
9 |
10 | namespace CsvHelper.Tests
11 | {
12 |
13 | public class CsvReaderSubClassingTests
14 | {
15 | [Fact]
16 | public void GetRecordTest()
17 | {
18 | var parserMock = new ParserMock
19 | {
20 | { "Id", "Name" },
21 | { "1", "one" },
22 | { "2", "two" },
23 | };
24 |
25 | var csvReader = new MyCsvReader(parserMock);
26 | csvReader.GetRecords().ToList();
27 | }
28 |
29 | private class MyCsvReader : CsvReader
30 | {
31 | public MyCsvReader(IParser parser) : base(parser) { }
32 | }
33 |
34 | private class Test
35 | {
36 | public int Id { get; set; }
37 | public string Name { get; set; } = string.Empty;
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/CsvWriterConstructorTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using System.Globalization;
6 | using System.IO;
7 | using Xunit;
8 |
9 | namespace CsvHelper.Tests
10 | {
11 |
12 | public class CsvWriterConstructorTests
13 | {
14 | [Fact]
15 | public void EnsureInternalsAreSetupWhenPassingWriterAndConfigTest()
16 | {
17 | using( var stream = new MemoryStream() )
18 | using( var writer = new StreamWriter( stream ) )
19 | {
20 | var config = new CsvHelper.Configuration.CsvConfiguration(CultureInfo.InvariantCulture);
21 | using( var csv = new CsvWriter( writer, config ) )
22 | {
23 | Assert.Same( config, csv.Configuration );
24 | }
25 | }
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/CsvWriterSubClassingTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using System.Collections.Generic;
6 | using System.Globalization;
7 | using System.IO;
8 | using Xunit;
9 |
10 | namespace CsvHelper.Tests
11 | {
12 |
13 | public class CsvWriterSubClassingTests
14 | {
15 | [Fact]
16 | public void WriteRecordTest()
17 | {
18 | var data = new List
19 | {
20 | new Test { Id = 1, Name = "one" },
21 | new Test { Id = 2, Name = "two" }
22 | };
23 |
24 | var stream = new MemoryStream();
25 | var writer = new StreamWriter(stream);
26 | var csvWriter = new MyCsvWriter(writer);
27 |
28 | csvWriter.WriteRecords(data);
29 | }
30 |
31 | private class MyCsvWriter : CsvWriter
32 | {
33 | public MyCsvWriter(TextWriter writer) : base(writer, CultureInfo.InvariantCulture) { }
34 | }
35 |
36 | private class Test
37 | {
38 | public int Id { get; set; }
39 | public string? Name { get; set; }
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/Issues/Issue2060.cs:
--------------------------------------------------------------------------------
1 | using System.Data;
2 | using System.Globalization;
3 | using System.IO;
4 | using Xunit;
5 |
6 | namespace CsvHelper.Tests.Issues
7 | {
8 | public class Issue2060
9 | {
10 | [Fact]
11 | public void Test1()
12 | {
13 | var data =
14 | """
15 | A
16 | B
17 | C
18 | Id,Name
19 | 1,Jeff
20 | 2,Kevin
21 | """;
22 | using var reader = new StringReader(data);
23 | using var csv = new CsvReader(reader, CultureInfo.InvariantCulture);
24 | while (csv.Read())
25 | {
26 | if (csv[0] == "Id")
27 | {
28 | break;
29 | }
30 | }
31 |
32 | csv.ReadHeader();
33 |
34 | using var dr = new CsvDataReader(csv);
35 | var dt = new DataTable();
36 | dt.Load(dr);
37 |
38 | Assert.Equal("Id", dt.Columns[0].ColumnName);
39 | Assert.Equal("Name", dt.Columns[1].ColumnName);
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/Issues/Issue2118.cs:
--------------------------------------------------------------------------------
1 | using CsvHelper.Configuration;
2 | using System.Collections.Generic;
3 | using System.Globalization;
4 | using System.IO;
5 | using Xunit;
6 |
7 | namespace CsvHelper.Tests.Issues
8 | {
9 | public class Issue2118
10 | {
11 | [Fact]
12 | public void Issue2118Test()
13 | {
14 | var records = new List
15 | {
16 | new() { Bar = new HashSet { "foo" } },
17 | new() { Bar = new HashSet { "bar" } },
18 | };
19 |
20 | string csvString;
21 | using (var writer = new StringWriter())
22 | using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture))
23 | {
24 | csv.Context.RegisterClassMap();
25 | csv.WriteRecords(records);
26 | csvString = writer.ToString();
27 | }
28 |
29 | Assert.Equal("Foo,Bar\r\nTrue,False\r\nFalse,True\r\n", csvString);
30 | }
31 |
32 | private class Foo
33 | {
34 | public HashSet Bar { get; set; } = new();
35 | }
36 |
37 | private sealed class FooMap : ClassMap
38 | {
39 | public FooMap()
40 | {
41 | Map().Index(0).Name("Foo").Convert(x => ((Foo)x.Value).Bar.Contains("foo") ? "True" : "False");
42 | Map().Index(1).Name("Bar").Convert(x => ((Foo)x.Value).Bar.Contains("bar") ? "True" : "False");
43 | }
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/MappingInheritedClassTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using CsvHelper.Configuration;
6 | using Xunit;
7 | using System.Globalization;
8 |
9 | namespace CsvHelper.Tests
10 | {
11 |
12 | public class MappingInheritedClassTests
13 | {
14 | [Fact]
15 | public void Test()
16 | {
17 | var map = new AMap();
18 | Assert.Equal( 2, map.MemberMaps.Count );
19 | }
20 |
21 | private interface IA
22 | {
23 | int Id { get; set; }
24 | }
25 |
26 | private class A : IA
27 | {
28 | public int Id { get; set; }
29 |
30 | public int Name { get; set; }
31 | }
32 |
33 | private sealed class AMap : ClassMap where T : IA
34 | {
35 | public AMap()
36 | {
37 | AutoMap(CultureInfo.InvariantCulture);
38 | Map( m => m.Id );
39 | }
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/Mappings/Attribute/AllowCommentsTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using CsvHelper.Configuration;
6 | using CsvHelper.Configuration.Attributes;
7 | using System.Globalization;
8 | using Xunit;
9 |
10 | namespace CsvHelper.Tests.AttributeMapping
11 | {
12 | public class AllowCommentsTests
13 | {
14 | [Fact]
15 | public void AllowCommentsTest()
16 | {
17 | Assert.True(CsvConfiguration.FromAttributes(CultureInfo.InvariantCulture).AllowComments);
18 | Assert.False(CsvConfiguration.FromAttributes(CultureInfo.InvariantCulture).AllowComments);
19 | }
20 |
21 | [AllowComments]
22 | private class AllowCommentsTrueTestClass
23 | {
24 | public int Id { get; set; }
25 |
26 | public string? Name { get; set; }
27 | }
28 |
29 | [AllowComments(false)]
30 | private class AllowCommentsFalseTestClass
31 | {
32 | public int Id { get; set; }
33 |
34 | public string? Name { get; set; }
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/Mappings/Attribute/BooleanValuesTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using CsvHelper.Configuration.Attributes;
6 | using Xunit;
7 | using System.Globalization;
8 | using System.IO;
9 | using System.Linq;
10 |
11 | namespace CsvHelper.Tests.Mappings.Attribute
12 | {
13 |
14 | public class BooleanValuesTests
15 | {
16 | [Fact]
17 | public void BooleanValuesTest()
18 | {
19 | using (var reader = new StringReader("IsTrue,IsFalse\r\ntrue,false\r\n"))
20 | using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
21 | {
22 | var records = csv.GetRecords().ToList();
23 | Assert.Equal(true, records[0].IsTrue);
24 | Assert.Equal(false, records[0].IsFalse);
25 | }
26 | }
27 |
28 | private class BooleanValuesTestClass
29 | {
30 | [BooleanTrueValues("true")]
31 | public bool? IsTrue { get; set; }
32 |
33 | [BooleanFalseValues("false")]
34 | public bool? IsFalse { get; set; }
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/Mappings/Attribute/BufferSizeTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using CsvHelper.Configuration;
6 | using CsvHelper.Configuration.Attributes;
7 | using System;
8 | using System.Collections.Generic;
9 | using System.Globalization;
10 | using System.Linq;
11 | using System.Text;
12 | using System.Threading.Tasks;
13 | using Xunit;
14 |
15 | namespace CsvHelper.Tests.Mappings.Attribute
16 | {
17 | public class BufferSizeTests
18 | {
19 | [Fact]
20 | public void ConstructorAttributeTest()
21 | {
22 | var config = CsvConfiguration.FromAttributes(CultureInfo.InvariantCulture);
23 | Assert.Equal(2, config.BufferSize);
24 | }
25 |
26 | [BufferSize(2)]
27 | private class Foo { }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/Mappings/Attribute/CacheFieldsTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using CsvHelper.Configuration;
6 | using CsvHelper.Configuration.Attributes;
7 | using System.Globalization;
8 | using Xunit;
9 |
10 | namespace CsvHelper.Tests.Mappings.Attribute
11 | {
12 | public class CacheFieldsTests
13 | {
14 | [Fact]
15 | public void ConstructorAttributeTest()
16 | {
17 | Assert.True(CsvConfiguration.FromAttributes(CultureInfo.InvariantCulture).CacheFields);
18 | Assert.False(CsvConfiguration.FromAttributes(CultureInfo.InvariantCulture).CacheFields);
19 | }
20 |
21 | [CacheFields]
22 | private class FooTrue { }
23 |
24 | [CacheFields(false)]
25 | private class FooFalse { }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/Mappings/Attribute/CommentTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using CsvHelper.Configuration;
6 | using CsvHelper.Configuration.Attributes;
7 | using System.Globalization;
8 | using System.IO;
9 | using System.Linq;
10 | using Xunit;
11 |
12 | namespace CsvHelper.Tests.AttributeMapping
13 | {
14 | public class CommentTests
15 | {
16 | [Fact]
17 | public void CommentTest()
18 | {
19 | var config = CsvConfiguration.FromAttributes(CultureInfo.InvariantCulture);
20 | Assert.Equal('x', config.Comment);
21 | }
22 |
23 | [Comment('x')]
24 | private class CommentTestClass
25 | {
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/Mappings/Attribute/CountBytesTest.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using CsvHelper.Configuration;
6 | using CsvHelper.Configuration.Attributes;
7 | using System.Globalization;
8 | using Xunit;
9 |
10 | namespace CsvHelper.Tests.Mappings.Attribute
11 | {
12 | public class CountBytesTest
13 | {
14 | [Fact]
15 | public void ConstructorAttributeTest()
16 | {
17 | Assert.True(CsvConfiguration.FromAttributes(CultureInfo.InvariantCulture).CountBytes);
18 | Assert.False(CsvConfiguration.FromAttributes(CultureInfo.InvariantCulture).CountBytes);
19 | }
20 |
21 | [CountBytes]
22 | private class FooTrue { }
23 |
24 | [CountBytes(false)]
25 | private class FooFalse { }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/Mappings/Attribute/DefaultTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using CsvHelper.Configuration.Attributes;
6 | using Xunit;
7 | using System.Globalization;
8 | using System.IO;
9 | using System.Linq;
10 |
11 | namespace CsvHelper.Tests.Mappings.Attribute
12 | {
13 |
14 | public class DefaultTests
15 | {
16 | [Fact]
17 | public void DefaultTest()
18 | {
19 | using (var reader = new StringReader("Id,Name\r\n1,\r\n"))
20 | using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
21 | {
22 | var records = csv.GetRecords().ToList();
23 |
24 | Assert.Equal(1, records[0].Id);
25 | Assert.Equal("one", records[0].Name);
26 | }
27 | }
28 |
29 | private class DefaultTestClass
30 | {
31 | public int Id { get; set; }
32 |
33 | [Default("one")]
34 | public string? Name { get; set; }
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/Mappings/Attribute/DelimiterTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using CsvHelper.Configuration;
6 | using CsvHelper.Configuration.Attributes;
7 | using System.Globalization;
8 | using System.IO;
9 | using System.Linq;
10 | using Xunit;
11 |
12 | namespace CsvHelper.Tests.AttributeMapping
13 | {
14 | public class DelimiterTests
15 | {
16 | [Fact]
17 | public void DelimiterReaderTest()
18 | {
19 | var configuration = CsvConfiguration.FromAttributes(CultureInfo.InvariantCulture);
20 |
21 | Assert.Equal("§", configuration.Delimiter);
22 | }
23 |
24 | [Delimiter("§")]
25 | private class DelimiterTestClass
26 | {
27 | public int Id { get; set; }
28 |
29 | public string? Name { get; set; }
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/Mappings/Attribute/DetectColumnCountChangesTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using CsvHelper.Configuration;
6 | using CsvHelper.Configuration.Attributes;
7 | using System.Globalization;
8 | using Xunit;
9 |
10 | namespace CsvHelper.Tests.Mappings.Attribute
11 | {
12 | public class DetectColumnCountChangesTests
13 | {
14 | [Fact]
15 | public void ConstructorAttributeTest()
16 | {
17 | Assert.True(CsvConfiguration.FromAttributes(CultureInfo.InvariantCulture).DetectColumnCountChanges);
18 | Assert.False(CsvConfiguration.FromAttributes(CultureInfo.InvariantCulture).DetectColumnCountChanges);
19 | }
20 |
21 | [DetectColumnCountChanges]
22 | private class FooTrue { }
23 |
24 | [DetectColumnCountChanges(false)]
25 | private class FooFalse { }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/Mappings/Attribute/DetectDelimiterTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using CsvHelper.Configuration;
6 | using CsvHelper.Configuration.Attributes;
7 | using System.Globalization;
8 | using Xunit;
9 |
10 | namespace CsvHelper.Tests.Mappings.Attribute
11 | {
12 | public class DetectDelimiterTests
13 | {
14 | [Fact]
15 | public void ConstructorAttributeTest()
16 | {
17 | Assert.True(CsvConfiguration.FromAttributes(CultureInfo.InvariantCulture).DetectDelimiter);
18 | Assert.False(CsvConfiguration.FromAttributes(CultureInfo.InvariantCulture).DetectDelimiter);
19 | }
20 |
21 | [DetectDelimiter]
22 | private class FooTrue { }
23 |
24 | [DetectDelimiter(false)]
25 | private class FooFalse { }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/Mappings/Attribute/DetectDelimiterValuesTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using CsvHelper.Configuration;
6 | using CsvHelper.Configuration.Attributes;
7 | using System;
8 | using System.Collections.Generic;
9 | using System.Globalization;
10 | using System.Linq;
11 | using System.Text;
12 | using System.Threading.Tasks;
13 | using Xunit;
14 |
15 | namespace CsvHelper.Tests.Mappings.Attribute
16 | {
17 | public class DetectDelimiterValuesTests
18 | {
19 | [Fact]
20 | public void ConstructorAttributeTest()
21 | {
22 | var config = CsvConfiguration.FromAttributes(CultureInfo.InvariantCulture);
23 | Assert.Equal(new[] { "a", "b" }, config.DetectDelimiterValues);
24 | }
25 |
26 | [DetectDelimiterValues("a b")]
27 | private class Foo { }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/Mappings/Attribute/EncodingTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using CsvHelper.Configuration;
6 | using CsvHelper.Configuration.Attributes;
7 | using System.Globalization;
8 | using System.Text;
9 | using Xunit;
10 |
11 | namespace CsvHelper.Tests.AttributeMapping
12 | {
13 | public class EncodingTests
14 | {
15 | [Fact]
16 | public void EncodingTest()
17 | {
18 | Assert.Equal(Encoding.ASCII, CsvConfiguration.FromAttributes(CultureInfo.InvariantCulture).Encoding);
19 | Assert.Equal(Encoding.ASCII, CsvConfiguration.FromAttributes(CultureInfo.InvariantCulture).Encoding);
20 | }
21 |
22 | [Encoding("ASCII")]
23 | private class EncodingNameTestClass
24 | {
25 | public int Id { get; set; }
26 |
27 | public string? Name { get; set; }
28 | }
29 |
30 | [Encoding(20127)]
31 | private class EncodingCodepageTestClass
32 | {
33 | public int Id { get; set; }
34 |
35 | public string? Name { get; set; }
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/Mappings/Attribute/EscapeTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using CsvHelper.Configuration;
6 | using CsvHelper.Configuration.Attributes;
7 | using System.Globalization;
8 | using System.IO;
9 | using System.Linq;
10 | using Xunit;
11 |
12 | namespace CsvHelper.Tests.AttributeMapping
13 | {
14 | public class EscapeTests
15 | {
16 | [Fact]
17 | public void EscapeTest()
18 | {
19 | var config = CsvConfiguration.FromAttributes(CultureInfo.InvariantCulture);
20 |
21 | Assert.Equal('x', config.Escape);
22 | }
23 |
24 | [Escape('x')]
25 | private class EscapeTestClass
26 | {
27 | public int Id { get; set; }
28 |
29 | public string? Name { get; set; }
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/Mappings/Attribute/ExceptionMessagesContainRawDataTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using CsvHelper.Configuration;
6 | using CsvHelper.Configuration.Attributes;
7 | using System.Globalization;
8 | using Xunit;
9 |
10 | namespace CsvHelper.Tests.Mappings.Attribute
11 | {
12 | public class ExceptionMessagesContainRawDataTests
13 | {
14 | [Fact]
15 | public void ConstructorAttributeTest()
16 | {
17 | Assert.True(CsvConfiguration.FromAttributes(CultureInfo.InvariantCulture).ExceptionMessagesContainRawData);
18 | Assert.False(CsvConfiguration.FromAttributes(CultureInfo.InvariantCulture).ExceptionMessagesContainRawData);
19 | }
20 |
21 | [ExceptionMessagesContainRawData]
22 | private class FooTrue { }
23 |
24 | [ExceptionMessagesContainRawData(false)]
25 | private class FooFalse { }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/Mappings/Attribute/FormatTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using CsvHelper.Configuration.Attributes;
6 | using Xunit;
7 | using System.Globalization;
8 | using System.IO;
9 | using System.Linq;
10 |
11 | namespace CsvHelper.Tests.Mappings.Attribute
12 | {
13 |
14 | public class FormatTests
15 | {
16 | [Fact]
17 | public void FormatTest()
18 | {
19 | using (var reader = new StringReader("Id,Name\r\n1,one\r\n"))
20 | using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
21 | {
22 | var records = csv.GetRecords().ToList();
23 | var actual = csv.Context.Maps.Find()?.MemberMaps[1].Data.TypeConverterOptions.Formats?.First();
24 |
25 | Assert.Equal("abc", actual);
26 | }
27 | }
28 |
29 | private class FormatTestClass
30 | {
31 | public int Id { get; set; }
32 |
33 | [Format("abc")]
34 | public string? Name { get; set; }
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/Mappings/Attribute/HasHeaderRecordTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using CsvHelper.Configuration;
6 | using CsvHelper.Configuration.Attributes;
7 | using System.Globalization;
8 | using Xunit;
9 |
10 | namespace CsvHelper.Tests.AttributeMapping
11 | {
12 | public class HasHeaderRecordTests
13 | {
14 | [Fact]
15 | public void HasHeaderRecordTest()
16 | {
17 | Assert.True(CsvConfiguration.FromAttributes(CultureInfo.InvariantCulture).HasHeaderRecord);
18 | Assert.False(CsvConfiguration.FromAttributes(CultureInfo.InvariantCulture).HasHeaderRecord);
19 | }
20 |
21 | [HasHeaderRecord]
22 | private class HasHeaderRecordTrueTestClass
23 | {
24 | public int Id { get; set; }
25 |
26 | public string? Name { get; set; }
27 | }
28 |
29 | [HasHeaderRecord(false)]
30 | private class HasHeaderRecordFalseTestClass
31 | {
32 | public int Id { get; set; }
33 |
34 | public string? Name { get; set; }
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/Mappings/Attribute/IgnoreBlankLinesTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using CsvHelper.Configuration;
6 | using CsvHelper.Configuration.Attributes;
7 | using System.Globalization;
8 | using Xunit;
9 |
10 | namespace CsvHelper.Tests.AttributeMapping
11 | {
12 | public class IgnoreBlankLinesTests
13 | {
14 | [Fact]
15 | public void IgnoreBlankLinesTest()
16 | {
17 | Assert.True(CsvConfiguration.FromAttributes(CultureInfo.InvariantCulture).IgnoreBlankLines);
18 | Assert.False(CsvConfiguration.FromAttributes(CultureInfo.InvariantCulture).IgnoreBlankLines);
19 | }
20 |
21 | [IgnoreBlankLines]
22 | private class IgnoreBlankLinesTrueTestClass
23 | {
24 | public int Id { get; set; }
25 |
26 | public string? Name { get; set; }
27 | }
28 |
29 | [IgnoreBlankLines(false)]
30 | private class IgnoreBlankLinesFalseTestClass
31 | {
32 | public int Id { get; set; }
33 |
34 | public string? Name { get; set; }
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/Mappings/Attribute/IgnoreReferencesTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using CsvHelper.Configuration;
6 | using CsvHelper.Configuration.Attributes;
7 | using System.Globalization;
8 | using Xunit;
9 |
10 | namespace CsvHelper.Tests.Mappings.Attribute
11 | {
12 | public class IgnoreReferencesTests
13 | {
14 | [Fact]
15 | public void ConstructorAttributeTest()
16 | {
17 | Assert.True(CsvConfiguration.FromAttributes(CultureInfo.InvariantCulture).IgnoreReferences);
18 | Assert.False(CsvConfiguration.FromAttributes(CultureInfo.InvariantCulture).IgnoreReferences);
19 | }
20 |
21 | [IgnoreReferences]
22 | private class FooTrue { }
23 |
24 | [IgnoreReferences(false)]
25 | private class FooFalse { }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/Mappings/Attribute/IndexTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using CsvHelper.Configuration;
6 | using CsvHelper.Configuration.Attributes;
7 | using Xunit;
8 | using System.Globalization;
9 | using System.IO;
10 | using System.Linq;
11 |
12 | namespace CsvHelper.Tests.Mappings.Attribute
13 | {
14 | public class IndexTests
15 | {
16 | [Fact]
17 | public void IndexTest()
18 | {
19 | var config = new CsvConfiguration(CultureInfo.InvariantCulture)
20 | {
21 | HasHeaderRecord = false,
22 | };
23 | using (var reader = new StringReader("a,1,b,one,c\r\n"))
24 | using (var csv = new CsvReader(reader, config))
25 | {
26 | var records = csv.GetRecords().ToList();
27 |
28 | Assert.Equal(1, records[0].Id);
29 | Assert.Equal("one", records[0].Name);
30 | }
31 | }
32 |
33 | private class IndexTestClass
34 | {
35 | [Index(1)]
36 | public int Id { get; set; }
37 |
38 | [Index(3)]
39 | public string? Name { get; set; }
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/Mappings/Attribute/InjectionCharactersTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using CsvHelper.Configuration;
6 | using CsvHelper.Configuration.Attributes;
7 | using System;
8 | using System.Collections.Generic;
9 | using System.Globalization;
10 | using System.Linq;
11 | using System.Text;
12 | using System.Threading.Tasks;
13 | using Xunit;
14 |
15 | namespace CsvHelper.Tests.Mappings.Attribute
16 | {
17 | public class InjectionCharactersTests
18 | {
19 | [Fact]
20 | public void ConstructorAttributeTest()
21 | {
22 | var config = CsvConfiguration.FromAttributes(CultureInfo.InvariantCulture);
23 | Assert.Equal(new[] { 'a', 'b' }, config.InjectionCharacters);
24 | }
25 |
26 | [InjectionCharacters("a b")]
27 | private class Foo { }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/Mappings/Attribute/InjectionEscapeCharacterTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using CsvHelper.Configuration;
6 | using CsvHelper.Configuration.Attributes;
7 | using System;
8 | using System.Collections.Generic;
9 | using System.Globalization;
10 | using System.Linq;
11 | using System.Text;
12 | using System.Threading.Tasks;
13 | using Xunit;
14 |
15 | namespace CsvHelper.Tests.Mappings.Attribute
16 | {
17 | public class InjectionEscapeCharacterTests
18 | {
19 | [Fact]
20 | public void ConstructorAttributeTest()
21 | {
22 | var config = CsvConfiguration.FromAttributes(CultureInfo.InvariantCulture);
23 | Assert.Equal('a', config.InjectionEscapeCharacter);
24 | }
25 |
26 | [InjectionEscapeCharacter('a')]
27 | private class Foo { }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/Mappings/Attribute/InjectionOptionsTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using CsvHelper.Configuration;
6 | using CsvHelper.Configuration.Attributes;
7 | using System;
8 | using System.Collections.Generic;
9 | using System.Globalization;
10 | using System.Linq;
11 | using System.Text;
12 | using System.Threading.Tasks;
13 | using Xunit;
14 |
15 | namespace CsvHelper.Tests.Mappings.Attribute
16 | {
17 | public class InjectionOptionsTests
18 | {
19 | [Fact]
20 | public void ConstructorAttributeTest()
21 | {
22 | var config = CsvConfiguration.FromAttributes(CultureInfo.InvariantCulture);
23 | Assert.Equal(InjectionOptions.Escape, config.InjectionOptions);
24 | }
25 |
26 | [InjectionOptions(InjectionOptions.Escape)]
27 | private class Foo { }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/Mappings/Attribute/LineBreakInQuotedFieldIsBadDataTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using CsvHelper.Configuration;
6 | using CsvHelper.Configuration.Attributes;
7 | using System.Globalization;
8 | using Xunit;
9 |
10 | namespace CsvHelper.Tests.Mappings.Attribute
11 | {
12 | public class LineBreakInQuotedFieldIsBadDataTests
13 | {
14 | [Fact]
15 | public void ConstructorAttributeTest()
16 | {
17 | Assert.True(CsvConfiguration.FromAttributes(CultureInfo.InvariantCulture).LineBreakInQuotedFieldIsBadData);
18 | Assert.False(CsvConfiguration.FromAttributes(CultureInfo.InvariantCulture).LineBreakInQuotedFieldIsBadData);
19 | }
20 |
21 | [LineBreakInQuotedFieldIsBadData]
22 | private class FooTrue { }
23 |
24 | [LineBreakInQuotedFieldIsBadData(false)]
25 | private class FooFalse { }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/Mappings/Attribute/MaxFieldSizeTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using CsvHelper.Configuration;
6 | using CsvHelper.Configuration.Attributes;
7 | using System.Globalization;
8 | using Xunit;
9 |
10 | namespace CsvHelper.Tests.Mappings.Attribute
11 | {
12 | public class MaxFieldSizeTests
13 | {
14 | [Fact]
15 | public void ConstructorAttributeTest()
16 | {
17 | var config = CsvConfiguration.FromAttributes(CultureInfo.InvariantCulture);
18 | Assert.Equal(2, config.MaxFieldSize);
19 | }
20 |
21 | [MaxFieldSize(2)]
22 | private class Foo { }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/Mappings/Attribute/MemberTypesTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using CsvHelper.Configuration;
6 | using CsvHelper.Configuration.Attributes;
7 | using System.Globalization;
8 | using Xunit;
9 |
10 | namespace CsvHelper.Tests.Mappings.Attribute
11 | {
12 | public class MemberTypesTests
13 | {
14 | [Fact]
15 | public void ConstructorAttributeTest()
16 | {
17 | var config = CsvConfiguration.FromAttributes(CultureInfo.InvariantCulture);
18 | Assert.Equal(MemberTypes.Fields, config.MemberTypes);
19 | }
20 |
21 | [MemberTypes(MemberTypes.Fields)]
22 | private class Foo { }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/Mappings/Attribute/ModeTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using CsvHelper.Configuration;
6 | using CsvHelper.Configuration.Attributes;
7 | using System.Globalization;
8 | using Xunit;
9 |
10 | namespace CsvHelper.Tests.Mappings.Attribute
11 | {
12 | public class ModeTests
13 | {
14 | [Fact]
15 | public void ConstructorAttributeTest()
16 | {
17 | var config = CsvConfiguration.FromAttributes(CultureInfo.InvariantCulture);
18 | Assert.Equal(CsvMode.Escape, config.Mode);
19 | }
20 |
21 | [Mode(CsvMode.Escape)]
22 | private class Foo { }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/Mappings/Attribute/NameIndexTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using CsvHelper.Configuration.Attributes;
6 | using Xunit;
7 | using System.Globalization;
8 | using System.IO;
9 | using System.Linq;
10 |
11 | namespace CsvHelper.Tests.Mappings.Attribute
12 | {
13 |
14 | public class NameIndexTests
15 | {
16 | [Fact]
17 | public void NameIndexTest()
18 | {
19 | using (var reader = new StringReader("Id,Name,Name\r\n1,one,two\r\n"))
20 | using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
21 | {
22 | var records = csv.GetRecords().ToList();
23 |
24 | Assert.Equal(1, records[0].Id);
25 | Assert.Equal("two", records[0].Name);
26 | }
27 | }
28 |
29 | private class NameIndexClass
30 | {
31 | public int Id { get; set; }
32 |
33 | [NameIndex(1)]
34 | public string? Name { get; set; }
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/Mappings/Attribute/NameTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using CsvHelper.Configuration.Attributes;
6 | using Xunit;
7 | using System.Globalization;
8 | using System.IO;
9 | using System.Linq;
10 |
11 | namespace CsvHelper.Tests.Mappings.Attribute
12 | {
13 |
14 | public class NameTests
15 | {
16 | [Fact]
17 | public void NameTest()
18 | {
19 | using (var reader = new StringReader("id,name\r\n1,one\r\n"))
20 | using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
21 | {
22 | var records = csv.GetRecords().ToList();
23 |
24 | Assert.Equal(1, records[0].Id);
25 | Assert.Equal("one", records[0].Name);
26 | }
27 | }
28 |
29 | private class NameTestClass
30 | {
31 | [Name("id")]
32 | public int Id { get; set; }
33 |
34 | [Name("name")]
35 | public string? Name { get; set; }
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/Mappings/Attribute/NewLineTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using CsvHelper.Configuration;
6 | using CsvHelper.Configuration.Attributes;
7 | using System.Globalization;
8 | using Xunit;
9 |
10 | namespace CsvHelper.Tests.Mappings.Attribute
11 | {
12 | public class NewLineTests
13 | {
14 | [Fact]
15 | public void ConstructorAttributeTest()
16 | {
17 | var config = CsvConfiguration.FromAttributes(CultureInfo.InvariantCulture);
18 | Assert.Equal("a", config.NewLine);
19 | }
20 |
21 | [NewLine("a")]
22 | private class Foo { }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/Mappings/Attribute/NullValuesTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using CsvHelper.Configuration.Attributes;
6 | using Xunit;
7 | using System.Globalization;
8 | using System.IO;
9 | using System.Linq;
10 |
11 | namespace CsvHelper.Tests.Mappings.Attribute
12 | {
13 |
14 | public class NullValuesTests
15 | {
16 | [Fact]
17 | public void NullValuesTest()
18 | {
19 | using (var reader = new StringReader("Id,Name\r\nNULL,null\r\n"))
20 | using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
21 | {
22 | var records = csv.GetRecords().ToList();
23 | Assert.Null(records[0].Id);
24 | Assert.Null(records[0].Name);
25 | }
26 | }
27 |
28 | private class NullValuesTestClass
29 | {
30 | [NullValues("NULL")]
31 | public int? Id { get; set; }
32 |
33 | [NullValues("null")]
34 | public string? Name { get; set; }
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/Mappings/Attribute/NumberStylesTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using CsvHelper.Configuration.Attributes;
6 | using Xunit;
7 | using System.Globalization;
8 | using System.IO;
9 | using System.Linq;
10 |
11 | namespace CsvHelper.Tests.Mappings.Attribute
12 | {
13 |
14 | public class NumberStylesTests
15 | {
16 | [Fact]
17 | public void DateTimeStylesTest()
18 | {
19 | using (var reader = new StringReader("Id,Name\r\n1,one\r\n"))
20 | using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
21 | {
22 | var records = csv.GetRecords().ToList();
23 | var actual = csv.Context.Maps.Find()?.MemberMaps[1].Data.TypeConverterOptions.NumberStyles;
24 |
25 | Assert.Equal(NumberStyles.AllowCurrencySymbol, actual);
26 | }
27 | }
28 |
29 | private class NumberStylesTestClass
30 | {
31 | public int Id { get; set; }
32 |
33 | [NumberStyles(NumberStyles.AllowCurrencySymbol)]
34 | public string? Name { get; set; }
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/Mappings/Attribute/OptionalTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using CsvHelper.Configuration.Attributes;
6 | using CsvHelper.Tests.Mocks;
7 | using Xunit;
8 | using System.Linq;
9 |
10 | namespace CsvHelper.Tests.Mappings.Attribute
11 | {
12 |
13 | public class OptionalTests
14 | {
15 | [Fact]
16 | public void OptionalTest()
17 | {
18 | var parser = new ParserMock
19 | {
20 | { "Id" },
21 | { "1" },
22 | };
23 |
24 | using (var csv = new CsvReader(parser))
25 | {
26 | var records = csv.GetRecords().ToList();
27 |
28 | Assert.Equal(1, records[0].Id);
29 | Assert.Null(records[0].Name);
30 | }
31 | }
32 |
33 | private class OptionalTestClass
34 | {
35 | public int Id { get; set; }
36 |
37 | [Optional]
38 | public string? Name { get; set; }
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/Mappings/Attribute/ProcessFieldBufferSizeTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using CsvHelper.Configuration;
6 | using CsvHelper.Configuration.Attributes;
7 | using System.Globalization;
8 | using Xunit;
9 |
10 | namespace CsvHelper.Tests.Mappings.Attribute
11 | {
12 | public class ProcessFieldBufferSizeTests
13 | {
14 | [Fact]
15 | public void ConstructorAttributeTest()
16 | {
17 | var config = CsvConfiguration.FromAttributes(CultureInfo.InvariantCulture);
18 | Assert.Equal(2, config.ProcessFieldBufferSize);
19 | }
20 |
21 | [ProcessFieldBufferSize(2)]
22 | private class Foo { }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/Mappings/Attribute/QuoteTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using CsvHelper.Configuration;
6 | using CsvHelper.Configuration.Attributes;
7 | using System.Globalization;
8 | using Xunit;
9 |
10 | namespace CsvHelper.Tests.AttributeMapping
11 | {
12 | public class QuoteTests
13 | {
14 | [Fact]
15 | public void QuoteTest()
16 | {
17 | var config = CsvConfiguration.FromAttributes(CultureInfo.InvariantCulture);
18 | Assert.Equal('x', config.Quote);
19 | }
20 |
21 | [Quote('x')]
22 | private class QuoteTestClass
23 | {
24 | public int Id { get; set; }
25 |
26 | public string? Name { get; set; }
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/Mappings/Attribute/ReferenceTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using CsvHelper.Configuration.Attributes;
6 | using Xunit;
7 | using System.Globalization;
8 | using System.IO;
9 | using System.Linq;
10 |
11 | namespace CsvHelper.Tests.Mappings.Attribute
12 | {
13 |
14 | public class ReferenceTests
15 | {
16 | [Fact]
17 | public void ReferenceTest()
18 | {
19 | using (var reader = new StringReader("id,name\r\n1,one\r\n"))
20 | using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
21 | {
22 | var records = csv.GetRecords().ToList();
23 |
24 | Assert.Equal(1, records[0].Id);
25 | Assert.Equal("one", records[0].B?.Name);
26 | }
27 | }
28 |
29 | private class ReferenceTestClassA
30 | {
31 | [Name("id")]
32 | public int Id { get; set; }
33 |
34 | public ReferenceTestClassB? B { get; set; }
35 | }
36 |
37 | private class ReferenceTestClassB
38 | {
39 | [Name("name")]
40 | public string? Name { get; set; }
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/Mappings/Attribute/TrimOptionsTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using CsvHelper.Configuration;
6 | using CsvHelper.Configuration.Attributes;
7 | using System.Globalization;
8 | using System.IO;
9 | using System.Linq;
10 | using Xunit;
11 |
12 | namespace CsvHelper.Tests.AttributeMapping
13 | {
14 | public class TrimOptionsTests
15 | {
16 | [Fact]
17 | public void TrimOptionsTest()
18 | {
19 | var config = CsvConfiguration.FromAttributes(CultureInfo.InvariantCulture);
20 | Assert.Equal(TrimOptions.InsideQuotes, config.TrimOptions);
21 | }
22 |
23 | [TrimOptions(TrimOptions.InsideQuotes)]
24 | private class TrimOptionsTestClass
25 | {
26 | public int Id { get; set; }
27 |
28 | public string? Name { get; set; }
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/Mappings/Attribute/UseNewObjectForNullReferenceMembersTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using CsvHelper.Configuration;
6 | using CsvHelper.Configuration.Attributes;
7 | using System.Globalization;
8 | using Xunit;
9 |
10 | namespace CsvHelper.Tests.Mappings.Attribute
11 | {
12 | public class UseNewObjectForNullReferenceMembersTests
13 | {
14 | [Fact]
15 | public void ConstructorAttributeTest()
16 | {
17 | Assert.True(CsvConfiguration.FromAttributes(CultureInfo.InvariantCulture).UseNewObjectForNullReferenceMembers);
18 | Assert.False(CsvConfiguration.FromAttributes(CultureInfo.InvariantCulture).UseNewObjectForNullReferenceMembers);
19 | }
20 |
21 | [UseNewObjectForNullReferenceMembers]
22 | private class FooTrue { }
23 |
24 | [UseNewObjectForNullReferenceMembers(false)]
25 | private class FooFalse { }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/Mappings/Attribute/WhiteSpaceCharsTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using CsvHelper.Configuration;
6 | using CsvHelper.Configuration.Attributes;
7 | using System.Globalization;
8 | using Xunit;
9 |
10 | namespace CsvHelper.Tests.Mappings.Attribute
11 | {
12 | public class WhiteSpaceCharsTests
13 | {
14 | [Fact]
15 | public void ConstructorAttributeTest()
16 | {
17 | var config = CsvConfiguration.FromAttributes(CultureInfo.InvariantCulture);
18 | Assert.Equal(new[] { 'a', 'b' }, config.WhiteSpaceChars);
19 | }
20 |
21 | [WhiteSpaceChars("a b")]
22 | private class Foo { }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/Mappings/ConstructorParameter/HeaderPrefixMapTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 |
6 | // It doesn't make sense to map a prefix as you would just set the header name you want including the prefix.
7 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/Mappings/MapConstructorTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using System;
6 | using System.Globalization;
7 | using System.IO;
8 | using CsvHelper.Configuration;
9 | using Xunit;
10 |
11 | namespace CsvHelper.Tests.Mappings
12 | {
13 |
14 | public class MapConstructorTests
15 | {
16 | [Fact]
17 | public void NoConstructor()
18 | {
19 | using (var stream = new MemoryStream())
20 | using (var reader = new StreamReader(stream))
21 | using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
22 | {
23 | Assert.Throws(() => csv.Context.RegisterClassMap());
24 | }
25 | }
26 |
27 | private class Test
28 | {
29 | public int Id { get; set; }
30 | public string? Name { get; set; }
31 | }
32 |
33 | private sealed class TestMap : ClassMap
34 | {
35 | private TestMap(string test)
36 | {
37 | Map(m => m.Id);
38 | Map(m => m.Name);
39 | }
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/Mocks/DynamicObjectMock.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using System.Collections.Generic;
6 | using System.Dynamic;
7 |
8 | namespace CsvHelper.Tests.Mocks
9 | {
10 | public class DynamicObjectMock : DynamicObject
11 | {
12 | private Dictionary dictionary = new Dictionary();
13 |
14 | public override bool TryGetMember(GetMemberBinder binder, out object? result)
15 | {
16 | return dictionary.TryGetValue(binder.Name, out result);
17 | }
18 |
19 | public override bool TrySetMember(SetMemberBinder binder, object? value)
20 | {
21 | dictionary[binder.Name] = value;
22 |
23 | return true;
24 | }
25 |
26 | public override IEnumerable GetDynamicMemberNames()
27 | {
28 | return dictionary.Keys;
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/Mocks/ParserMockTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using Xunit;
6 | using System;
7 | using System.Collections.Generic;
8 | using System.Linq;
9 | using System.Text;
10 | using System.Threading.Tasks;
11 |
12 | namespace CsvHelper.Tests.Mocks
13 | {
14 |
15 | public class ParserMockTests
16 | {
17 | [Fact]
18 | public void Test()
19 | {
20 | var parser = new ParserMock
21 | {
22 | { "Id", "Name" },
23 | { "1", "one" },
24 | };
25 | Assert.True(parser.Read());
26 | Assert.Equal("Id", parser[0]);
27 | Assert.Equal("Name", parser[1]);
28 |
29 | Assert.True(parser.Read());
30 | Assert.Equal("1", parser[0]);
31 | Assert.Equal("one", parser[1]);
32 |
33 | Assert.False(parser.Read());
34 | Assert.False(parser.Read());
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/Parsing/BufferSplittingEscapeAndQuoteTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using CsvHelper.Configuration;
6 | using Xunit;
7 | using System;
8 | using System.Collections.Generic;
9 | using System.Globalization;
10 | using System.IO;
11 | using System.Linq;
12 | using System.Text;
13 | using System.Threading.Tasks;
14 |
15 | namespace CsvHelper.Tests.Parsing
16 | {
17 |
18 | public class BufferSplittingEscapeAndQuoteTests
19 | {
20 | [Fact]
21 | public void Read_BufferEndsAtEscape_FieldIsNotBadData()
22 | {
23 | var s = new StringBuilder();
24 | s.Append("a,\"bcdefghijklm\"\"nopqrstuvwxyz\"\r\n");
25 | var config = new CsvConfiguration(CultureInfo.InvariantCulture)
26 | {
27 | BufferSize = 16,
28 | };
29 | using (var reader = new StringReader(s.ToString()))
30 | using (var parser = new CsvParser(reader, config))
31 | {
32 | parser.Read();
33 | Assert.Equal("a", parser[0]);
34 | Assert.Equal("bcdefghijklm\"nopqrstuvwxyz", parser[1]);
35 | }
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/Reading/EmptyTextReaderTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using System.Globalization;
6 | using System.IO;
7 | using Xunit;
8 |
9 | namespace CsvHelper.Tests.Reading
10 | {
11 |
12 | public class EmptyTextReaderTests
13 | {
14 | [Fact]
15 | public void EmptyStreamDoesntFailTest()
16 | {
17 | using( var stream = new MemoryStream() )
18 | using( var reader = new StreamReader( stream ) )
19 | using( var csv = new CsvReader(reader, CultureInfo.InvariantCulture) )
20 | {
21 | Assert.False( csv.Read() );
22 | }
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/Reading/NumberReadingTests.cs:
--------------------------------------------------------------------------------
1 | using System.Globalization;
2 | using System.IO;
3 | using System.Linq;
4 | using CsvHelper.Configuration;
5 | using Xunit;
6 |
7 | namespace CsvHelper.Tests.Reading
8 | {
9 | public class NumberReadingTests
10 | {
11 | [Fact]
12 | public void ReadDecimalDoubleCultureDeInvariantMix()
13 | {
14 | var input = new StringReader("""
15 | MyMoney;YourMoney;MoreMoney;BigMoney
16 | 1.2;3.4;5.6;7.8
17 | """);
18 |
19 | using var cr = new CsvReader(input, new CsvConfiguration(CultureInfo.InvariantCulture) { Delimiter = ";" });
20 | var records = cr.GetRecords(new
21 | {
22 | MyMoney = default(decimal),
23 | YourMoney = default(double),
24 | MoreMoney = default(decimal?),
25 | BigMoney = default(double?),
26 | }).ToArray();
27 |
28 | Assert.Equal(1.2m, records.Single().MyMoney);
29 | Assert.Equal(3.4, records.Single().YourMoney);
30 | Assert.Equal(5.6m, records.Single().MoreMoney);
31 | Assert.Equal(7.8, records.Single().BigMoney);
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/TestStringBuilder.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using System;
6 | using System.Text;
7 |
8 | namespace CsvHelper.Tests
9 | {
10 | ///
11 | /// A like class with configurable line ending for unit tests.
12 | ///
13 | public class TestStringBuilder
14 | {
15 | private readonly string newLine;
16 | private readonly StringBuilder builder;
17 |
18 | public TestStringBuilder(string newLine)
19 | {
20 | this.newLine = newLine ?? throw new ArgumentNullException(nameof(newLine));
21 | builder = new StringBuilder();
22 | }
23 |
24 | public TestStringBuilder AppendLine(string value)
25 | {
26 | builder.Append(value).Append(newLine);
27 | return this;
28 | }
29 |
30 | public override string ToString() => builder.ToString();
31 |
32 | public static implicit operator string(TestStringBuilder sb) => sb.ToString();
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/TestStringWriter.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using System;
6 | using System.IO;
7 |
8 | namespace CsvHelper.Tests
9 | {
10 | ///
11 | /// A class with configurable line ending for unit tests.
12 | ///
13 | public class TestStreamWriter : StreamWriter
14 | {
15 | private readonly string newLine;
16 |
17 | public TestStreamWriter(Stream stream, string newLine = "\r\n") : base(stream)
18 | {
19 | this.newLine = newLine ?? throw new ArgumentNullException(nameof(newLine));
20 | }
21 |
22 | public override void WriteLine(string? value)
23 | {
24 | base.Write(value);
25 | base.Write(newLine);
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/TypeConversion/EnumerableConverterTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using System.Globalization;
6 | using Xunit;
7 | using CsvHelper.Configuration;
8 | using CsvHelper.TypeConversion;
9 | using CsvHelper.Tests.Mocks;
10 | using System.IO;
11 |
12 | namespace CsvHelper.Tests.TypeConversion
13 | {
14 |
15 | public class EnumerableConverterTests
16 | {
17 | [Fact]
18 | public void ConvertTest()
19 | {
20 | var converter = new EnumerableConverter();
21 |
22 | var propertyMapData = new MemberMapData(null);
23 | propertyMapData.TypeConverterOptions.CultureInfo = CultureInfo.CurrentCulture;
24 |
25 | var readerRow = new CsvReader(new ParserMock());
26 | var writerRow = new CsvWriter(new StringWriter(), CultureInfo.InvariantCulture);
27 |
28 | Assert.Throws(() => converter.ConvertFromString("", readerRow, propertyMapData));
29 | Assert.Throws(() => converter.ConvertToString(5, writerRow, propertyMapData));
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/TypeConversion/TypeConverter`1Tests.cs:
--------------------------------------------------------------------------------
1 | using CsvHelper.Configuration;
2 | using CsvHelper.TypeConversion;
3 | using Xunit;
4 |
5 | namespace CsvHelper.Tests.TypeConversion
6 | {
7 | public class TypeConverter1Tests
8 | {
9 | [Fact]
10 | public void ConvertToString_NullableBoolean_Converts()
11 | {
12 | ITypeConverter converter = new GenericBoolConverter();
13 | var result = converter.ConvertToString(null, null!, null!);
14 |
15 | Assert.Equal(string.Empty, result);
16 | }
17 |
18 | [Fact]
19 | public void ConvertFromString_NullableBoolean_Converts()
20 | {
21 | ITypeConverter converter = new GenericBoolConverter();
22 | var result = (bool?)converter.ConvertFromString("true", null!, null!);
23 |
24 | Assert.True(result);
25 | }
26 |
27 | private class GenericBoolConverter : TypeConverter
28 | {
29 | public override bool? ConvertFromString(string? text, IReaderRow row, MemberMapData memberMapData)
30 | {
31 | if (bool.TryParse(text, out var result))
32 | {
33 | return result;
34 | }
35 |
36 | return null;
37 | }
38 |
39 | public override string ConvertToString(bool? value, IWriterRow row, MemberMapData memberMapData)
40 | {
41 | return value?.ToString() ?? "";
42 | }
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/Writing/AnonymousTypesTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using System.Collections;
6 | using System.Globalization;
7 | using System.IO;
8 | using Xunit;
9 |
10 | namespace CsvHelper.Tests.Writing
11 | {
12 |
13 | public class AnonymousTypesTests
14 | {
15 | [Fact]
16 | public void AnonymousIEnumerableTest()
17 | {
18 | using (var writer = new StringWriter())
19 | using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture))
20 | {
21 | IEnumerable records = new ArrayList
22 | {
23 | new
24 | {
25 | Id = 1,
26 | Name = "one",
27 | }
28 | };
29 |
30 | csv.WriteRecords(records);
31 | }
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/Writing/EnumerableTests.cs:
--------------------------------------------------------------------------------
1 | using CsvHelper.Configuration;
2 | using System.Globalization;
3 | using System.IO;
4 | using System.Linq;
5 | using Xunit;
6 |
7 | namespace CsvHelper.Tests.Writing
8 | {
9 | public class EnumerableTests
10 | {
11 | [Fact]
12 | public void WriteRecords_WithProjection_CalledOnce()
13 | {
14 | var writer = new StringWriter();
15 | var csv = new CsvWriter(writer, CultureInfo.InvariantCulture);
16 |
17 | var i = 0;
18 | var r = Enumerable.Range(0, 1).Select(r =>
19 | {
20 | i++;
21 | return (object)new Foo { Id = i, Name = "bar" };
22 | });
23 |
24 | csv.WriteRecords(r);
25 |
26 | var expected = "Id,Name\r\n1,bar\r\n";
27 |
28 | Assert.Equal(expected, writer.ToString());
29 | }
30 |
31 | private class Foo
32 | {
33 | public int Id { get; set; }
34 | public string? Name { get; set; }
35 | }
36 |
37 | private class FooMap : ClassMap
38 | {
39 | public FooMap()
40 | {
41 | Map(m => m.Id);
42 | Map(m => m.Name);
43 | }
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/Writing/WriteBufferTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using CsvHelper.Configuration;
6 | using Xunit;
7 | using System;
8 | using System.Collections.Generic;
9 | using System.Globalization;
10 | using System.IO;
11 | using System.Linq;
12 | using System.Text;
13 | using System.Threading.Tasks;
14 |
15 | namespace CsvHelper.Tests.Writing
16 | {
17 |
18 | public class WriteBufferTests
19 | {
20 | [Fact]
21 | public void Write_FieldThatIsLargerThenTwiceTheBuffer_Writes()
22 | {
23 | var config = new CsvConfiguration(CultureInfo.InvariantCulture)
24 | {
25 | BufferSize = 16
26 | };
27 | using (var writer = new StringWriter())
28 | using (var csv = new CsvWriter(writer, config))
29 | {
30 | var random = new Random();
31 | csv.WriteField("one");
32 | csv.WriteField(new string(Enumerable.Range(0, 1000).Select(i => (char)random.Next((int)'a', (int)'z' + 1)).ToArray()));
33 | }
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/XunitException.cs:
--------------------------------------------------------------------------------
1 | // Copyright 2009-2024 Josh Close
2 | // This file is a part of CsvHelper and is dual licensed under MS-PL and Apache 2.0.
3 | // 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.
4 | // https://github.com/JoshClose/CsvHelper
5 | using System;
6 | using System.Collections.Generic;
7 | using System.Linq;
8 | using System.Text;
9 | using System.Threading.Tasks;
10 |
11 | namespace CsvHelper.Tests
12 | {
13 | public class XUnitException : Exception
14 | {
15 | public XUnitException() : base() { }
16 |
17 | public XUnitException(string message) : base(message) { }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/tests/CsvHelper.Tests/xunit.runner.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://xunit.net/schema/current/xunit.runner.schema.json",
3 | "parallelizeTestCollections": false
4 | }
--------------------------------------------------------------------------------