Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
878 changes: 878 additions & 0 deletions Enumerables-Technet/Article/article-en.md

Large diffs are not rendered by default.

878 changes: 878 additions & 0 deletions Enumerables-Technet/Article/article-fr.md

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions Enumerables-Technet/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Enumérables - Version Technet
=============================

Ce projet est une refonte des articles sur les énumérables pour une version Wiki Technet.

This project is a rewrite of my articles about enumerables for a Wiki Technet version.
6 changes: 6 additions & 0 deletions Enumerables-Technet/Source/Enumerables-en/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
</startup>
</configuration>
90 changes: 90 additions & 0 deletions Enumerables-Technet/Source/Enumerables-en/EnumFilesV1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Enumerables
{
/// <summary>
/// Enumerable enumerates the text lines of a set of files
/// </summary>
public class EnumFilesV1 : IEnumerable<String>
{

private List<String> _Lines;

/// <summary>
/// Create a new enumerable
/// </summary>
public EnumFilesV1(IEnumerable<String> files)
{
// Init the files
this.Files = files.ToArray();

// Mark the lines list as 'to load' by setting it to null
_Lines = null;
}

void LoadFiles()
{
// Create the lines list
_Lines = new List<string>();

if (this.Files != null)
{
// For each file
foreach (var file in Files)
{
try
{
// Open a file text reader
using (var reader = new StreamReader(file))
{
// Read each line of the file
String line;
while ((line = reader.ReadLine()) != null)
{
// Add the line to the list
_Lines.Add(line);
}
}
}
catch { } // When an error raised while reading the file, go to the next
}
}
}

/// <summary>
/// Returns the lines enumerator
/// </summary>
public IEnumerator<string> GetEnumerator()
{
// If the lines list is null then read the files
if (_Lines == null)
{
// Load the files
LoadFiles();
}

// Returns the list enumerator
return _Lines.GetEnumerator();
}

/// <summary>
/// Implements IEnumerator.GetEnumerator() (non generic version)
/// </summary>
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return GetEnumerator();
}

/// <summary>
/// List of the files
/// </summary>
public String[] Files { get; private set; }

}

}
84 changes: 84 additions & 0 deletions Enumerables-Technet/Source/Enumerables-en/EnumFilesV2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Enumerables
{
/// <summary>
/// Enumerable enumerates the text lines of a set of files, rebuilding the list on each call
/// </summary>
public class EnumFilesV2 : IEnumerable<String>
{

/// <summary>
/// Create a new enumerable
/// </summary>
public EnumFilesV2(IEnumerable<String> files)
{
// Init the files
this.Files = files.ToArray();
}

IList<String> LoadFiles()
{
// Create the lines list
var result = new List<string>();

if (this.Files != null)
{
// For each file
foreach (var file in Files)
{
try
{
// Open a file text reader
using (var reader = new StreamReader(file))
{
// Read each line of the file
String line;
while ((line = reader.ReadLine()) != null)
{
// Add the line of the list
result.Add(line);
}
}
}
catch { } // When an error raised while reading the file, go to the next
}
}

// Returns the list
return result;
}

/// <summary>
/// Returns the enumerator of the lines
/// </summary>
public IEnumerator<string> GetEnumerator()
{
// Build the list
var list = LoadFiles();

// Return the list enumerator
return list.GetEnumerator();
}

/// <summary>
/// Implements IEnumerator.GetEnumerator() (non generic version)
/// </summary>
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return GetEnumerator();
}

/// <summary>
/// List of the files
/// </summary>
public String[] Files { get; private set; }

}

}
Loading