Skip to content

Instantly share code, notes, and snippets.

View erikdietrich's full-sized avatar

Erik Dietrich erikdietrich

View GitHub Profile
@erikdietrich
erikdietrich / Readability2.cs
Created November 7, 2015 20:51
The second installment of the experiment is about cyclomatic complexity.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CodeReadability
{
public class CyclomaticComplexity
{
using System;
using System.Collections.Generic;
using System.Linq;
namespace CodeReadability
{
public class Arithmetic
{
public static int FirstProcessNumberA(int number)
{
@erikdietrich
erikdietrich / DTO.tt
Created January 29, 2014 17:54
Sort of poorly named, but this is where the IWhatever interfaces are defined for the domain objects to implement.
<#@ template language="C#" debug="false" hostspecific="true"#>
<#@ include file="EF.Utility.CS.ttinclude"#><#@
output extension=".cs"#><#
const string inputFile = @"..\WebPortal.Domain\Entities.edmx";
var textTransform = DynamicTextTransformation.Create(this);
var code = new CodeGenerationTools(this);
var ef = new MetadataTools(this);
var typeMapper = new TypeMapper(code, ef, textTransform.Errors);
var fileManager = EntityFrameworkTemplateFileManager.Create(this);
@erikdietrich
erikdietrich / Entities.tt
Created January 29, 2014 17:52
This generates the actual domain objects that reside underneath the repo layer.
<#@ template language="C#" debug="false" hostspecific="true"#>
<#@ include file="EF.Utility.CS.ttinclude"#><#@
output extension=".cs"#><#
const string inputFile = @"Entities.edmx";
var textTransform = DynamicTextTransformation.Create(this);
var code = new CodeGenerationTools(this);
var ef = new MetadataTools(this);
var typeMapper = new TypeMapper(code, ef, textTransform.Errors);
var fileManager = EntityFrameworkTemplateFileManager.Create(this);
@erikdietrich
erikdietrich / Entities.Context.tt
Created January 29, 2014 17:47
This is the modified context file for the entities.
<#@ template language="C#" debug="false" hostspecific="true"#>
<#@ include file="EF.Utility.CS.ttinclude"#><#@
output extension=".cs"#><#
const string inputFile = @"Entities.edmx";
var textTransform = DynamicTextTransformation.Create(this);
var code = new CodeGenerationTools(this);
var ef = new MetadataTools(this);
var typeMapper = new TypeMapper(code, ef, textTransform.Errors);
var loader = new EdmMetadataLoader(textTransform.Host, textTransform.Errors);
static void Main(string[] args)
{
var factory = new MailPieceFactory();
var zipCodes = new List<int>();
for (int index = 0; index < 23458333; index++)
{
zipCodes.Add(index % 100000);
var randomPiece = factory.GetPiece(GetRandomKey());
string pieceStatistics = randomPiece.GetStatistics(zipCodes[index]);
public class MailPieceFactory
{
private readonly Dictionary<char, MailPiece> _mailPieces = new Dictionary<char,MailPiece>();
public MailPiece GetPiece(char key)
{
if (!_mailPieces.ContainsKey(key))
_mailPieces[key] = BuildPiece(key);
return _mailPieces[key];
static void Main(string[] args)
{
var zipCodes = new List<int>();
var letter = new Letter();
for (int index = 0; index < 23458333; index++)
{
zipCodes.Add(index % 100000);
string pieceStatistics = letter.GetStatistics(zipCodes[index]);
Console.Write(pieceStatistics);
}
public abstract class MailPiece
{
public abstract decimal Postage { get; set; }
public abstract decimal Width { get; set; }
public abstract decimal Height { get; set; }
public abstract decimal Thickness { get; set; }
public string GetStatistics(int zipCode)
{
return string.Format("Zip code is {0}, postage is {1} and height is {2}",
static void Main(string[] args)
{
var zipCodes = new List<int>();
var letter = new Letter();
for (int index = 0; index < 23458333; index++)
{
zipCodes.Add(index % 100000);
Console.Write(string.Format("Zip code is {0}, postage is {1} and height is {2}",
zipCodes[index], letter.Postage, letter.Height));
}