📄 enumeratefile.cs
字号:
using System;
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Text;
namespace Microsoft.Mobile.Data
{
/// <summary>
/// Enumerate a file as a single column row.
/// </summary>
[SuppressMessage("Microsoft.Naming",
"CA1710:IdentifiersShouldHaveCorrectSuffix",
Justification="More readable as EnumerateFile")]
public class EnumerateFile : RowEnumerator
{
#region Fields
String _fileName;
StreamReader _stream;
#endregion
#region Constructor(s) & Dispose
/// <summary>
/// Build an enumerator using the filename as what file to open and
/// read. The file contents will be read a single line at a time and
/// put into a single column row.
/// </summary>
/// <param name="fileName">Filename including the path to open</param>
public EnumerateFile(String fileName)
{
_fileName = fileName;
_stream = new StreamReader(fileName);
}
/// <summary>
/// Close the open stream and dispose of it.
/// </summary>
protected override void Dispose(bool disposing)
{
_stream.Close();
_stream.Dispose();
}
#endregion
#region Methods
/// <summary>
/// Read in the next line of the file. If a line exist then build a
/// row otherwise return false to denote the end of the file.
/// </summary>
/// <returns></returns>
public override bool MoveNext()
{
bool result = false;
if (!_stream.EndOfStream)
{
currentRow = new DataRow();
currentRow.Add("FileValue", _stream.ReadLine());
result = true;
}
return result;
}
/// <summary>
/// Close the current stream reading the file and re-open the file to
/// start reading the file again.
/// </summary>
public override void Reset()
{
_stream.Close();
_stream.Dispose();
_stream = new StreamReader(_fileName);
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -