本文整理汇总了C#中System.IO.FileInfo.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# FileInfo.Dispose方法的具体用法?C# FileInfo.Dispose怎么用?C# FileInfo.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.FileInfo
的用法示例。
在下文中一共展示了FileInfo.Dispose方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OpenFile
void OpenFile(string name)
{
_name = name;
// Open and read the file
try {
TextReader reader = new FileInfo(name).OpenText();
var text = reader.ReadToEnd();
reader.Dispose();
var lines = text.Split(new[] {"\r\n"}, StringSplitOptions.RemoveEmptyEntries);
// Create a new model and solver, and add event listeners
if (_model != null) {
_model.ModelChanged -= HandleModelModelChanged;
_solver.ScanFinished -= HandleSolverScanFinished;
_solver.Finished -= HandleSolverFinished;
}
_model = new SudokuModel(lines.Length);
_solver = new Solver(_model);
_model.ModelChanged += HandleModelModelChanged;
_solver.ScanFinished += HandleSolverScanFinished;
_solver.Finished += HandleSolverFinished;
// Update the screen
_grid.Model = _model;
_txtProgress.Clear();
// Load data into the model
for (var row = 0; row < lines.Length; ++row) {
var cells = lines[row].Split(',');
for (var col = 0; col < lines.Length; ++col) {
if (!string.IsNullOrEmpty(cells[col])) {
_model.SetValue(col, row, cells[col][0] - 'A');
}
}
}
} catch (FileNotFoundException) {}
}
示例2: Refresh
public void Refresh() {
string fileName = "test1";
string fullPath = Path.Combine(this.testFolder.FullName, fileName);
IFileSystemInfo fileInfo = Factory.CreateFileInfo(fullPath);
// trigger lacy loading
Assert.That(fileInfo.Exists, Is.EqualTo(false));
var stream = new FileInfo(fullPath).Create();
stream.Dispose();
fileInfo.Refresh();
Assert.That(fileInfo.Exists, Is.EqualTo(true));
}
示例3: GetFilesFor2
public void GetFilesFor2() {
string file1 = "file1";
string file2 = "file2";
string fullPath1 = Path.Combine(this.testFolder.FullName, file1);
string fullPath2 = Path.Combine(this.testFolder.FullName, file2);
var stream = new FileInfo(fullPath1).Create();
stream.Dispose();
var stream2 = new FileInfo(fullPath2).Create();
stream2.Dispose();
IDirectoryInfo dirInfo = Factory.CreateDirectoryInfo(this.testFolder.FullName);
Assert.That(dirInfo.GetFiles().Length, Is.EqualTo(2));
Assert.That(dirInfo.GetFiles()[0].Name, Is.EqualTo(file1));
Assert.That(dirInfo.GetFiles()[1].Name, Is.EqualTo(file2));
}
示例4: AssertFilesBinaryEqual
private void AssertFilesBinaryEqual(string expectedFileName, string actualFileName)
{
int row = 0;
FileStream expectedStream = new FileInfo(expectedFileName).Open(FileMode.Open, FileAccess.Read);
FileStream actualStream = new FileInfo(actualFileName).Open(FileMode.Open, FileAccess.Read);
string failMessage = string.Empty;
try
{
while (!IsEOF(expectedStream) && !IsEOF(actualStream))
{
byte[] bufferExpected = new byte[16];
byte[] bufferActual = new byte[16];
expectedStream.Read(bufferExpected, 0, 16);
actualStream.Read(bufferActual, 0, 16);
int i = 0;
for (; i < 16; i++)
if (bufferExpected[i] != bufferActual[i]) break;
if (i < 16)
{
int diffPosition = row * 16 + i;
failMessage = string.Format("files differ at byte {0}", diffPosition);
break;
}
row++;
}
if (failMessage == string.Empty)
{
if (!IsEOF(expectedStream))
Assert.Fail("expected is longer");
else if (!IsEOF(actualStream))
Assert.Fail("actual is longer");
}
}
finally
{
expectedStream.Close();
expectedStream.Dispose();
actualStream.Close();
actualStream.Dispose();
}
if (failMessage != string.Empty)
{
Console.WriteLine("AssertBinaryFilesEqual failed expected file {0} actual file {1}: {2}",
expectedFileName, actualFileName, failMessage);
AssertFailMyXls(failMessage, expectedFileName, actualFileName);
}
}