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 static class Extensions | |
{ | |
public static IEnumerable<IEnumerable<T>> Permute<T>(this IEnumerable<T> items) | |
{ | |
var isEmpty = true; | |
foreach (var item in items) | |
{ | |
isEmpty = false; | |
foreach (var p in items.Except(item.Yield()).Permute()) | |
yield return item.Yield().Concat(p); |
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 static class Async | |
{ | |
public static Func<Task<T>> Make<T>(Action<TaskCompletionSource<T>> action) | |
{ | |
var completionSource = new TaskCompletionSource<T>(); | |
action(completionSource); | |
return completionSource.Task; | |
} |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<Extract> | |
<Orders> | |
<Order DateCreated="2012-03-21" CustomerNumber="1234"> | |
<OrderLine Qty="2" UnitPrice="15.00" ProductCode="TAC123" /> | |
<OrderLine Qty="45" UnitPrice="0.15" ProductCode="TAC321" /> | |
</Order> | |
<Order DateCreated="2012-03-21" CustomerNumber="5678"> | |
<OrderLine Qty="9" UnitPrice="27.00" ProductCode="TAC987" /> | |
</Order> |
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 builder = new ContainerBuilder(); | |
builder.AddModule(new ModuleA()); | |
builder.AddModule(new ModuleB()); | |
builder.AddModule(new DebugFakesModule()); | |
var container = builder.Build(); | |
// Will be FakeEmailService if compiled with DEBUG |
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 ignoredColumns = new[] { | |
"CreatedBy", | |
"CreatedDate", | |
"ModifiedBy", | |
"ModifiedDate", | |
"LogicallyDeletedBy", | |
"LogicallyDeletedDate", | |
"LastModified" | |
}; |
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
interface IHaveAttachments { } | |
interface IAttachment<T> where T : IHaveAttachments { | |
void AttachTo(T obj); | |
} | |
class AttachmentsModule : Autofac.Module | |
{ | |
private static readonly MethodInfo _attach = typeof(AttachmentsModule).GetMethod("Attach", BindingFlags.Static | BindingFlags.NonPublic); |
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
void Main() | |
{ | |
var start = new DateTime(2012, 10, 1); | |
var end = new DateTime(2012, 10, 31); | |
var days = from d in start.UpTo(end) | |
where d.DayOfWeek == DayOfWeek.Wednesday | |
select d; | |
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
void Main() | |
{ | |
var items = new List<string>{ "A", "B", "C", "D", "E", "F", "G", "H", "I" }; | |
items.Chunk(2).Dump(); | |
} | |
public static class Ext | |
{ | |
public static IEnumerable<IEnumerable<T>> Chunk<T>(this IEnumerable<T> source, int chunkSize) |
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
void Main() | |
{ | |
DoTheThing(1); | |
DoTheThing(2); | |
DoTheThing("Banana"); | |
} | |
public static void DoTheThing(object o) | |
{ | |
DoTheThingInternal((dynamic)o); |
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
void Main() | |
{ | |
var refDate = DateTime.Today.AddMonths(-1); | |
var start = refDate.StartOfMonth().Backwards().FirstOrDefault (d => d.DayOfWeek == DayOfWeek.Monday); | |
var end = refDate.EndOfMonth().Forwards().FirstOrDefault (d => d.DayOfWeek == DayOfWeek.Sunday); | |
start.UpTo(end).ToArray().Dump(); | |
} |