Skip to content

Instantly share code, notes, and snippets.

View seesharper's full-sized avatar
🏠
Working from home

Bernhard Richter seesharper

🏠
Working from home
View GitHub Profile
@seesharper
seesharper / example.cs
Last active May 10, 2016 20:26
Kill child process when console terminates
process.Start();
ProcessKiller.KillWhenConsoleTerminates(process);
RunAndWait(process);

Strongly typed configuration

var reader = new ConfigurationReader();
var config = reader.Read("/A/B/C").As<CommonConfig>();
string someValue = config.SomeValue;

Loosely typed configuration

@seesharper
seesharper / TestOutputHelper
Created March 4, 2016 13:35
Capture Xunit20 output
public static class TestOutputHelper
{
private static readonly AsyncLocal<ITestOutputHelper> CurrentTestOutputHelper
= new AsyncLocal<ITestOutputHelper>();
public static void Capture(this ITestOutputHelper outputHelper)
{
CurrentTestOutputHelper.Value = outputHelper;
}
@seesharper
seesharper / asyncservices.md
Last active February 3, 2016 13:33
Injecting asynchronous services

Injecting asynchronous services

How often have you found yourself in a situation where you have some synchronous code where you would like to call an asynchronous method?

My guess is pretty often. Especially if you are working with legacy code and just starting to learn about async and await.

I am going to show you an example of such a situation and ways to deals with it.

Note: The sample code uses LightInject as the IoC container, but this example applies to all containers and even if you are doing "manual" dependency injection. Being the author of LightInject I felt it was a natural choice :)

@seesharper
seesharper / asyncservices
Created February 2, 2016 20:13
Injecting asynchronous services
# Injecting asynchronous services
How often have you found yourself in a situation where you have some synchronous code where you would like to call an asynchronous method?
My guess is pretty often. Especially if you are working with legacy code and just starting to learn about **async** and **await**.
I am going to show you an example of such a situation and ways to deals with it.
> Note: The sample code uses LightInject as the IoC container, but this example applies to all containers and even if you are doing "manual" dependency injection. Being the author of LightInject I felt it was a natural choice :)
@seesharper
seesharper / xd2md.cs
Created January 20, 2016 08:42 — forked from formix/xd2md.cs
Generates Markdown From VisualSturio XML documentation files
using System;
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
using System.Xml;
using System.Xml.Linq;
namespace Formix.Utils
{
class Program
//Filter
git filter-branch --prune-empty --subdirectory-filter src/LightInject.AutoFactory master
//Push to new repo
git push [email protected]:seesharper/LightInject.Interception.git -f
//Add gitignore and attributes
//Pull new repo
@seesharper
seesharper / RunOnce.cs
Created December 14, 2015 11:39
RunOnce v2
/// <summary>
/// A thread safe class that ensures that a given
/// <see cref="Action"/> is only executed once.
/// </summary>
public class RunOnce
{
private Action action;
private bool hasExecuted;
private readonly object lockObject = new object();
@seesharper
seesharper / ExpressionExtensions.cs
Created November 11, 2015 10:01
Flatten Expression Tree's
/// <summary>
/// Extends the <see cref="Expression"/> class.
/// </summary>
public static class ExpressionExtensions
{
/// <summary>
/// Flattens the <paramref name="expression"/> into an <see cref="IEnumerable{T}"/>.
/// </summary>
/// <param name="expression">The target <see cref="Expression"/>.</param>
/// <returns>The <see cref="Expression"/> represented as a list of sub expressions.</returns>
@seesharper
seesharper / program.cs
Created November 4, 2015 09:59
Using Lazy<T,TMetadata>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using LightInject;
namespace ConsoleApplication2
{
class Program
{