This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
public class Program | |
{ | |
public static void Main() | |
{ | |
bool divByThree = false; | |
bool divByFive = false; | |
for (var n = 0; n <= 100; n++) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Web.Mvc; | |
namespace Some.Extensions | |
{ | |
public static class ListExtensions | |
{ | |
public static IEnumerable<SelectListItem> ToSelectList<T>( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class DataController : Controller | |
{ | |
public DataController() | |
{ | |
DbEfAccess = new YourEfDbEntitiesLib(); | |
//#if DEBUG | |
// YourEfDbLib.Database.Log = s => Debug.Write(s); | |
//#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public IEnumerable<string> ReadLines(Stream inputStream) | |
{ | |
using (var reader = new StreamReader(inputStream, Encoding.UTF8)) | |
{ | |
while (!reader.EndOfStream) | |
{ | |
yield return reader.ReadLine(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var processedLines = File.ReadLines(filePathToRead).AsParallel().AsOrdered().WithDegreeOfParallelism() | |
Select(l => GetProcessedLine(l)); | |
string outputFilename = @"output.csv"; | |
using (var output = new StreamWriter(outputFilename)) | |
{ | |
output.AutoFlush = true; | |
foreach (var processedLine in processedLines) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
public class FieldMap | |
{ | |
public Dictionary<string,string> Items { get; set; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
using System.IO; | |
public class FileIterator : IDisposable | |
{ | |
StreamReader reader; | |
public FileIterator(string path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
public class FixedWidthLineParser | |
{ | |
public string[] Parse(string lineToParse, int[] widths, bool trimWhiteSpace = false, int maxFields = -1) | |
{ | |
char[] characters = lineToParse.ToCharArray(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
public class DelimitedLineParserResult | |
{ | |
public string[] Values { get; set; } | |
public bool Errored { get; set; } | |
public string ErrorMessage { get; set; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Newtonsoft.Json; | |
public static T ToClass<T>(string data, JsonSerializerSettings jsonSettings = null) | |
{ | |
var response = default(T); | |
if (!string.IsNullOrEmpty(data)) | |
response = jsonSettings == null | |
? JsonConvert.DeserializeObject<T>(data) | |
: JsonConvert.DeserializeObject<T>(data, jsonSettings); |