Skip to content

Commit ad0bfde

Browse files
committed
Allow disabling quotes within delimited files.
1 parent d7ef6d9 commit ad0bfde

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 4.5.0 (2019-05-29)
2+
**Summary** - Disable wrapping delimited values in quotes.
3+
4+
### New Features
5+
* The `QuoteBehavior` enum now supports a `Never` option, to disable quotes within delimited files. This is set on the `SeparatedValueOptions.QuoteBehavior` property.
6+
* *NOTE - This can allow the generation of invalid delimited files if they contain the separator token*
7+
18
## 4.4.0 (2019-05-25)
29
**Summary** - Allow pre- and post- parsing and formatting on columns. Allow specifying a global `IFormatProvider` in `IOptions`.
310

FlatFiles/FlatFiles.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
<RepositoryUrl>https://github.com/jehugaleahsa/FlatFiles.git</RepositoryUrl>
1111
<RepositoryType>git</RepositoryType>
1212
<PackageTags>csv;comma;tab;separated;value;delimited;flat;file;fixed;width;fixed-width;length;fixed-length;parser;parsing;parse</PackageTags>
13-
<PackageReleaseNotes>Support pre- and post-parsing and formatting operations. Support overriding IFormatProvider globally in IOptions.</PackageReleaseNotes>
13+
<PackageReleaseNotes>Allow disabling quotes in delimited files.</PackageReleaseNotes>
1414
<SignAssembly>true</SignAssembly>
1515
<AssemblyOriginatorKeyFile>FlatFiles.snk</AssemblyOriginatorKeyFile>
16-
<Version>4.4.0</Version>
16+
<Version>4.5.0</Version>
1717
</PropertyGroup>
1818

1919
<PropertyGroup Condition=" '$(TargetFramework)' == 'net451' ">
@@ -27,8 +27,8 @@
2727
<PropertyGroup>
2828
<LangVersion>7.3</LangVersion>
2929
<PackageIconUrl>https://raw.githubusercontent.com/jehugaleahsa/FlatFiles/master/icon.png</PackageIconUrl>
30-
<AssemblyVersion>4.4.0.0</AssemblyVersion>
31-
<FileVersion>4.4.0.0</FileVersion>
30+
<AssemblyVersion>4.5.0.0</AssemblyVersion>
31+
<FileVersion>4.5.0.0</FileVersion>
3232
</PropertyGroup>
3333

3434
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|netstandard1.6|AnyCPU'">

FlatFiles/QuoteBehavior.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public enum QuoteBehavior
1616
/// <summary>
1717
/// FlatFiles will never put quotes around values.
1818
/// </summary>
19+
/// <remarks>This can result in the generation of invalid files.</remarks>
1920
Never = 2
2021
}
2122
}

README.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ Download using NuGet: [FlatFiles](http://nuget.org/packages/FlatFiles)
77
You can check out all of the awesome enhancements and new features in the [CHANGELOG](https://github.com/jehugaleahsa/FlatFiles/blob/master/CHANGELOG.md).
88

99
## Overview
10-
A lot of us still need to work with flat files (e.g. CSV, fixed-length, etc.) either because we're interfacing with older systems or because we're running one-time migration scripts. As common as these legacy file formats are, it's surprising there's nothing built-in to .NET for handling them. Worse, it seems like each system has its own little quirks. People have a pretty easy time reading most flat file formats but we as developers spend an enormous amount of time tweaking our code to handle every oddball edge case.
10+
Plain-text formats primarily come in two variations: delimited (CSV, TSV, etc.) and fixed-width. FlatFiles comes with support for working with both formats. Unlike most other libraries, FlatFiles puts a focus on schema definition. You build and pass a schema to a reader or writer and it will use the schema to extract or write out your values.
1111

12-
FlatFiles focuses on schema configuration, allowing you to very clearly define the schema of your file, whether reading or writing. It gives complete control over the way dates, numbers, enums, etc. are interpreted in your files. This means less time chasing down edge cases and dealing with conversion issues.
12+
A schema is defined by specifying what data columns are in your file. A column has a name, a type and an ordinal position in the file. The order matches whatever order you add the columns to the schema, so you're left just specifying the name and the type. Beyond that, you have a lot of control over the parsing/formatting behavior when reading and writing, respectively. Most of the time, the out-of-the-box options will *just work*, too. But when you need that level of extra control, you don't have to bend over backward to work around the API, like with many other libraries. FlatFiles was designed to make handling oddball edge cases either.
1313

14-
FlatFiles makes it easy to work with flat files in many different ways. It supports type mappers for directly reading and writing with data objects. It even has support for `DataTable`s and `IDataReader` if you need to interface with ADO.NET classes. If you really want to, you can read and write values using raw `object` arrays.
14+
If you are working with data classes, defining schemas is even easier. You can use the type mappers to map your properties directly. This saves you from having to specify column names or types, since both can be derived from the property. For those working with ADO.NET, there's even support for `DataTable`s and `IDataReader`. If you really want to, you can read and write values using raw `object[]`.
1515

1616
## Table of Contents
1717
* [Overview](#overview)
@@ -41,6 +41,13 @@ FlatFiles makes it easy to work with flat files in many different ways. It suppo
4141
## Type Mappers
4242
Using the type mappers, you can directly read file contents into your classes:
4343

44+
```csv
45+
customer_id,name,created,avg_sales
46+
1,bob,20120321,12.34
47+
2,Susan,20130108,13.88
48+
3,Tom,20180519,88.23
49+
```
50+
4451
```csharp
4552
var mapper = SeparatedValueTypeMapper.Define<Customer>();
4653
mapper.Property(c => c.CustomerId).ColumnName("customer_id");
@@ -49,13 +56,14 @@ mapper.Property(c => c.Created).ColumnName("created").InputFormat("yyyyMMdd");
4956
mapper.Property(c => c.AverageSales).ColumnName("avg_sales");
5057
using (var reader = new StreamReader(File.OpenRead(@"C:\path\to\file.csv")))
5158
{
52-
var customers = mapper.Read(reader).ToList();
59+
var options = new SeparatedValueOptions() { IsFirstRecordSchema = true };
60+
var customers = mapper.Read(reader, options).ToList();
5361
}
5462
```
5563

5664
To define the schema when working with type mappers, call `Property` in the order that the fields appear in the file. The type of the column is determined by the type of the mapped property. Each property configuration provides options for controlling the way FlatFiles handles strings, numbers, date/times, GUIDs, enums and more. Once the properties are configured, you can call `Read` or `Write` on the type mapper.
5765

58-
*Note* The `Read` method only retrieves records from the underlying file on-demand. To bring the entire file into memory at once, just call `ToList` or `ToArray`, or loop over the records inside of a `foreach`.
66+
*Note* The `Read` method only retrieves records from the underlying file on-demand. To bring the entire file into memory at once, just call `ToList` or `ToArray`, or loop over the records inside of a `foreach`. This is good news for people working with enormous files!
5967

6068
Writing to a file is just as easily:
6169

@@ -64,7 +72,8 @@ mapper.Property(c => c.Created).OutputFormat("yyyyMMdd");
6472
mapper.Property(c => c.AverageSales).OutputFormat("N2");
6573
using (var writer = new StreamWriter(File.OpenCreate(@"C:\path\to\file2.csv")))
6674
{
67-
mapper.Write(writer, customers);
75+
var options = new SeparatedValueOptions() { IsFirstRecordSchema = true };
76+
mapper.Write(writer, customers, options);
6877
}
6978
```
7079

0 commit comments

Comments
 (0)