From 2a1cd4fda8a4a8e649910d16b4dfa1ce7ae63543 Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Fri, 12 May 2023 09:24:40 +0800 Subject: *misc --- .../docs/examples/prerequisites/index.html | 454 +++++++++++++++++++ .../reading-and-writing-files/index.html | 480 +++++++++++++++++++++ .../docs/examples/prerequisites/streams/index.html | 453 +++++++++++++++++++ .../prerequisites/using-and-dispose/index.html | 444 +++++++++++++++++++ 4 files changed, 1831 insertions(+) create mode 100644 ThirdParty/CsvHelper-master/docs/examples/prerequisites/index.html create mode 100644 ThirdParty/CsvHelper-master/docs/examples/prerequisites/reading-and-writing-files/index.html create mode 100644 ThirdParty/CsvHelper-master/docs/examples/prerequisites/streams/index.html create mode 100644 ThirdParty/CsvHelper-master/docs/examples/prerequisites/using-and-dispose/index.html (limited to 'ThirdParty/CsvHelper-master/docs/examples/prerequisites') diff --git a/ThirdParty/CsvHelper-master/docs/examples/prerequisites/index.html b/ThirdParty/CsvHelper-master/docs/examples/prerequisites/index.html new file mode 100644 index 0000000..3e6af69 --- /dev/null +++ b/ThirdParty/CsvHelper-master/docs/examples/prerequisites/index.html @@ -0,0 +1,454 @@ + + + + + + + + + + + + + + + + + + + + + + + Prerequisites | CsvHelper + + + + + + + + + + + + + + + + +
+
+
+ + + +
+
+
+

Prerequisites

+

Here are some prerequisites that are needed for using CsvHelper. These are .NET basics that are implied knowledge when using CsvHelper. Microsoft has excellent documentation that can you can use to learn more.

+ + + + + + + + + + + + + + + + + + + + + +
Topics 
Using and Dispose
Reading and Writing Files
Streams
+ +
+
+
+
+ +

+ + + + + + + + + + + diff --git a/ThirdParty/CsvHelper-master/docs/examples/prerequisites/reading-and-writing-files/index.html b/ThirdParty/CsvHelper-master/docs/examples/prerequisites/reading-and-writing-files/index.html new file mode 100644 index 0000000..72fa8a0 --- /dev/null +++ b/ThirdParty/CsvHelper-master/docs/examples/prerequisites/reading-and-writing-files/index.html @@ -0,0 +1,480 @@ + + + + + + + + + + + + + + + + + + + + + + + Reading And Writing Files | CsvHelper + + + + + + + + + + + + + + + + +
+
+
+ + + +
+
+
+

Reading and Writing Files

+

To open a file for reading or writing, we can use System.IO.File.

+
using (var stream = File.OpenRead("path\\to\\file.csv"))
+{
+}
+
+using (var stream = File.OpenWrite("path\\to\\file.csv"))
+{	
+}
+
+

These both return a FileStream for working with our file. Since our data is text, we will need to use a StreamReader and StreamWriter to read and write the text.

+
using (var stream = File.OpenRead("path\\to\\file.csv"))
+using (var reader = new StreamReader(stream))
+{
+}
+
+using (var stream = File.OpenWrite("path\\to\\file.csv"))
+using (var writer = new StreamWriter(stream))
+{	
+}
+
+

StreamReader and StreamWriter have shortcuts for doing this.

+
using (var reader = new StreamReader("path\\to\\file.csv"))
+{
+}
+
+using (var writer = new StreamWriter("path\\to\\file.csv"))
+{	
+}
+
+

CsvHelper doesn't know anything about your encoding, so if you have a specific encoding, you'll need to specify that in your stream.

+
using (var reader = new StreamReader("path\\to\\file.csv", Encoding.UTF8))
+{
+}
+
+using (var writer = new StreamWriter("path\\to\\file.csv", Encoding.UTF8))
+{	
+}
+
+

CsvReader and CsvWriter take a TextReader and TextWriter in their constructors. TextReader and TextWriter are abstract classes for reading and writing text. StreamReader inherits TextReader and StreamWriter inherits TextWriter, so we can use those with CsvReader and CsvWriter.

+
using (var reader = new StreamReader("path\\to\\file.csv"))
+using (var csv = new CsvReader(reader))
+{
+}
+
+using (var writer = new StreamWriter("path\\to\\file.csv"))
+using (var csv = new CsvWriter(writer))
+{	
+}
+
+ +
+
+
+
+ +

+ + + + + + + + + + + diff --git a/ThirdParty/CsvHelper-master/docs/examples/prerequisites/streams/index.html b/ThirdParty/CsvHelper-master/docs/examples/prerequisites/streams/index.html new file mode 100644 index 0000000..4168219 --- /dev/null +++ b/ThirdParty/CsvHelper-master/docs/examples/prerequisites/streams/index.html @@ -0,0 +1,453 @@ + + + + + + + + + + + + + + + + + + + + + + + Streams | CsvHelper + + + + + + + + + + + + + + + + +
+
+
+ + + +
+
+
+

Streams

+

When reading from a stream, if you need to go back to the beginning of the stream, you can use the Stream.Position property.

+
using (var stream = new File.OpenRead("path\\to\\file"))
+using (var reader = new StreamReader(stream))
+{	
+	// Read file content.
+	var content = reader.ReadToEnd();
+
+	// Go back to beginning of the stream.
+	stream.Position = 0;
+
+	// Read file content again.
+	content = reader.ReadToEnd();
+}
+
+

When writing to a file, you need to flush the writer for the data to be written to the stream. StreamWriter contains an internal buffer and the data is only written to the stream when the buffer is full, or Flush is called. Flush is automatically called when a using block exits.

+
using (var stream = new File.OpenWrite("path\\to\\file"))
+using (var writer = new StreamWriter(stream))
+{	
+	writer.WriteLine("Foo");
+	writer.Flush(); // Data is written from the writer buffer to the stream.
+} // Flush is also called here.
+
+ +
+
+
+
+ +

+ + + + + + + + + + + diff --git a/ThirdParty/CsvHelper-master/docs/examples/prerequisites/using-and-dispose/index.html b/ThirdParty/CsvHelper-master/docs/examples/prerequisites/using-and-dispose/index.html new file mode 100644 index 0000000..1b06644 --- /dev/null +++ b/ThirdParty/CsvHelper-master/docs/examples/prerequisites/using-and-dispose/index.html @@ -0,0 +1,444 @@ + + + + + + + + + + + + + + + + + + + + + + + Using And Dispose | CsvHelper + + + + + + + + + + + + + + + + +
+
+
+ + + +
+
+
+

Using and Dispose

+

Whenever you have an object the implements IDisposable, you need to dispose of the resource when you're done with it. Most classes that use unmanaged resources will implement IDisposable. This means a lot of classes in the System.IO namespace will need to be disposed of.

+

The best practice to dispose of an object when you're done with it is to wrap the code in a using block. When the using block exits, the resource will automatically be disposed of as soon as possible.

+
using (var stream = new MemoryStream())
+{
+	// Use the stream.
+}
+// The stream will be disposed of as soon as possible.
+
+

If you need to keep keep it around for a while and dispose of it later, using does some error handling for you, so it's still a good idea to use it instead of calling Dispose directly. There is some debate on whether this is a good idea because it doesn't show intent.

+
var stream = new MemoryStream();
+// Later in a different part of your code.
+using (stream) { }
+
+ +
+
+
+
+ +

+ + + + + + + + + + + -- cgit v1.1-26-g67d0