Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing Delimiter Documentation #1653

Closed
corykroll opened this issue Jan 19, 2021 · 12 comments
Closed

Changing Delimiter Documentation #1653

corykroll opened this issue Jan 19, 2021 · 12 comments

Comments

@corykroll
Copy link

I'm unable to find an example of how to change the delimiter when reading a file.
The following code no longer works since 20.0.0 since the Delimiter parameter is read-only:

csvReader.Configuration.Delimiter = "|";

If you look around the internet (Stack Overflow, etc.) this is always the way that it seems to be done. I can't seem to find an example or pattern on how to now accomplish this.

@JoshClose
Copy link
Owner

Configuration is read only now. You can pass an instance into the constructor of the reader. The documentation examples are updated. https://joshclose.github.io/CsvHelper/getting-started

@madhon
Copy link

madhon commented Jan 19, 2021

The documentation doesn't really say, for example the following wont compile.

Dim config = New CsvConfiguration(CultureInfo.InvariantCulture) With {.Delimiter = fieldDelim}

results in the following errors

'Delimiter' has a return type that is not supported or parameter types that are not supported.
Property 'Delimiter' is 'ReadOnly'.

@EricZimmerman
Copy link

you have to do it like this:

 var config = new CsvConfiguration(CultureInfo.InvariantCulture)
  {
      Delimiter = "|",
  };
  
  _bodyWriter = new CsvWriter(swBody,config);

and yea, i agree. update the documentation before stuff breaks =)

@JoshClose
Copy link
Owner

@madhon I'm looking into how C#'s record and init works in VB.NET. Since everything compiles down, I figured it would just work. It would be strange if it didn't.

@JoshClose
Copy link
Owner

@madhon I created a constructor that takes in every parameter but they're all optional named (except culture). Can you give this a try and see if this fixes things for you?

https://www.nuget.org/packages/CsvHelper/21.0.5-beta0001

@madhon
Copy link

madhon commented Jan 20, 2021

@madhon I created a constructor that takes in every parameter but they're all optional named (except culture). Can you give this a try and see if this fixes things for you?

https://www.nuget.org/packages/CsvHelper/21.0.5-beta0001

That works ok for me

@JoshClose
Copy link
Owner

@madhon The fix is in 21.0.5 on NuGet. https://www.nuget.org/packages/CsvHelper/21.0.5

@JoshClose
Copy link
Owner

@corykroll @EricZimmerman Are the updated docs sufficient?

@EricZimmerman
Copy link

seems good to me. i think the confusion was having to init everything via the constructor, vs setting properties after.

@JoshClose
Copy link
Owner

Great. It was made immutable to solve mutli treading issues.

@corykroll
Copy link
Author

@JoshClose That worked for me! Thank you for the updated info, I really appreciate it. Sorry for the delay in response, got sidetracked there for a bit.

@fernandoweiler
Copy link

you have to do it like this:

 var config = new CsvConfiguration(CultureInfo.InvariantCulture)
  {
      Delimiter = "|",
  };
  
  _bodyWriter = new CsvWriter(swBody,config);

and yea, i agree. update the documentation before stuff breaks =)

This worked 100% for me. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants