From a9377b2a55e3c96d8759a13a8f50043c8dcc28b6 Mon Sep 17 00:00:00 2001 From: Gabriel Bider <1554615+silkfire@users.noreply.github.com> Date: Fri, 16 Jul 2021 02:17:42 +0200 Subject: [PATCH 1/2] Target .NET Framework 4.6.2, .NET Standard 2.0 and 2.1 --- FlatFiles/DataRecordExtensions.cs | 4 +- FlatFiles/DataTableExtensions.cs | 4 -- FlatFiles/FlatFileDataReader.cs | 14 +---- FlatFiles/FlatFileDataReaderOptions.cs | 4 -- FlatFiles/FlatFiles.csproj | 56 ++++++------------- FlatFiles/IFlatFileDataRecord.cs | 6 +- .../TypeMapping/FixedLengthTypeMapper.cs | 8 --- .../TypeMapping/SeparatedValueTypeMapper.cs | 8 --- 8 files changed, 20 insertions(+), 84 deletions(-) diff --git a/FlatFiles/DataRecordExtensions.cs b/FlatFiles/DataRecordExtensions.cs index 38d8748..e324705 100644 --- a/FlatFiles/DataRecordExtensions.cs +++ b/FlatFiles/DataRecordExtensions.cs @@ -1,5 +1,4 @@ -#if NET451 || NETSTANDARD2_0 || NETCOREAPP -using System; +using System; using System.Data; using System.Reflection; @@ -1087,4 +1086,3 @@ private static T Get(IDataRecord record, string name, Func getter) } } } -#endif \ No newline at end of file diff --git a/FlatFiles/DataTableExtensions.cs b/FlatFiles/DataTableExtensions.cs index b412999..785872d 100644 --- a/FlatFiles/DataTableExtensions.cs +++ b/FlatFiles/DataTableExtensions.cs @@ -1,5 +1,3 @@ -#if NET451 || NETSTANDARD2_0 || NETCOREAPP - using System; using System.Data; using System.Linq; @@ -77,5 +75,3 @@ public static void WriteFlatFile(this DataTable table, IWriter writer) } } } - -#endif \ No newline at end of file diff --git a/FlatFiles/FlatFileDataReader.cs b/FlatFiles/FlatFileDataReader.cs index 7435dfe..cfdf688 100644 --- a/FlatFiles/FlatFileDataReader.cs +++ b/FlatFiles/FlatFileDataReader.cs @@ -1,6 +1,4 @@ -#if NET451 || NETSTANDARD2_0 || NETCOREAPP - -using System; +using System; using System.Data; using System.Data.Common; using System.Globalization; @@ -230,11 +228,7 @@ public long GetBytes(int i, long fieldOffset, byte[] buffer, int bufferoffset, i { var values = GetValues(); var bytes = (byte[])values[i]!; -#if NET451 - Array.Copy(bytes, fieldOffset, buffer, bufferoffset, length); -#else Array.Copy(bytes, (int)fieldOffset, buffer, bufferoffset, length); -#endif return Math.Min(bytes.Length - fieldOffset, length); } @@ -266,11 +260,7 @@ public long GetChars(int i, long fieldoffset, char[] buffer, int bufferoffset, i } var values = GetValues(); var chars = (char[])values[i]!; -#if NET451 - Array.Copy(chars, fieldoffset, buffer, bufferoffset, length); -#else Array.Copy(chars, (int)fieldoffset, buffer, bufferoffset, length); -#endif return Math.Min(chars.Length - fieldoffset, length); } @@ -611,5 +601,3 @@ private ColumnCollection GetColumns(ISchema schema) } } } - -#endif diff --git a/FlatFiles/FlatFileDataReaderOptions.cs b/FlatFiles/FlatFileDataReaderOptions.cs index d3a1de1..9898a93 100644 --- a/FlatFiles/FlatFileDataReaderOptions.cs +++ b/FlatFiles/FlatFileDataReaderOptions.cs @@ -1,5 +1,3 @@ -#if NET451 || NETSTANDARD2_0 || NETCOREAPP - using System; namespace FlatFiles @@ -28,5 +26,3 @@ public FlatFileDataReaderOptions() public bool IsNullStringAllowed { get; set; } } } - -#endif \ No newline at end of file diff --git a/FlatFiles/FlatFiles.csproj b/FlatFiles/FlatFiles.csproj index b11be6b..a655110 100644 --- a/FlatFiles/FlatFiles.csproj +++ b/FlatFiles/FlatFiles.csproj @@ -1,7 +1,7 @@  - netcoreapp3.0;netstandard2.1;netstandard2.0;netstandard1.6;net451 + net462;netstandard2.0;netstandard2.1 en-US Reads and writes CSV, fixed-length and other flat file formats with a focus on schema definition, configuration and speed. Supports mapping directly between files and classes. Copyright @ 2021 @@ -26,14 +26,14 @@ enable - - bin\Debug\netstandard1.6\FlatFiles.xml + + bin\Debug\net462\FlatFiles.xml - - bin\Release\netstandard1.6\FlatFiles.xml + + bin\Release\net462\FlatFiles.xml - + bin\Debug\netstandard2.0\FlatFiles.xml @@ -42,24 +42,12 @@ bin\Release\netstandard2.0\FlatFiles.xml - - bin\Release\netstandard2.1\FlatFiles.xml - - - - bin\Debug\netcoreapp3.0\FlatFiles.xml - - - - bin\Release\netcoreapp3.0\FlatFiles.xml - - - - bin\Debug\net451\FlatFiles.xml + + bin\Debug\netstandard2.1\FlatFiles.xml - - bin\Release\net451\FlatFiles.xml + + bin\Release\netstandard2.1\FlatFiles.xml @@ -78,27 +66,17 @@ - - - - - - - - - - - + - - - + + + - - - + + + diff --git a/FlatFiles/IFlatFileDataRecord.cs b/FlatFiles/IFlatFileDataRecord.cs index 5d8bcc4..dfa35bf 100644 --- a/FlatFiles/IFlatFileDataRecord.cs +++ b/FlatFiles/IFlatFileDataRecord.cs @@ -1,6 +1,4 @@ -#if NET451 || NETSTANDARD2_0 || NETCOREAPP - -using System; +using System; using System.Data; namespace FlatFiles @@ -53,5 +51,3 @@ public interface IFlatFileDataRecord : IDataRecord ulong GetUInt64(int i); } } - -#endif \ No newline at end of file diff --git a/FlatFiles/TypeMapping/FixedLengthTypeMapper.cs b/FlatFiles/TypeMapping/FixedLengthTypeMapper.cs index dd523bb..4225b64 100644 --- a/FlatFiles/TypeMapping/FixedLengthTypeMapper.cs +++ b/FlatFiles/TypeMapping/FixedLengthTypeMapper.cs @@ -639,13 +639,11 @@ public IEnumerable Read(TextReader reader, FixedLengthOptions? options return typedReader.ReadAll(); } -#if !NET451 && !NETSTANDARD1_6 && !NETSTANDARD2_0 public IAsyncEnumerable ReadAsync(TextReader reader, FixedLengthOptions? options = null) { var typedReader = GetReader(reader, options); return typedReader.ReadAllAsync(); } -#endif public IFixedLengthTypedReader GetReader(TextReader reader, FixedLengthOptions? options = null) { @@ -680,7 +678,6 @@ public Task WriteAsync(TextWriter writer, IEnumerable entities, FixedLe return typedWriter.WriteAllAsync(entities); } -#if !NET451 && !NETSTANDARD1_6 && !NETSTANDARD2_0 public Task WriteAsync(TextWriter writer, IAsyncEnumerable entities, FixedLengthOptions? options = null) { if (entities == null) @@ -690,7 +687,6 @@ public Task WriteAsync(TextWriter writer, IAsyncEnumerable entities, Fi var typedWriter = GetWriter(writer, options); return typedWriter.WriteAllAsync(entities); } -#endif public ITypedWriter GetWriter(TextWriter writer, FixedLengthOptions? options = null) { @@ -902,14 +898,12 @@ IEnumerable IDynamicFixedLengthTypeMapper.Read(TextReader reader, FixedL return untypedReader.ReadAll(); } -#if !NET451 && !NETSTANDARD1_6 && !NETSTANDARD2_0 IAsyncEnumerable IDynamicFixedLengthTypeMapper.ReadAsync(TextReader reader, FixedLengthOptions? options) { IDynamicFixedLengthTypeMapper untypedMapper = this; var untypedReader = untypedMapper.GetReader(reader, options); return untypedReader.ReadAllAsync(); } -#endif IFixedLengthTypedReader IDynamicFixedLengthTypeMapper.GetReader(TextReader reader, FixedLengthOptions? options) { @@ -930,14 +924,12 @@ Task IDynamicFixedLengthTypeMapper.WriteAsync(TextWriter writer, IEnumerable entities, FixedLengthOptions? options) { IDynamicFixedLengthTypeMapper untypedMapper = this; var untypedWriter = untypedMapper.GetWriter(writer, options); return untypedWriter.WriteAllAsync(entities); } -#endif ITypedWriter IDynamicFixedLengthTypeMapper.GetWriter(TextWriter writer, FixedLengthOptions? options) { diff --git a/FlatFiles/TypeMapping/SeparatedValueTypeMapper.cs b/FlatFiles/TypeMapping/SeparatedValueTypeMapper.cs index 9923a84..9d44609 100644 --- a/FlatFiles/TypeMapping/SeparatedValueTypeMapper.cs +++ b/FlatFiles/TypeMapping/SeparatedValueTypeMapper.cs @@ -839,13 +839,11 @@ public IEnumerable Read(TextReader reader, SeparatedValueOptions? optio return typedReader.ReadAll(); } -#if !NET451 && !NETSTANDARD1_6 && !NETSTANDARD2_0 public IAsyncEnumerable ReadAsync(TextReader reader, SeparatedValueOptions? options = null) { var typedReader = GetReader(reader, options); return typedReader.ReadAllAsync(); } -#endif public ISeparatedValueTypedReader GetReader(TextReader reader, SeparatedValueOptions? options = null) { @@ -886,7 +884,6 @@ public Task WriteAsync(TextWriter writer, IEnumerable entities, Separat return typedWriter.WriteAllAsync(entities); } -#if !NET451 && !NETSTANDARD1_6 && !NETSTANDARD2_0 public Task WriteAsync(TextWriter writer, IAsyncEnumerable entities, SeparatedValueOptions? options = null) { if (entities == null) @@ -896,7 +893,6 @@ public Task WriteAsync(TextWriter writer, IAsyncEnumerable entities, Se var typedWriter = GetWriter(writer, options); return typedWriter.WriteAllAsync(entities); } -#endif public ITypedWriter GetWriter(TextWriter writer, SeparatedValueOptions? options = null) { @@ -1107,14 +1103,12 @@ IEnumerable IDynamicSeparatedValueTypeMapper.Read(TextReader reader, Sep return untypedReader.ReadAll(); } -#if !NET451 && !NETSTANDARD1_6 && !NETSTANDARD2_0 IAsyncEnumerable IDynamicSeparatedValueTypeMapper.ReadAsync(TextReader reader, SeparatedValueOptions? options) { IDynamicSeparatedValueTypeMapper untypedMapper = this; var untypedReader = untypedMapper.GetReader(reader, options); return untypedReader.ReadAllAsync(); } -#endif ISeparatedValueTypedReader IDynamicSeparatedValueTypeMapper.GetReader(TextReader reader, SeparatedValueOptions? options) { @@ -1135,14 +1129,12 @@ Task IDynamicSeparatedValueTypeMapper.WriteAsync(TextWriter writer, IEnumerable< return untypedWriter.WriteAllAsync(entities); } -#if !NET451 && !NETSTANDARD1_6 && !NETSTANDARD2_0 Task IDynamicSeparatedValueTypeMapper.WriteAsync(TextWriter writer, IAsyncEnumerable entities, SeparatedValueOptions? options) { IDynamicSeparatedValueTypeMapper untypedMapper = this; var untypedWriter = untypedMapper.GetWriter(writer, options); return untypedWriter.WriteAllAsync(entities); } -#endif ITypedWriter IDynamicSeparatedValueTypeMapper.GetWriter(TextWriter writer, SeparatedValueOptions? options) { From 85935b5c53cfef738ed8096c0f7bef74e847736b Mon Sep 17 00:00:00 2001 From: Gabriel Bider <1554615+silkfire@users.noreply.github.com> Date: Sat, 14 Aug 2021 23:34:24 +0200 Subject: [PATCH 2/2] * Rebase onto master * Simplify some basic type names --- .gitignore | 4 +- FlatFiles.Benchmark/AsyncVsSyncTest.cs | 12 +- FlatFiles.Benchmark/CoreBenchmarkSuite.cs | 52 +++---- FlatFiles.Benchmark/DirectVsDynamicTester.cs | 4 +- .../EmitVsReflectionWriteTester.cs | 4 +- FlatFiles.Benchmark/Program.cs | 4 +- FlatFiles.Benchmark/PropertyVsFieldTester.cs | 8 +- FlatFiles.Benchmark/RealWorldCsvTester.cs | 2 +- FlatFiles.Test/AutoMapTester.cs | 34 ++--- FlatFiles.Test/ColumnContextTester.cs | 2 +- FlatFiles.Test/ComplexColumnTester.cs | 6 +- FlatFiles.Test/CustomMappingTester.cs | 52 +++---- FlatFiles.Test/DataRecordExtensionsTester.cs | 17 +-- FlatFiles.Test/DataTableExtensionsTester.cs | 74 ++++----- .../FixedLengthAsyncReaderTester.cs | 6 +- .../FixedLengthMultipleSchemaTester.cs | 12 +- .../FixedLengthReaderMetadataTester.cs | 104 ++++++------- FlatFiles.Test/FixedLengthReaderTester.cs | 44 +++--- .../FixedLengthRuntimeTypeTester.cs | 8 +- .../FixedLengthTypeMapperFieldTester.cs | 4 +- .../FixedLengthTypeMapperMixedMemberTester.cs | 4 +- .../FixedLengthWriterMetadataTester.cs | 64 ++++---- FlatFiles.Test/FixedLengthWriterTester.cs | 12 +- FlatFiles.Test/FlatFileDataReaderTester.cs | 6 +- FlatFiles.Test/IgnoredColumnTester.cs | 4 +- FlatFiles.Test/Int32ColumnTester.cs | 8 +- FlatFiles.Test/NestedTypeTester.cs | 92 +++++------ FlatFiles.Test/NonPublicAccessTester.cs | 8 +- .../SeparatedValueAsyncReaderTester.cs | 2 +- .../SeparatedValueMultipleSchemaTester.cs | 6 +- .../SeparatedValueReaderMetadataTester.cs | 80 +++++----- FlatFiles.Test/SeparatedValueReaderTester.cs | 34 ++--- .../SeparatedValueRuntimeTypeTester.cs | 8 +- FlatFiles.Test/SeparatedValueTester.cs | 144 +++++++++--------- .../SeparatedValueTypeMapperFieldTester.cs | 2 +- ...paratedValueTypeMapperMixedMemberTester.cs | 2 +- .../SeparatedValueWriterMetadataTester.cs | 50 +++--- FlatFiles.Test/SeparatedValueWriterTester.cs | 12 +- FlatFiles.Test/TimeSpanColumnTester.cs | 4 +- FlatFiles.Test/UnusualTypesTester.cs | 24 +-- FlatFiles/BooleanColumn.cs | 10 +- FlatFiles/ByteColumn.cs | 2 +- FlatFiles/CharArrayColumn.cs | 2 +- FlatFiles/ColumnCollection.cs | 4 +- FlatFiles/ColumnDefinition.cs | 10 +- FlatFiles/ColumnProcessingException.cs | 2 +- FlatFiles/DecimalColumn.cs | 2 +- FlatFiles/DoubleColumn.cs | 2 +- FlatFiles/EnumColumn.cs | 2 +- FlatFiles/FixedLengthComplexColumn.cs | 2 +- FlatFiles/FixedLengthRecordParser.cs | 4 +- FlatFiles/FixedLengthRecordWriter.cs | 4 +- FlatFiles/FixedLengthWriter.cs | 4 +- FlatFiles/FlatFileDataReader.cs | 6 +- FlatFiles/IgnoredColumn.cs | 10 +- FlatFiles/Int16Column.cs | 2 +- FlatFiles/Int32Column.cs | 2 +- FlatFiles/Int64Column.cs | 2 +- FlatFiles/MetadataColumn.cs | 2 +- FlatFiles/NullFormatter.cs | 4 +- FlatFiles/RecordProcessingException.cs | 4 +- FlatFiles/RetryReader.cs | 2 +- FlatFiles/SByteColumn.cs | 2 +- FlatFiles/Schema.cs | 4 +- FlatFiles/SeparatedValueComplexColumn.cs | 2 +- FlatFiles/SeparatedValueOptions.cs | 2 +- FlatFiles/SeparatedValueRecordParser.cs | 4 +- FlatFiles/SeparatedValueRecordWriter.cs | 12 +- FlatFiles/SingleColumn.cs | 2 +- FlatFiles/TypeMapping/EmitCodeGenerator.cs | 18 +-- .../FixedLengthComplexPropertyMapping.cs | 2 +- .../TypeMapping/FixedLengthTypeMapper.cs | 7 +- .../IDynamicFixedLengthTypeMapper.cs | 4 - .../IDynamicSeparatedValueTypeMapper.cs | 4 - .../TypeMapping/IFixedLengthTypeMapper.cs | 4 - .../TypeMapping/ISeparatedValueTypeMapper.cs | 4 - FlatFiles/TypeMapping/Mapper.cs | 4 +- .../SeparatedValueComplexPropertyMapping.cs | 2 +- .../TypeMapping/SeparatedValueTypeMapper.cs | 12 +- .../TypeMapping/TypedReaderExtensions.cs | 2 - .../TypeMapping/TypedWriterExtensions.cs | 2 - FlatFiles/UInt16Column.cs | 2 +- FlatFiles/UInt32Column.cs | 2 +- FlatFiles/UInt64Column.cs | 2 +- 84 files changed, 578 insertions(+), 624 deletions(-) diff --git a/.gitignore b/.gitignore index c9add35..446c7b9 100644 --- a/.gitignore +++ b/.gitignore @@ -108,5 +108,5 @@ Backup*/ UpgradeLog*.XML -.vs/ -.vscode/ \ No newline at end of file +.vs +.vscode \ No newline at end of file diff --git a/FlatFiles.Benchmark/AsyncVsSyncTest.cs b/FlatFiles.Benchmark/AsyncVsSyncTest.cs index ec6a0ba..cd29c9f 100644 --- a/FlatFiles.Benchmark/AsyncVsSyncTest.cs +++ b/FlatFiles.Benchmark/AsyncVsSyncTest.cs @@ -55,8 +55,8 @@ public string SyncTest() using (var response = http.GetResponse()) using (var textReader = new StreamReader(response.GetResponseStream())) { - var entities = mapper.Read(textReader, new SeparatedValueOptions() { IsFirstRecordSchema = true }); - mapper.Write(textWriter, entities, new SeparatedValueOptions() { IsFirstRecordSchema = true }); + var entities = mapper.Read(textReader, new SeparatedValueOptions { IsFirstRecordSchema = true }); + mapper.Write(textWriter, entities, new SeparatedValueOptions { IsFirstRecordSchema = true }); } return textWriter.ToString(); } @@ -107,8 +107,8 @@ public async Task AsyncTest() using (var response = await http.GetResponseAsync().ConfigureAwait(false)) using (var textReader = new StreamReader(response.GetResponseStream())) { - var entities = mapper.ReadAsync(textReader, new SeparatedValueOptions() { IsFirstRecordSchema = true }); - await mapper.WriteAsync(textWriter, entities, new SeparatedValueOptions() { IsFirstRecordSchema = true }).ConfigureAwait(false); + var entities = mapper.ReadAsync(textReader, new SeparatedValueOptions { IsFirstRecordSchema = true }); + await mapper.WriteAsync(textWriter, entities, new SeparatedValueOptions { IsFirstRecordSchema = true }).ConfigureAwait(false); } return textWriter.ToString(); @@ -227,8 +227,8 @@ protected override string OnFormat(IColumnContext context, GeoLocation value) protected override GeoLocation OnParse(IColumnContext context, string value) { string[] parts = value.Substring(1, value.Length - 2).Split(',', 2); - var result = new GeoLocation() - { + var result = new GeoLocation + { Latitude = Convert.ToDecimal(parts[0].Trim()), Longitude = Convert.ToDecimal(parts[1].Trim()) }; diff --git a/FlatFiles.Benchmark/CoreBenchmarkSuite.cs b/FlatFiles.Benchmark/CoreBenchmarkSuite.cs index 331ddba..8e2c0f6 100644 --- a/FlatFiles.Benchmark/CoreBenchmarkSuite.cs +++ b/FlatFiles.Benchmark/CoreBenchmarkSuite.cs @@ -25,16 +25,16 @@ public CoreBenchmarkSuite() { "John", "Smith", "29", "West Street Rd", "Apt 23", "Lexington", "DE", "001569", "Blue", "Cheese and Crackers", "Soccer", "2017-01-01", "true" }; - string header = String.Join(",", headers); - string record = String.Join(",", values); - data = String.Join(Environment.NewLine, (new[] { header }).Concat(Enumerable.Repeat(0, 10000).Select(i => record))); + string header = string.Join(",", headers); + string record = string.Join(",", values); + data = string.Join(Environment.NewLine, (new[] { header }).Concat(Enumerable.Repeat(0, 10000).Select(i => record))); string[] quotedValues = new string[] { "Joe", "Smith", "29", "\"West Street Rd, Apt. 23\"", "ATTN: Will Smith", "Lexington", "DE", "001569", "Blue", "\"Cheese, and Crackers\"", "Soccer", "2017-01-01", "true" }; - string quotedRecord = String.Join(",", quotedValues); - quotedData = String.Join(Environment.NewLine, (new[] { header }).Concat(Enumerable.Repeat(0, 10000).Select(i => record))); + string quotedRecord = string.Join(",", quotedValues); + quotedData = string.Join(Environment.NewLine, (new[] { header }).Concat(Enumerable.Repeat(0, 10000).Select(i => record))); } [Benchmark] @@ -68,7 +68,7 @@ public void RunFlatFiles_TypeMapper() mapper.Property(x => x.IsActive); var reader = new StringReader(data); - var people = mapper.Read(reader, new SeparatedValueOptions() { IsFirstRecordSchema = true }).ToArray(); + var people = mapper.Read(reader, new SeparatedValueOptions { IsFirstRecordSchema = true }).ToArray(); } [Benchmark] @@ -90,7 +90,7 @@ public async Task RunFlatFiles_TypeMapper_Async() mapper.Property(x => x.IsActive); var textReader = new StringReader(data); - var reader = mapper.GetReader(textReader, new SeparatedValueOptions() { IsFirstRecordSchema = true }); + var reader = mapper.GetReader(textReader, new SeparatedValueOptions { IsFirstRecordSchema = true }); var people = new List(); await foreach (var person in reader.ReadAllAsync().ConfigureAwait(false)) { @@ -117,7 +117,7 @@ public void RunFlatFiles_TypeMapper_Quoted() mapper.Property(x => x.IsActive); var reader = new StringReader(quotedData); - var people = mapper.Read(reader, new SeparatedValueOptions() { IsFirstRecordSchema = true }).ToArray(); + var people = mapper.Read(reader, new SeparatedValueOptions { IsFirstRecordSchema = true }).ToArray(); } [Benchmark] @@ -139,7 +139,7 @@ public void RunFlatFiles_TypeMapper_Fields() mapper.Property(x => x.IsActive); var reader = new StringReader(data); - var people = mapper.Read(reader, new SeparatedValueOptions() { IsFirstRecordSchema = true }).ToArray(); + var people = mapper.Read(reader, new SeparatedValueOptions { IsFirstRecordSchema = true }).ToArray(); } [Benchmark] @@ -162,7 +162,7 @@ public void RunFlatFiles_TypeMapper_Unoptimized() mapper.Property(x => x.IsActive); var reader = new StringReader(data); - var people = mapper.Read(reader, new SeparatedValueOptions() { IsFirstRecordSchema = true }).ToArray(); + var people = mapper.Read(reader, new SeparatedValueOptions { IsFirstRecordSchema = true }).ToArray(); } [Benchmark] @@ -184,7 +184,7 @@ public void RunFlatFiles_TypeMapper_CustomMapping() mapper.CustomMapping(new BooleanColumn("IsActive")).WithReader(p => p.IsActive); var reader = new StringReader(data); - var people = mapper.Read(reader, new SeparatedValueOptions() { IsFirstRecordSchema = true }).ToArray(); + var people = mapper.Read(reader, new SeparatedValueOptions { IsFirstRecordSchema = true }).ToArray(); } [Benchmark] @@ -207,7 +207,7 @@ public void RunFlatFiles_TypeMapper_CustomMapping_Unoptimized() mapper.CustomMapping(new BooleanColumn("IsActive")).WithReader(p => p.IsActive); var reader = new StringReader(data); - var people = mapper.Read(reader, new SeparatedValueOptions() { IsFirstRecordSchema = true }).ToArray(); + var people = mapper.Read(reader, new SeparatedValueOptions { IsFirstRecordSchema = true }).ToArray(); } [Benchmark] @@ -239,13 +239,13 @@ public void RunFlatFiles_FlatFileDataReader_ByPosition() { var reader = new StringReader(data); var schema = GetSchema(); - var csvReader = new SeparatedValueReader(reader, schema, new SeparatedValueOptions() { IsFirstRecordSchema = true }); + var csvReader = new SeparatedValueReader(reader, schema, new SeparatedValueOptions { IsFirstRecordSchema = true }); var dataReader = new FlatFileDataReader(csvReader); var people = new List(); while (dataReader.Read()) { - var person = new Person() - { + var person = new Person + { FirstName = dataReader.GetString(0), LastName = dataReader.GetString(1), Age = dataReader.GetInt32(2), @@ -269,13 +269,13 @@ public void RunFlatFiles_FlatFileDataReader_ByName() { var reader = new StringReader(data); var schema = GetSchema(); - var csvReader = new SeparatedValueReader(reader, schema, new SeparatedValueOptions() { IsFirstRecordSchema = true }); + var csvReader = new SeparatedValueReader(reader, schema, new SeparatedValueOptions { IsFirstRecordSchema = true }); var dataReader = new FlatFileDataReader(csvReader); var people = new List(); while (dataReader.Read()) { - var person = new Person() - { + var person = new Person + { FirstName = dataReader.GetString("FirstName"), LastName = dataReader.GetString("LastName"), Age = dataReader.GetInt32("Age"), @@ -299,13 +299,13 @@ public void RunFlatFiles_FlatFileDataReader_GetValue() { var reader = new StringReader(data); var schema = GetSchema(); - var csvReader = new SeparatedValueReader(reader, schema, new SeparatedValueOptions() { IsFirstRecordSchema = true }); + var csvReader = new SeparatedValueReader(reader, schema, new SeparatedValueOptions { IsFirstRecordSchema = true }); var dataReader = new FlatFileDataReader(csvReader); var people = new List(); while (dataReader.Read()) { - var person = new Person() - { + var person = new Person + { FirstName = dataReader.GetValue(0), LastName = dataReader.GetValue(1), Age = dataReader.GetValue(2), @@ -329,7 +329,7 @@ public void RunFlatFiles_DataTable() { var reader = new StringReader(data); var schema = GetSchema(); - var csvReader = new SeparatedValueReader(reader, schema, new SeparatedValueOptions() { IsFirstRecordSchema = true }); + var csvReader = new SeparatedValueReader(reader, schema, new SeparatedValueOptions { IsFirstRecordSchema = true }); var dataTable = new DataTable(); dataTable.ReadFlatFile(csvReader); } @@ -399,11 +399,11 @@ public void RunStringSplit() var people = new List(); foreach (var record in records) { - var person = new Person() - { + var person = new Person + { FirstName = record[0], LastName = record[1], - Age = Int32.Parse(record[2]), + Age = int.Parse(record[2]), Street1 = record[3], Street2 = record[4], City = record[5], @@ -413,7 +413,7 @@ public void RunStringSplit() FavoriteFood = record[9], FavoriteSport = record[10], CreatedOn = DateTime.Parse(record[11]), - IsActive = Boolean.Parse(record[12]) + IsActive = bool.Parse(record[12]) }; people.Add(person); } diff --git a/FlatFiles.Benchmark/DirectVsDynamicTester.cs b/FlatFiles.Benchmark/DirectVsDynamicTester.cs index 61007a2..1b40484 100644 --- a/FlatFiles.Benchmark/DirectVsDynamicTester.cs +++ b/FlatFiles.Benchmark/DirectVsDynamicTester.cs @@ -30,8 +30,8 @@ public DirectVsDynamicTester() dynamicMapper.BooleanProperty("IsActive").ColumnName("IsActive"); this.dynamicMapper = dynamicMapper; - people = Enumerable.Range(0, 10000).Select(i => new Person() - { + people = Enumerable.Range(0, 10000).Select(i => new Person + { Name = "Susan", IQ = 132, BirthDate = new DateTime(1984, 3, 15), diff --git a/FlatFiles.Benchmark/EmitVsReflectionWriteTester.cs b/FlatFiles.Benchmark/EmitVsReflectionWriteTester.cs index 4c349d1..3fe20f0 100644 --- a/FlatFiles.Benchmark/EmitVsReflectionWriteTester.cs +++ b/FlatFiles.Benchmark/EmitVsReflectionWriteTester.cs @@ -20,8 +20,8 @@ public EmitVsReflectionWriteTester() mapper.Property(x => x.TopSpeed).ColumnName("TopSpeed"); this.mapper = mapper; - people = Enumerable.Range(0, 10000).Select(i => new Person() - { + people = Enumerable.Range(0, 10000).Select(i => new Person + { Name = "Susan", IQ = 132, BirthDate = new DateTime(1984, 3, 15), diff --git a/FlatFiles.Benchmark/Program.cs b/FlatFiles.Benchmark/Program.cs index a882f0d..ae72a56 100644 --- a/FlatFiles.Benchmark/Program.cs +++ b/FlatFiles.Benchmark/Program.cs @@ -19,8 +19,8 @@ static void Main() private static void RunBenchmarks() { - var configuration = new ManualConfig() - { + var configuration = new ManualConfig + { Options = ConfigOptions.KeepBenchmarkFiles }; configuration.AddColumn(StatisticColumn.Min); diff --git a/FlatFiles.Benchmark/PropertyVsFieldTester.cs b/FlatFiles.Benchmark/PropertyVsFieldTester.cs index dc5fe39..7e06a10 100644 --- a/FlatFiles.Benchmark/PropertyVsFieldTester.cs +++ b/FlatFiles.Benchmark/PropertyVsFieldTester.cs @@ -13,8 +13,8 @@ public class PropertyVsFieldTester public PropertyVsFieldTester() { - PropertyPerson propertyPerson = new PropertyPerson() - { + PropertyPerson propertyPerson = new PropertyPerson + { FirstName = "John", LastName = "Smith", Age = 29, @@ -31,8 +31,8 @@ public PropertyVsFieldTester() }; propertyPeople = Enumerable.Repeat(0, 10000).Select(i => propertyPerson).ToArray(); - FieldPerson fieldPerson = new FieldPerson() - { + FieldPerson fieldPerson = new FieldPerson + { FirstName = "John", LastName = "Smith", Age = 29, diff --git a/FlatFiles.Benchmark/RealWorldCsvTester.cs b/FlatFiles.Benchmark/RealWorldCsvTester.cs index 4c5b8cb..afc10b1 100644 --- a/FlatFiles.Benchmark/RealWorldCsvTester.cs +++ b/FlatFiles.Benchmark/RealWorldCsvTester.cs @@ -106,7 +106,7 @@ public void RunFlatFiles() string path = Path.Combine(directory, "TestFiles", "SampleData.csv"); using var stream = File.OpenRead(path); using var textReader = new StreamReader(stream); - var people = mapper.Read(textReader, new SeparatedValueOptions() { IsFirstRecordSchema = true }).ToArray(); + var people = mapper.Read(textReader, new SeparatedValueOptions { IsFirstRecordSchema = true }).ToArray(); } private class SampleData diff --git a/FlatFiles.Test/AutoMapTester.cs b/FlatFiles.Test/AutoMapTester.cs index f095998..3bd5866 100644 --- a/FlatFiles.Test/AutoMapTester.cs +++ b/FlatFiles.Test/AutoMapTester.cs @@ -18,9 +18,9 @@ public void ShouldDeduceSchemaForType() var writer = SeparatedValueTypeMapper.GetAutoMappedWriter(stringWriter); var expected = new[] { - new Person() { Id = 1, Name = "Bob", CreatedOn = new DateTime(2018, 07, 01), IsActive = true, VisitCount = 1 }, - new Person() { Id = 2, Name = "John", CreatedOn = new DateTime(2018, 07, 02), IsActive = false, VisitCount = null }, - new Person() { Id = 3, Name = "Susan", CreatedOn = new DateTime(2018, 07, 03), IsActive = false, VisitCount = 10 } + new Person { Id = 1, Name = "Bob", CreatedOn = new DateTime(2018, 07, 01), IsActive = true, VisitCount = 1 }, + new Person { Id = 2, Name = "John", CreatedOn = new DateTime(2018, 07, 02), IsActive = false, VisitCount = null }, + new Person { Id = 3, Name = "Susan", CreatedOn = new DateTime(2018, 07, 03), IsActive = false, VisitCount = 10 } }; writer.WriteAll(expected); string output = stringWriter.ToString(); @@ -42,9 +42,9 @@ public async Task ShouldDeduceSchemaForTypeAsync() var writer = SeparatedValueTypeMapper.GetAutoMappedWriter(stringWriter); var expected = new[] { - new Person() { Id = 1, Name = "Bob", CreatedOn = new DateTime(2018, 07, 01), IsActive = true, VisitCount = 1 }, - new Person() { Id = 2, Name = "John", CreatedOn = new DateTime(2018, 07, 02), IsActive = false, VisitCount = null }, - new Person() { Id = 3, Name = "Susan", CreatedOn = new DateTime(2018, 07, 03), IsActive = false, VisitCount = 10 } + new Person { Id = 1, Name = "Bob", CreatedOn = new DateTime(2018, 07, 01), IsActive = true, VisitCount = 1 }, + new Person { Id = 2, Name = "John", CreatedOn = new DateTime(2018, 07, 02), IsActive = false, VisitCount = null }, + new Person { Id = 3, Name = "Susan", CreatedOn = new DateTime(2018, 07, 03), IsActive = false, VisitCount = 10 } }; await writer.WriteAllAsync(expected); string output = stringWriter.ToString(); @@ -71,9 +71,9 @@ public void ShouldDeduceSchemaForType_ColumnNameCustomization() var writer = SeparatedValueTypeMapper.GetAutoMappedWriter(stringWriter, null, nameResolver); var expected = new[] { - new Person() { Id = 1, Name = "Bob", CreatedOn = new DateTime(2018, 07, 01), IsActive = true, VisitCount = 1 }, - new Person() { Id = 2, Name = "John", CreatedOn = new DateTime(2018, 07, 02), IsActive = false, VisitCount = null }, - new Person() { Id = 3, Name = "Susan", CreatedOn = new DateTime(2018, 07, 03), IsActive = false, VisitCount = 10 } + new Person { Id = 1, Name = "Bob", CreatedOn = new DateTime(2018, 07, 01), IsActive = true, VisitCount = 1 }, + new Person { Id = 2, Name = "John", CreatedOn = new DateTime(2018, 07, 02), IsActive = false, VisitCount = null }, + new Person { Id = 3, Name = "Susan", CreatedOn = new DateTime(2018, 07, 03), IsActive = false, VisitCount = 10 } }; writer.WriteAll(expected); string output = stringWriter.ToString(); @@ -97,8 +97,8 @@ public void ShouldWriteHeadersWhenNoRecordsProvided_Writer() mapper.Property(x => x.CreatedOn); mapper.Property(x => x.IsActive); var stringWriter = new StringWriter(); - var options = new SeparatedValueOptions() - { + var options = new SeparatedValueOptions + { IsFirstRecordSchema = true }; var writer = mapper.GetWriter(stringWriter, options); @@ -126,8 +126,8 @@ public void ShouldWriteHeadersWhenNoRecordsProvided_Mapper() mapper.Property(x => x.CreatedOn); mapper.Property(x => x.IsActive); var stringWriter = new StringWriter(); - var options = new SeparatedValueOptions() - { + var options = new SeparatedValueOptions + { IsFirstRecordSchema = true }; mapper.Write(stringWriter, new Person[0], options); @@ -153,13 +153,13 @@ public void ShouldNotWriteHeaderWhenHeaderNotConfigured() mapper.Property(x => x.CreatedOn); mapper.Property(x => x.IsActive); var stringWriter = new StringWriter(); - var options = new SeparatedValueOptions() - { + var options = new SeparatedValueOptions + { IsFirstRecordSchema = false }; var people = new Person[] { - new Person() + new Person { Id = 1, Name = "Tom", @@ -180,7 +180,7 @@ public void ShouldNotWriteHeaderWhenHeaderNotConfigured() [TestMethod] public void ShouldReturnEmptySchemaWhenFileEmpty() { - var stringReader = new StringReader(String.Empty); + var stringReader = new StringReader(string.Empty); var reader = SeparatedValueTypeMapper.GetAutoMappedReader(stringReader); var results = reader.ReadAll().ToArray(); diff --git a/FlatFiles.Test/ColumnContextTester.cs b/FlatFiles.Test/ColumnContextTester.cs index 8aeef4d..61e0e36 100644 --- a/FlatFiles.Test/ColumnContextTester.cs +++ b/FlatFiles.Test/ColumnContextTester.cs @@ -66,7 +66,7 @@ public void ShouldPassCorrectIndexesWhenReading() [TestMethod] public void ShouldPassCorrectIndexesWhenWriting() { - var data = new[] { new Person() { Id = 1, Name = "Bob", CreatedOn = new DateTime(2018, 06, 30), IsActive = true } }; + var data = new[] { new Person { Id = 1, Name = "Bob", CreatedOn = new DateTime(2018, 06, 30), IsActive = true } }; var mapper = SeparatedValueTypeMapper.Define(() => new Person()); var colPhysicalIndexes = new List(); var colLogicalIndexes = new List(); diff --git a/FlatFiles.Test/ComplexColumnTester.cs b/FlatFiles.Test/ComplexColumnTester.cs index 0807f0c..37fd1c4 100644 --- a/FlatFiles.Test/ComplexColumnTester.cs +++ b/FlatFiles.Test/ComplexColumnTester.cs @@ -26,7 +26,7 @@ public void ShouldRoundTrip() outerSchema.AddColumn(new FixedLengthComplexColumn("PlayerStats", innerSchema)); outerSchema.AddColumn(new StringColumn("Nickname")); - SeparatedValueReader reader = new SeparatedValueReader(stringReader, outerSchema); + SeparatedValueReader reader = new SeparatedValueReader(stringReader, outerSchema, new SeparatedValueOptions { RecordSeparator = "\n" }); Assert.IsTrue(reader.Read(), "A record should have been read."); object[] values = reader.GetValues(); Assert.AreEqual("Tom", values[0]); @@ -39,7 +39,7 @@ public void ShouldRoundTrip() Assert.AreEqual("Ace", values[3]); StringWriter stringWriter = new StringWriter(); - SeparatedValueWriter writer = new SeparatedValueWriter(stringWriter, outerSchema); + SeparatedValueWriter writer = new SeparatedValueWriter(stringWriter, outerSchema, new SeparatedValueOptions { RecordSeparator = "\n" }); writer.Write(values); string output = stringWriter.GetStringBuilder().ToString(); @@ -78,7 +78,7 @@ public void ShouldRoundTrip_TypeMappers() Assert.AreEqual("Ace", player.NickName); StringWriter stringWriter = new StringWriter(); - mapper.Write(stringWriter, new Player[] { player }); + mapper.Write(stringWriter, new Player[] { player }, new SeparatedValueOptions { RecordSeparator = "\n" }); string output = stringWriter.ToString(); Assert.AreEqual(message, output); diff --git a/FlatFiles.Test/CustomMappingTester.cs b/FlatFiles.Test/CustomMappingTester.cs index 5eddac1..86ef486 100644 --- a/FlatFiles.Test/CustomMappingTester.cs +++ b/FlatFiles.Test/CustomMappingTester.cs @@ -19,9 +19,9 @@ public void ShouldManuallyReadWriteEntity_WithReflection() StringWriter writer = new StringWriter(); var data = new[] { - new Person() { Id = 1, Name = "Bob", CreatedOn = new DateTime(2018, 6, 28), Amount = 12.34m }, - new Person() { Id = 2, Name = "John", CreatedOn = new DateTime(2018, 6, 29), Amount = 23.45m }, - new Person() { Id = 3, Name = "Susan", CreatedOn= new DateTime(2018, 6, 30), Amount = null } + new Person { Id = 1, Name = "Bob", CreatedOn = new DateTime(2018, 6, 28), Amount = 12.34m }, + new Person { Id = 2, Name = "John", CreatedOn = new DateTime(2018, 6, 29), Amount = 23.45m }, + new Person { Id = 3, Name = "Susan", CreatedOn= new DateTime(2018, 6, 30), Amount = null } }; mapper.Write(writer, data); string output = writer.ToString(); @@ -41,9 +41,9 @@ public void ShouldManuallyReadWriteEntity_WithEmit() StringWriter writer = new StringWriter(); var data = new[] { - new Person() { Id = 1, Name = "Bob", CreatedOn = new DateTime(2018, 6, 28), Amount = 12.34m }, - new Person() { Id = 2, Name = "John", CreatedOn = new DateTime(2018, 6, 29), Amount = 23.45m }, - new Person() { Id = 3, Name = "Susan", CreatedOn= new DateTime(2018, 6, 30), Amount = null } + new Person { Id = 1, Name = "Bob", CreatedOn = new DateTime(2018, 6, 28), Amount = 12.34m }, + new Person { Id = 2, Name = "John", CreatedOn = new DateTime(2018, 6, 29), Amount = 23.45m }, + new Person { Id = 3, Name = "Susan", CreatedOn= new DateTime(2018, 6, 30), Amount = null } }; mapper.Write(writer, data); string output = writer.ToString(); @@ -150,26 +150,26 @@ private static Contact[] GetContacts() { var data = new[] { - new Contact() + new Contact { Id = 1, Name = "Bob", - PhoneNumbers = new List() { "555-1111", "555-2222" }, - Emails = new List() { "bob@x.com" } + PhoneNumbers = new List { "555-1111", "555-2222" }, + Emails = new List { "bob@x.com" } }, - new Contact() + new Contact { Id = 2, Name = "John", - PhoneNumbers = new List() { "555-3333" }, - Emails = new List() { "john@x.com", "john@y.com" } + PhoneNumbers = new List { "555-3333" }, + Emails = new List { "john@x.com", "john@y.com" } }, - new Contact() + new Contact { Id = 3, Name = "Susan", PhoneNumbers = new List(), - Emails = new List() { "Susan@x.com", "Susan@y.com", "susan@z.com" } + Emails = new List { "Susan@x.com", "Susan@y.com", "susan@z.com" } } }; return data; @@ -270,8 +270,8 @@ public void ShouldManuallyReadWriteEntityWithNestedMember_WithEmit() private static ISeparatedValueTypeMapper GetNestedTypeMapper() { - var mapper = SeparatedValueTypeMapper.Define(() => new RealtyProperty() - { + var mapper = SeparatedValueTypeMapper.Define(() => new RealtyProperty + { Address = new Address(), Coordinates = new Geolocation() }); @@ -301,32 +301,32 @@ private static RealtyProperty[] GetRealtyProperties() { return new[] { - new RealtyProperty() + new RealtyProperty { Id = 1, - Coordinates = new Geolocation() - { + Coordinates = new Geolocation + { Latitude = 90, Longitude = 120 }, - Address = new Address() - { + Address = new Address + { Street = "123 Ardvark Ln", City = "Los Alimos", State = "NM", Zip = "55555" } }, - new RealtyProperty() + new RealtyProperty { Id = 2, - Coordinates = new Geolocation() - { + Coordinates = new Geolocation + { Latitude = 33, Longitude = 80 }, - Address = new Address() - { + Address = new Address + { Street = "23 Hamburger Rd", City = "Greenwich", State = "NY", diff --git a/FlatFiles.Test/DataRecordExtensionsTester.cs b/FlatFiles.Test/DataRecordExtensionsTester.cs index a63d7b5..b3532c5 100644 --- a/FlatFiles.Test/DataRecordExtensionsTester.cs +++ b/FlatFiles.Test/DataRecordExtensionsTester.cs @@ -13,7 +13,7 @@ public class DataRecordExtensionsTester [TestMethod] public void TestNullableExtensions_AllNull() { - string data = String.Join(",", typeof(NullableValues).GetProperties().Select(x => (string)null)); + string data = string.Join(",", typeof(NullableValues).GetProperties().Select(x => (string)null)); var schema = GetSchema(); var stringReader = new StringReader(data); var csvReader = new SeparatedValueReader(stringReader, schema); @@ -36,20 +36,7 @@ public void TestNullableExtensions_AllNull() [TestMethod] public void TestNullableExtensions_AllNotNull() { - string data = String.Join(",", new object[] - { - (byte)0, // Byte - (short)1, // Short - 2, // Int - 3L, // Long - 4f, // Float - 5.0, // Double - 6m, // Decimal - "abc", // String - new DateTime(2018, 07, 08), // DateTime - new Guid("{2E13CDEB-6A06-4A79-A446-B057F2881406}"), // Guid - DayOfWeek.Sunday // Enum - }); + string data = string.Join(",", (byte)0, (short)1, 2, 3L, 4f, 5.0, 6m, "abc", new DateTime(2018, 07, 08), new Guid("{2E13CDEB-6A06-4A79-A446-B057F2881406}"), DayOfWeek.Sunday); var schema = GetSchema(); var stringReader = new StringReader(data); var csvReader = new SeparatedValueReader(stringReader, schema); diff --git a/FlatFiles.Test/DataTableExtensionsTester.cs b/FlatFiles.Test/DataTableExtensionsTester.cs index bea3da4..4597d6a 100644 --- a/FlatFiles.Test/DataTableExtensionsTester.cs +++ b/FlatFiles.Test/DataTableExtensionsTester.cs @@ -32,7 +32,7 @@ public DataTableExtensionsTester() public void TestReadFlatFile_DataTableNull_Throws() { DataTable table = null; - StringReader stringReader = new StringReader(String.Empty); + StringReader stringReader = new StringReader(string.Empty); IReader parser = new SeparatedValueReader(stringReader); Assert.ThrowsException(() => DataTableExtensions.ReadFlatFile(table, parser)); } @@ -59,7 +59,7 @@ public void TestReadFlatFile_ExtractsSchema_PopulatesTable() .AddColumn(new StringColumn("name")) .AddColumn(new DateTimeColumn("created") { InputFormat = "MM/dd/yyyy", OutputFormat = "MM/dd/yyyy" }) .AddColumn(new DecimalColumn("avg")); - SeparatedValueOptions options = new SeparatedValueOptions() { IsFirstRecordSchema = true }; + SeparatedValueOptions options = new SeparatedValueOptions { IsFirstRecordSchema = true }; StringWriter stringWriter = new StringWriter(); SeparatedValueWriter builder = new SeparatedValueWriter(stringWriter, schema, options); @@ -94,13 +94,13 @@ public void TestReadFlatFile_AddsData() DataColumn createdColumn = table.Columns.Add("created", typeof(DateTime)); DataColumn avgColumn = table.Columns.Add("avg", typeof(decimal)); table.Constraints.Add("PK_blah", idColumn, true); - DataRow row = table.Rows.Add(new object[] { 1, "Bob", new DateTime(2018, 07, 16), 12.34m }); + DataRow row = table.Rows.Add(1, "Bob", new DateTime(2018, 07, 16), 12.34m); row.AcceptChanges(); const string text = @"id,name,created,avg 2,John,07/17/2018,23.45 3,Susan,07/18/2018,34.56"; - SeparatedValueOptions options = new SeparatedValueOptions() { IsFirstRecordSchema = true }; + SeparatedValueOptions options = new SeparatedValueOptions { IsFirstRecordSchema = true }; StringReader stringReader = new StringReader(text); IReader csvReader = new SeparatedValueReader(stringReader, options); table.ReadFlatFile(csvReader); @@ -130,13 +130,13 @@ public void TestReadFlatFile_ColumnMissing_InsertsNulls() DataColumn createdColumn = table.Columns.Add("created", typeof(DateTime)); DataColumn avgColumn = table.Columns.Add("avg", typeof(string)); table.Constraints.Add("PK_blah", idColumn, true); - DataRow row = table.Rows.Add(new object[] { 1, "Bob", new DateTime(2018, 07, 16), "12.34" }); + DataRow row = table.Rows.Add(1, "Bob", new DateTime(2018, 07, 16), "12.34"); row.AcceptChanges(); const string text = @"id,name,created 2,John,07/17/2018 3,Susan,07/18/2018"; - SeparatedValueOptions options = new SeparatedValueOptions() { IsFirstRecordSchema = true }; + SeparatedValueOptions options = new SeparatedValueOptions { IsFirstRecordSchema = true }; StringReader stringReader = new StringReader(text); var schema = new SeparatedValueSchema(); schema.AddColumn(new Int32Column("id")); @@ -170,7 +170,7 @@ public void TestReadFlatFile_Merge_PreserveChanges() DataColumn createdColumn = table.Columns.Add("created", typeof(DateTime)); DataColumn avgColumn = table.Columns.Add("avg", typeof(decimal)); table.Constraints.Add("PK_blah", idColumn, true); - DataRow row = table.Rows.Add(new object[] { 1, "Bob", new DateTime(2018, 07, 16), 12.34m }); + DataRow row = table.Rows.Add(1, "Bob", new DateTime(2018, 07, 16), 12.34m); row.AcceptChanges(); row.SetField(avgColumn, 99.99m); // Change but do not accept @@ -179,7 +179,7 @@ public void TestReadFlatFile_Merge_PreserveChanges() 1,Robert,07/19/2018,78.90 2,John,07/17/2018,23.45 3,Susan,07/18/2018,34.56"; - SeparatedValueOptions options = new SeparatedValueOptions() { IsFirstRecordSchema = true }; + SeparatedValueOptions options = new SeparatedValueOptions { IsFirstRecordSchema = true }; StringReader stringReader = new StringReader(text); var schema = new SeparatedValueSchema(); schema.AddColumn(new Int32Column("id")); @@ -221,7 +221,7 @@ public void TestReadFlatFile_Merge_Upsert() DataColumn createdColumn = table.Columns.Add("created", typeof(DateTime)); DataColumn avgColumn = table.Columns.Add("avg", typeof(decimal)); table.Constraints.Add("PK_blah", idColumn, true); - DataRow row = table.Rows.Add(new object[] { 1, "Bob", new DateTime(2018, 07, 16), 12.34m }); + DataRow row = table.Rows.Add(1, "Bob", new DateTime(2018, 07, 16), 12.34m); row.AcceptChanges(); row.SetField(avgColumn, 99.99m); // Change but do not accept @@ -230,7 +230,7 @@ public void TestReadFlatFile_Merge_Upsert() 1,Robert,07/19/2018,78.90 2,John,07/17/2018,23.45 3,Susan,07/18/2018,34.56"; - SeparatedValueOptions options = new SeparatedValueOptions() { IsFirstRecordSchema = true }; + SeparatedValueOptions options = new SeparatedValueOptions { IsFirstRecordSchema = true }; StringReader stringReader = new StringReader(text); var schema = new SeparatedValueSchema(); schema.AddColumn(new Int32Column("id")); @@ -273,7 +273,7 @@ public void TestReadFlatFile_Merge_Overwrite() DataColumn createdColumn = table.Columns.Add("created", typeof(DateTime)); DataColumn avgColumn = table.Columns.Add("avg", typeof(decimal)); table.Constraints.Add("PK_blah", idColumn, true); - DataRow row = table.Rows.Add(new object[] { 1, "Bob", new DateTime(2018, 07, 16), 12.34m }); + DataRow row = table.Rows.Add(1, "Bob", new DateTime(2018, 07, 16), 12.34m); row.AcceptChanges(); row.SetField(avgColumn, 99.99m); // Change but do not accept @@ -282,7 +282,7 @@ public void TestReadFlatFile_Merge_Overwrite() 1,Robert,07/19/2018,78.90 2,John,07/17/2018,23.45 3,Susan,07/18/2018,34.56"; - SeparatedValueOptions options = new SeparatedValueOptions() { IsFirstRecordSchema = true }; + SeparatedValueOptions options = new SeparatedValueOptions { IsFirstRecordSchema = true }; StringReader stringReader = new StringReader(text); var schema = new SeparatedValueSchema(); schema.AddColumn(new Int32Column("id")); @@ -321,15 +321,15 @@ public void TestWriteFlatFile_MatchingSchema() table.Columns.Add("avg", typeof(decimal)); table.Constraints.Add("PK_blah", idColumn, true); - table.Rows.Add(new object[] { 1, "Bob", new DateTime(2018, 07, 16), 12.34m }); - table.Rows.Add(new object[] { 2, "John", new DateTime(2018, 07, 17), 23.45m }); - table.Rows.Add(new object[] { 3, "Susan", new DateTime(2018, 07, 18), 34.56m }); - table.Rows.Add(new object[] { 4, null, null, null }); + table.Rows.Add(1, "Bob", new DateTime(2018, 07, 16), 12.34m); + table.Rows.Add(2, "John", new DateTime(2018, 07, 17), 23.45m); + table.Rows.Add(3, "Susan", new DateTime(2018, 07, 18), 34.56m); + table.Rows.Add(4, null, null, null); - var options = new SeparatedValueOptions() - { + var options = new SeparatedValueOptions + { IsFirstRecordSchema = true, - RecordSeparator = "\r\n", + RecordSeparator = "\n", FormatProvider = CultureInfo.InvariantCulture }; var stringWriter = new StringWriter(); @@ -360,11 +360,11 @@ public void TestWriteFlatFile_MissingColumn_WritesNull() table.Columns.Add("avg", typeof(decimal)); table.Constraints.Add("PK_blah", idColumn, true); - table.Rows.Add(new object[] { 1, "Bob", 12.34m }); - table.Rows.Add(new object[] { 2, "John", 23.45m }); - table.Rows.Add(new object[] { 3, "Susan", 34.56m }); + table.Rows.Add(1, "Bob", 12.34m); + table.Rows.Add(2, "John", 23.45m); + table.Rows.Add(3, "Susan", 34.56m); - var options = new SeparatedValueOptions() { IsFirstRecordSchema = true }; + var options = new SeparatedValueOptions { IsFirstRecordSchema = true, RecordSeparator = "\n" }; var stringWriter = new StringWriter(); var schema = new SeparatedValueSchema(); schema.AddColumn(new Int32Column("id")); @@ -393,11 +393,11 @@ public void TestWriteFlatFile_ExtraColumn_Ignores() table.Columns.Add("avg", typeof(decimal)); table.Constraints.Add("PK_blah", idColumn, true); - table.Rows.Add(new object[] { 1, "Bob", new DateTime(2018, 07, 16), 12.34m }); - table.Rows.Add(new object[] { 2, "John", new DateTime(2018, 07, 17), 23.45m }); - table.Rows.Add(new object[] { 3, "Susan", new DateTime(2018, 07, 18), 34.56m }); + table.Rows.Add(1, "Bob", new DateTime(2018, 07, 16), 12.34m); + table.Rows.Add(2, "John", new DateTime(2018, 07, 17), 23.45m); + table.Rows.Add(3, "Susan", new DateTime(2018, 07, 18), 34.56m); - var options = new SeparatedValueOptions() { IsFirstRecordSchema = true }; + var options = new SeparatedValueOptions { IsFirstRecordSchema = true, RecordSeparator = "\n" }; var stringWriter = new StringWriter(); var schema = new SeparatedValueSchema(); schema.AddColumn(new Int32Column("id")); @@ -427,8 +427,8 @@ public void TestReadFlatFile_IgnoredColumns2() schema.AddColumn(new IgnoredColumn("Ignored")); schema.AddColumn(new StringColumn("C")); - var options = new SeparatedValueOptions() - { + var options = new SeparatedValueOptions + { IsFirstRecordSchema = true }; @@ -458,14 +458,14 @@ public void TestWriteFlatFile_IgnoredColumns() table.Columns.Add("avg", typeof(decimal)); table.Constraints.Add("PK_blah", idColumn, true); - table.Rows.Add(new object[] { 1, "Bob", new DateTime(2018, 07, 16), 12.34m }); - table.Rows.Add(new object[] { 2, "John", new DateTime(2018, 07, 17), 23.45m }); - table.Rows.Add(new object[] { 3, "Susan", new DateTime(2018, 07, 18), 34.56m }); + table.Rows.Add(1, "Bob", new DateTime(2018, 07, 16), 12.34m); + table.Rows.Add(2, "John", new DateTime(2018, 07, 17), 23.45m); + table.Rows.Add(3, "Susan", new DateTime(2018, 07, 18), 34.56m); - var options = new SeparatedValueOptions() - { + var options = new SeparatedValueOptions + { IsFirstRecordSchema = true, - RecordSeparator = "\r\n", + RecordSeparator = "\n", FormatProvider = CultureInfo.InvariantCulture }; var stringWriter = new StringWriter(); @@ -513,8 +513,8 @@ public void TestReadFlatFile_DuplicateHeaderNames() NumberStyles = NumberStyles.Currency }); - var options = new SeparatedValueOptions() - { + var options = new SeparatedValueOptions + { IsFirstRecordSchema = true }; var reader = new SeparatedValueReader(new StringReader(data), schema, options); diff --git a/FlatFiles.Test/FixedLengthAsyncReaderTester.cs b/FlatFiles.Test/FixedLengthAsyncReaderTester.cs index a614c65..98e2928 100644 --- a/FlatFiles.Test/FixedLengthAsyncReaderTester.cs +++ b/FlatFiles.Test/FixedLengthAsyncReaderTester.cs @@ -32,7 +32,7 @@ public async Task TestTypeMapper_Roundtrip() mapper.Property(p => p.Created, new Window(8)).ColumnName("created").InputFormat("yyyyMMdd").OutputFormat("yyyyMMdd"); mapper.Property(p => p.IsActive, new Window(5)).ColumnName("active"); - var bob = new Person() { Id = 123, Name = "Bob", Created = new DateTime(2013, 1, 19), IsActive = true }; + var bob = new Person { Id = 123, Name = "Bob", Created = new DateTime(2013, 1, 19), IsActive = true }; StringWriter stringWriter = new StringWriter(); await mapper.WriteAsync(stringWriter, new Person[] { bob }).ConfigureAwait(false); @@ -61,8 +61,8 @@ public async Task TestTypeMapper_Roundtrip_NoSeparator() mapper.Property(p => p.Created, new Window(8)).ColumnName("created").InputFormat("yyyyMMdd").OutputFormat("yyyyMMdd"); mapper.Property(p => p.IsActive, new Window(5)).ColumnName("active"); - var bob = new Person() { Id = 123, Name = "Bob", Created = new DateTime(2013, 1, 19), IsActive = true }; - var options = new FixedLengthOptions() { HasRecordSeparator = false }; + var bob = new Person { Id = 123, Name = "Bob", Created = new DateTime(2013, 1, 19), IsActive = true }; + var options = new FixedLengthOptions { HasRecordSeparator = false }; StringWriter stringWriter = new StringWriter(); await mapper.WriteAsync(stringWriter, new Person[] { bob, bob }, options).ConfigureAwait(false); diff --git a/FlatFiles.Test/FixedLengthMultipleSchemaTester.cs b/FlatFiles.Test/FixedLengthMultipleSchemaTester.cs index 37d86fe..1439405 100644 --- a/FlatFiles.Test/FixedLengthMultipleSchemaTester.cs +++ b/FlatFiles.Test/FixedLengthMultipleSchemaTester.cs @@ -19,7 +19,7 @@ public void TestReader_ReadThreeTypes() { StringWriter stringWriter = new StringWriter(); var injector = getSchemaInjector(); - var options = new FixedLengthOptions() { Alignment = FixedAlignment.RightAligned }; + var options = new FixedLengthOptions { Alignment = FixedAlignment.RightAligned, RecordSeparator = "\n" }; var writer = new FixedLengthWriter(stringWriter, injector, options); writer.Write(new object[] { "First Batch", 2 }); writer.Write(new object[] { 1, "Bob Smith", new DateTime(2018, 06, 04), 12.34m }); @@ -110,12 +110,12 @@ public void TestTypeMapper_ReadThreeTypes() { StringWriter stringWriter = new StringWriter(); var injector = getTypeMapperInjector(); - var options = new FixedLengthOptions() { Alignment = FixedAlignment.RightAligned }; + var options = new FixedLengthOptions { Alignment = FixedAlignment.RightAligned, RecordSeparator = "\n" }; var writer = injector.GetWriter(stringWriter, options); - writer.Write(new HeaderRecord() { BatchName = "First Batch", RecordCount = 2 }); - writer.Write(new DataRecord() { Id = 1, Name = "Bob Smith", CreatedOn = new DateTime(2018, 06, 04), TotalAmount = 12.34m }); - writer.Write(new DataRecord() { Id = 2, Name = "Jane Doe", CreatedOn = new DateTime(2018, 06, 05), TotalAmount = 34.56m }); - writer.Write(new FooterRecord() { TotalAmount = 46.9m, AverageAmount = 23.45m, IsCriteriaMet = true }); + writer.Write(new HeaderRecord { BatchName = "First Batch", RecordCount = 2 }); + writer.Write(new DataRecord { Id = 1, Name = "Bob Smith", CreatedOn = new DateTime(2018, 06, 04), TotalAmount = 12.34m }); + writer.Write(new DataRecord { Id = 2, Name = "Jane Doe", CreatedOn = new DateTime(2018, 06, 05), TotalAmount = 34.56m }); + writer.Write(new FooterRecord { TotalAmount = 46.9m, AverageAmount = 23.45m, IsCriteriaMet = true }); string output = stringWriter.ToString(); Assert.AreEqual(@" First Batch 2 1 Bob Smith 20180604 12.34 diff --git a/FlatFiles.Test/FixedLengthReaderMetadataTester.cs b/FlatFiles.Test/FixedLengthReaderMetadataTester.cs index 298a009..96c8105 100644 --- a/FlatFiles.Test/FixedLengthReaderMetadataTester.cs +++ b/FlatFiles.Test/FixedLengthReaderMetadataTester.cs @@ -17,20 +17,20 @@ public void TestReader_WithSchema_NoFilter_LogicalRecordsOnly() var people = new[] { - new Person() { Name = "Bob" }, - new Person() { Name = "Tom" }, - new Person() { Name = "Jane" } + new Person { Name = "Bob" }, + new Person { Name = "Tom" }, + new Person { Name = "Jane" } }; StringWriter writer = new StringWriter(); - mapper.Write(writer, people, new FixedLengthOptions() { IsFirstRecordHeader = true }); + mapper.Write(writer, people, new FixedLengthOptions { IsFirstRecordHeader = true }); string output = writer.ToString(); mapper.CustomMapping(new RecordNumberColumn("RecordNumber"), 10) .WithReader((p, v) => p.RecordNumber = (int)v) .WithWriter(p => p.RecordNumber); StringReader reader = new StringReader(output); - var results = mapper.Read(reader, new FixedLengthOptions() { IsFirstRecordHeader = true }).ToArray(); + var results = mapper.Read(reader, new FixedLengthOptions { IsFirstRecordHeader = true }).ToArray(); Assert.AreEqual(3, results.Length); Assert.AreEqual("Bob", results[0].Name); Assert.AreEqual(1, results[0].RecordNumber); @@ -48,20 +48,20 @@ public void TestReader_WithSchema_WithFilter_LogicalRecordsOnly() var people = new[] { - new Person() { Name = "Bob" }, - new Person() { Name = "Tom" }, - new Person() { Name = "Jane" } + new Person { Name = "Bob" }, + new Person { Name = "Tom" }, + new Person { Name = "Jane" } }; StringWriter writer = new StringWriter(); - mapper.Write(writer, people, new FixedLengthOptions() { IsFirstRecordHeader = true }); + mapper.Write(writer, people, new FixedLengthOptions { IsFirstRecordHeader = true }); string output = writer.ToString(); mapper.CustomMapping(new RecordNumberColumn("RecordNumber"), 10) .WithReader((p, v) => p.RecordNumber = (int)v) .WithWriter(p => p.RecordNumber); StringReader stringReader = new StringReader(output); - var options = new FixedLengthOptions() { IsFirstRecordHeader = true }; + var options = new FixedLengthOptions { IsFirstRecordHeader = true }; var reader = mapper.GetReader(stringReader, options); reader.RecordPartitioned += (sender, e) => { @@ -83,20 +83,20 @@ public void TestReader_WithSchema_WithFilter_LineCount() var people = new[] { - new Person() { Name = "Bob" }, - new Person() { Name = "Tom" }, - new Person() { Name = "Jane" } + new Person { Name = "Bob" }, + new Person { Name = "Tom" }, + new Person { Name = "Jane" } }; StringWriter writer = new StringWriter(); - mapper.Write(writer, people, new FixedLengthOptions() { IsFirstRecordHeader = true }); + mapper.Write(writer, people, new FixedLengthOptions { IsFirstRecordHeader = true }); string output = writer.ToString(); mapper.CustomMapping(new RecordNumberColumn("RecordNumber") { IncludeSchema = true, IncludeSkippedRecords = true }, 10) .WithReader((p, v) => p.RecordNumber = (int)v) .WithWriter(p => p.RecordNumber); StringReader stringReader = new StringReader(output); - var options = new FixedLengthOptions() { IsFirstRecordHeader = true }; + var options = new FixedLengthOptions { IsFirstRecordHeader = true }; var reader = mapper.GetReader(stringReader, options); reader.RecordPartitioned += (sender, e) => { @@ -118,20 +118,20 @@ public void TestReader_WithSchema_NoFilter_LineCount() var people = new[] { - new Person() { Name = "Bob" }, - new Person() { Name = "Tom" }, - new Person() { Name = "Jane" } + new Person { Name = "Bob" }, + new Person { Name = "Tom" }, + new Person { Name = "Jane" } }; StringWriter writer = new StringWriter(); - mapper.Write(writer, people, new FixedLengthOptions() { IsFirstRecordHeader = true }); + mapper.Write(writer, people, new FixedLengthOptions { IsFirstRecordHeader = true }); string output = writer.ToString(); mapper.CustomMapping(new RecordNumberColumn("RecordNumber") { IncludeSchema = true, IncludeSkippedRecords = true }, 10) .WithReader((p, v) => p.RecordNumber = (int)v) .WithWriter(p => p.RecordNumber); StringReader reader = new StringReader(output); - var results = mapper.Read(reader, new FixedLengthOptions() { IsFirstRecordHeader = true }).ToArray(); + var results = mapper.Read(reader, new FixedLengthOptions { IsFirstRecordHeader = true }).ToArray(); Assert.AreEqual(3, results.Length); Assert.AreEqual("Bob", results[0].Name); Assert.AreEqual(2, results[0].RecordNumber); @@ -149,20 +149,20 @@ public void TestReader_WithSchema_SchemaNotCounted_WithFilter_LineCount() var people = new[] { - new Person() { Name = "Bob" }, - new Person() { Name = "Tom" }, - new Person() { Name = "Jane" } + new Person { Name = "Bob" }, + new Person { Name = "Tom" }, + new Person { Name = "Jane" } }; StringWriter writer = new StringWriter(); - mapper.Write(writer, people, new FixedLengthOptions() { IsFirstRecordHeader = true }); + mapper.Write(writer, people, new FixedLengthOptions { IsFirstRecordHeader = true }); string output = writer.ToString(); mapper.CustomMapping(new RecordNumberColumn("RecordNumber") { IncludeSchema = false, IncludeSkippedRecords = true }, 10) .WithReader((p, v) => p.RecordNumber = (int)v) .WithWriter(p => p.RecordNumber); StringReader stringReader = new StringReader(output); - var options = new FixedLengthOptions() { IsFirstRecordHeader = true }; + var options = new FixedLengthOptions { IsFirstRecordHeader = true }; var reader = mapper.GetReader(stringReader, options); reader.RecordPartitioned += (sender, e) => { @@ -184,20 +184,20 @@ public void TestReader_WithSchema_SchemaNotCounted_NoFilter_LineCountMinusOne() var people = new[] { - new Person() { Name = "Bob" }, - new Person() { Name = "Tom" }, - new Person() { Name = "Jane" } + new Person { Name = "Bob" }, + new Person { Name = "Tom" }, + new Person { Name = "Jane" } }; StringWriter writer = new StringWriter(); - mapper.Write(writer, people, new FixedLengthOptions() { IsFirstRecordHeader = true }); + mapper.Write(writer, people, new FixedLengthOptions { IsFirstRecordHeader = true }); string output = writer.ToString(); mapper.CustomMapping(new RecordNumberColumn("RecordNumber") { IncludeSchema = false, IncludeSkippedRecords = true }, 10) .WithReader((p, v) => p.RecordNumber = (int)v) .WithWriter(p => p.RecordNumber); StringReader reader = new StringReader(output); - var results = mapper.Read(reader, new FixedLengthOptions() { IsFirstRecordHeader = true }).ToArray(); + var results = mapper.Read(reader, new FixedLengthOptions { IsFirstRecordHeader = true }).ToArray(); Assert.AreEqual(3, results.Length); Assert.AreEqual("Bob", results[0].Name); Assert.AreEqual(1, results[0].RecordNumber); @@ -216,20 +216,20 @@ public void TestReader_WithSchema_NoFilter_WithIgnoredColumn_LogicalRecordsOnly( var people = new[] { - new Person() { Name = "Bob" }, - new Person() { Name = "Tom" }, - new Person() { Name = "Jane" } + new Person { Name = "Bob" }, + new Person { Name = "Tom" }, + new Person { Name = "Jane" } }; StringWriter writer = new StringWriter(); - mapper.Write(writer, people, new FixedLengthOptions() { IsFirstRecordHeader = true }); + mapper.Write(writer, people, new FixedLengthOptions { IsFirstRecordHeader = true }); string output = writer.ToString(); mapper.CustomMapping(new RecordNumberColumn("RecordNumber"), 10) .WithReader((p, v) => p.RecordNumber = (int)v) .WithWriter(p => p.RecordNumber); StringReader reader = new StringReader(output); - var results = mapper.Read(reader, new FixedLengthOptions() { IsFirstRecordHeader = true }).ToArray(); + var results = mapper.Read(reader, new FixedLengthOptions { IsFirstRecordHeader = true }).ToArray(); Assert.AreEqual(3, results.Length); Assert.AreEqual("Bob", results[0].Name); Assert.AreEqual(1, results[0].RecordNumber); @@ -248,20 +248,20 @@ public void TestReader_WithSchema_WithIgnoredColumn_WithFilter_LogicalRecordsOnl var people = new[] { - new Person() { Name = "Bob" }, - new Person() { Name = "Tom" }, - new Person() { Name = "Jane" } + new Person { Name = "Bob" }, + new Person { Name = "Tom" }, + new Person { Name = "Jane" } }; StringWriter writer = new StringWriter(); - mapper.Write(writer, people, new FixedLengthOptions() { IsFirstRecordHeader = true }); + mapper.Write(writer, people, new FixedLengthOptions { IsFirstRecordHeader = true }); string output = writer.ToString(); mapper.CustomMapping(new RecordNumberColumn("RecordNumber"), 10) .WithReader((p, v) => p.RecordNumber = (int)v) .WithWriter(p => p.RecordNumber); StringReader stringReader = new StringReader(output); - var options = new FixedLengthOptions() { IsFirstRecordHeader = true }; + var options = new FixedLengthOptions { IsFirstRecordHeader = true }; var reader = mapper.GetReader(stringReader, options); reader.RecordPartitioned += (sender, e) => { @@ -285,14 +285,14 @@ public void TestReader_WithSchema_WithIgnoredColumn_NoRecordSeparator_WithFilter var people = new[] { - new Person() { Name = "Bob" }, - new Person() { Name = "Tom" }, - new Person() { Name = "Jane" } + new Person { Name = "Bob" }, + new Person { Name = "Tom" }, + new Person { Name = "Jane" } }; StringWriter writer = new StringWriter(); - mapper.Write(writer, people, new FixedLengthOptions() - { + mapper.Write(writer, people, new FixedLengthOptions + { IsFirstRecordHeader = true, HasRecordSeparator = false }); @@ -302,8 +302,8 @@ public void TestReader_WithSchema_WithIgnoredColumn_NoRecordSeparator_WithFilter .WithReader((p, v) => p.RecordNumber = (int)v) .WithWriter(p => p.RecordNumber); StringReader stringReader = new StringReader(output); - var options = new FixedLengthOptions() - { + var options = new FixedLengthOptions + { IsFirstRecordHeader = true, HasRecordSeparator = false }; @@ -333,20 +333,20 @@ public void TestReader_WrappedWithIgnoredColumns() var people = new[] { - new ComplicatedPerson() { PersonId = 1, Name = "Bob", CreatedOn = new DateTime(2018, 04, 25) }, - new ComplicatedPerson() { PersonId = 2, Name = "Tom", CreatedOn = new DateTime(2018, 04, 26) }, - new ComplicatedPerson() { PersonId = 3, Name = "Jane", CreatedOn = new DateTime(2018, 04, 27) } + new ComplicatedPerson { PersonId = 1, Name = "Bob", CreatedOn = new DateTime(2018, 04, 25) }, + new ComplicatedPerson { PersonId = 2, Name = "Tom", CreatedOn = new DateTime(2018, 04, 26) }, + new ComplicatedPerson { PersonId = 3, Name = "Jane", CreatedOn = new DateTime(2018, 04, 27) } }; StringWriter writer = new StringWriter(); - mapper.Write(writer, people, new FixedLengthOptions() { IsFirstRecordHeader = true }); + mapper.Write(writer, people, new FixedLengthOptions { IsFirstRecordHeader = true }); string output = writer.ToString(); mapper.CustomMapping(new RecordNumberColumn("RecordNumber"), 10) .WithReader((p, v) => p.RecordNumber = (int)v) .WithWriter(p => p.RecordNumber); StringReader stringReader = new StringReader(output); - var options = new FixedLengthOptions() { IsFirstRecordHeader = true }; + var options = new FixedLengthOptions { IsFirstRecordHeader = true }; var reader = mapper.GetReader(stringReader, options); reader.RecordPartitioned += (sender, e) => { diff --git a/FlatFiles.Test/FixedLengthReaderTester.cs b/FlatFiles.Test/FixedLengthReaderTester.cs index 9e898c7..4e8fb3c 100644 --- a/FlatFiles.Test/FixedLengthReaderTester.cs +++ b/FlatFiles.Test/FixedLengthReaderTester.cs @@ -37,7 +37,7 @@ public void TestCtor_Options_TextNull_Throws() [TestMethod] public void TestCtor_SchemaNull_Throws() { - StringReader reader = new StringReader(String.Empty); + StringReader reader = new StringReader(string.Empty); FixedLengthSchema schema = null; Assert.ThrowsException(() => new FixedLengthReader(reader, schema)); } @@ -215,7 +215,7 @@ public void TestGetValues_CustomRecordSeparator_SplitsFile() schema.AddColumn(new Int32Column("id"), new Window(10)) .AddColumn(new StringColumn("name"), new Window(25)) .AddColumn(new DateTimeColumn("created"), new Window(10)); - FixedLengthOptions options = new FixedLengthOptions() { RecordSeparator = "BOOM" }; + FixedLengthOptions options = new FixedLengthOptions { RecordSeparator = "BOOM" }; StringReader stringReader = new StringReader(text); FixedLengthReader parser = new FixedLengthReader(stringReader, schema, options); @@ -243,7 +243,7 @@ public void TestGetValues_NoRecordSeparator_SplitsFile() schema.AddColumn(new Int32Column("id"), new Window(10)) .AddColumn(new StringColumn("name"), new Window(25)) .AddColumn(new DateTimeColumn("created"), new Window(10)); - FixedLengthOptions options = new FixedLengthOptions() { HasRecordSeparator = false }; + FixedLengthOptions options = new FixedLengthOptions { HasRecordSeparator = false }; StringReader stringReader = new StringReader(text); FixedLengthReader parser = new FixedLengthReader(stringReader, schema, options); @@ -269,7 +269,7 @@ public void TestGetValues_CustomFillCharacter_TrimsFill() schema.AddColumn(new Int32Column("id"), new Window(10) { Alignment = FixedAlignment.LeftAligned }) .AddColumn(new StringColumn("name"), new Window(25) { Alignment = FixedAlignment.LeftAligned }) .AddColumn(new DateTimeColumn("created") { InputFormat = "M/d/yyyy", OutputFormat = "M/d/yyyy" }, new Window(10) { Alignment = FixedAlignment.LeftAligned }); - FixedLengthOptions options = new FixedLengthOptions() { FillCharacter = '@' }; + FixedLengthOptions options = new FixedLengthOptions { FillCharacter = '@' }; object[] sources = new object[] { 123, "Bob", new DateTime(2013, 1, 19) }; StringWriter stringWriter = new StringWriter(); @@ -361,8 +361,8 @@ public void TestTypeMapper_Roundtrip() mapper.Property(p => p.Name, new Window(100)).ColumnName("name"); mapper.Property(p => p.Created, new Window(8)).ColumnName("created").InputFormat("yyyyMMdd").OutputFormat("yyyyMMdd"); - var bob = new Person() { Id = 123, Name = "Bob", Created = new DateTime(2013, 1, 19) }; - var options = new FixedLengthOptions() { FillCharacter = '@' }; + var bob = new Person { Id = 123, Name = "Bob", Created = new DateTime(2013, 1, 19) }; + var options = new FixedLengthOptions { FillCharacter = '@' }; StringWriter stringWriter = new StringWriter(); mapper.Write(stringWriter, new Person[] { bob }, options); @@ -387,8 +387,8 @@ public void TestTypeMapper_RoundTrip_SkipHeaderRow() mapper.Property(p => p.Name, new Window(100)).ColumnName("name"); mapper.Property(p => p.Created, new Window(8)).ColumnName("created").InputFormat("yyyyMMdd").OutputFormat("yyyyMMdd"); - var bob = new Person() { Id = 123, Name = "Bob", Created = new DateTime(2013, 1, 19) }; - var options = new FixedLengthOptions() { IsFirstRecordHeader = true, FillCharacter = '@' }; + var bob = new Person { Id = 123, Name = "Bob", Created = new DateTime(2013, 1, 19) }; + var options = new FixedLengthOptions { IsFirstRecordHeader = true, FillCharacter = '@' }; StringWriter stringWriter = new StringWriter(); mapper.Write(stringWriter, new Person[] { bob }, options); @@ -413,8 +413,8 @@ public void TestTypeMapper_RoundtripWithNull() mapper.Property(p => p.Name, new Window(100)).ColumnName("name"); mapper.Property(p => p.Created, new Window(8)).ColumnName("created").InputFormat("yyyyMMdd").OutputFormat("yyyyMMdd"); - var bob = new Person() { Id = 123, Name = null, Created = new DateTime(2013, 1, 19) }; - var options = new FixedLengthOptions() { FillCharacter = '@' }; + var bob = new Person { Id = 123, Name = null, Created = new DateTime(2013, 1, 19) }; + var options = new FixedLengthOptions { FillCharacter = '@' }; StringWriter stringWriter = new StringWriter(); mapper.Write(stringWriter, new Person[] { bob }, options); @@ -442,8 +442,8 @@ public void TestTypeMapper_IgnoredSeparators_RoundTrip() mapper.Ignored(new Window(1) { FillCharacter = '|' }); mapper.Property(p => p.Created, new Window(8)).ColumnName("created").InputFormat("yyyyMMdd").OutputFormat("yyyyMMdd"); - var bob = new Person() { Id = 123, Name = "Bob Smith", Created = new DateTime(2013, 1, 19) }; - var options = new FixedLengthOptions() { FillCharacter = ' ' }; + var bob = new Person { Id = 123, Name = "Bob Smith", Created = new DateTime(2013, 1, 19) }; + var options = new FixedLengthOptions { FillCharacter = ' ' }; StringWriter stringWriter = new StringWriter(); mapper.Write(stringWriter, new Person[] { bob }, options); @@ -525,7 +525,7 @@ public void TestTypeMapper_NullableBoolean_RoundTripsNull() var mapper = FixedLengthTypeMapper.Define(); mapper.Property(x => x.IsActive, 10).ColumnName("is_active"); - Person person = new Person() { IsActive = null }; + Person person = new Person { IsActive = null }; StringWriter stringWriter = new StringWriter(); mapper.Write(stringWriter, new Person[] { person }); @@ -544,7 +544,7 @@ public void TestTypeMapper_NullableBoolean_RoundTripsFalse() var mapper = FixedLengthTypeMapper.Define(); mapper.Property(x => x.IsActive, 10).ColumnName("is_active"); - Person person = new Person() { IsActive = false }; + Person person = new Person { IsActive = false }; StringWriter stringWriter = new StringWriter(); mapper.Write(stringWriter, new Person[] { person }); @@ -563,7 +563,7 @@ public void TestTypeMapper_NullableBoolean_RoundTripsTrue() var mapper = FixedLengthTypeMapper.Define(); mapper.Property(x => x.IsActive, 10).ColumnName("is_active"); - Person person = new Person() { IsActive = true }; + Person person = new Person { IsActive = true }; StringWriter stringWriter = new StringWriter(); mapper.Write(stringWriter, new Person[] { person }); @@ -623,7 +623,7 @@ public void TestTypeMapper_DefaultRecordSeparator_Intermixed() string rawData = "123 Bob 20130119\r\n234 Sam 20130119\r345 Ron 20130119\n456 Carl 20130119\r\n"; StringReader stringReader = new StringReader(rawData); - var options = new FixedLengthOptions() { HasRecordSeparator = true, RecordSeparator = null }; + var options = new FixedLengthOptions { HasRecordSeparator = true, RecordSeparator = null }; var people = mapper.Read(stringReader, options).ToArray(); Assert.AreEqual(4, people.Length); @@ -646,8 +646,8 @@ 234 Jay Smith 5/21/2017extra StringReader stringReader = new StringReader(lines); FixedLengthReader parser = new FixedLengthReader(stringReader, schema); - List records = new List() - { + List records = new List + { AssertExtra(parser, "This"), AssertExtra(parser, "is"), AssertExtra(parser, "extra") @@ -655,7 +655,7 @@ 234 Jay Smith 5/21/2017extra Assert.IsFalse(parser.Read()); StringWriter stringWriter = new StringWriter(); - FixedLengthWriter writer = new FixedLengthWriter(stringWriter, schema); + FixedLengthWriter writer = new FixedLengthWriter(stringWriter, schema, new FixedLengthOptions { RecordSeparator = "\n" }); foreach (object[] record in records) { writer.Write(record); @@ -665,7 +665,7 @@ 234 Jay Smith 5/21/2017extra Assert.AreEqual(lines, formatted, "The records did not round-trip."); } - private static object[] AssertExtra(FixedLengthReader reader, String expected) + private static object[] AssertExtra(FixedLengthReader reader, string expected) { Assert.IsTrue(reader.Read(), "Could not read the next record."); object[] values = reader.GetValues(); @@ -703,7 +703,7 @@ 234 Jay Smith 5/21/2017extra Assert.AreEqual("extra", people[2].Extra); StringWriter stringWriter = new StringWriter(); - mapper.Write(stringWriter, people); + mapper.Write(stringWriter, people, new FixedLengthOptions { RecordSeparator = "\n" }); string formatted = stringWriter.ToString(); Assert.AreEqual(lines, formatted, "The records did not round-trip."); @@ -711,7 +711,7 @@ 234 Jay Smith 5/21/2017extra internal class ExtraPerson : Person { - public String Extra { get; set; } + public string Extra { get; set; } } } } diff --git a/FlatFiles.Test/FixedLengthRuntimeTypeTester.cs b/FlatFiles.Test/FixedLengthRuntimeTypeTester.cs index b18ddd7..00cd163 100644 --- a/FlatFiles.Test/FixedLengthRuntimeTypeTester.cs +++ b/FlatFiles.Test/FixedLengthRuntimeTypeTester.cs @@ -39,8 +39,8 @@ public void TestRuntimeTypeDefinition() var people = new[] { - new Person() { Name = "John", IQ = null, BirthDate = new DateTime(1954, 10, 29), TopSpeed = 3.4m }, - new Person() { Name = "Susan", IQ = 132, BirthDate = new DateTime(1984, 3, 15), TopSpeed = 10.1m } + new Person { Name = "John", IQ = null, BirthDate = new DateTime(1954, 10, 29), TopSpeed = 3.4m }, + new Person { Name = "Susan", IQ = 132, BirthDate = new DateTime(1984, 3, 15), TopSpeed = 10.1m } }; StringWriter writer = new StringWriter(); @@ -67,8 +67,8 @@ public void TestRuntimeTypeDefinition_ReaderWriter() var people = new[] { - new Person() { Name = "John", IQ = null, BirthDate = new DateTime(1954, 10, 29), TopSpeed = 3.4m }, - new Person() { Name = "Susan", IQ = 132, BirthDate = new DateTime(1984, 3, 15), TopSpeed = 10.1m } + new Person { Name = "John", IQ = null, BirthDate = new DateTime(1954, 10, 29), TopSpeed = 3.4m }, + new Person { Name = "Susan", IQ = 132, BirthDate = new DateTime(1984, 3, 15), TopSpeed = 10.1m } }; StringWriter writer = new StringWriter(); diff --git a/FlatFiles.Test/FixedLengthTypeMapperFieldTester.cs b/FlatFiles.Test/FixedLengthTypeMapperFieldTester.cs index 0aea681..8531dad 100644 --- a/FlatFiles.Test/FixedLengthTypeMapperFieldTester.cs +++ b/FlatFiles.Test/FixedLengthTypeMapperFieldTester.cs @@ -21,8 +21,8 @@ public void TestTypeMapper_Roundtrip() mapper.Property(p => p.Created, new Window(8)).ColumnName("created").InputFormat("yyyyMMdd").OutputFormat("yyyyMMdd"); mapper.Property(p => p.IsActive, new Window(5)).ColumnName("active"); - var bob = new Person() { Id = 123, Name = "Bob", Created = new DateTime(2013, 1, 19), IsActive = true }; - var options = new FixedLengthOptions() { FillCharacter = '@' }; + var bob = new Person { Id = 123, Name = "Bob", Created = new DateTime(2013, 1, 19), IsActive = true }; + var options = new FixedLengthOptions { FillCharacter = '@' }; StringWriter stringWriter = new StringWriter(); mapper.Write(stringWriter, new Person[] { bob }, options); diff --git a/FlatFiles.Test/FixedLengthTypeMapperMixedMemberTester.cs b/FlatFiles.Test/FixedLengthTypeMapperMixedMemberTester.cs index ef4d1a0..e1e966a 100644 --- a/FlatFiles.Test/FixedLengthTypeMapperMixedMemberTester.cs +++ b/FlatFiles.Test/FixedLengthTypeMapperMixedMemberTester.cs @@ -21,8 +21,8 @@ public void TestTypeMapper_Roundtrip() mapper.Property(p => p.Created, new Window(8)).ColumnName("created").InputFormat("yyyyMMdd").OutputFormat("yyyyMMdd"); mapper.Property(p => p.IsActive, new Window(5)).ColumnName("active"); - var bob = new Person() { Id = 123, Name = "Bob", Created = new DateTime(2013, 1, 19), IsActive = true }; - var options = new FixedLengthOptions() { FillCharacter = '@' }; + var bob = new Person { Id = 123, Name = "Bob", Created = new DateTime(2013, 1, 19), IsActive = true }; + var options = new FixedLengthOptions { FillCharacter = '@' }; StringWriter stringWriter = new StringWriter(); mapper.Write(stringWriter, new Person[] { bob }, options); diff --git a/FlatFiles.Test/FixedLengthWriterMetadataTester.cs b/FlatFiles.Test/FixedLengthWriterMetadataTester.cs index 6500787..018841c 100644 --- a/FlatFiles.Test/FixedLengthWriterMetadataTester.cs +++ b/FlatFiles.Test/FixedLengthWriterMetadataTester.cs @@ -21,13 +21,13 @@ public void TestWriter_WithSchema_SchemaNotCounted() var people = new[] { - new Person() { Name = "Bob", CreatedOn = new DateTime(2018, 04, 25) }, - new Person() { Name = "Tom", CreatedOn = new DateTime(2018, 04, 26) }, - new Person() { Name = "Jane", CreatedOn = new DateTime(2018, 04, 27) } + new Person { Name = "Bob", CreatedOn = new DateTime(2018, 04, 25) }, + new Person { Name = "Tom", CreatedOn = new DateTime(2018, 04, 26) }, + new Person { Name = "Jane", CreatedOn = new DateTime(2018, 04, 27) } }; StringWriter writer = new StringWriter(); - outputMapper.Write(writer, people, new FixedLengthOptions() { IsFirstRecordHeader = true }); + outputMapper.Write(writer, people, new FixedLengthOptions { IsFirstRecordHeader = true }); string output = writer.ToString(); var inputMapper = FixedLengthTypeMapper.Define(() => new Person()); @@ -36,7 +36,7 @@ public void TestWriter_WithSchema_SchemaNotCounted() inputMapper.Property(x => x.CreatedOn, 10).InputFormat("MM/dd/yyyy"); StringReader reader = new StringReader(output); - var results = inputMapper.Read(reader, new FixedLengthOptions() { IsFirstRecordHeader = true }).ToArray(); + var results = inputMapper.Read(reader, new FixedLengthOptions { IsFirstRecordHeader = true }).ToArray(); Assert.AreEqual(3, results.Length); Assert.AreEqual("Bob", results[0].Name); Assert.AreEqual(1, results[0].RecordNumber); @@ -61,13 +61,13 @@ public void TestWriter_WithSchema_SchemaCounted() var people = new[] { - new Person() { Name = "Bob", CreatedOn = new DateTime(2018, 04, 25) }, - new Person() { Name = "Tom", CreatedOn = new DateTime(2018, 04, 26) }, - new Person() { Name = "Jane", CreatedOn = new DateTime(2018, 04, 27) } + new Person { Name = "Bob", CreatedOn = new DateTime(2018, 04, 25) }, + new Person { Name = "Tom", CreatedOn = new DateTime(2018, 04, 26) }, + new Person { Name = "Jane", CreatedOn = new DateTime(2018, 04, 27) } }; StringWriter writer = new StringWriter(); - outputMapper.Write(writer, people, new FixedLengthOptions() { IsFirstRecordHeader = true }); + outputMapper.Write(writer, people, new FixedLengthOptions { IsFirstRecordHeader = true }); string output = writer.ToString(); var inputMapper = FixedLengthTypeMapper.Define(() => new Person()); @@ -76,7 +76,7 @@ public void TestWriter_WithSchema_SchemaCounted() inputMapper.Property(x => x.CreatedOn, 10).InputFormat("MM/dd/yyyy"); StringReader reader = new StringReader(output); - var results = inputMapper.Read(reader, new FixedLengthOptions() { IsFirstRecordHeader = true }).ToArray(); + var results = inputMapper.Read(reader, new FixedLengthOptions { IsFirstRecordHeader = true }).ToArray(); Assert.AreEqual(3, results.Length); Assert.AreEqual("Bob", results[0].Name); Assert.AreEqual(2, results[0].RecordNumber); @@ -101,13 +101,13 @@ public void TestWriter_NoSchema_SchemaNotCounted() var people = new[] { - new Person() { Name = "Bob", CreatedOn = new DateTime(2018, 04, 25) }, - new Person() { Name = "Tom", CreatedOn = new DateTime(2018, 04, 26) }, - new Person() { Name = "Jane", CreatedOn = new DateTime(2018, 04, 27) } + new Person { Name = "Bob", CreatedOn = new DateTime(2018, 04, 25) }, + new Person { Name = "Tom", CreatedOn = new DateTime(2018, 04, 26) }, + new Person { Name = "Jane", CreatedOn = new DateTime(2018, 04, 27) } }; StringWriter writer = new StringWriter(); - outputMapper.Write(writer, people, new FixedLengthOptions() { IsFirstRecordHeader = true }); + outputMapper.Write(writer, people, new FixedLengthOptions { IsFirstRecordHeader = true }); string output = writer.ToString(); var inputMapper = FixedLengthTypeMapper.Define(() => new Person()); @@ -116,7 +116,7 @@ public void TestWriter_NoSchema_SchemaNotCounted() inputMapper.Property(x => x.CreatedOn, 10).InputFormat("MM/dd/yyyy"); StringReader reader = new StringReader(output); - var results = inputMapper.Read(reader, new FixedLengthOptions() { IsFirstRecordHeader = true }).ToArray(); + var results = inputMapper.Read(reader, new FixedLengthOptions { IsFirstRecordHeader = true }).ToArray(); Assert.AreEqual(3, results.Length); Assert.AreEqual("Bob", results[0].Name); Assert.AreEqual(1, results[0].RecordNumber); @@ -143,13 +143,13 @@ public void TestWriter_WithSchema_WithIgnoredColumns() var people = new[] { - new Person() { Name = "Bob", CreatedOn = new DateTime(2018, 04, 25) }, - new Person() { Name = "Tom", CreatedOn = new DateTime(2018, 04, 26) }, - new Person() { Name = "Jane", CreatedOn = new DateTime(2018, 04, 27) } + new Person { Name = "Bob", CreatedOn = new DateTime(2018, 04, 25) }, + new Person { Name = "Tom", CreatedOn = new DateTime(2018, 04, 26) }, + new Person { Name = "Jane", CreatedOn = new DateTime(2018, 04, 27) } }; StringWriter writer = new StringWriter(); - outputMapper.Write(writer, people, new FixedLengthOptions() { IsFirstRecordHeader = true }); + outputMapper.Write(writer, people, new FixedLengthOptions { IsFirstRecordHeader = true }); string output = writer.ToString(); var inputMapper = FixedLengthTypeMapper.Define(() => new Person()); @@ -160,7 +160,7 @@ public void TestWriter_WithSchema_WithIgnoredColumns() inputMapper.Property(x => x.CreatedOn, 10).InputFormat("MM/dd/yyyy"); StringReader reader = new StringReader(output); - var results = inputMapper.Read(reader, new FixedLengthOptions() { IsFirstRecordHeader = true }).ToArray(); + var results = inputMapper.Read(reader, new FixedLengthOptions { IsFirstRecordHeader = true }).ToArray(); Assert.AreEqual(3, results.Length); Assert.AreEqual("Bob", results[0].Name); Assert.AreEqual(2, results[0].RecordNumber); @@ -187,14 +187,14 @@ public void TestWriter_NoRecordSeparator_ValidRecordCounts() var people = new[] { - new Person() { Name = "Bob", CreatedOn = new DateTime(2018, 04, 25) }, - new Person() { Name = "Tom", CreatedOn = new DateTime(2018, 04, 26) }, - new Person() { Name = "Jane", CreatedOn = new DateTime(2018, 04, 27) } + new Person { Name = "Bob", CreatedOn = new DateTime(2018, 04, 25) }, + new Person { Name = "Tom", CreatedOn = new DateTime(2018, 04, 26) }, + new Person { Name = "Jane", CreatedOn = new DateTime(2018, 04, 27) } }; StringWriter writer = new StringWriter(); - outputMapper.Write(writer, people, new FixedLengthOptions() - { + outputMapper.Write(writer, people, new FixedLengthOptions + { IsFirstRecordHeader = true, HasRecordSeparator = false }); @@ -208,8 +208,8 @@ public void TestWriter_NoRecordSeparator_ValidRecordCounts() inputMapper.Property(x => x.CreatedOn, 10).InputFormat("MM/dd/yyyy"); StringReader reader = new StringReader(output); - var results = inputMapper.Read(reader, new FixedLengthOptions() - { + var results = inputMapper.Read(reader, new FixedLengthOptions + { IsFirstRecordHeader = true, HasRecordSeparator = false }).ToArray(); @@ -237,13 +237,13 @@ public void TestWriter_WriteOnlyColumn_WithIgnoredColumn() var people = new[] { - new Person() { Name = "Bob", CreatedOn = new DateTime(2018, 04, 25) }, - new Person() { Name = "Tom", CreatedOn = new DateTime(2018, 04, 26) }, - new Person() { Name = "Jane", CreatedOn = new DateTime(2018, 04, 27) } + new Person { Name = "Bob", CreatedOn = new DateTime(2018, 04, 25) }, + new Person { Name = "Tom", CreatedOn = new DateTime(2018, 04, 26) }, + new Person { Name = "Jane", CreatedOn = new DateTime(2018, 04, 27) } }; StringWriter writer = new StringWriter(); - outputMapper.Write(writer, people, new FixedLengthOptions() { IsFirstRecordHeader = true }); + outputMapper.Write(writer, people, new FixedLengthOptions { IsFirstRecordHeader = true }); string output = writer.ToString(); var inputMapper = FixedLengthTypeMapper.Define(() => new Person()); @@ -254,7 +254,7 @@ public void TestWriter_WriteOnlyColumn_WithIgnoredColumn() inputMapper.Property(x => x.CreatedOn, 10).InputFormat("MM/dd/yyyy"); StringReader reader = new StringReader(output); - var results = inputMapper.Read(reader, new FixedLengthOptions() { IsFirstRecordHeader = true }).ToArray(); + var results = inputMapper.Read(reader, new FixedLengthOptions { IsFirstRecordHeader = true }).ToArray(); Assert.AreEqual(3, results.Length); Assert.AreEqual("Bob", results[0].Name); Assert.AreEqual(2, results[0].RecordNumber); diff --git a/FlatFiles.Test/FixedLengthWriterTester.cs b/FlatFiles.Test/FixedLengthWriterTester.cs index b9f2de1..477ae8f 100644 --- a/FlatFiles.Test/FixedLengthWriterTester.cs +++ b/FlatFiles.Test/FixedLengthWriterTester.cs @@ -43,7 +43,7 @@ public void ShouldWriteHeader() schema.AddColumn(new StringColumn("First"), new Window(10) { FillCharacter = '@' }); schema.AddColumn(new StringColumn("Second"), new Window(10) { FillCharacter = '!' }); schema.AddColumn(new StringColumn("Third"), new Window(10) { FillCharacter = '$' }); - FixedLengthOptions options = new FixedLengthOptions() { IsFirstRecordHeader = true }; + FixedLengthOptions options = new FixedLengthOptions { IsFirstRecordHeader = true }; StringWriter stringWriter = new StringWriter(); FixedLengthWriter writer = new FixedLengthWriter(stringWriter, schema, options); @@ -67,7 +67,7 @@ public void ShouldWriteHeader_IgnoredColumns() schema.AddColumn(new StringColumn("Second"), new Window(10) { FillCharacter = '!' }); schema.AddColumn(new IgnoredColumn(), new Window(1) { FillCharacter = '|' }); schema.AddColumn(new StringColumn("Third"), new Window(10) { FillCharacter = '$' }); - FixedLengthOptions options = new FixedLengthOptions() { IsFirstRecordHeader = true }; + FixedLengthOptions options = new FixedLengthOptions { IsFirstRecordHeader = true }; StringWriter stringWriter = new StringWriter(); FixedLengthWriter writer = new FixedLengthWriter(stringWriter, schema, options); @@ -89,7 +89,7 @@ public void ShouldWriteHeader_NoRecordSeparator() schema.AddColumn(new StringColumn("First"), new Window(10) { FillCharacter = '@' }); schema.AddColumn(new StringColumn("Second"), new Window(10) { FillCharacter = '!' }); schema.AddColumn(new StringColumn("Third"), new Window(10) { FillCharacter = '$' }); - FixedLengthOptions options = new FixedLengthOptions() { IsFirstRecordHeader = true, HasRecordSeparator = false }; + FixedLengthOptions options = new FixedLengthOptions { IsFirstRecordHeader = true, HasRecordSeparator = false }; StringWriter stringWriter = new StringWriter(); FixedLengthWriter writer = new FixedLengthWriter(stringWriter, schema, options); @@ -125,15 +125,15 @@ public void ShouldWriteSchemaIfExplicit() // Explicitly indicate that the first record is NOT the schema FixedLengthSchema schema = new FixedLengthSchema(); schema.AddColumn(new StringColumn("Col1"), 10); - FixedLengthWriter writer = new FixedLengthWriter(stringWriter, schema, new FixedLengthOptions() - { + FixedLengthWriter writer = new FixedLengthWriter(stringWriter, schema, new FixedLengthOptions + { IsFirstRecordHeader = false }); writer.WriteSchema(); // Explicitly write the schema writer.Write(new string[] { "a" }); StringReader stringReader = new StringReader(stringWriter.ToString()); - var reader = new FixedLengthReader(stringReader, schema, new FixedLengthOptions() { IsFirstRecordHeader = true }); + var reader = new FixedLengthReader(stringReader, schema, new FixedLengthOptions { IsFirstRecordHeader = true }); Assert.IsTrue(reader.Read(), "The record was not retrieved after the schema."); Assert.IsFalse(reader.Read(), "Encountered more than the expected number of records."); diff --git a/FlatFiles.Test/FlatFileDataReaderTester.cs b/FlatFiles.Test/FlatFileDataReaderTester.cs index 67d375b..ce3556a 100644 --- a/FlatFiles.Test/FlatFileDataReaderTester.cs +++ b/FlatFiles.Test/FlatFileDataReaderTester.cs @@ -61,7 +61,7 @@ private static FlatFileDataReader GetFlatFileReaderWithDefaultSchema() 2,Susan,2018-07-04,false,,{24C250EB-87C9-45DE-B01F-71A7754C6AAD},5 "; var reader = new StringReader(data); - var csvReader = new SeparatedValueReader(reader, new SeparatedValueOptions() { IsFirstRecordSchema = true }); + var csvReader = new SeparatedValueReader(reader, new SeparatedValueOptions { IsFirstRecordSchema = true }); var dataReader = new FlatFileDataReader(csvReader); return dataReader; } @@ -159,8 +159,8 @@ public void TestFlatFileReader_IgnoreIgnoredColumns() schema.AddColumn(new IgnoredColumn("Ignored")); schema.AddColumn(new StringColumn("C")); - var options = new SeparatedValueOptions() - { + var options = new SeparatedValueOptions + { IsFirstRecordSchema = true }; diff --git a/FlatFiles.Test/IgnoredColumnTester.cs b/FlatFiles.Test/IgnoredColumnTester.cs index 5523729..873841d 100644 --- a/FlatFiles.Test/IgnoredColumnTester.cs +++ b/FlatFiles.Test/IgnoredColumnTester.cs @@ -9,8 +9,8 @@ public class IgnoredColumnTester [TestMethod] public void TestIgnoredColumn_HandlePreAndPostProcessing() { - var ignored = new IgnoredColumn() - { + var ignored = new IgnoredColumn + { ColumnName = "Ignored", NullFormatter = NullFormatter.ForValue("NULL"), OnParsing = (ctx, value) => diff --git a/FlatFiles.Test/Int32ColumnTester.cs b/FlatFiles.Test/Int32ColumnTester.cs index e43ff9d..f4a77ec 100644 --- a/FlatFiles.Test/Int32ColumnTester.cs +++ b/FlatFiles.Test/Int32ColumnTester.cs @@ -37,8 +37,8 @@ public void TestCtor_SetsName_Trimmed() public void TestParse_ValueBlank_NullReturned() { Int32Column column = new Int32Column("count"); - Int32? actual = (Int32?)column.Parse(null, " "); - Int32? expected = null; + int? actual = (int?)column.Parse(null, " "); + int? expected = null; Assert.AreEqual(expected, actual); } @@ -83,7 +83,7 @@ public void TestParse_NotNullable_NullValue_Throws() IsNullable = false, DefaultValue = DefaultValue.Disabled() }; - Assert.ThrowsException(() => column.Parse(null, String.Empty)); + Assert.ThrowsException(() => column.Parse(null, string.Empty)); } /// @@ -97,7 +97,7 @@ public void TestParse_NotNullable_NullValue_DefaultProvided() IsNullable = false, DefaultValue = DefaultValue.Use(0) }; - int value = (int)column.Parse(null, String.Empty); + int value = (int)column.Parse(null, string.Empty); Assert.AreEqual(0, value, "A default was not provided."); } } diff --git a/FlatFiles.Test/NestedTypeTester.cs b/FlatFiles.Test/NestedTypeTester.cs index baab91c..7fbda89 100644 --- a/FlatFiles.Test/NestedTypeTester.cs +++ b/FlatFiles.Test/NestedTypeTester.cs @@ -23,18 +23,18 @@ public void TestMappingNestedMember() mapper.Property(x => x.CreatedOn).ColumnName("CreatedOn"); var recordValues = new[] { "123", "Bob", "Test Street 1", "Test City", "PA", "55555", "true", "2017-11-05" }; - var record = String.Join(",", recordValues); + var record = string.Join(",", recordValues); StringReader reader = new StringReader(record); var results = mapper.Read(reader).ToArray(); Assert.AreEqual(1, results.Length); var result = results[0]; - var expected = new Person() - { + var expected = new Person + { Id = 123, Name = "Bob", - Address1 = new Address() - { + Address1 = new Address + { Street = "Test Street 1", City = "Test City", State = "PA", @@ -61,19 +61,19 @@ public void TestMappingNestedMemberDynamically() mapper.DateTimeProperty("CreatedOn").ColumnName("CreatedOn"); var recordValues = new[] { "123", "Bob", "Test Street 1", "Test City", "PA", "55555", "true", "2017-11-05" }; - var record = String.Join(",", recordValues); + var record = string.Join(",", recordValues); StringReader reader = new StringReader(record); var results = mapper.Read(reader).ToArray(); Assert.AreEqual(1, results.Length); var result = results[0]; Assert.IsInstanceOfType(result, typeof(Person)); - var expected = new Person() - { + var expected = new Person + { Id = 123, Name = "Bob", - Address1 = new Address() - { + Address1 = new Address + { Street = "Test Street 1", City = "Test City", State = "PA", @@ -100,12 +100,12 @@ public void TestRoundTrip_FixedLength() mapper.Property(x => x.CreatedOn, 10).ColumnName("CreatedOn").InputFormat("yyyyMMdd").OutputFormat("yyyyMMdd"); mapper.UseFactory(() => new Address()); - var expected = new Person() - { + var expected = new Person + { Id = 123, Name = "Bob", - Address1 = new Address() - { + Address1 = new Address + { Street = "Test Street 1", City = "Test City", State = "PA", @@ -141,12 +141,12 @@ public void TestRoundTrip_FixedLength_Dynamic() mapper.DateTimeProperty("CreatedOn", 10).ColumnName("CreatedOn").InputFormat("yyyyMMdd").OutputFormat("yyyyMMdd"); mapper.UseFactory(typeof(Address), () => new Address()); - var expected = new Person() - { + var expected = new Person + { Id = 123, Name = "Bob", - Address1 = new Address() - { + Address1 = new Address + { Street = "Test Street 1", City = "Test City", State = "PA", @@ -186,19 +186,19 @@ public void TestMappingNestedMembers_MultipleSameType() mapper.Property(x => x.IsActive).ColumnName("IsActive"); mapper.Property(x => x.CreatedOn).ColumnName("CreatedOn"); - var expected = new Person() - { + var expected = new Person + { Id = 123, Name = "Bob", - Address1 = new Address() - { + Address1 = new Address + { Street = "Test Street 1", City = "Test City", State = "PA", Zip = "55555" }, - Address2 = new Address() - { + Address2 = new Address + { Street = "Test Street 2", City = "Test City 2", State = "WA", @@ -278,20 +278,20 @@ public void TestMappingNestedMembers_DeepNesting() mapper.Property(x => x.Level2.Level3.Level4.IsActive).ColumnName("IsActive"); mapper.Property(x => x.Level2.Level3.CreatedOn).ColumnName("CreatedOn"); - var expected = new Level1() - { + var expected = new Level1 + { Id = 123, - Level2 = new Level2() - { + Level2 = new Level2 + { Name = "Bob", - Level3 = new Level3() - { + Level3 = new Level3 + { CreatedOn = new DateTime(2017, 11, 05), - Level4 = new Level4() - { + Level4 = new Level4 + { IsActive = true, - Address = new Address() - { + Address = new Address + { Street = "Test Street 1", City = "Test City", State = "PA", @@ -335,27 +335,27 @@ public void TestMappingNestedMembers_DeepNesting_RecurringMemberNames() mapper.Property(x => x.Level2.Level3.Level4.IsActive).ColumnName("IsActive"); mapper.Property(x => x.Level2.Level3.CreatedOn).ColumnName("CreatedOn"); - var expected = new Level1() - { + var expected = new Level1 + { Id = 123, - Address = new Address() - { + Address = new Address + { Street = "Test Street 2", City = "Test City 2", State = "WA", Zip = "44444" }, - Level2 = new Level2() - { + Level2 = new Level2 + { Name = "Bob", - Level3 = new Level3() - { + Level3 = new Level3 + { CreatedOn = new DateTime(2017, 11, 05), - Level4 = new Level4() - { + Level4 = new Level4 + { IsActive = true, - Address = new Address() - { + Address = new Address + { Street = "Test Street 1", City = "Test City", State = "PA", diff --git a/FlatFiles.Test/NonPublicAccessTester.cs b/FlatFiles.Test/NonPublicAccessTester.cs index ad95f7f..90a9bd1 100644 --- a/FlatFiles.Test/NonPublicAccessTester.cs +++ b/FlatFiles.Test/NonPublicAccessTester.cs @@ -22,8 +22,8 @@ public void MapInternalClass() string rawData = @"ABC123,Doing Fine,20180115,20180115145100,true"; StringReader reader = new StringReader(rawData); - var data = mapper.Read(reader, new SeparatedValueOptions() - { + var data = mapper.Read(reader, new SeparatedValueOptions + { IsFirstRecordSchema = false, RecordSeparator = "\n", Separator = ",", @@ -52,8 +52,8 @@ public void MapInternalClass_Dynamic() string rawData = @"ABC123,Doing Fine,20180115,20180115145100,true"; StringReader reader = new StringReader(rawData); - var data = mapper.Read(reader, new SeparatedValueOptions() - { + var data = mapper.Read(reader, new SeparatedValueOptions + { IsFirstRecordSchema = false, RecordSeparator = "\n", Separator = ",", diff --git a/FlatFiles.Test/SeparatedValueAsyncReaderTester.cs b/FlatFiles.Test/SeparatedValueAsyncReaderTester.cs index dfc9e92..f5c5392 100644 --- a/FlatFiles.Test/SeparatedValueAsyncReaderTester.cs +++ b/FlatFiles.Test/SeparatedValueAsyncReaderTester.cs @@ -26,7 +26,7 @@ public async Task TestTypeMapper_Roundtrip() mapper.Property(p => p.Created).ColumnName("created").InputFormat("yyyyMMdd").OutputFormat("yyyyMMdd"); mapper.Property(p => p.IsActive).ColumnName("active"); - var bob = new Person() { Id = 123, Name = "Bob", Created = new DateTime(2013, 1, 19), IsActive = true }; + var bob = new Person { Id = 123, Name = "Bob", Created = new DateTime(2013, 1, 19), IsActive = true }; StringWriter stringWriter = new StringWriter(); await mapper.WriteAsync(stringWriter, new Person[] { bob }).ConfigureAwait(false); diff --git a/FlatFiles.Test/SeparatedValueMultipleSchemaTester.cs b/FlatFiles.Test/SeparatedValueMultipleSchemaTester.cs index cb83670..af41bf3 100644 --- a/FlatFiles.Test/SeparatedValueMultipleSchemaTester.cs +++ b/FlatFiles.Test/SeparatedValueMultipleSchemaTester.cs @@ -19,7 +19,7 @@ public void TestReader_ReadThreeTypes() { var stringWriter = new StringWriter(); var injector = GetSchemaInjector(); - var writer = new SeparatedValueWriter(stringWriter, injector); + var writer = new SeparatedValueWriter(stringWriter, injector, new SeparatedValueOptions { RecordSeparator = "\n" }); writer.Write(new object[] { "First Batch", 2 }); writer.Write(new object[] { 1, "Bob Smith", new DateTime(2018, 06, 04), 12.34m }); writer.Write(new object[] { 2, "Jane Doe", new DateTime(2018, 06, 05), 34.56m }); @@ -108,7 +108,7 @@ public void TestTypeMapper_ReadThreeTypes() { var stringWriter = new StringWriter(); var injector = GetTypeMapperInjector(); - var writer = injector.GetWriter(stringWriter); + var writer = injector.GetWriter(stringWriter, new SeparatedValueOptions { RecordSeparator = "\n" }); writer.Write(new HeaderRecord { BatchName = "First Batch", RecordCount = 2 }); writer.Write(new DataRecord { Id = 1, Name = "Bob Smith", CreatedOn = new DateTime(2018, 06, 04), TotalAmount = 12.34m }); writer.Write(new DataRecord { Id = 2, Name = "Jane Doe", CreatedOn = new DateTime(2018, 06, 05), TotalAmount = 34.56m }); @@ -157,7 +157,7 @@ public void TestTypeMapper_ReadThreeTypes_WithMetadataRecord() { var stringWriter = new StringWriter(); var injector = GetTypeMapperInjector(); - var writer = injector.GetWriter(stringWriter); + var writer = injector.GetWriter(stringWriter, new SeparatedValueOptions { RecordSeparator = "\n" }); writer.Write(new HeaderRecord { BatchName = "First Batch", RecordCount = 2 }); writer.Write(new DataRecord { Id = 1, Name = "Bob Smith", CreatedOn = new DateTime(2018, 06, 04), TotalAmount = 12.34m }); writer.Write(new DataRecord { Id = 2, Name = "Jane Doe", CreatedOn = new DateTime(2018, 06, 05), TotalAmount = 34.56m }); diff --git a/FlatFiles.Test/SeparatedValueReaderMetadataTester.cs b/FlatFiles.Test/SeparatedValueReaderMetadataTester.cs index d87fad2..d30b6cc 100644 --- a/FlatFiles.Test/SeparatedValueReaderMetadataTester.cs +++ b/FlatFiles.Test/SeparatedValueReaderMetadataTester.cs @@ -16,20 +16,20 @@ public void TestReader_WithSchema_NoFilter_LogicalRecordsOnly() var people = new[] { - new Person() { Name = "Bob" }, - new Person() { Name = "Tom" }, - new Person() { Name = "Jane" } + new Person { Name = "Bob" }, + new Person { Name = "Tom" }, + new Person { Name = "Jane" } }; StringWriter writer = new StringWriter(); - mapper.Write(writer, people, new SeparatedValueOptions() { IsFirstRecordSchema = true }); + mapper.Write(writer, people, new SeparatedValueOptions { IsFirstRecordSchema = true }); string output = writer.ToString(); mapper.CustomMapping(new RecordNumberColumn("RecordNumber")) .WithReader((p, v) => p.RecordNumber = (int)v) .WithWriter(p => p.RecordNumber); StringReader reader = new StringReader(output); - var results = mapper.Read(reader, new SeparatedValueOptions() { IsFirstRecordSchema = true }).ToArray(); + var results = mapper.Read(reader, new SeparatedValueOptions { IsFirstRecordSchema = true }).ToArray(); Assert.AreEqual(3, results.Length); Assert.AreEqual("Bob", results[0].Name); Assert.AreEqual(1, results[0].RecordNumber); @@ -47,20 +47,20 @@ public void TestReader_WithSchema_WithFilter_LogicalRecordsOnly() var people = new[] { - new Person() { Name = "Bob" }, - new Person() { Name = "Tom" }, - new Person() { Name = "Jane" } + new Person { Name = "Bob" }, + new Person { Name = "Tom" }, + new Person { Name = "Jane" } }; StringWriter writer = new StringWriter(); - mapper.Write(writer, people, new SeparatedValueOptions() { IsFirstRecordSchema = true }); + mapper.Write(writer, people, new SeparatedValueOptions { IsFirstRecordSchema = true }); string output = writer.ToString(); mapper.CustomMapping(new RecordNumberColumn("RecordNumber")) .WithReader((p, v) => p.RecordNumber = (int)v) .WithWriter(p => p.RecordNumber); StringReader stringReader = new StringReader(output); - var options = new SeparatedValueOptions() { IsFirstRecordSchema = true }; + var options = new SeparatedValueOptions { IsFirstRecordSchema = true }; var reader = mapper.GetReader(stringReader, options); reader.RecordRead += (sender, e) => { @@ -82,20 +82,20 @@ public void TestReader_WithSchema_WithFilter_LineCount() var people = new[] { - new Person() { Name = "Bob" }, - new Person() { Name = "Tom" }, - new Person() { Name = "Jane" } + new Person { Name = "Bob" }, + new Person { Name = "Tom" }, + new Person { Name = "Jane" } }; StringWriter writer = new StringWriter(); - mapper.Write(writer, people, new SeparatedValueOptions() { IsFirstRecordSchema = true }); + mapper.Write(writer, people, new SeparatedValueOptions { IsFirstRecordSchema = true }); string output = writer.ToString(); mapper.CustomMapping(new RecordNumberColumn("RecordNumber") { IncludeSchema = true, IncludeSkippedRecords = true }) .WithReader((p, v) => p.RecordNumber = (int)v) .WithWriter(p => p.RecordNumber); StringReader stringReader = new StringReader(output); - var options = new SeparatedValueOptions() { IsFirstRecordSchema = true }; + var options = new SeparatedValueOptions { IsFirstRecordSchema = true }; var reader = mapper.GetReader(stringReader, options); reader.RecordRead += (sender, e) => { @@ -117,20 +117,20 @@ public void TestReader_WithSchema_NoFilter_LineCount() var people = new[] { - new Person() { Name = "Bob" }, - new Person() { Name = "Tom" }, - new Person() { Name = "Jane" } + new Person { Name = "Bob" }, + new Person { Name = "Tom" }, + new Person { Name = "Jane" } }; StringWriter writer = new StringWriter(); - mapper.Write(writer, people, new SeparatedValueOptions() { IsFirstRecordSchema = true }); + mapper.Write(writer, people, new SeparatedValueOptions { IsFirstRecordSchema = true }); string output = writer.ToString(); mapper.CustomMapping(new RecordNumberColumn("RecordNumber") { IncludeSchema = true, IncludeSkippedRecords = true }) .WithReader((p, v) => p.RecordNumber = (int)v) .WithWriter(p => p.RecordNumber); StringReader reader = new StringReader(output); - var results = mapper.Read(reader, new SeparatedValueOptions() { IsFirstRecordSchema = true }).ToArray(); + var results = mapper.Read(reader, new SeparatedValueOptions { IsFirstRecordSchema = true }).ToArray(); Assert.AreEqual(3, results.Length); Assert.AreEqual("Bob", results[0].Name); Assert.AreEqual(2, results[0].RecordNumber); @@ -148,20 +148,20 @@ public void TestReader_WithSchema_SchemaNotCounted_WithFilter_LineCount() var people = new[] { - new Person() { Name = "Bob" }, - new Person() { Name = "Tom" }, - new Person() { Name = "Jane" } + new Person { Name = "Bob" }, + new Person { Name = "Tom" }, + new Person { Name = "Jane" } }; StringWriter writer = new StringWriter(); - mapper.Write(writer, people, new SeparatedValueOptions() { IsFirstRecordSchema = true }); + mapper.Write(writer, people, new SeparatedValueOptions { IsFirstRecordSchema = true }); string output = writer.ToString(); mapper.CustomMapping(new RecordNumberColumn("RecordNumber") { IncludeSchema = false, IncludeSkippedRecords = true }) .WithReader((p, v) => p.RecordNumber = (int)v) .WithWriter(p => p.RecordNumber); StringReader stringReader = new StringReader(output); - var options = new SeparatedValueOptions() { IsFirstRecordSchema = true }; + var options = new SeparatedValueOptions { IsFirstRecordSchema = true }; var reader = mapper.GetReader(stringReader, options); reader.RecordRead += (sender, e) => { @@ -183,20 +183,20 @@ public void TestReader_WithSchema_SchemaNotCounted_NoFilter_LineCountMinusOne() var people = new[] { - new Person() { Name = "Bob" }, - new Person() { Name = "Tom" }, - new Person() { Name = "Jane" } + new Person { Name = "Bob" }, + new Person { Name = "Tom" }, + new Person { Name = "Jane" } }; StringWriter writer = new StringWriter(); - mapper.Write(writer, people, new SeparatedValueOptions() { IsFirstRecordSchema = true }); + mapper.Write(writer, people, new SeparatedValueOptions { IsFirstRecordSchema = true }); string output = writer.ToString(); mapper.CustomMapping(new RecordNumberColumn("RecordNumber") { IncludeSchema = false, IncludeSkippedRecords = true }) .WithReader((p, v) => p.RecordNumber = (int)v) .WithWriter(p => p.RecordNumber); StringReader reader = new StringReader(output); - var results = mapper.Read(reader, new SeparatedValueOptions() { IsFirstRecordSchema = true }).ToArray(); + var results = mapper.Read(reader, new SeparatedValueOptions { IsFirstRecordSchema = true }).ToArray(); Assert.AreEqual(3, results.Length); Assert.AreEqual("Bob", results[0].Name); Assert.AreEqual(1, results[0].RecordNumber); @@ -215,20 +215,20 @@ public void TestReader_WithSchema_NoFilter_WithIgnoredColumn_LogicalRecordsOnly( var people = new[] { - new Person() { Name = "Bob" }, - new Person() { Name = "Tom" }, - new Person() { Name = "Jane" } + new Person { Name = "Bob" }, + new Person { Name = "Tom" }, + new Person { Name = "Jane" } }; StringWriter writer = new StringWriter(); - mapper.Write(writer, people, new SeparatedValueOptions() { IsFirstRecordSchema = true }); + mapper.Write(writer, people, new SeparatedValueOptions { IsFirstRecordSchema = true }); string output = writer.ToString(); mapper.CustomMapping(new RecordNumberColumn("RecordNumber")) .WithReader((p, v) => p.RecordNumber = (int)v) .WithWriter(p => p.RecordNumber); StringReader reader = new StringReader(output); - var results = mapper.Read(reader, new SeparatedValueOptions() { IsFirstRecordSchema = true }).ToArray(); + var results = mapper.Read(reader, new SeparatedValueOptions { IsFirstRecordSchema = true }).ToArray(); Assert.AreEqual(3, results.Length); Assert.AreEqual("Bob", results[0].Name); Assert.AreEqual(1, results[0].RecordNumber); @@ -247,20 +247,20 @@ public void TestReader_WithSchema_WithIgnoredColumn_WithFilter_LogicalRecordsOnl var people = new[] { - new Person() { Name = "Bob" }, - new Person() { Name = "Tom" }, - new Person() { Name = "Jane" } + new Person { Name = "Bob" }, + new Person { Name = "Tom" }, + new Person { Name = "Jane" } }; StringWriter writer = new StringWriter(); - mapper.Write(writer, people, new SeparatedValueOptions() { IsFirstRecordSchema = true }); + mapper.Write(writer, people, new SeparatedValueOptions { IsFirstRecordSchema = true }); string output = writer.ToString(); mapper.CustomMapping(new RecordNumberColumn("RecordNumber")) .WithReader((p, v) => p.RecordNumber = (int)v) .WithWriter(p => p.RecordNumber); StringReader stringReader = new StringReader(output); - var options = new SeparatedValueOptions() { IsFirstRecordSchema = true }; + var options = new SeparatedValueOptions { IsFirstRecordSchema = true }; var reader = mapper.GetReader(stringReader, options); reader.RecordRead += (sender, e) => { diff --git a/FlatFiles.Test/SeparatedValueReaderTester.cs b/FlatFiles.Test/SeparatedValueReaderTester.cs index 1f4a123..01f71d6 100644 --- a/FlatFiles.Test/SeparatedValueReaderTester.cs +++ b/FlatFiles.Test/SeparatedValueReaderTester.cs @@ -49,7 +49,7 @@ public void TestCtor_NullWriter_WithSchema_Throws() [TestMethod] public void TestCtor_SchemaNull_Throws() { - TextReader reader = new StringReader(String.Empty); + TextReader reader = new StringReader(string.Empty); SeparatedValueSchema schema = null; Assert.ThrowsException(() => new SeparatedValueReader(reader, schema)); } @@ -185,7 +185,7 @@ public void TestGetSchema_NotExtracted_Throws() { string text = "a,b,c"; var stringReader = new StringReader(text); - var options = new SeparatedValueOptions() { IsFirstRecordSchema = false }; + var options = new SeparatedValueOptions { IsFirstRecordSchema = false }; IReader parser = new SeparatedValueReader(stringReader, options); var schema = parser.GetSchema(); Assert.IsNull(schema, "No schema was provided or located in the file. Null should be returned."); @@ -199,7 +199,7 @@ public void TestGetSchema_Extracted_ReturnsColumnNames() { string text = "a,b,c"; StringReader stringReader = new StringReader(text); - SeparatedValueOptions options = new SeparatedValueOptions() { IsFirstRecordSchema = true }; + SeparatedValueOptions options = new SeparatedValueOptions { IsFirstRecordSchema = true }; IReader parser = new SeparatedValueReader(stringReader, options); ISchema schema = parser.GetSchema(); Assert.IsTrue(schema.ColumnDefinitions.All(d => d is StringColumn), "Not all of the columns were treated as strings."); @@ -222,7 +222,7 @@ public void TestGetSchema_SchemaProvided_FirstRecordSchema_SkipsFirstRecord() .AddColumn(new DateTimeColumn("created")); StringReader stringReader = new StringReader(text); - SeparatedValueOptions options = new SeparatedValueOptions() { IsFirstRecordSchema = true }; + SeparatedValueOptions options = new SeparatedValueOptions { IsFirstRecordSchema = true }; IReader parser = new SeparatedValueReader(stringReader, schema, options); ISchema actual = parser.GetSchema(); Assert.AreSame(schema, actual); @@ -367,7 +367,7 @@ public void TestGetSchema_FirstRecordSchema_TooFewColumns_Throws() const string text = @"id,name,created 123,Bob"; StringReader stringReader = new StringReader(text); - SeparatedValueOptions options = new SeparatedValueOptions() { IsFirstRecordSchema = true }; + SeparatedValueOptions options = new SeparatedValueOptions { IsFirstRecordSchema = true }; SeparatedValueReader parser = new SeparatedValueReader(stringReader, options); Assert.ThrowsException(() => parser.Read()); } @@ -381,7 +381,7 @@ public void TestGetSchema_FirstRecordSchema_TooManyColumns_IgnoresTrailing() const string text = @"id,name,created 123,Bob,1/19/2013,Hello"; StringReader stringReader = new StringReader(text); - SeparatedValueOptions options = new SeparatedValueOptions() { IsFirstRecordSchema = true }; + SeparatedValueOptions options = new SeparatedValueOptions { IsFirstRecordSchema = true }; SeparatedValueReader parser = new SeparatedValueReader(stringReader, options); Assert.IsTrue(parser.Read(), "The record could not be read."); Assert.AreEqual(parser.GetSchema().ColumnDefinitions.Count, parser.GetValues().Length); @@ -394,7 +394,7 @@ public void TestGetSchema_FirstRecordSchema_TooManyColumns_IgnoresTrailing() [TestMethod] public void TestGetValues_BlankTrailingSection_ReturnsNull() { - SeparatedValueOptions options = new SeparatedValueOptions() { IsFirstRecordSchema = true }; + SeparatedValueOptions options = new SeparatedValueOptions { IsFirstRecordSchema = true }; SeparatedValueSchema schema = new SeparatedValueSchema(); schema.AddColumn(new Int32Column("id")) .AddColumn(new StringColumn("name")) @@ -427,7 +427,7 @@ public void TestGetValues_BlankMiddleSection_ReturnsNull() { using (MemoryStream stream = new MemoryStream()) { - SeparatedValueOptions options = new SeparatedValueOptions() { IsFirstRecordSchema = true }; + SeparatedValueOptions options = new SeparatedValueOptions { IsFirstRecordSchema = true }; SeparatedValueSchema schema = new SeparatedValueSchema(); schema.AddColumn(new Int32Column("id")) .AddColumn(new StringColumn("name")) @@ -461,7 +461,7 @@ public void TestGetValues_BlankLeadingSection_ReturnsNull() { using (MemoryStream stream = new MemoryStream()) { - SeparatedValueOptions options = new SeparatedValueOptions() { IsFirstRecordSchema = true }; + SeparatedValueOptions options = new SeparatedValueOptions { IsFirstRecordSchema = true }; SeparatedValueSchema schema = new SeparatedValueSchema(); schema.AddColumn(new StringColumn("leading")) .AddColumn(new Int32Column("id")) @@ -530,8 +530,8 @@ public void TestTypeMapper_Roundtrip() mapper.Property(p => p.Created).ColumnName("created").InputFormat("yyyyMMdd").OutputFormat("yyyyMMdd"); mapper.Property(p => p.ParentId).ColumnName("parent_id"); - var bob = new Person() { Id = 123, Name = "Bob", Created = new DateTime(2013, 1, 19), ParentId = null }; - var options = new SeparatedValueOptions() { IsFirstRecordSchema = true, Separator = "\t" }; + var bob = new Person { Id = 123, Name = "Bob", Created = new DateTime(2013, 1, 19), ParentId = null }; + var options = new SeparatedValueOptions { IsFirstRecordSchema = true, Separator = "\t" }; StringWriter stringWriter = new StringWriter(); mapper.Write(stringWriter, new Person[] { bob }, options); @@ -558,8 +558,8 @@ public void TestTypeMapper_RoundtripWithNull() mapper.Property(p => p.Name).ColumnName("name"); mapper.Property(p => p.Created).ColumnName("created").InputFormat("yyyyMMdd").OutputFormat("yyyyMMdd"); - var bob = new Person() { Id = 123, Name = null, Created = new DateTime(2013, 1, 19) }; - var options = new SeparatedValueOptions() { IsFirstRecordSchema = true, Separator = "\t" }; + var bob = new Person { Id = 123, Name = null, Created = new DateTime(2013, 1, 19) }; + var options = new SeparatedValueOptions { IsFirstRecordSchema = true, Separator = "\t" }; StringWriter stringWriter = new StringWriter(); mapper.Write(stringWriter, new Person[] { bob }, options); @@ -588,7 +588,7 @@ public void TestTypeMapper_IgnoredColumns_RoundTrips() mapper.Ignored(); mapper.Property(p => p.Created).ColumnName("created").InputFormat("yyyyMMdd").OutputFormat("yyyyMMdd"); - var bob = new Person() { Id = 123, Name = "Bob Smith", Created = new DateTime(2013, 1, 19) }; + var bob = new Person { Id = 123, Name = "Bob Smith", Created = new DateTime(2013, 1, 19) }; StringWriter stringWriter = new StringWriter(); mapper.Write(stringWriter, new Person[] { bob }); @@ -651,7 +651,7 @@ public void TestTypeMapper_NullableBoolean_RoundTripsNull() var mapper = SeparatedValueTypeMapper.Define(); mapper.Property(x => x.IsActive).ColumnName("is_active"); - Person person = new Person() { IsActive = null }; + Person person = new Person { IsActive = null }; StringWriter stringWriter = new StringWriter(); mapper.Write(stringWriter, new Person[] { person }); @@ -670,7 +670,7 @@ public void TestTypeMapper_NullableBoolean_RoundTripsFalse() var mapper = SeparatedValueTypeMapper.Define(); mapper.Property(x => x.IsActive).ColumnName("is_active"); - Person person = new Person() { IsActive = false }; + Person person = new Person { IsActive = false }; StringWriter stringWriter = new StringWriter(); mapper.Write(stringWriter, new Person[] { person }); @@ -689,7 +689,7 @@ public void TestTypeMapper_NullableBoolean_RoundTripsTrue() var mapper = SeparatedValueTypeMapper.Define(); mapper.Property(x => x.IsActive).ColumnName("is_active"); - Person person = new Person() { IsActive = true }; + Person person = new Person { IsActive = true }; StringWriter stringWriter = new StringWriter(); mapper.Write(stringWriter, new Person[] { person }); diff --git a/FlatFiles.Test/SeparatedValueRuntimeTypeTester.cs b/FlatFiles.Test/SeparatedValueRuntimeTypeTester.cs index ddf9e82..a72826b 100644 --- a/FlatFiles.Test/SeparatedValueRuntimeTypeTester.cs +++ b/FlatFiles.Test/SeparatedValueRuntimeTypeTester.cs @@ -39,8 +39,8 @@ public void TestRuntimeTypeDefinition() var people = new[] { - new Person() { Name = "John", IQ = null, BirthDate = new DateTime(1954, 10, 29), TopSpeed = 3.4m }, - new Person() { Name = "Susan", IQ = 132, BirthDate = new DateTime(1984, 3, 15), TopSpeed = 10.1m } + new Person { Name = "John", IQ = null, BirthDate = new DateTime(1954, 10, 29), TopSpeed = 3.4m }, + new Person { Name = "Susan", IQ = 132, BirthDate = new DateTime(1984, 3, 15), TopSpeed = 10.1m } }; StringWriter writer = new StringWriter(); @@ -67,8 +67,8 @@ public void TestRuntimeTypeDefinition_ReaderWriter() var people = new[] { - new Person() { Name = "John", IQ = null, BirthDate = new DateTime(1954, 10, 29), TopSpeed = 3.4m }, - new Person() { Name = "Susan", IQ = 132, BirthDate = new DateTime(1984, 3, 15), TopSpeed = 10.1m } + new Person { Name = "John", IQ = null, BirthDate = new DateTime(1954, 10, 29), TopSpeed = 3.4m }, + new Person { Name = "Susan", IQ = 132, BirthDate = new DateTime(1984, 3, 15), TopSpeed = 10.1m } }; StringWriter writer = new StringWriter(); diff --git a/FlatFiles.Test/SeparatedValueTester.cs b/FlatFiles.Test/SeparatedValueTester.cs index 19c58ad..383b51f 100644 --- a/FlatFiles.Test/SeparatedValueTester.cs +++ b/FlatFiles.Test/SeparatedValueTester.cs @@ -10,9 +10,9 @@ public class SeparatedValueTester [TestMethod] public void ShouldNotFindRecordsInEmptyFile() { - var source = String.Empty; + var source = string.Empty; var stringReader = new StringReader(source); - var options = new SeparatedValueOptions() { IsFirstRecordSchema = false }; + var options = new SeparatedValueOptions { IsFirstRecordSchema = false }; var reader = new SeparatedValueReader(stringReader, options); Assert.IsFalse(reader.Read(), "No records should be read from an empty file."); } @@ -22,7 +22,7 @@ public void ShouldFindOneRecordOneColumn_CharactersFollowedByEndOfStream() { var source = "Hello"; var stringReader = new StringReader(source); - var options = new SeparatedValueOptions() { IsFirstRecordSchema = false }; + var options = new SeparatedValueOptions { IsFirstRecordSchema = false }; var reader = new SeparatedValueReader(stringReader, options); var expected = new object[][] { @@ -36,7 +36,7 @@ public void ShouldFindOneRecordTwoColumn_CharactersFollowedByEndOfStream() { var source = "Hello,World"; var stringReader = new StringReader(source); - var options = new SeparatedValueOptions() { IsFirstRecordSchema = false }; + var options = new SeparatedValueOptions { IsFirstRecordSchema = false }; var reader = new SeparatedValueReader(stringReader, options); var expected = new object[][] { @@ -50,7 +50,7 @@ public void ShouldFindTwoRecordsOneColumn() { var source = "Hello\r\nWorld\r\n"; var stringReader = new StringReader(source); - var options = new SeparatedValueOptions() { IsFirstRecordSchema = false }; + var options = new SeparatedValueOptions { IsFirstRecordSchema = false }; var reader = new SeparatedValueReader(stringReader, options); var expected = new object[][] { @@ -65,7 +65,7 @@ public void ShouldFindTwoRecordsOneColumn_MissingClosingRecordSeparator() { var source = "Hello\r\nWorld"; var stringReader = new StringReader(source); - var options = new SeparatedValueOptions() { IsFirstRecordSchema = false }; + var options = new SeparatedValueOptions { IsFirstRecordSchema = false }; var reader = new SeparatedValueReader(stringReader, options); var expected = new object[][] { @@ -80,8 +80,8 @@ public void ShouldFindOneRecordTwoColumn_EOROverlapsEOT() { var source = "a\rb\r\n"; var stringReader = new StringReader(source); - var options = new SeparatedValueOptions() - { + var options = new SeparatedValueOptions + { IsFirstRecordSchema = false, RecordSeparator = "\r\n", Separator = "\r" @@ -99,8 +99,8 @@ public void ShouldFindTwoRecordsOneColumn_EOROverlapsEOT() { var source = "a\r\nb"; var stringReader = new StringReader(source); - var options = new SeparatedValueOptions() - { + var options = new SeparatedValueOptions + { IsFirstRecordSchema = false, RecordSeparator = "\r\n", Separator = "\r" @@ -119,8 +119,8 @@ public void ShouldFindOneRecordTwoColumn_EOTOverlapsEOR() { var source = "a\r\nb\r"; var stringReader = new StringReader(source); - var options = new SeparatedValueOptions() - { + var options = new SeparatedValueOptions + { IsFirstRecordSchema = false, RecordSeparator = "\r", Separator = "\r\n" @@ -138,8 +138,8 @@ public void ShouldFindTwoRecordsOneColumn_EOTOverlapsEOR() { var source = "a\rb"; var stringReader = new StringReader(source); - var options = new SeparatedValueOptions() - { + var options = new SeparatedValueOptions + { IsFirstRecordSchema = false, RecordSeparator = "\r", Separator = "\r\n" @@ -158,7 +158,7 @@ public void ShouldSeparateBlanks() { var source = ","; var stringReader = new StringReader(source); - var options = new SeparatedValueOptions() { IsFirstRecordSchema = false }; + var options = new SeparatedValueOptions { IsFirstRecordSchema = false }; var reader = new SeparatedValueReader(stringReader, options); var expected = new object[][] { @@ -172,7 +172,7 @@ public void ShouldSeparateBlanksAcrossRecords() { var source = ",,\r\n,,"; var stringReader = new StringReader(source); - var options = new SeparatedValueOptions() { IsFirstRecordSchema = false }; + var options = new SeparatedValueOptions { IsFirstRecordSchema = false }; var reader = new SeparatedValueReader(stringReader, options); var expected = new object[][] { @@ -187,7 +187,7 @@ public void ShouldHandleSingleEmptyRecord() { var source = "\r\n"; var stringReader = new StringReader(source); - var options = new SeparatedValueOptions() { IsFirstRecordSchema = false }; + var options = new SeparatedValueOptions { IsFirstRecordSchema = false }; var reader = new SeparatedValueReader(stringReader, options); var expected = new object[][] { @@ -201,7 +201,7 @@ public void ShouldHandleMultipleEmptyRecords() { var source = "\r\n\r\n"; var stringReader = new StringReader(source); - var options = new SeparatedValueOptions() { IsFirstRecordSchema = false }; + var options = new SeparatedValueOptions { IsFirstRecordSchema = false }; var reader = new SeparatedValueReader(stringReader, options); var expected = new object[][] { @@ -216,7 +216,7 @@ public void ShouldStripLeadingWhitespace() { var source = " a"; var stringReader = new StringReader(source); - var options = new SeparatedValueOptions() { IsFirstRecordSchema = false }; + var options = new SeparatedValueOptions { IsFirstRecordSchema = false }; var reader = new SeparatedValueReader(stringReader, options); var expected = new object[][] { @@ -232,8 +232,8 @@ public void ShouldPreserveLeadingWhitespaceIfConfigured() var stringReader = new StringReader(source); var schema = new SeparatedValueSchema(); schema.AddColumn(new StringColumn("a") { Trim = false }); - var options = new SeparatedValueOptions() - { + var options = new SeparatedValueOptions + { IsFirstRecordSchema = false, PreserveWhiteSpace = true }; @@ -250,8 +250,8 @@ public void ShouldStripLeadingWhitespace_MultipleSpaces_TwoColumn() { var source = " a, \t\n b"; var stringReader = new StringReader(source); - var options = new SeparatedValueOptions() - { + var options = new SeparatedValueOptions + { IsFirstRecordSchema = false, RecordSeparator = "\r\n" }; @@ -271,8 +271,8 @@ public void ShouldPreserveLeadingWhitespaceIfConfigured_MultipleSpaces_TwoColumn //SeparatedValueSchema schema = new SeparatedValueSchema(); //schema.AddColumn(new StringColumn("a") { Trim = false }); //schema.AddColumn(new StringColumn("b") { Trim = false }); - var options = new SeparatedValueOptions() - { + var options = new SeparatedValueOptions + { IsFirstRecordSchema = false, RecordSeparator = "\r\n", PreserveWhiteSpace = true @@ -290,7 +290,7 @@ public void ShouldStripTrailingWhitespace() { var source = "a "; var stringReader = new StringReader(source); - var options = new SeparatedValueOptions() { IsFirstRecordSchema = false }; + var options = new SeparatedValueOptions { IsFirstRecordSchema = false }; var reader = new SeparatedValueReader(stringReader, options); var expected = new object[][] { @@ -306,8 +306,8 @@ public void ShouldPreserveTrailingWhitespaceIfConfigured() var stringReader = new StringReader(source); var schema = new SeparatedValueSchema(); schema.AddColumn(new StringColumn("a") { Trim = false }); - var options = new SeparatedValueOptions() - { + var options = new SeparatedValueOptions + { IsFirstRecordSchema = false, PreserveWhiteSpace = true }; @@ -324,8 +324,8 @@ public void ShouldStripTrailingWhitespace_MultipleSpaces_TwoColumn() { var source = "a ,b \t\n "; var stringReader = new StringReader(source); - var options = new SeparatedValueOptions() - { + var options = new SeparatedValueOptions + { IsFirstRecordSchema = false, RecordSeparator = "\r\n" }; @@ -345,7 +345,7 @@ public void ShouldPreserveTrailingWhitespaceIfConfigured_MultipleSpaces_TwoColum var schema = new SeparatedValueSchema(); schema.AddColumn(new StringColumn("a") { Trim = false }); schema.AddColumn(new StringColumn("b") { Trim = false }); - var options = new SeparatedValueOptions() { IsFirstRecordSchema = false, RecordSeparator = "\r\n", PreserveWhiteSpace = true }; + var options = new SeparatedValueOptions { IsFirstRecordSchema = false, RecordSeparator = "\r\n", PreserveWhiteSpace = true }; var reader = new SeparatedValueReader(stringReader, schema, options); var expected = new object[][] { @@ -359,7 +359,7 @@ public void ShouldStripLeadingAndTrailingWhitespace() { var source = " a "; var stringReader = new StringReader(source); - var options = new SeparatedValueOptions() { IsFirstRecordSchema = false }; + var options = new SeparatedValueOptions { IsFirstRecordSchema = false }; var reader = new SeparatedValueReader(stringReader, options); var expected = new object[][] { @@ -375,7 +375,7 @@ public void ShouldPreserveLeadingAndTrailingWhitespaceIfConfigured() var stringReader = new StringReader(source); var schema = new SeparatedValueSchema(); schema.AddColumn(new StringColumn("a") { Trim = false }); - var options = new SeparatedValueOptions() { IsFirstRecordSchema = false, PreserveWhiteSpace = true }; + var options = new SeparatedValueOptions { IsFirstRecordSchema = false, PreserveWhiteSpace = true }; var reader = new SeparatedValueReader(stringReader, schema, options); var expected = new object[][] { @@ -389,7 +389,7 @@ public void ShouldStripLeadingAndTrailingWhitespace_MultipleSpaces_TwoColumn() { var source = " a , \t\n b \t\n "; var stringReader = new StringReader(source); - var options = new SeparatedValueOptions() { IsFirstRecordSchema = false, RecordSeparator = "\r\n" }; + var options = new SeparatedValueOptions { IsFirstRecordSchema = false, RecordSeparator = "\r\n" }; var reader = new SeparatedValueReader(stringReader, options); var expected = new object[][] { @@ -406,8 +406,8 @@ public void ShouldPreserveLeadingAndTrailingWhitespaceIfConfigured_MultipleSpace var schema = new SeparatedValueSchema(); schema.AddColumn(new StringColumn("a") { Trim = false }); schema.AddColumn(new StringColumn("b") { Trim = false }); - var options = new SeparatedValueOptions() - { + var options = new SeparatedValueOptions + { IsFirstRecordSchema = false, RecordSeparator = "\r\n", PreserveWhiteSpace = true @@ -425,7 +425,7 @@ public void ShouldFindOneColumnOneRecordIfAllWhitespace() { var source = " \t\n\r "; var stringReader = new StringReader(source); - var options = new SeparatedValueOptions() { IsFirstRecordSchema = false, RecordSeparator = "\r\n" }; + var options = new SeparatedValueOptions { IsFirstRecordSchema = false, RecordSeparator = "\r\n" }; var reader = new SeparatedValueReader(stringReader, options); var expected = new object[][] { @@ -441,8 +441,8 @@ public void ShouldPreserveWhiteSpaceIfConfigured_AllWhitespace() var stringReader = new StringReader(source); var schema = new SeparatedValueSchema(); schema.AddColumn(new StringColumn("a") { Trim = false, NullFormatter = NullFormatter.ForValue(null) }); - var options = new SeparatedValueOptions() - { + var options = new SeparatedValueOptions + { IsFirstRecordSchema = false, RecordSeparator = "\r\n", PreserveWhiteSpace = true @@ -460,7 +460,7 @@ public void ShouldNotStripEmbeddedWhitespace() { var source = " a b "; var stringReader = new StringReader(source); - var options = new SeparatedValueOptions() { IsFirstRecordSchema = false }; + var options = new SeparatedValueOptions { IsFirstRecordSchema = false }; var reader = new SeparatedValueReader(stringReader, options); var expected = new object[][] { @@ -476,7 +476,7 @@ public void ShouldNotStripEmbeddedWhitespace_PreservingWhiteSpace() var stringReader = new StringReader(source); var schema = new SeparatedValueSchema(); schema.AddColumn(new StringColumn("a") { Trim = false }); - var options = new SeparatedValueOptions() { IsFirstRecordSchema = false, PreserveWhiteSpace = true }; + var options = new SeparatedValueOptions { IsFirstRecordSchema = false, PreserveWhiteSpace = true }; var reader = new SeparatedValueReader(stringReader, schema, options); var expected = new object[][] { @@ -490,7 +490,7 @@ public void ShouldHandleDoubleWhitespaceAsSeparator() { var source = " a b "; var stringReader = new StringReader(source); - var options = new SeparatedValueOptions() { IsFirstRecordSchema = false, Separator = " " }; + var options = new SeparatedValueOptions { IsFirstRecordSchema = false, Separator = " " }; var reader = new SeparatedValueReader(stringReader, options); var expected = new object[][] { @@ -504,8 +504,8 @@ public void ShouldIgnoreInvalidSeparatorSharingSharedPrefix() { var source = "axxcb"; var stringReader = new StringReader(source); - var options = new SeparatedValueOptions() - { + var options = new SeparatedValueOptions + { IsFirstRecordSchema = false, Separator = "xxa", RecordSeparator = "xxb" @@ -523,7 +523,7 @@ public void ShouldHandleLongUndoOperation() { var source = "axxxb"; var stringReader = new StringReader(source); - var options = new SeparatedValueOptions() { IsFirstRecordSchema = false, Separator = "xxxx" }; + var options = new SeparatedValueOptions { IsFirstRecordSchema = false, Separator = "xxxx" }; var reader = new SeparatedValueReader(stringReader, options); var expected = new object[][] { @@ -537,8 +537,8 @@ public void ShouldExtractQuotedValue() { var source = "'a'"; var stringReader = new StringReader(source); - var options = new SeparatedValueOptions() - { + var options = new SeparatedValueOptions + { IsFirstRecordSchema = false, Quote = '\'' }; @@ -555,8 +555,8 @@ public void ShouldIncludeSpacesBetweenQuotes() { var source = "' a '"; var stringReader = new StringReader(source); - var options = new SeparatedValueOptions() - { + var options = new SeparatedValueOptions + { IsFirstRecordSchema = false, Quote = '\'' }; @@ -575,8 +575,8 @@ public void ShouldIgnoreSeparatorsBetweenQuotes() { var source = "'a,b'"; var stringReader = new StringReader(source); - var options = new SeparatedValueOptions() - { + var options = new SeparatedValueOptions + { IsFirstRecordSchema = false, Quote = '\'' }; @@ -593,8 +593,8 @@ public void ShouldHandleEscapedQuotesWithinQuotes() { var source = "'a''b'"; var stringReader = new StringReader(source); - var options = new SeparatedValueOptions() - { + var options = new SeparatedValueOptions + { IsFirstRecordSchema = false, Quote = '\'' }; @@ -611,8 +611,8 @@ public void ShouldIgnoreLeadingWhiteSpaceBeforeQuote() { var source = " 'a'"; var stringReader = new StringReader(source); - var options = new SeparatedValueOptions() - { + var options = new SeparatedValueOptions + { IsFirstRecordSchema = false, Quote = '\'' }; @@ -629,8 +629,8 @@ public void ShouldIgnoreTrailingWhiteSpaceAfterQuote() { var source = "'a' "; var stringReader = new StringReader(source); - var options = new SeparatedValueOptions() - { + var options = new SeparatedValueOptions + { IsFirstRecordSchema = false, Quote = '\'' }; @@ -647,8 +647,8 @@ public void ShouldThrowSyntaxExceptionIfQuoteFollowedByEOS() { var source = "'"; var stringReader = new StringReader(source); - var options = new SeparatedValueOptions() - { + var options = new SeparatedValueOptions + { IsFirstRecordSchema = false, Quote = '\'' }; @@ -661,8 +661,8 @@ public void ShouldThrowSyntaxExceptionIfQuoteFollowedByNonSeparator() { var source = "'a'b"; var stringReader = new StringReader(source); - var options = new SeparatedValueOptions() - { + var options = new SeparatedValueOptions + { IsFirstRecordSchema = false, Quote = '\'' }; @@ -678,8 +678,8 @@ public void ShouldIgnoreRecordSeparatorsWithinQuotes() When he''s not traveling, he''s at home with his lovely wife, children and leather armchair.' Mary,Smith,'1821 Grover''s Village',West Chattingham,WA,43221,'Likes cats.'"; var stringReader = new StringReader(source); - var options = new SeparatedValueOptions() - { + var options = new SeparatedValueOptions + { IsFirstRecordSchema = false, Quote = '\'' }; @@ -701,8 +701,8 @@ public void ShouldHandleSeparatorAfterQuoteIfPreservingWhiteSpace() { var source = "26087,C Country C,,1,3,7,Randy E,(555) 555-5500,,\"P.O.Box 60,\",,,Woodsland,CA,56281,,,,0292315c-0daa-df11-9397-0019b9e7d4cd,,0,8713cbdd-fb50-dc11-a545-000423c05bf1,40,79527,,False"; var stringReader = new StringReader(source); - var options = new SeparatedValueOptions() - { + var options = new SeparatedValueOptions + { IsFirstRecordSchema = false, PreserveWhiteSpace = true }; @@ -747,8 +747,8 @@ public void ShouldHandleEmbeddedQuotes() { var source = "x\ty\tabc\"def\tz"; var stringReader = new StringReader(source); - var options = new SeparatedValueOptions() - { + var options = new SeparatedValueOptions + { IsFirstRecordSchema = false, Separator = "\t" }; @@ -767,8 +767,8 @@ public void ShouldHandleEmbeddedQuotes2() "\t0\t0\tmonetary\tD\tC\tDebt Conversion, Converted Instrument, Amount" + "\tThe value of the financial instrument(s) that the original debt is being converted into in a noncash (or part noncash) transaction. \"Part noncash refers to that portion of the transaction not resulting in cash receipts or cash payments in the period."; var stringReader = new StringReader(source); - var options = new SeparatedValueOptions() - { + var options = new SeparatedValueOptions + { IsFirstRecordSchema = false, Separator = "\t", PreserveWhiteSpace = false, @@ -800,8 +800,8 @@ public void ShouldHandleNonTerminatingEmbeddedQuotes() { var source = "This\tis\t\"not\"the\tend\"\tof\tthe\tmessage"; var stringReader = new StringReader(source); - var options = new SeparatedValueOptions() - { + var options = new SeparatedValueOptions + { IsFirstRecordSchema = false, Separator = "\t" }; @@ -820,7 +820,7 @@ private static void AssertRecords(object[][] expected, SeparatedValueReader read { for (var recordIndex = 0; recordIndex != expected.Length; ++recordIndex) { - Assert.IsTrue(reader.Read(), String.Format("The record could not be read (Record {0}).", recordIndex)); + Assert.IsTrue(reader.Read(), string.Format("The record could not be read (Record {0}).", recordIndex)); var actualValues = reader.GetValues(); var expectedValues = expected[recordIndex]; AssertRecord(expectedValues, actualValues); diff --git a/FlatFiles.Test/SeparatedValueTypeMapperFieldTester.cs b/FlatFiles.Test/SeparatedValueTypeMapperFieldTester.cs index 22340ff..6a9904d 100644 --- a/FlatFiles.Test/SeparatedValueTypeMapperFieldTester.cs +++ b/FlatFiles.Test/SeparatedValueTypeMapperFieldTester.cs @@ -21,7 +21,7 @@ public void TestTypeMapper_Roundtrip() mapper.Property(p => p.Created).ColumnName("created").InputFormat("yyyyMMdd").OutputFormat("yyyyMMdd"); mapper.Property(p => p.IsActive).ColumnName("active"); - var bob = new Person() { Id = 123, Name = "Bob", Created = new DateTime(2013, 1, 19), IsActive = true }; + var bob = new Person { Id = 123, Name = "Bob", Created = new DateTime(2013, 1, 19), IsActive = true }; StringWriter stringWriter = new StringWriter(); mapper.Write(stringWriter, new Person[] { bob }); diff --git a/FlatFiles.Test/SeparatedValueTypeMapperMixedMemberTester.cs b/FlatFiles.Test/SeparatedValueTypeMapperMixedMemberTester.cs index c8ff3da..fc901e3 100644 --- a/FlatFiles.Test/SeparatedValueTypeMapperMixedMemberTester.cs +++ b/FlatFiles.Test/SeparatedValueTypeMapperMixedMemberTester.cs @@ -21,7 +21,7 @@ public void TestTypeMapper_Roundtrip() mapper.Property(p => p.Created).ColumnName("created").InputFormat("yyyyMMdd").OutputFormat("yyyyMMdd"); mapper.Property(p => p.IsActive).ColumnName("active"); - var bob = new Person() { Id = 123, Name = "Bob", Created = new DateTime(2013, 1, 19), IsActive = true }; + var bob = new Person { Id = 123, Name = "Bob", Created = new DateTime(2013, 1, 19), IsActive = true }; StringWriter stringWriter = new StringWriter(); mapper.Write(stringWriter, new Person[] { bob }); diff --git a/FlatFiles.Test/SeparatedValueWriterMetadataTester.cs b/FlatFiles.Test/SeparatedValueWriterMetadataTester.cs index a872d73..182f0f8 100644 --- a/FlatFiles.Test/SeparatedValueWriterMetadataTester.cs +++ b/FlatFiles.Test/SeparatedValueWriterMetadataTester.cs @@ -21,13 +21,13 @@ public void TestWriter_WithSchema_SchemaNotCounted() var people = new[] { - new Person() { Name = "Bob", CreatedOn = new DateTime(2018, 04, 25) }, - new Person() { Name = "Tom", CreatedOn = new DateTime(2018, 04, 26) }, - new Person() { Name = "Jane", CreatedOn = new DateTime(2018, 04, 27) } + new Person { Name = "Bob", CreatedOn = new DateTime(2018, 04, 25) }, + new Person { Name = "Tom", CreatedOn = new DateTime(2018, 04, 26) }, + new Person { Name = "Jane", CreatedOn = new DateTime(2018, 04, 27) } }; StringWriter writer = new StringWriter(); - outputMapper.Write(writer, people, new SeparatedValueOptions() { IsFirstRecordSchema = true }); + outputMapper.Write(writer, people, new SeparatedValueOptions { IsFirstRecordSchema = true }); string output = writer.ToString(); var inputMapper = SeparatedValueTypeMapper.Define(() => new Person()); @@ -36,7 +36,7 @@ public void TestWriter_WithSchema_SchemaNotCounted() inputMapper.Property(x => x.CreatedOn).InputFormat("MM/dd/yyyy"); StringReader reader = new StringReader(output); - var results = inputMapper.Read(reader, new SeparatedValueOptions() { IsFirstRecordSchema = true }).ToArray(); + var results = inputMapper.Read(reader, new SeparatedValueOptions { IsFirstRecordSchema = true }).ToArray(); Assert.AreEqual(3, results.Length); Assert.AreEqual("Bob", results[0].Name); Assert.AreEqual(1, results[0].RecordNumber); @@ -61,13 +61,13 @@ public void TestWriter_WithSchema_SchemaCounted() var people = new[] { - new Person() { Name = "Bob", CreatedOn = new DateTime(2018, 04, 25) }, - new Person() { Name = "Tom", CreatedOn = new DateTime(2018, 04, 26) }, - new Person() { Name = "Jane", CreatedOn = new DateTime(2018, 04, 27) } + new Person { Name = "Bob", CreatedOn = new DateTime(2018, 04, 25) }, + new Person { Name = "Tom", CreatedOn = new DateTime(2018, 04, 26) }, + new Person { Name = "Jane", CreatedOn = new DateTime(2018, 04, 27) } }; StringWriter writer = new StringWriter(); - outputMapper.Write(writer, people, new SeparatedValueOptions() { IsFirstRecordSchema = true }); + outputMapper.Write(writer, people, new SeparatedValueOptions { IsFirstRecordSchema = true }); string output = writer.ToString(); var inputMapper = SeparatedValueTypeMapper.Define(() => new Person()); @@ -76,7 +76,7 @@ public void TestWriter_WithSchema_SchemaCounted() inputMapper.Property(x => x.CreatedOn).InputFormat("MM/dd/yyyy"); StringReader reader = new StringReader(output); - var results = inputMapper.Read(reader, new SeparatedValueOptions() { IsFirstRecordSchema = true }).ToArray(); + var results = inputMapper.Read(reader, new SeparatedValueOptions { IsFirstRecordSchema = true }).ToArray(); Assert.AreEqual(3, results.Length); Assert.AreEqual("Bob", results[0].Name); Assert.AreEqual(2, results[0].RecordNumber); @@ -101,13 +101,13 @@ public void TestWriter_NoSchema_SchemaNotCounted() var people = new[] { - new Person() { Name = "Bob", CreatedOn = new DateTime(2018, 04, 25) }, - new Person() { Name = "Tom", CreatedOn = new DateTime(2018, 04, 26) }, - new Person() { Name = "Jane", CreatedOn = new DateTime(2018, 04, 27) } + new Person { Name = "Bob", CreatedOn = new DateTime(2018, 04, 25) }, + new Person { Name = "Tom", CreatedOn = new DateTime(2018, 04, 26) }, + new Person { Name = "Jane", CreatedOn = new DateTime(2018, 04, 27) } }; StringWriter writer = new StringWriter(); - outputMapper.Write(writer, people, new SeparatedValueOptions() { IsFirstRecordSchema = true }); + outputMapper.Write(writer, people, new SeparatedValueOptions { IsFirstRecordSchema = true }); string output = writer.ToString(); var inputMapper = SeparatedValueTypeMapper.Define(() => new Person()); @@ -116,7 +116,7 @@ public void TestWriter_NoSchema_SchemaNotCounted() inputMapper.Property(x => x.CreatedOn).InputFormat("MM/dd/yyyy"); StringReader reader = new StringReader(output); - var results = inputMapper.Read(reader, new SeparatedValueOptions() { IsFirstRecordSchema = true }).ToArray(); + var results = inputMapper.Read(reader, new SeparatedValueOptions { IsFirstRecordSchema = true }).ToArray(); Assert.AreEqual(3, results.Length); Assert.AreEqual("Bob", results[0].Name); Assert.AreEqual(1, results[0].RecordNumber); @@ -143,13 +143,13 @@ public void TestWriter_WithSchema_WithIgnoredColumn() var people = new[] { - new Person() { Name = "Bob", CreatedOn = new DateTime(2018, 04, 25) }, - new Person() { Name = "Tom", CreatedOn = new DateTime(2018, 04, 26) }, - new Person() { Name = "Jane", CreatedOn = new DateTime(2018, 04, 27) } + new Person { Name = "Bob", CreatedOn = new DateTime(2018, 04, 25) }, + new Person { Name = "Tom", CreatedOn = new DateTime(2018, 04, 26) }, + new Person { Name = "Jane", CreatedOn = new DateTime(2018, 04, 27) } }; StringWriter writer = new StringWriter(); - outputMapper.Write(writer, people, new SeparatedValueOptions() { IsFirstRecordSchema = true }); + outputMapper.Write(writer, people, new SeparatedValueOptions { IsFirstRecordSchema = true }); string output = writer.ToString(); var inputMapper = SeparatedValueTypeMapper.Define(() => new Person()); @@ -160,7 +160,7 @@ public void TestWriter_WithSchema_WithIgnoredColumn() inputMapper.Property(x => x.CreatedOn).InputFormat("MM/dd/yyyy"); StringReader reader = new StringReader(output); - var results = inputMapper.Read(reader, new SeparatedValueOptions() { IsFirstRecordSchema = true }).ToArray(); + var results = inputMapper.Read(reader, new SeparatedValueOptions { IsFirstRecordSchema = true }).ToArray(); Assert.AreEqual(3, results.Length); Assert.AreEqual("Bob", results[0].Name); Assert.AreEqual(2, results[0].RecordNumber); @@ -185,13 +185,13 @@ public void TestWriter_WriteOnlyColumn_WithIgnoredColumn() var people = new[] { - new Person() { Name = "Bob", CreatedOn = new DateTime(2018, 04, 25) }, - new Person() { Name = "Tom", CreatedOn = new DateTime(2018, 04, 26) }, - new Person() { Name = "Jane", CreatedOn = new DateTime(2018, 04, 27) } + new Person { Name = "Bob", CreatedOn = new DateTime(2018, 04, 25) }, + new Person { Name = "Tom", CreatedOn = new DateTime(2018, 04, 26) }, + new Person { Name = "Jane", CreatedOn = new DateTime(2018, 04, 27) } }; StringWriter writer = new StringWriter(); - outputMapper.Write(writer, people, new SeparatedValueOptions() { IsFirstRecordSchema = true }); + outputMapper.Write(writer, people, new SeparatedValueOptions { IsFirstRecordSchema = true }); string output = writer.ToString(); var inputMapper = SeparatedValueTypeMapper.Define(() => new Person()); @@ -202,7 +202,7 @@ public void TestWriter_WriteOnlyColumn_WithIgnoredColumn() inputMapper.Property(x => x.CreatedOn).InputFormat("MM/dd/yyyy"); StringReader reader = new StringReader(output); - var results = inputMapper.Read(reader, new SeparatedValueOptions() { IsFirstRecordSchema = true }).ToArray(); + var results = inputMapper.Read(reader, new SeparatedValueOptions { IsFirstRecordSchema = true }).ToArray(); Assert.AreEqual(3, results.Length); Assert.AreEqual("Bob", results[0].Name); Assert.AreEqual(2, results[0].RecordNumber); diff --git a/FlatFiles.Test/SeparatedValueWriterTester.cs b/FlatFiles.Test/SeparatedValueWriterTester.cs index 17ec94c..df18aa8 100644 --- a/FlatFiles.Test/SeparatedValueWriterTester.cs +++ b/FlatFiles.Test/SeparatedValueWriterTester.cs @@ -11,7 +11,7 @@ public class SeparatedValueWriterTester public void ShouldNotWriteSchemaIfNoSchemaProvided() { StringWriter stringWriter = new StringWriter(); - SeparatedValueWriter writer = new SeparatedValueWriter(stringWriter, new SeparatedValueOptions() { IsFirstRecordSchema = true }); + SeparatedValueWriter writer = new SeparatedValueWriter(stringWriter, new SeparatedValueOptions { IsFirstRecordSchema = true }); writer.Write(new string[] { "a" }); string output = stringWriter.ToString(); @@ -26,15 +26,15 @@ public void ShouldWriteSchemaIfExplicit() // Explicitly indicate that the first record is NOT the schema SeparatedValueSchema schema = new SeparatedValueSchema(); schema.AddColumn(new StringColumn("Col1")); - SeparatedValueWriter writer = new SeparatedValueWriter(stringWriter, schema, new SeparatedValueOptions() - { + SeparatedValueWriter writer = new SeparatedValueWriter(stringWriter, schema, new SeparatedValueOptions + { IsFirstRecordSchema = false }); writer.WriteSchema(); // Explicitly write the schema writer.Write(new string[] { "a" }); StringReader stringReader = new StringReader(stringWriter.ToString()); - var reader = new SeparatedValueReader(stringReader, new SeparatedValueOptions() { IsFirstRecordSchema = true }); + var reader = new SeparatedValueReader(stringReader, new SeparatedValueOptions { IsFirstRecordSchema = true }); var parsedSchema = reader.GetSchema(); Assert.AreEqual(schema.ColumnDefinitions.Count, parsedSchema.ColumnDefinitions.Count); Assert.AreEqual(schema.ColumnDefinitions[0].ColumnName, parsedSchema.ColumnDefinitions[0].ColumnName); @@ -50,8 +50,8 @@ public void ShouldNotWriteSchemaAfterFirstRecordWritten() // Explicitly indicate that the first record is NOT the schema SeparatedValueSchema schema = new SeparatedValueSchema(); schema.AddColumn(new StringColumn("Col1")); - var options = new SeparatedValueOptions() - { + var options = new SeparatedValueOptions + { IsFirstRecordSchema = false }; SeparatedValueWriter writer = new SeparatedValueWriter(stringWriter, schema, options); diff --git a/FlatFiles.Test/TimeSpanColumnTester.cs b/FlatFiles.Test/TimeSpanColumnTester.cs index 97bd64a..6cb8735 100644 --- a/FlatFiles.Test/TimeSpanColumnTester.cs +++ b/FlatFiles.Test/TimeSpanColumnTester.cs @@ -115,7 +115,7 @@ public void TestFromDays_FromNull() var daysColumn = new DoubleColumn("Duration"); var durationColumn = TimeSpanColumn.FromDays(daysColumn); - var actual = (TimeSpan?)durationColumn.Parse(null, String.Empty); + var actual = (TimeSpan?)durationColumn.Parse(null, string.Empty); Assert.IsNull(actual); } @@ -126,7 +126,7 @@ public void TestFromDays_ToNull() var durationColumn = TimeSpanColumn.FromDays(daysColumn); var actual = durationColumn.Format(null, null); - Assert.AreEqual(String.Empty, actual); + Assert.AreEqual(string.Empty, actual); } [TestMethod] diff --git a/FlatFiles.Test/UnusualTypesTester.cs b/FlatFiles.Test/UnusualTypesTester.cs index 916da0c..47f7793 100644 --- a/FlatFiles.Test/UnusualTypesTester.cs +++ b/FlatFiles.Test/UnusualTypesTester.cs @@ -13,12 +13,12 @@ public class UnusualTypesTester public void ShouldRoundTripMaxValues() { var mapper = getWeirdMapper(); - var thing = new WeirdThing() - { - Small = SByte.MaxValue, - Big = UInt16.MaxValue, - Bigger = UInt32.MaxValue, - Huge = UInt64.MaxValue + var thing = new WeirdThing + { + Small = sbyte.MaxValue, + Big = ushort.MaxValue, + Bigger = uint.MaxValue, + Huge = ulong.MaxValue }; var deserialized = roundTrip(mapper, thing); assertEqual(thing, deserialized); @@ -28,12 +28,12 @@ public void ShouldRoundTripMaxValues() public void ShouldRoundTripMinValues() { var mapper = getWeirdMapper(); - var thing = new WeirdThing() - { - Small = SByte.MinValue, - Big = UInt16.MinValue, - Bigger = UInt32.MinValue, - Huge = UInt64.MinValue + var thing = new WeirdThing + { + Small = sbyte.MinValue, + Big = ushort.MinValue, + Bigger = uint.MinValue, + Huge = ulong.MinValue }; var deserialized = roundTrip(mapper, thing); assertEqual(thing, deserialized); diff --git a/FlatFiles/BooleanColumn.cs b/FlatFiles/BooleanColumn.cs index ee0e373..181bb4a 100644 --- a/FlatFiles/BooleanColumn.cs +++ b/FlatFiles/BooleanColumn.cs @@ -19,12 +19,12 @@ public BooleanColumn(string columnName) /// /// Gets or sets the value representing true. /// - public string? TrueString { get; set; } = Boolean.TrueString; + public string? TrueString { get; set; } = bool.TrueString; /// /// Gets or sets the value representing false. /// - public string? FalseString { get; set; } = Boolean.FalseString; + public string? FalseString { get; set; } = bool.FalseString; /// /// Parses the given value into its equivilent boolean value. @@ -34,11 +34,11 @@ public BooleanColumn(string columnName) /// True if the value equals the TrueString; otherwise, false. protected override bool OnParse(IColumnContext? context, string value) { - if (String.Equals(value, TrueString, StringComparison.CurrentCultureIgnoreCase)) + if (string.Equals(value, TrueString, StringComparison.CurrentCultureIgnoreCase)) { return true; } - if (String.Equals(value, FalseString, StringComparison.CurrentCultureIgnoreCase)) + if (string.Equals(value, FalseString, StringComparison.CurrentCultureIgnoreCase)) { return false; } @@ -54,7 +54,7 @@ protected override bool OnParse(IColumnContext? context, string value) protected override string OnFormat(IColumnContext? context, bool value) { string? formatted = value ? TrueString : FalseString; - return formatted ?? String.Empty; + return formatted ?? string.Empty; } } } diff --git a/FlatFiles/ByteColumn.cs b/FlatFiles/ByteColumn.cs index 1cdf039..544d775 100644 --- a/FlatFiles/ByteColumn.cs +++ b/FlatFiles/ByteColumn.cs @@ -41,7 +41,7 @@ public ByteColumn(string columnName) protected override byte OnParse(IColumnContext? context, string value) { var provider = GetFormatProvider(context, FormatProvider); - return Byte.Parse(value, NumberStyles, provider); + return byte.Parse(value, NumberStyles, provider); } /// diff --git a/FlatFiles/CharArrayColumn.cs b/FlatFiles/CharArrayColumn.cs index 2f58a37..7cceb8c 100644 --- a/FlatFiles/CharArrayColumn.cs +++ b/FlatFiles/CharArrayColumn.cs @@ -45,7 +45,7 @@ protected override char[] OnParse(IColumnContext? context, string value) /// The formatted value. protected override string OnFormat(IColumnContext? context, char[] value) { - return new String(value); + return new string(value); } } } diff --git a/FlatFiles/ColumnCollection.cs b/FlatFiles/ColumnCollection.cs index 51eaa36..b552368 100644 --- a/FlatFiles/ColumnCollection.cs +++ b/FlatFiles/ColumnCollection.cs @@ -79,7 +79,7 @@ internal void AddColumn(IColumnDefinition definition) { throw new ArgumentNullException(nameof(definition)); } - if (!String.IsNullOrEmpty(definition.ColumnName) && ordinals.ContainsKey(definition.ColumnName!)) + if (!string.IsNullOrEmpty(definition.ColumnName) && ordinals.ContainsKey(definition.ColumnName!)) { throw new ArgumentException(Resources.DuplicateColumnName, nameof(definition)); } @@ -97,7 +97,7 @@ private void AddColumnInternal(IColumnDefinition definition) { ++IgnoredCount; } - if (!String.IsNullOrEmpty(definition.ColumnName)) + if (!string.IsNullOrEmpty(definition.ColumnName)) { ordinals.Add(definition.ColumnName!, definitions.Count - 1); } diff --git a/FlatFiles/ColumnDefinition.cs b/FlatFiles/ColumnDefinition.cs index ae9be3c..ea6de19 100644 --- a/FlatFiles/ColumnDefinition.cs +++ b/FlatFiles/ColumnDefinition.cs @@ -42,7 +42,7 @@ public string? ColumnName internal set { value = value?.Trim(); - if (!IsIgnored && String.IsNullOrEmpty(value)) + if (!IsIgnored && string.IsNullOrEmpty(value)) { throw new ArgumentException(Resources.BlankColumnName); } @@ -182,12 +182,12 @@ protected ColumnDefinition(string columnName) #pragma warning disable CS0618 // Type or member is obsolete if (Preprocessor != null) { - value = Preprocessor(value) ?? String.Empty; + value = Preprocessor(value) ?? string.Empty; } #pragma warning restore CS0618 // Type or member is obsolete if (OnParsing != null) { - value = OnParsing(context, value) ?? String.Empty; + value = OnParsing(context, value) ?? string.Empty; } object? result = ParseValue(context, value); if (OnParsed != null) @@ -245,7 +245,7 @@ public override string Format(IColumnContext? context, object? value) string result = FormatValue(context, value); if (OnFormatted != null) { - result = OnFormatted(context, result) ?? String.Empty; + result = OnFormatted(context, result) ?? string.Empty; } return result; } @@ -254,7 +254,7 @@ private string FormatValue(IColumnContext? context, object? value) { if (value == null) { - return NullFormatter.FormatNull(context) ?? String.Empty; + return NullFormatter.FormatNull(context) ?? string.Empty; } else { diff --git a/FlatFiles/ColumnProcessingException.cs b/FlatFiles/ColumnProcessingException.cs index f46a1b4..c61398e 100644 --- a/FlatFiles/ColumnProcessingException.cs +++ b/FlatFiles/ColumnProcessingException.cs @@ -24,7 +24,7 @@ internal ColumnProcessingException(IColumnContext context, object? value, Except private static string GetErrorMessage(IColumnDefinition definition, int position, object? value) { - var message = String.Format(null, Resources.InvalidColumnConversion, value, definition.ColumnType.FullName, definition.ColumnName, position); + var message = string.Format(null, Resources.InvalidColumnConversion, value, definition.ColumnType.FullName, definition.ColumnName, position); return message; } diff --git a/FlatFiles/DecimalColumn.cs b/FlatFiles/DecimalColumn.cs index 897aafc..3a232ea 100644 --- a/FlatFiles/DecimalColumn.cs +++ b/FlatFiles/DecimalColumn.cs @@ -41,7 +41,7 @@ public DecimalColumn(string columnName) protected override decimal OnParse(IColumnContext? context, string value) { var provider = GetFormatProvider(context, FormatProvider); - return Decimal.Parse(value, NumberStyles, provider); + return decimal.Parse(value, NumberStyles, provider); } /// diff --git a/FlatFiles/DoubleColumn.cs b/FlatFiles/DoubleColumn.cs index ddfd3f1..0de1901 100644 --- a/FlatFiles/DoubleColumn.cs +++ b/FlatFiles/DoubleColumn.cs @@ -41,7 +41,7 @@ public DoubleColumn(string columnName) protected override double OnParse(IColumnContext? context, string value) { var provider = GetFormatProvider(context, FormatProvider); - return Double.Parse(value, NumberStyles, provider); + return double.Parse(value, NumberStyles, provider); } /// diff --git a/FlatFiles/EnumColumn.cs b/FlatFiles/EnumColumn.cs index 7cb40f9..8e041ba 100644 --- a/FlatFiles/EnumColumn.cs +++ b/FlatFiles/EnumColumn.cs @@ -69,7 +69,7 @@ protected override TEnum OnParse(IColumnContext? context, string value) /// The formatted value. protected override string OnFormat(IColumnContext? context, TEnum value) { - return formatter(value) ?? String.Empty; + return formatter(value) ?? string.Empty; } } } diff --git a/FlatFiles/FixedLengthComplexColumn.cs b/FlatFiles/FixedLengthComplexColumn.cs index 6639785..cd4da1a 100644 --- a/FlatFiles/FixedLengthComplexColumn.cs +++ b/FlatFiles/FixedLengthComplexColumn.cs @@ -57,7 +57,7 @@ protected override string OnFormat(IColumnContext? context, object?[]? values) { if (values == null) { - return String.Empty; + return string.Empty; } var writer = new StringWriter(); var recordWriter = new FixedLengthRecordWriter(writer, schema, Options); diff --git a/FlatFiles/FixedLengthRecordParser.cs b/FlatFiles/FixedLengthRecordParser.cs index 2f118dc..0142fa9 100644 --- a/FlatFiles/FixedLengthRecordParser.cs +++ b/FlatFiles/FixedLengthRecordParser.cs @@ -176,12 +176,12 @@ public async ValueTask IsEndOfStreamAsync() public string ReadRecord() { - return new String(buffer, 0, length); + return new string(buffer, 0, length); } public Task ReadRecordAsync() { - return Task.FromResult(new String(buffer, 0, length)); + return Task.FromResult(new string(buffer, 0, length)); } } } diff --git a/FlatFiles/FixedLengthRecordWriter.cs b/FlatFiles/FixedLengthRecordWriter.cs index 4fc744c..738587e 100644 --- a/FlatFiles/FixedLengthRecordWriter.cs +++ b/FlatFiles/FixedLengthRecordWriter.cs @@ -108,7 +108,7 @@ private void FitWindows(FixedLengthSchema schema, string[] values) } else { - values[index] = value ?? String.Empty; + values[index] = value ?? string.Empty; } } } @@ -155,7 +155,7 @@ private string FitWidth(Window window, string? value) { if (value == null) { - value = String.Empty; + value = string.Empty; } if (value.Length > window.Width) { diff --git a/FlatFiles/FixedLengthWriter.cs b/FlatFiles/FixedLengthWriter.cs index 0349b11..7ceca3b 100644 --- a/FlatFiles/FixedLengthWriter.cs +++ b/FlatFiles/FixedLengthWriter.cs @@ -201,7 +201,7 @@ public async Task WriteAsync(object?[] values) /// /// The data to write to the output. /// Indicates whether a newline should be written after the data. - public void WriteRaw(String data, bool writeRecordSeparator = false) + public void WriteRaw(string data, bool writeRecordSeparator = false) { recordWriter.WriteRaw(data); if (writeRecordSeparator) @@ -216,7 +216,7 @@ public void WriteRaw(String data, bool writeRecordSeparator = false) /// /// The data to write to the output. /// Indicates whether a record separator should be written after the data. - public async Task WriteRawAsync(String data, bool writeRecordSeparator = false) + public async Task WriteRawAsync(string data, bool writeRecordSeparator = false) { await recordWriter.WriteRawAsync(data); if (writeRecordSeparator) diff --git a/FlatFiles/FlatFileDataReader.cs b/FlatFiles/FlatFileDataReader.cs index cfdf688..fa84976 100644 --- a/FlatFiles/FlatFileDataReader.cs +++ b/FlatFiles/FlatFileDataReader.cs @@ -87,7 +87,7 @@ public DataTable GetSchemaTable() null, // BaseTableName null, // ColumnName 0, // ColumnOrdinal - Int32.MaxValue, // ColumnSize + int.MaxValue, // ColumnSize null, // DataType null, // DataTypeName false, // IsAliased @@ -123,8 +123,8 @@ public DataTable GetSchemaTable() private static DataTable GetEmptySchemaDataTable(ISchema schema) { - var schemaTable = new DataTable() - { + var schemaTable = new DataTable + { Locale = CultureInfo.InvariantCulture, MinimumCapacity = schema.ColumnDefinitions.PhysicalCount }; diff --git a/FlatFiles/IgnoredColumn.cs b/FlatFiles/IgnoredColumn.cs index 18a23f2..c23fc56 100644 --- a/FlatFiles/IgnoredColumn.cs +++ b/FlatFiles/IgnoredColumn.cs @@ -12,7 +12,7 @@ public sealed class IgnoredColumn : ColumnDefinition /// Initializes a new IgnoredColumn. /// public IgnoredColumn() - : base(String.Empty, true) + : base(string.Empty, true) { } @@ -41,12 +41,12 @@ public IgnoredColumn(string columnName) #pragma warning disable CS0618 // Type or member is obsolete if (Preprocessor != null) { - value = Preprocessor(value) ?? String.Empty; + value = Preprocessor(value) ?? string.Empty; } #pragma warning restore CS0618 // Type or member is obsolete if (OnParsing != null) { - value = OnParsing(context, value) ?? String.Empty; + value = OnParsing(context, value) ?? string.Empty; } object? result = null; if (OnParsed != null) @@ -68,10 +68,10 @@ public override string Format(IColumnContext? context, object? value) { value = OnFormatting(context, value); } - string result = NullFormatter.FormatNull(context) ?? String.Empty; + string result = NullFormatter.FormatNull(context) ?? string.Empty; if (OnFormatted != null) { - result = OnFormatted(context, result) ?? String.Empty; + result = OnFormatted(context, result) ?? string.Empty; } return result; } diff --git a/FlatFiles/Int16Column.cs b/FlatFiles/Int16Column.cs index 16d2bc4..58876ad 100644 --- a/FlatFiles/Int16Column.cs +++ b/FlatFiles/Int16Column.cs @@ -41,7 +41,7 @@ public Int16Column(string columnName) protected override short OnParse(IColumnContext? context, string value) { var provider = GetFormatProvider(context, FormatProvider); - return Int16.Parse(value, NumberStyles, provider); + return short.Parse(value, NumberStyles, provider); } /// diff --git a/FlatFiles/Int32Column.cs b/FlatFiles/Int32Column.cs index 4b219f3..546698b 100644 --- a/FlatFiles/Int32Column.cs +++ b/FlatFiles/Int32Column.cs @@ -41,7 +41,7 @@ public Int32Column(string columnName) protected override int OnParse(IColumnContext? context, string value) { var provider = GetFormatProvider(context, FormatProvider); - return Int32.Parse(value, NumberStyles, provider); + return int.Parse(value, NumberStyles, provider); } /// diff --git a/FlatFiles/Int64Column.cs b/FlatFiles/Int64Column.cs index 8cf22df..dd12b38 100644 --- a/FlatFiles/Int64Column.cs +++ b/FlatFiles/Int64Column.cs @@ -41,7 +41,7 @@ public Int64Column(string columnName) protected override long OnParse(IColumnContext? context, string value) { var provider = GetFormatProvider(context, FormatProvider); - return Int64.Parse(value, NumberStyles, provider); + return long.Parse(value, NumberStyles, provider); } /// diff --git a/FlatFiles/MetadataColumn.cs b/FlatFiles/MetadataColumn.cs index a7c5188..7b27934 100644 --- a/FlatFiles/MetadataColumn.cs +++ b/FlatFiles/MetadataColumn.cs @@ -30,7 +30,7 @@ protected MetadataColumn(string columnName) /// The formatted value. public sealed override string Format(IColumnContext? context, object? value) { - return OnFormat(context) ?? String.Empty; + return OnFormat(context) ?? string.Empty; } /// diff --git a/FlatFiles/NullFormatter.cs b/FlatFiles/NullFormatter.cs index 57e5f3b..d21fb60 100644 --- a/FlatFiles/NullFormatter.cs +++ b/FlatFiles/NullFormatter.cs @@ -11,8 +11,8 @@ public sealed class NullFormatter : INullFormatter /// Creates a new that treats solid whitespace as null. /// public static readonly INullFormatter Default = new NullFormatter( - (ctx, v) => String.IsNullOrWhiteSpace(v), - ctx => String.Empty + (ctx, v) => string.IsNullOrWhiteSpace(v), + ctx => string.Empty ); private readonly Func isNullValue; diff --git a/FlatFiles/RecordProcessingException.cs b/FlatFiles/RecordProcessingException.cs index 05bb322..cb74818 100644 --- a/FlatFiles/RecordProcessingException.cs +++ b/FlatFiles/RecordProcessingException.cs @@ -8,13 +8,13 @@ namespace FlatFiles public sealed class RecordProcessingException : FlatFileException { internal RecordProcessingException(IRecordContext context, string message) - : base(String.Format(null, message, context.PhysicalRecordNumber)) + : base(string.Format(null, message, context.PhysicalRecordNumber)) { RecordContext = context; } internal RecordProcessingException(IRecordContext context, string message, Exception innerException) - : base(String.Format(null, message, context.PhysicalRecordNumber), innerException) + : base(string.Format(null, message, context.PhysicalRecordNumber), innerException) { RecordContext = context; } diff --git a/FlatFiles/RetryReader.cs b/FlatFiles/RetryReader.cs index d68ee5c..7859aa9 100644 --- a/FlatFiles/RetryReader.cs +++ b/FlatFiles/RetryReader.cs @@ -74,7 +74,7 @@ public async Task LoadBufferAsync() public bool IsWhitespace() { - if (queue.Count == 0 || !Char.IsWhiteSpace(queue.Peek())) + if (queue.Count == 0 || !char.IsWhiteSpace(queue.Peek())) { return false; } diff --git a/FlatFiles/SByteColumn.cs b/FlatFiles/SByteColumn.cs index 6c9915a..45e7d3e 100644 --- a/FlatFiles/SByteColumn.cs +++ b/FlatFiles/SByteColumn.cs @@ -41,7 +41,7 @@ public SByteColumn(string columnName) protected override sbyte OnParse(IColumnContext? context, string value) { var provider = GetFormatProvider(context, FormatProvider); - return SByte.Parse(value, NumberStyles, provider); + return sbyte.Parse(value, NumberStyles, provider); } /// diff --git a/FlatFiles/Schema.cs b/FlatFiles/Schema.cs index ea461e6..c653b1c 100644 --- a/FlatFiles/Schema.cs +++ b/FlatFiles/Schema.cs @@ -56,7 +56,7 @@ protected void AddColumnBase(IColumnDefinition definition) if (definition is IMetadataColumn) { var columnContext = NewColumnContext(context, columnIndex, destinationIndex); - var metadata = ParseWithContext(columnContext, String.Empty); + var metadata = ParseWithContext(columnContext, string.Empty); parsedValues[destinationIndex] = metadata; ++destinationIndex; } @@ -198,7 +198,7 @@ private string FormatWithContext(IColumnContext columnContext, object? value) recordContext.ProcessError(this, e); if (e.IsHandled) { - return (string?)e.Substitution ?? String.Empty; + return (string?)e.Substitution ?? string.Empty; } } throw columnException; diff --git a/FlatFiles/SeparatedValueComplexColumn.cs b/FlatFiles/SeparatedValueComplexColumn.cs index 43f2daf..5afd7c1 100644 --- a/FlatFiles/SeparatedValueComplexColumn.cs +++ b/FlatFiles/SeparatedValueComplexColumn.cs @@ -86,7 +86,7 @@ protected override string OnFormat(IColumnContext? context, object?[]? values) { if (values == null) { - return String.Empty; + return string.Empty; } var writer = new StringWriter(); var recordWriter = GetWriter(writer); diff --git a/FlatFiles/SeparatedValueOptions.cs b/FlatFiles/SeparatedValueOptions.cs index 0253efa..316a0bb 100644 --- a/FlatFiles/SeparatedValueOptions.cs +++ b/FlatFiles/SeparatedValueOptions.cs @@ -27,7 +27,7 @@ public string Separator get => separator; set { - if (String.IsNullOrEmpty(value)) + if (string.IsNullOrEmpty(value)) { throw new ArgumentException(Resources.EmptySeparator); } diff --git a/FlatFiles/SeparatedValueRecordParser.cs b/FlatFiles/SeparatedValueRecordParser.cs index 19890d0..194e444 100644 --- a/FlatFiles/SeparatedValueRecordParser.cs +++ b/FlatFiles/SeparatedValueRecordParser.cs @@ -181,10 +181,10 @@ private void TrimTokenEnd() { return; } - if (Char.IsWhiteSpace(token[token.Length - 1])) + if (char.IsWhiteSpace(token[token.Length - 1])) { int trailingSize = 1; - while (Char.IsWhiteSpace(token[token.Length - trailingSize - 1])) + while (char.IsWhiteSpace(token[token.Length - trailingSize - 1])) { ++trailingSize; } diff --git a/FlatFiles/SeparatedValueRecordWriter.cs b/FlatFiles/SeparatedValueRecordWriter.cs index ad19d93..0f47379 100644 --- a/FlatFiles/SeparatedValueRecordWriter.cs +++ b/FlatFiles/SeparatedValueRecordWriter.cs @@ -67,7 +67,7 @@ private string FormatAndJoinValues(object?[] values) } var formattedValues = FormatValues(recordContext, values); EscapeValues(formattedValues); - var joined = String.Join(Options.Separator, formattedValues); + var joined = string.Join(Options.Separator, formattedValues); return joined; } @@ -108,7 +108,7 @@ private string[] FormatValues(SeparatedValueRecordContext recordContext, object? private static string ToString(object? value) { - return value?.ToString() ?? String.Empty; + return value?.ToString() ?? string.Empty; } private void EscapeValues(string[] values) @@ -123,7 +123,7 @@ private string Escape(string? value) { if (value == null) { - return String.Empty; + return string.Empty; } if (NeedsEscaped(value)) { @@ -143,12 +143,12 @@ private bool NeedsEscaped(string value) return false; } // Don't escape empty strings. - if (value == String.Empty) + if (value == string.Empty) { return false; } // Escape strings beginning or ending in whitespace. - if (Char.IsWhiteSpace(value[0]) || Char.IsWhiteSpace(value[value.Length - 1])) + if (char.IsWhiteSpace(value[0]) || char.IsWhiteSpace(value[value.Length - 1])) { return true; } @@ -201,7 +201,7 @@ public async Task WriteSchemaAsync() private string JoinSchema(SeparatedValueSchema schema) { var names = GetColumnNames(schema); - var joined = String.Join(Options.Separator, names); + var joined = string.Join(Options.Separator, names); return joined; } diff --git a/FlatFiles/SingleColumn.cs b/FlatFiles/SingleColumn.cs index b6fd896..319ed10 100644 --- a/FlatFiles/SingleColumn.cs +++ b/FlatFiles/SingleColumn.cs @@ -41,7 +41,7 @@ public SingleColumn(string columnName) protected override float OnParse(IColumnContext? context, string value) { var provider = GetFormatProvider(context, FormatProvider); - return Single.Parse(value, NumberStyles, provider); + return float.Parse(value, NumberStyles, provider); } /// diff --git a/FlatFiles/TypeMapping/EmitCodeGenerator.cs b/FlatFiles/TypeMapping/EmitCodeGenerator.cs index a6a5ebf..855e84d 100644 --- a/FlatFiles/TypeMapping/EmitCodeGenerator.cs +++ b/FlatFiles/TypeMapping/EmitCodeGenerator.cs @@ -102,7 +102,7 @@ private static void EmitMemberRead(ILGenerator generator, IMemberAccessor member MethodInfo? setter = propertyInfo.GetSetMethod(true); if (setter == null) { - string message = String.Format(null, Resources.ReadOnlyProperty, propertyInfo.Name); + string message = string.Format(null, Resources.ReadOnlyProperty, propertyInfo.Name); throw new FlatFileException(message); } generator.Emit(OpCodes.Unbox_Any, propertyInfo.PropertyType); @@ -139,12 +139,7 @@ private static void EmitCustomRead(ILGenerator generator, FieldInfo fieldInfo, i generator.Emit(OpCodes.Dup); generator.Emit(OpCodes.Stloc, indexBuilder); - var contextCtorInfo = MemberAccessorBuilder.GetConstructor(new[] - { - typeof(IRecordContext), - typeof(int), - typeof(int) - })!; + var contextCtorInfo = MemberAccessorBuilder.GetConstructor(typeof(IRecordContext), typeof(int), typeof(int))!; generator.Emit(OpCodes.Newobj, contextCtorInfo); generator.Emit(OpCodes.Stloc, contextBuilder); @@ -221,7 +216,7 @@ private static void EmitMemberWrite(ILGenerator generator, IMemberAccessor membe var getter = propertyInfo.GetGetMethod(true); if (getter == null) { - string message = String.Format(null, Resources.WriteOnlyProperty, propertyInfo.Name); + string message = string.Format(null, Resources.WriteOnlyProperty, propertyInfo.Name); throw new FlatFileException(message); } generator.Emit(OpCodes.Callvirt, getter); @@ -261,12 +256,7 @@ private static void EmitCustomWrite(ILGenerator generator, FieldInfo fi var logicalIndexGetter = logicalIndexGetInfo.GetGetMethod()!; generator.Emit(OpCodes.Callvirt, logicalIndexGetter); - var contextCtorInfo = MemberAccessorBuilder.GetConstructor(new[] - { - typeof(IRecordContext), - typeof(int), - typeof(int) - })!; + var contextCtorInfo = MemberAccessorBuilder.GetConstructor(typeof(IRecordContext), typeof(int), typeof(int))!; generator.Emit(OpCodes.Newobj, contextCtorInfo); generator.Emit(OpCodes.Stloc, contextBuilder); diff --git a/FlatFiles/TypeMapping/FixedLengthComplexPropertyMapping.cs b/FlatFiles/TypeMapping/FixedLengthComplexPropertyMapping.cs index b2f866a..d340912 100644 --- a/FlatFiles/TypeMapping/FixedLengthComplexPropertyMapping.cs +++ b/FlatFiles/TypeMapping/FixedLengthComplexPropertyMapping.cs @@ -65,7 +65,7 @@ public IColumnDefinition ColumnDefinition public IFixedLengthComplexPropertyMapping ColumnName(string name) { - if (String.IsNullOrWhiteSpace(name)) + if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentException(Resources.BlankColumnName); } diff --git a/FlatFiles/TypeMapping/FixedLengthTypeMapper.cs b/FlatFiles/TypeMapping/FixedLengthTypeMapper.cs index 4225b64..881e845 100644 --- a/FlatFiles/TypeMapping/FixedLengthTypeMapper.cs +++ b/FlatFiles/TypeMapping/FixedLengthTypeMapper.cs @@ -616,14 +616,11 @@ public IIgnoredMapping Ignored(Window window) public ICustomMapping CustomMapping(IColumnDefinition column, Window window) { var columnName = column.ColumnName; - if (String.IsNullOrWhiteSpace(columnName)) + if (string.IsNullOrWhiteSpace(columnName)) { throw new ArgumentException(Resources.BlankColumnName, nameof(column)); } - var mapping = lookup.GetOrAddCustomMapping(columnName, (physicalIndex, logicalIndex) => - { - return new CustomMapping(column, physicalIndex, logicalIndex); - }); + var mapping = lookup.GetOrAddCustomMapping(columnName!, (physicalIndex, logicalIndex) => new CustomMapping(column, physicalIndex, logicalIndex)); windowLookup[mapping] = window; return mapping; } diff --git a/FlatFiles/TypeMapping/IDynamicFixedLengthTypeMapper.cs b/FlatFiles/TypeMapping/IDynamicFixedLengthTypeMapper.cs index 66f9743..eaaf155 100644 --- a/FlatFiles/TypeMapping/IDynamicFixedLengthTypeMapper.cs +++ b/FlatFiles/TypeMapping/IDynamicFixedLengthTypeMapper.cs @@ -17,7 +17,6 @@ public interface IDynamicFixedLengthTypeMapper : IDynamicFixedLengthTypeConfigur /// The entities that are extracted from the file. IEnumerable Read(TextReader reader, FixedLengthOptions? options = null); -#if !NET451 && !NETSTANDARD1_6 && !NETSTANDARD2_0 /// /// Reads the entities from the given reader. /// @@ -25,7 +24,6 @@ public interface IDynamicFixedLengthTypeMapper : IDynamicFixedLengthTypeConfigur /// The options controlling how the fixed-length document is read. /// An asynchronous enumerable over the entities. IAsyncEnumerable ReadAsync(TextReader reader, FixedLengthOptions? options = null); -#endif /// /// Gets a typed reader to read entities from the underlying document. @@ -51,7 +49,6 @@ public interface IDynamicFixedLengthTypeMapper : IDynamicFixedLengthTypeConfigur /// The options used to format the output. Task WriteAsync(TextWriter writer, IEnumerable entities, FixedLengthOptions? options = null); -#if !NET451 && !NETSTANDARD1_6 && !NETSTANDARD2_0 /// /// Writes the given entities to the given stream. /// @@ -59,7 +56,6 @@ public interface IDynamicFixedLengthTypeMapper : IDynamicFixedLengthTypeConfigur /// The entities to write to the stream. /// The options used to format the output. Task WriteAsync(TextWriter writer, IAsyncEnumerable entities, FixedLengthOptions? options = null); -#endif /// /// Gets a typed writer to write entities to the underlying document. diff --git a/FlatFiles/TypeMapping/IDynamicSeparatedValueTypeMapper.cs b/FlatFiles/TypeMapping/IDynamicSeparatedValueTypeMapper.cs index ccc2d48..de4df30 100644 --- a/FlatFiles/TypeMapping/IDynamicSeparatedValueTypeMapper.cs +++ b/FlatFiles/TypeMapping/IDynamicSeparatedValueTypeMapper.cs @@ -17,7 +17,6 @@ public interface IDynamicSeparatedValueTypeMapper : IDynamicSeparatedValueTypeCo /// The entities that are extracted from the file. IEnumerable Read(TextReader reader, SeparatedValueOptions? options = null); -#if !NET451 && !NETSTANDARD1_6 && !NETSTANDARD2_0 /// /// Reads the entities from the given reader. /// @@ -25,7 +24,6 @@ public interface IDynamicSeparatedValueTypeMapper : IDynamicSeparatedValueTypeCo /// The options controlling how the separated value document is read. /// An asynchronous enumerable over the entities. IAsyncEnumerable ReadAsync(TextReader reader, SeparatedValueOptions? options = null); -#endif /// /// Gets a typed reader to read entities from the underlying document. @@ -51,7 +49,6 @@ public interface IDynamicSeparatedValueTypeMapper : IDynamicSeparatedValueTypeCo /// The options used to format the output. Task WriteAsync(TextWriter writer, IEnumerable entities, SeparatedValueOptions? options = null); -#if !NET451 && !NETSTANDARD1_6 && !NETSTANDARD2_0 /// /// Writes the given entities to the given stream. /// @@ -59,7 +56,6 @@ public interface IDynamicSeparatedValueTypeMapper : IDynamicSeparatedValueTypeCo /// The entities to write to the stream. /// The options used to format the output. Task WriteAsync(TextWriter writer, IAsyncEnumerable entities, SeparatedValueOptions? options = null); -#endif /// /// Gets a typed writer to write entities to the underlying document. diff --git a/FlatFiles/TypeMapping/IFixedLengthTypeMapper.cs b/FlatFiles/TypeMapping/IFixedLengthTypeMapper.cs index 1107080..b1f048c 100644 --- a/FlatFiles/TypeMapping/IFixedLengthTypeMapper.cs +++ b/FlatFiles/TypeMapping/IFixedLengthTypeMapper.cs @@ -18,7 +18,6 @@ public interface IFixedLengthTypeMapper : IFixedLengthTypeConfiguration /// The entities that are extracted from the file. IEnumerable Read(TextReader reader, FixedLengthOptions? options = null); -#if !NET451 && !NETSTANDARD1_6 && !NETSTANDARD2_0 /// /// Reads the entities from the given reader. /// @@ -26,7 +25,6 @@ public interface IFixedLengthTypeMapper : IFixedLengthTypeConfiguration /// The options controlling how the fixed-length document is read. /// An asynchronous enumerable over the entities. IAsyncEnumerable ReadAsync(TextReader reader, FixedLengthOptions? options = null); -#endif /// /// Gets a typed reader to read entities from the underlying document. @@ -52,7 +50,6 @@ public interface IFixedLengthTypeMapper : IFixedLengthTypeConfiguration /// The options controlling how the separated value document is written. Task WriteAsync(TextWriter writer, IEnumerable entities, FixedLengthOptions? options = null); -#if !NET451 && !NETSTANDARD1_6 && !NETSTANDARD2_0 /// /// Writes the given entities to the given writer. /// @@ -60,7 +57,6 @@ public interface IFixedLengthTypeMapper : IFixedLengthTypeConfiguration /// The entities to write to the document. /// The options controlling how the separated value document is written. Task WriteAsync(TextWriter writer, IAsyncEnumerable entities, FixedLengthOptions? options = null); -#endif /// /// Gets a typed writer to write entities to the underlying document. diff --git a/FlatFiles/TypeMapping/ISeparatedValueTypeMapper.cs b/FlatFiles/TypeMapping/ISeparatedValueTypeMapper.cs index 740d8b4..16989f1 100644 --- a/FlatFiles/TypeMapping/ISeparatedValueTypeMapper.cs +++ b/FlatFiles/TypeMapping/ISeparatedValueTypeMapper.cs @@ -18,7 +18,6 @@ public interface ISeparatedValueTypeMapper : ISeparatedValueTypeConfigu /// The entities that are extracted from the file. IEnumerable Read(TextReader reader, SeparatedValueOptions? options = null); -#if !NET451 && !NETSTANDARD1_6 && !NETSTANDARD2_0 /// /// Reads the entities from the given reader. /// @@ -26,7 +25,6 @@ public interface ISeparatedValueTypeMapper : ISeparatedValueTypeConfigu /// The options controlling how the separated value document is read. /// An asynchronous enumerable over the entities. IAsyncEnumerable ReadAsync(TextReader reader, SeparatedValueOptions? options = null); -#endif /// /// Gets a typed reader to read entities from the underlying document. @@ -52,7 +50,6 @@ public interface ISeparatedValueTypeMapper : ISeparatedValueTypeConfigu /// The options used to format the output. Task WriteAsync(TextWriter writer, IEnumerable entities, SeparatedValueOptions? options = null); -#if !NET451 && !NETSTANDARD1_6 && !NETSTANDARD2_0 /// /// Writes the given entities to the given stream. /// @@ -60,7 +57,6 @@ public interface ISeparatedValueTypeMapper : ISeparatedValueTypeConfigu /// The entities to write to the stream. /// The options used to format the output. Task WriteAsync(TextWriter writer, IAsyncEnumerable entities, SeparatedValueOptions? options = null); -#endif /// /// Gets a typed writer to write entities to the underlying document. diff --git a/FlatFiles/TypeMapping/Mapper.cs b/FlatFiles/TypeMapping/Mapper.cs index ed12294..e1e5456 100644 --- a/FlatFiles/TypeMapping/Mapper.cs +++ b/FlatFiles/TypeMapping/Mapper.cs @@ -129,7 +129,7 @@ private IMapper[] GetNestedMappers(IMemberMapping[] mappings) var mappers = mappings .Where(m => m.Member != null) .Where(m => Member?.Name != m.Member!.ParentAccessor?.Name) - .Where(m => m.Member!.Name.StartsWith(Member?.Name ?? String.Empty)) + .Where(m => m.Member!.Name.StartsWith(Member?.Name ?? string.Empty)) .Select(GetParentAccessor) .GroupBy(p => p.Name) .Select(g => g.First()) @@ -140,7 +140,7 @@ private IMapper[] GetNestedMappers(IMemberMapping[] mappings) private IMemberAccessor GetParentAccessor(IMemberMapping mapping) { - string accessorName = Member?.Name ?? String.Empty; + string accessorName = Member?.Name ?? string.Empty; var childAccessor = mapping.Member!; var parentAccessor = childAccessor.ParentAccessor; while (parentAccessor != null && accessorName != parentAccessor.Name) diff --git a/FlatFiles/TypeMapping/SeparatedValueComplexPropertyMapping.cs b/FlatFiles/TypeMapping/SeparatedValueComplexPropertyMapping.cs index 4cd7776..ef632df 100644 --- a/FlatFiles/TypeMapping/SeparatedValueComplexPropertyMapping.cs +++ b/FlatFiles/TypeMapping/SeparatedValueComplexPropertyMapping.cs @@ -66,7 +66,7 @@ public IColumnDefinition ColumnDefinition public ISeparatedValueComplexPropertyMapping ColumnName(string name) { - if (String.IsNullOrWhiteSpace(name)) + if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentException(Resources.BlankColumnName); } diff --git a/FlatFiles/TypeMapping/SeparatedValueTypeMapper.cs b/FlatFiles/TypeMapping/SeparatedValueTypeMapper.cs index 9d44609..137b112 100644 --- a/FlatFiles/TypeMapping/SeparatedValueTypeMapper.cs +++ b/FlatFiles/TypeMapping/SeparatedValueTypeMapper.cs @@ -188,7 +188,7 @@ private static ITypedReader GetAutoMapReader(SeparatedValueSch var columnDefinition = GetColumnDefinition(memberExpression.Type, column.ColumnName!); if (columnDefinition == null) { - throw new FlatFileException(String.Format(null, Resources.NoAutoMapPropertyType, column.ColumnName)); + throw new FlatFileException(string.Format(null, Resources.NoAutoMapPropertyType, column.ColumnName)); } var lambdaExpression = Expression.Lambda>(body, contextParameter, entityParameter, valueParameter); var compiledSetter = lambdaExpression.Compile(); @@ -205,7 +205,7 @@ private static MemberExpression GetMemberExpression(ParameterExpression entityPa { if (!propertyInfo.CanWrite) { - throw new FlatFileException(String.Format(null, Resources.ReadOnlyProperty, column.ColumnName)); + throw new FlatFileException(string.Format(null, Resources.ReadOnlyProperty, column.ColumnName)); } return Expression.Property(Expression.Convert(entityParameter, entityType), propertyInfo); } @@ -265,7 +265,7 @@ private static MemberExpression GetMemberExpression(ParameterExpression entityPa public static ITypedWriter GetAutoMappedWriter(TextWriter writer, SeparatedValueOptions? options = null, IAutoMapResolver? resolver = null) { var optionsCopy = options == null - ? new SeparatedValueOptions() { IsFirstRecordSchema = true } + ? new SeparatedValueOptions { IsFirstRecordSchema = true } : options.Clone(); var entityType = typeof(TEntity); var typedMapper = Define(() => throw new InvalidOperationException("Unexpected entity creation within autom-mapped writer.")); @@ -279,7 +279,7 @@ public static ITypedWriter GetAutoMappedWriter(TextWriter writ foreach (var member in members) { var columnName = nameResolver.GetColumnName(member); - if (String.IsNullOrWhiteSpace(columnName)) + if (string.IsNullOrWhiteSpace(columnName)) { continue; } @@ -817,11 +817,11 @@ public IIgnoredMapping Ignored() public ICustomMapping CustomMapping(IColumnDefinition column) { var columnName = column.ColumnName; - if (String.IsNullOrWhiteSpace(columnName)) + if (string.IsNullOrWhiteSpace(columnName)) { throw new ArgumentException(Resources.BlankColumnName, nameof(column)); } - var mapping = lookup.GetOrAddCustomMapping(columnName, (fileIndex, workIndex) => + var mapping = lookup.GetOrAddCustomMapping(columnName!, (fileIndex, workIndex) => { return new CustomMapping(column, fileIndex, workIndex); }); diff --git a/FlatFiles/TypeMapping/TypedReaderExtensions.cs b/FlatFiles/TypeMapping/TypedReaderExtensions.cs index aa77854..16d22d4 100644 --- a/FlatFiles/TypeMapping/TypedReaderExtensions.cs +++ b/FlatFiles/TypeMapping/TypedReaderExtensions.cs @@ -23,7 +23,6 @@ public static IEnumerable ReadAll(this ITypedReader r } } -#if !NET451 && !NETSTANDARD1_6 && !NETSTANDARD2_0 /// /// Reads each record from the given reader, such that each record is retrieved asynchronously. /// @@ -38,6 +37,5 @@ public static async IAsyncEnumerable ReadAllAsync(this ITypedR yield return entity; } } -#endif } } diff --git a/FlatFiles/TypeMapping/TypedWriterExtensions.cs b/FlatFiles/TypeMapping/TypedWriterExtensions.cs index 84db39a..8237f60 100644 --- a/FlatFiles/TypeMapping/TypedWriterExtensions.cs +++ b/FlatFiles/TypeMapping/TypedWriterExtensions.cs @@ -46,7 +46,6 @@ public static async Task WriteAllAsync(this ITypedWriter write } } -#if !NET451 && !NETSTANDARD1_6 && !NETSTANDARD2_0 /// /// Writes all of the entities to the typed writer. /// @@ -65,6 +64,5 @@ public static async Task WriteAllAsync(this ITypedWriter write await writer.WriteAsync(entity).ConfigureAwait(false); } } -#endif } } diff --git a/FlatFiles/UInt16Column.cs b/FlatFiles/UInt16Column.cs index aed88cb..32eb674 100644 --- a/FlatFiles/UInt16Column.cs +++ b/FlatFiles/UInt16Column.cs @@ -41,7 +41,7 @@ public UInt16Column(string columnName) protected override ushort OnParse(IColumnContext? context, string value) { var provider = GetFormatProvider(context, FormatProvider); - return UInt16.Parse(value, NumberStyles, provider); + return ushort.Parse(value, NumberStyles, provider); } /// diff --git a/FlatFiles/UInt32Column.cs b/FlatFiles/UInt32Column.cs index 12eeb63..5289b17 100644 --- a/FlatFiles/UInt32Column.cs +++ b/FlatFiles/UInt32Column.cs @@ -44,7 +44,7 @@ public UInt32Column(string columnName) protected override uint OnParse(IColumnContext? context, string value) { var provider = GetFormatProvider(context, FormatProvider); - return UInt32.Parse(value, NumberStyles, provider); + return uint.Parse(value, NumberStyles, provider); } /// diff --git a/FlatFiles/UInt64Column.cs b/FlatFiles/UInt64Column.cs index f74959c..d77886c 100644 --- a/FlatFiles/UInt64Column.cs +++ b/FlatFiles/UInt64Column.cs @@ -41,7 +41,7 @@ public UInt64Column(string columnName) protected override ulong OnParse(IColumnContext? context, string value) { var provider = GetFormatProvider(context, FormatProvider); - return UInt64.Parse(value, NumberStyles, provider); + return ulong.Parse(value, NumberStyles, provider); } ///