From fc906ecc93f4dc7742a43f0c84eea90004db2829 Mon Sep 17 00:00:00 2001 From: Darren McDaniel Date: Thu, 17 May 2018 21:25:56 -0400 Subject: [PATCH 1/3] MIgrated to .NETStandard2.0 with Multiple Target Frameworks (3.5,4.5) for Backwards compatibility --- .gitattributes | 79 +++-- .gitignore | 291 ++++++++++++------ LINQtoCSV.sln | 17 +- LINQtoCSV/CsvContext.cs | 124 ++++++-- LINQtoCSV/CsvStream.cs | 86 +++++- LINQtoCSV/LINQtoCSV.NetClassic.csproj | 114 +++++++ LINQtoCSV/LINQtoCSV.csproj | 154 ++++----- LINQtoCSV/LINQtoCSV.nuspec | 21 -- LINQtoCSV/Properties/AssemblyInfo.cs | 36 --- .../TestFiles/output_anon.csv | 6 +- .../TestFiles/output_bad.csv | 2 +- .../TestFiles/output_newdata_names_nl.csv | Bin 652 -> 652 bytes 12 files changed, 627 insertions(+), 303 deletions(-) create mode 100644 LINQtoCSV/LINQtoCSV.NetClassic.csproj delete mode 100644 LINQtoCSV/LINQtoCSV.nuspec delete mode 100644 LINQtoCSV/Properties/AssemblyInfo.cs diff --git a/.gitattributes b/.gitattributes index 412eeda..1ff0c42 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,22 +1,63 @@ -# Auto detect text files and perform LF normalization +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### * text=auto -# Custom for Visual Studio -*.cs diff=csharp -*.sln merge=union -*.csproj merge=union -*.vbproj merge=union -*.fsproj merge=union -*.dbproj merge=union +############################################################################### +# Set default behavior for command prompt diff. +# +# This is need for earlier builds of msysgit that does not have it on by +# default for csharp files. +# Note: This is only used by command line +############################################################################### +#*.cs diff=csharp -# Standard to msysgit -*.doc diff=astextplain -*.DOC diff=astextplain -*.docx diff=astextplain -*.DOCX diff=astextplain -*.dot diff=astextplain -*.DOT diff=astextplain -*.pdf diff=astextplain -*.PDF diff=astextplain -*.rtf diff=astextplain -*.RTF diff=astextplain +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. To do so, just uncomment the entries below +############################################################################### +#*.sln merge=binary +#*.csproj merge=binary +#*.vbproj merge=binary +#*.vcxproj merge=binary +#*.vcproj merge=binary +#*.dbproj merge=binary +#*.fsproj merge=binary +#*.lsproj merge=binary +#*.wixproj merge=binary +#*.modelproj merge=binary +#*.sqlproj merge=binary +#*.wwaproj merge=binary + +############################################################################### +# behavior for image files +# +# image files are treated as binary by default. +############################################################################### +#*.jpg binary +#*.png binary +#*.gif binary + +############################################################################### +# diff behavior for common document formats +# +# Convert binary document formats to text before diffing them. This feature +# is only available from the command line. Turn it on by uncommenting the +# entries below. +############################################################################### +#*.doc diff=astextplain +#*.DOC diff=astextplain +#*.docx diff=astextplain +#*.DOCX diff=astextplain +#*.dot diff=astextplain +#*.DOT diff=astextplain +#*.pdf diff=astextplain +#*.PDF diff=astextplain +#*.rtf diff=astextplain +#*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore index b9d6bd9..40138ac 100644 --- a/.gitignore +++ b/.gitignore @@ -1,61 +1,66 @@ -################# -## Eclipse -################# - -*.pydevproject -.project -.metadata -bin/ -tmp/ -*.tmp -*.bak -*.swp -*~.nib -local.properties -.classpath -.settings/ -.loadpath - -# External tool builders -.externalToolBuilders/ - -# Locally stored "Eclipse launch configurations" -*.launch - -# CDT-specific -.cproject - -# PDT-specific -.buildpath - - -################# -## Visual Studio -################# - ## Ignore Visual Studio temporary files, build results, and ## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore # User-specific files *.suo *.user +*.userosscache *.sln.docstates -# Build results +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs +# Build results [Dd]ebug/ +[Dd]ebugPublic/ [Rr]elease/ +[Rr]eleases/ x64/ -build/ +x86/ +bld/ [Bb]in/ [Oo]bj/ +[Ll]og/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ # MSTest test Results [Tt]est[Rr]esult*/ [Bb]uild[Ll]og.* +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ +**/Properties/launchSettings.json + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio *_i.c *_p.c +*_i.h *.ilk *.meta *.obj @@ -75,21 +80,34 @@ build/ *.vssscc .builds *.pidb -*.log +*.svclog *.scc +# Chutzpah Test files +_Chutzpah* + # Visual C++ cache files ipch/ *.aps *.ncb +*.opendb *.opensdf *.sdf *.cachefile +*.VC.db +*.VC.VC.opendb # Visual Studio profiler *.psess *.vsp *.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ # Guidance Automation Toolkit *.gpState @@ -97,6 +115,10 @@ ipch/ # ReSharper is a .NET coding add-in _ReSharper*/ *.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode # TeamCity is a build add-in _TeamCity* @@ -104,9 +126,25 @@ _TeamCity* # DotCover is a Code Coverage Tool *.dotCover +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Visual Studio code coverage results +*.coverage +*.coveragexml + # NCrunch -*.ncrunch* +_NCrunch_* .*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ # Installshield output folder [Ee]xpress/ @@ -125,91 +163,160 @@ DocProject/Help/html publish/ # Publish Web Output -*.Publish.xml +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted *.pubxml - -# NuGet Packages Directory -## TODO: If you have NuGet Package Restore enabled, uncomment the next line -#packages/ - -# Windows Azure Build Output -csx +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ *.build.csdef -# Windows Store app package directory +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ # Others -sql/ -*.Cache ClientBin/ -[Ss]tyle[Cc]op.* ~$* *~ *.dbmdl -*.[Pp]ublish.xml +*.dbproj.schemaview +*.jfm *.pfx *.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ # RIA/Silverlight projects Generated_Code/ -# Backup & report files from converting an old project file to a newer -# Visual Studio version. Backup files are not needed, because we have git ;-) +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) _UpgradeReport_Files/ Backup*/ UpgradeLog*.XML UpgradeLog*.htm # SQL Server files -App_Data/*.mdf -App_Data/*.ldf +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# TypeScript v1 declaration files +typings/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw -############# -## Windows detritus -############# +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions -# Windows image file caches -Thumbs.db -ehthumbs.db +# Paket dependency manager +.paket/paket.exe +paket-files/ -# Folder config file -Desktop.ini +# FAKE - F# Make +.fake/ -# Recycle Bin used on file shares -$RECYCLE.BIN/ +# JetBrains Rider +.idea/ +*.sln.iml -# Mac crap -.DS_Store +# CodeRush +.cr/ +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc -############# -## Python -############# +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config -*.py[co] +# Tabs Studio +*.tss -# Packages -*.egg -*.egg-info -dist/ -build/ -eggs/ -parts/ -var/ -sdist/ -develop-eggs/ -.installed.cfg +# Telerik's JustMock configuration file +*.jmconfig -# Installer logs -pip-log.txt +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs -# Unit test / coverage reports -.coverage -.tox +# OpenCover UI analysis results +OpenCover/ -#Translations -*.mo +# Azure Stream Analytics local run output +ASALocalRun/ -#Mr Developer -.mr.developer.cfg +# MSBuild Binary and Structured Log +*.binlog \ No newline at end of file diff --git a/LINQtoCSV.sln b/LINQtoCSV.sln index 62bbb72..046d111 100644 --- a/LINQtoCSV.sln +++ b/LINQtoCSV.sln @@ -1,9 +1,11 @@  -Microsoft Visual Studio Solution File, Format Version 11.00 -# Visual Studio 2010 +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.27703.2000 +MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestConsoleApplication", "TestConsoleApplication\TestConsoleApplication.csproj", "{C3FE8ACB-688B-47E4-9E62-0EE09B0435E1}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINQtoCSV", "LINQtoCSV\LINQtoCSV.csproj", "{07058BF9-6F86-40FF-AE33-2A4F89B5758A}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINQtoCSV", "LINQtoCSV\LINQtoCSV.csproj", "{07058BF9-6F86-40FF-AE33-2A4F89B5758A}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleCode", "SampleCode\SampleCode.csproj", "{EEFD875B-5D48-41F4-80FD-5FAE3725ED83}" EndProject @@ -17,9 +19,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution EndProjectSection EndProject Global - GlobalSection(TestCaseManagementSettings) = postSolution - CategoryFile = LINQtoCSV.vsmdi - EndGlobalSection GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU @@ -45,4 +44,10 @@ Global GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {5AEDF037-153D-47BE-A9F9-705810C789A1} + EndGlobalSection + GlobalSection(TestCaseManagementSettings) = postSolution + CategoryFile = LINQtoCSV.vsmdi + EndGlobalSection EndGlobal diff --git a/LINQtoCSV/CsvContext.cs b/LINQtoCSV/CsvContext.cs index 62d799c..a3f7cf2 100644 --- a/LINQtoCSV/CsvContext.cs +++ b/LINQtoCSV/CsvContext.cs @@ -2,6 +2,10 @@ using System.Collections.Generic; using System.IO; +#if NETSTANDARD +using System.Threading.Tasks; +#endif + namespace LINQtoCSV { @@ -33,12 +37,42 @@ public class CsvContext /// /// Values read from the stream or file. /// - public IEnumerable Read(string fileName, CsvFileDescription fileDescription) where T : class, new() +#if NETSTANDARD + public IEnumerable Read(string fileName, CsvFileDescription fileDescription) where T : class, new() + { // Note that ReadData will not be called right away, but when the returned // IEnumerable actually gets accessed. + IEnumerable ie = ReadData (fileName, null, fileDescription); + + return ie; + } + + public IEnumerable ReadData (StreamReader stream) where T : class, new() + { + return Read (stream, new CsvFileDescription()); + } + + public IEnumerable Read (string fileName) where T : class, new() + { + return Read(fileName, new CsvFileDescription()); + } + + public IEnumerable Read (StreamReader stream, CsvFileDescription fileDescription) where T : class, new() + { + return ReadData (null, stream, fileDescription); + } +#else + + public IEnumerable Read(string fileName, CsvFileDescription fileDescription) where T : class, new() + + { + // Note that ReadData will not be called right away, but when the returned + // IEnumerable actually gets accessed. + IEnumerable ie = ReadData(fileName, null, fileDescription); + return ie; } @@ -56,7 +90,7 @@ public class CsvContext { return ReadData(null, stream, fileDescription); } - +#endif /// /////////////////////////////////////////////////////////////////////// /// ReadData /// @@ -78,9 +112,11 @@ public class CsvContext /// /// /// + private IEnumerable ReadData( - string fileName, - StreamReader stream, + + string fileName, + StreamReader stream, CsvFileDescription fileDescription) where T : class, new() { // If T implements IDataRow, then we're reading raw data rows @@ -110,7 +146,7 @@ private IEnumerable ReadData( if (readingFile) { stream = new StreamReader( - fileName, + fileName, fileDescription.TextEncoding, fileDescription.DetectEncodingFromByteOrderMarks); } @@ -129,7 +165,7 @@ private IEnumerable ReadData( // ---------- CsvStream cs = new CsvStream(stream, null, fileDescription.SeparatorChar, fileDescription.IgnoreTrailingSeparatorChar); - + // If we're reading raw data rows, instantiate a T so we return objects // of the type specified by the caller. // Otherwise, instantiate a DataRow, which also implements IDataRow. @@ -155,14 +191,18 @@ private IEnumerable ReadData( } bool firstRow = true; +#if NETSTANDARD + while ( cs.ReadRowAsync(row, charLengths).Result) +#else while (cs.ReadRow(row, charLengths)) +#endif { // Skip empty lines. // Important. If there is a newline at the end of the last data line, the code // thinks there is an empty line after that last data line. - if ((row.Count == 1) && + if ((row.Count == 1) && ((row[0].Value == null) || - (string.IsNullOrEmpty(row[0].Value.Trim())) )) + (string.IsNullOrEmpty(row[0].Value.Trim())))) { continue; } @@ -222,47 +262,85 @@ private IEnumerable ReadData( /// /////////////////////////////////////////////////////////////////////// /// Write /// +#if NETSTANDARD + public async Task WriteAsync( +#else public void Write( - IEnumerable values, - string fileName, - CsvFileDescription fileDescription) +#endif + IEnumerable values, + string fileName, + CsvFileDescription fileDescription) { using (StreamWriter sw = new StreamWriter( fileName, false, fileDescription.TextEncoding)) { +#if NETSTANDARD + await WriteDataAsync(values, fileName, sw, fileDescription); +#else WriteData(values, fileName, sw, fileDescription); +#endif } } - +#if NETSTANDARD + public async Task WriteAsync( +#else public void Write( +#endif IEnumerable values, - TextWriter stream) + TextWriter stream) { +#if NETSTANDARD + await WriteAsync(values, stream, new CsvFileDescription()); +#else Write(values, stream, new CsvFileDescription()); +#endif } + +#if NETSTANDARD + public async Task WriteAsync( +#else public void Write( - IEnumerable values, - string fileName) +#endif + IEnumerable values, + string fileName) { +#if NETSTANDARD + await WriteAsync(values, fileName, new CsvFileDescription()); +#else Write(values, fileName, new CsvFileDescription()); +#endif } - public void Write( + +#if NETSTANDARD + public async Task WriteAsync( +#else + public void Write( +#endif IEnumerable values, TextWriter stream, - CsvFileDescription fileDescription) + CsvFileDescription fileDescription) { +#if NETSTANDARD + await WriteDataAsync(values, null, stream, fileDescription); +#else WriteData(values, null, stream, fileDescription); +#endif } + +#if NETSTANDARD + private async Task WriteDataAsync( +#else private void WriteData( +#endif IEnumerable values, string fileName, - TextWriter stream, - CsvFileDescription fileDescription) + TextWriter stream, + CsvFileDescription fileDescription) { FieldMapper fm = new FieldMapper(fileDescription, fileName, true); CsvStream cs = new CsvStream(null, stream, fileDescription.SeparatorChar, fileDescription.IgnoreTrailingSeparatorChar); @@ -273,7 +351,11 @@ private void WriteData( if (fileDescription.FirstLineHasColumnNames) { fm.WriteNames(row); +#if NETSTANDARD + await cs.WriteRowAsync(row, fileDescription.QuoteAllFields); +#else cs.WriteRow(row, fileDescription.QuoteAllFields); +#endif } // ----- @@ -282,7 +364,11 @@ private void WriteData( { // Convert obj to row fm.WriteObject(obj, row); +#if NETSTANDARD + await cs.WriteRowAsync(row, fileDescription.QuoteAllFields); +#else cs.WriteRow(row, fileDescription.QuoteAllFields); +#endif } } diff --git a/LINQtoCSV/CsvStream.cs b/LINQtoCSV/CsvStream.cs index 9473893..b5e9408 100644 --- a/LINQtoCSV/CsvStream.cs +++ b/LINQtoCSV/CsvStream.cs @@ -3,6 +3,9 @@ using System.IO; using System.Linq; using System.Text; +#if NETSTANDARD +using System.Threading.Tasks; +#endif namespace LINQtoCSV { @@ -39,12 +42,23 @@ public CsvStream(TextReader inStream, TextWriter outStream, char SeparatorChar, /// /////////////////////////////////////////////////////////////////////// /// WriteRow /// +#if NETSTANDARD + public async Task WriteRowAsync(List row, bool quoteAllFields) +#else public void WriteRow(List row, bool quoteAllFields) +#endif { bool firstItem = true; foreach (string item in row) { - if (!firstItem) { m_outStream.Write(m_SeparatorChar); } + if (!firstItem) + { +#if NETSTANDARD + await m_outStream.WriteAsync(m_SeparatorChar); +#else + m_outStream.Write(m_SeparatorChar); +#endif + } // If the item is null, don't write anything. if (item != null) @@ -57,11 +71,19 @@ public void WriteRow(List row, bool quoteAllFields) (item.IndexOfAny(m_SpecialChars) > -1) || (item.Trim() == ""))) { +#if NETSTANDARD + await m_outStream.WriteAsync("\"" + item.Replace("\"", "\"\"") + "\""); +#else m_outStream.Write("\"" + item.Replace("\"", "\"\"") + "\""); +#endif } else { +#if NETSTANDARD + await m_outStream.WriteAsync(item); +#else m_outStream.Write(item); +#endif } } @@ -86,7 +108,11 @@ public void WriteRow(List row, bool quoteAllFields) /// True if a row was returned in parameter "row". /// False if no row returned. In that case, you're at the end of the file. /// +#if NETSTANDARD + public async Task ReadRowAsync(IDataRow row, List charactersLength = null) +#else public bool ReadRow(IDataRow row, List charactersLength = null) +#endif { row.Clear(); @@ -114,7 +140,11 @@ public bool ReadRow(IDataRow row, List charactersLength = null) if (!EOL) { +#if NETSTANDARD + await AdvanceToEndOfLineAsync(); +#else AdvanceToEndOfLine(); +#endif moreAvailable = false; } } @@ -135,12 +165,19 @@ public bool ReadRow(IDataRow row, List charactersLength = null) private bool EOL = false; private bool previousWasCr = false; +#if NETSTANDARD + private async Task AdvanceToEndOfLineAsync() +#else private void AdvanceToEndOfLine() +#endif { while (true) { +#if NETSTANDARD + char c = await GetNextCharAsync(true); +#else char c = GetNextChar(true); - +#endif if (EOS) break; @@ -151,11 +188,20 @@ private void AdvanceToEndOfLine() // we are at the end of the line, eat newline characters and exit EOL = true; +#if NETSTANDARD + if (c == '\x0D' && (await GetNextCharAsync(false)) == '\x0A') + { + // new line sequence is 0D0A + await GetNextCharAsync(true); + } +#else if (c == '\x0D' && GetNextChar(false) == '\x0A') { // new line sequence is 0D0A GetNextChar(true); } + +#endif EOL = false; break; @@ -164,6 +210,7 @@ private void AdvanceToEndOfLine() } private bool GetNextItem(ref string itemString, int? itemLength = null) + { itemString = null; if (EOL) @@ -188,8 +235,11 @@ private bool GetNextItem(ref string itemString, int? itemLength = null) return true; } - +#if NETSTANDARD + char c = GetNextCharAsync(true).Result; +#else char c = GetNextChar(true); +#endif cnt++; if (EOS) @@ -225,7 +275,11 @@ private bool GetNextItem(ref string itemString, int? itemLength = null) { if (m_IgnoreTrailingSeparatorChar) { +#if NETSTANDARD + char nC = GetNextCharAsync(false).Result; +#else char nC = GetNextChar(false); +#endif if ((nC == '\x0A' || nC == '\x0D')) continue; } @@ -238,12 +292,19 @@ private bool GetNextItem(ref string itemString, int? itemLength = null) { // we are at the end of the line, eat newline characters and exit EOL = true; +#if NETSTANDARD + if (c == '\x0D' && ( GetNextCharAsync(false).Result) == '\x0A') + { + // new line sequence is 0D0A + GetNextCharAsync(true).Wait(); + } +#else if (c == '\x0D' && GetNextChar(false) == '\x0A') { // new line sequence is 0D0A GetNextChar(true); } - +#endif if (itemFound) { itemString = item.ToString(); } return true; } @@ -272,11 +333,19 @@ private bool GetNextItem(ref string itemString, int? itemLength = null) if (c == '"' && quoted) { +#if NETSTANDARD + if ( GetNextCharAsync(false).Result == '"') + { + // double quotes within quoted string means add a quote + item.Append(GetNextCharAsync(true).Result); + } +#else if (GetNextChar(false) == '"') { // double quotes within quoted string means add a quote item.Append(GetNextChar(true)); } +#endif else { // end-quote reached @@ -295,11 +364,20 @@ private bool GetNextItem(ref string itemString, int? itemLength = null) private int pos = 0; private int length = 0; +#if NETSTANDARD + private async Task GetNextCharAsync(bool eat) +#else private char GetNextChar(bool eat) +#endif + { if (pos >= length) { +#if NETSTANDARD + length = await m_instream.ReadBlockAsync(buffer, 0, buffer.Length); +#else length = m_instream.ReadBlock(buffer, 0, buffer.Length); +#endif if (length == 0) { EOS = true; diff --git a/LINQtoCSV/LINQtoCSV.NetClassic.csproj b/LINQtoCSV/LINQtoCSV.NetClassic.csproj new file mode 100644 index 0000000..1a982fd --- /dev/null +++ b/LINQtoCSV/LINQtoCSV.NetClassic.csproj @@ -0,0 +1,114 @@ + + + + Debug + AnyCPU + 9.0.30729 + 2.0 + {77D87344-7D31-4234-A103-AF3EA7CC5634} + Library + Properties + LINQtoCSV + LINQtoCSV + v3.5 + 512 + + + + + 3.5 + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true + + + + + + + + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + AllRules.ruleset + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + AllRules.ruleset + + + + + 3.5 + + + 3.5 + + + 3.5 + + + + + + + + + + + + + + + + + + + False + .NET Framework 3.5 SP1 Client Profile + false + + + False + .NET Framework 3.5 SP1 + true + + + False + Windows Installer 3.1 + true + + + + + \ No newline at end of file diff --git a/LINQtoCSV/LINQtoCSV.csproj b/LINQtoCSV/LINQtoCSV.csproj index 17323b9..e421432 100644 --- a/LINQtoCSV/LINQtoCSV.csproj +++ b/LINQtoCSV/LINQtoCSV.csproj @@ -1,114 +1,64 @@ - - + - Debug - AnyCPU - 9.0.30729 - 2.0 - {07058BF9-6F86-40FF-AE33-2A4F89B5758A} - Library - Properties - LINQtoCSV - LINQtoCSV - v3.5 - 512 - - - - - 3.5 - publish\ - true - Disk - false - Foreground - 7 - Days - false - false - true - 0 - 1.0.0.%2a - false - false - true - - - - - - - - + netstandard2.0;net35;net45 + http://www.codeproject.com/Articles/25133/LINQ-to-CSV-library</ + http://nuget.org/Media/Default/Packages/LinqToCsv/1.0.0.0/logo.jpg + Popular, easy to use library to read and write CSV and tab delimited files. Supports data fields containing commas and line breaks. Supports different character encodings, separator characters and date and number formats. Robust error handling lets you quickly fix problems in large input files. + CSV LINQ tab delimited + Copyright 2014 + Matt Perdeck + 2.0.0.0 + 2.0.0.0 + true + 2.0.0 + - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - AllRules.ruleset + + + NETCORE;NETSTANDARD;NETSTANDARD2_0 - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - AllRules.ruleset - - + + + + + + + + - - 3.5 - - - 3.5 - - - 3.5 - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - + + - - False - .NET Framework 3.5 SP1 Client Profile - false - - - False - .NET Framework 3.5 SP1 - true - - - False - Windows Installer 3.1 - true - + - - + + NET35 + + + NET45;NETFULL + \ No newline at end of file diff --git a/LINQtoCSV/LINQtoCSV.nuspec b/LINQtoCSV/LINQtoCSV.nuspec deleted file mode 100644 index 0d70c1a..0000000 --- a/LINQtoCSV/LINQtoCSV.nuspec +++ /dev/null @@ -1,21 +0,0 @@ - - - - $id$ - $version$ - $title$ - $author$ - $author$ - http://www.codeproject.com/Articles/25133/LINQ-to-CSV-library - http://nuget.org/Media/Default/Packages/LinqToCsv/1.0.0.0/logo.jpg - false - - Serialise/Deserialize your classes to/from CSV and tab delimited files. Very flexible. Supports international date and number formats. - - $description$ - Copyright 2014 - CSV LINQ tab delimited - - - - \ No newline at end of file diff --git a/LINQtoCSV/Properties/AssemblyInfo.cs b/LINQtoCSV/Properties/AssemblyInfo.cs deleted file mode 100644 index 0605278..0000000 --- a/LINQtoCSV/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("LINQtoCSV")] -[assembly: AssemblyDescription("Popular, easy to use library to read and write CSV and tab delimited files. Supports data fields containing commas and line breaks. Supports different character encodings, separator characters and date and number formats. Robust error handling lets you quickly fix problems in large input files.")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Matt Perdeck")] -[assembly: AssemblyProduct("LINQtoCSV")] -[assembly: AssemblyCopyright("Copyright © 2014")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("734dd618-3346-49b5-879d-25c2a4cccd63")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.5.0.0")] -[assembly: AssemblyFileVersion("1.5.0.0")] diff --git a/TestConsoleApplication/TestFiles/output_anon.csv b/TestConsoleApplication/TestFiles/output_anon.csv index f22ff9c..4f91285 100644 --- a/TestConsoleApplication/TestFiles/output_anon.csv +++ b/TestConsoleApplication/TestFiles/output_anon.csv @@ -1,4 +1,4 @@ Markup,InShops,ProductName -39150.0,2/01/1985 12:00:00 AM,mouse trap -270.060,23/05/2008 12:00:00 AM,moonbuggy -6004.0,29/02/2004 12:00:00 AM,dog house +39150.0,1/2/1985 12:00:00 AM,mouse trap +270.060,5/23/2008 12:00:00 AM,moonbuggy +6004.0,2/29/2004 12:00:00 AM,dog house diff --git a/TestConsoleApplication/TestFiles/output_bad.csv b/TestConsoleApplication/TestFiles/output_bad.csv index 46b134b..5f28270 100644 --- a/TestConsoleApplication/TestFiles/output_bad.csv +++ b/TestConsoleApplication/TestFiles/output_bad.csv @@ -1 +1 @@ -ÿþ \ No newline at end of file + \ No newline at end of file diff --git a/TestConsoleApplication/TestFiles/output_newdata_names_nl.csv b/TestConsoleApplication/TestFiles/output_newdata_names_nl.csv index 35c7ee071d269c242e2f3f49cfcaf62619a0e2fd..4e3830ec4a6d06bdb02249d34f39c07477c7f236 100644 GIT binary patch delta 32 ncmeBS?O~npg4KvYm%(u3TX{xqLk2?z1%_OPREEsS;!LFgjim?I delta 32 ncmeBS?O~npg4K{gm%(V`TX{xq0|rwD1%^C^e1@{g;!LFgj#dZq From 2115b8d452f5481a8c37a2ab42201436783786cc Mon Sep 17 00:00:00 2001 From: Darren McDaniel Date: Thu, 17 May 2018 21:30:28 -0400 Subject: [PATCH 2/3] Remove unnecessary conditional compile --- LINQtoCSV/CsvContext.cs | 30 ++---------------------------- 1 file changed, 2 insertions(+), 28 deletions(-) diff --git a/LINQtoCSV/CsvContext.cs b/LINQtoCSV/CsvContext.cs index a3f7cf2..be05810 100644 --- a/LINQtoCSV/CsvContext.cs +++ b/LINQtoCSV/CsvContext.cs @@ -37,33 +37,7 @@ public class CsvContext /// /// Values read from the stream or file. /// -#if NETSTANDARD - public IEnumerable Read(string fileName, CsvFileDescription fileDescription) where T : class, new() - - { - // Note that ReadData will not be called right away, but when the returned - // IEnumerable actually gets accessed. - - IEnumerable ie = ReadData (fileName, null, fileDescription); - - return ie; - } - - public IEnumerable ReadData (StreamReader stream) where T : class, new() - { - return Read (stream, new CsvFileDescription()); - } - - public IEnumerable Read (string fileName) where T : class, new() - { - return Read(fileName, new CsvFileDescription()); - } - - public IEnumerable Read (StreamReader stream, CsvFileDescription fileDescription) where T : class, new() - { - return ReadData (null, stream, fileDescription); - } -#else + public IEnumerable Read(string fileName, CsvFileDescription fileDescription) where T : class, new() @@ -90,7 +64,7 @@ public class CsvContext { return ReadData(null, stream, fileDescription); } -#endif + /// /////////////////////////////////////////////////////////////////////// /// ReadData /// From c927f5f476ea279255fd93e073464e58e56f8b5a Mon Sep 17 00:00:00 2001 From: Darren McDaniel Date: Thu, 17 May 2018 21:32:50 -0400 Subject: [PATCH 3/3] Removed old project file --- LINQtoCSV/LINQtoCSV.NetClassic.csproj | 114 -------------------------- 1 file changed, 114 deletions(-) delete mode 100644 LINQtoCSV/LINQtoCSV.NetClassic.csproj diff --git a/LINQtoCSV/LINQtoCSV.NetClassic.csproj b/LINQtoCSV/LINQtoCSV.NetClassic.csproj deleted file mode 100644 index 1a982fd..0000000 --- a/LINQtoCSV/LINQtoCSV.NetClassic.csproj +++ /dev/null @@ -1,114 +0,0 @@ - - - - Debug - AnyCPU - 9.0.30729 - 2.0 - {77D87344-7D31-4234-A103-AF3EA7CC5634} - Library - Properties - LINQtoCSV - LINQtoCSV - v3.5 - 512 - - - - - 3.5 - publish\ - true - Disk - false - Foreground - 7 - Days - false - false - true - 0 - 1.0.0.%2a - false - false - true - - - - - - - - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - AllRules.ruleset - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - AllRules.ruleset - - - - - 3.5 - - - 3.5 - - - 3.5 - - - - - - - - - - - - - - - - - - - False - .NET Framework 3.5 SP1 Client Profile - false - - - False - .NET Framework 3.5 SP1 - true - - - False - Windows Installer 3.1 - true - - - - - \ No newline at end of file