Skip to content

Instantly share code, notes, and snippets.

@smudge202
smudge202 / The.csproj
Created December 8, 2017 13:19
Test shenanigans
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<RuntimeFrameworkVersion>2.0.3</RuntimeFrameworkVersion>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
@smudge202
smudge202 / ApplicationExtensions.cs
Last active October 23, 2015 09:17
Composition based Event bus subscriptions
using Composition;
using System;
namespace Domain
{
public static class ApplicationExtensions
{
/// <summary>
/// This extension will simply fire an <see cref="EventBusStarted"/> event.
/// In debug mode, the extension will also <see cref="System.Diagnostics.Debug.Assert">Assert</see> that
@smudge202
smudge202 / DemandSetup.cs
Created September 25, 2015 07:34
How to do fluent enumerable method mentioned in todo (@bathroomcommits)
public class Demand
{
public static DemandResult That(Func<bool> predicate) => new DemandResult(predicate);
public static void That(bool predicate, string reason)
{
if (!predicate) throw new InvalidOperationException(reason);
}
public static DemandSetup<IEnumerable<T>> That<T>(IEnumerable<T> source) => new EnumerableDemand<T>(source);
public interface IAnimal
{
string Type { get; }
}
public interface IDog : IAnimal { }
public class Foo
{
public Foo(IDog animal)
public interface IAnimal
{
string Type { get; }
}
public abstract class Dog : IAnimal
{
public virtual string Type { get; } = "Dog";
public abstract string Breed { get; }
@smudge202
smudge202 / factories
Created April 2, 2015 14:23
101 on Basic Factories
static void Main(string[] args)
{
var app = new Voldermort.CommandLineApplication();
app.UseServices(services =>
{
services.AddTransient<IChildFactory, A>();
services.AddTransient<IChild, B.Child>();
services.AddTransient<IDependencyFactory, C.DependencyFactory>();
});
app.OnExecute<IParent>(parent =>
@smudge202
smudge202 / Mindblown
Created April 1, 2015 08:47
How did I not know this!?
// What is printed?
// 1) I am A
// 2) I am B
// 3) I am overriden B
// 4) None - Compiler error; Ambiguous call
static void Main(string[] args)
{
var implement = new Implementation();
var overloads = new A();