Skip to content

Instantly share code, notes, and snippets.

Avatar

Erik Dietrich erikdietrich

View GitHub Profile
@erikdietrich
erikdietrich / Readability2.cs
Created Nov 7, 2015
The second installment of the experiment is about cyclomatic complexity.
View Readability2.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CodeReadability
{
public class CyclomaticComplexity
{
View Readability1.cs
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 Jan 29, 2014
Sort of poorly named, but this is where the IWhatever interfaces are defined for the domain objects to implement.
View DTO.tt
<#@ 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 Jan 29, 2014
This generates the actual domain objects that reside underneath the repo layer.
View Entities.tt
<#@ 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 Jan 29, 2014
This is the modified context file for the entities.
View Entities.Context.tt
<#@ 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);
View Program.cs
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]);
View MailPieceFactory.cs
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];
View Program.cs
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);
}
View MailPiece.cs
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}",
View Program.cs
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));
}