Skip to content

Instantly share code, notes, and snippets.

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Each member with an <inheritdoc/> tag does not render the <typeparamref> tag in its documentation tooltip correctly.
// Other documentation tags (<paramref/> and <c></c>) are included to demonstrate that other tags are rendered correctly.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public static class GenericStaticClass<TArgument>
{
/// <summary>
/// Summary:<br/>typeparamref: <typeparamref name="TArgument"/>.<br/>paramref: <paramref name="argument"/>.<br/><c>in-line code</c>
/// </summary>
void Main()
{
int barInt;
object barObj = Foo.GetBar();
barInt = (int)barObj; // Success!
dynamic barDynamic = Foo.GetBar();
barInt = (int)barDynamic; // RuntimeBinderException: Cannot convert type 'System.Enum' to 'int'
}
@bfriesen
bfriesen / Set.Immutable.cs
Last active August 29, 2015 14:15
Thread-safe, lock-free immutable collection transformation
<Query Kind="Program">
<NuGetReference>Microsoft.Bcl.Immutable</NuGetReference>
<NuGetReference>NUnit</NuGetReference>
<Namespace>NUnit.Framework</Namespace>
<Namespace>System.Collections.Concurrent</Namespace>
<Namespace>System.Collections.Immutable</Namespace>
<Namespace>System.Threading.Tasks</Namespace>
</Query>
#define NONEST
#region
public interface IRegexNode
{
ParseResult Parse(string input, int index);
}
public class ParseResult
{
public bool Success;
$/
  docs/
  src/
  tests/
  samples/
  artifacts/
  packages/
  build/
 lib/
@bfriesen
bfriesen / CompositionRoot.Generated.cs
Last active August 29, 2015 14:11
A general-purpose "DI container" for use by libraries to resolve static dependencies. Add a nuget reference to "InjectModuleInitializer".
//////////////////////////////////////////////////////////////////////////////////////
// //
// This file was generated by a tool. It would be a bad idea to make changes to it. //
// //
//////////////////////////////////////////////////////////////////////////////////////
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
@bfriesen
bfriesen / WhatTheFunc
Created December 3, 2012 07:13
My solution to David Poeschl's (‏@dpoeschl) twitter code golf challenge
// Make this C# code compile with minimal additional code (no commenting, etc.): Foo(0)(1)("two")("three")(4)(5)("six")("seven")(8)(9)("ten!");
// https://twitter.com/dpoeschl/status/275464052216573952
// How much more code to enforce the argument type pattern (i.e. int, int, string string, int, int, string, string...)?
// https://twitter.com/dpoeschl/status/275477464183103488
// https://twitter.com/dpoeschl/status/275478110290444288
// https://twitter.com/brianfriesen/status/275479513490669568
delegate WhatTheFunc<T2,T3,T4,T1> WhatTheFunc<T1,T2,T3,T4>(T1 _);
void CreateFoo()
@bfriesen
bfriesen / Factory.cs
Created January 21, 2012 03:36
Yo dawg, I heard you like dependency injection, so I injected a ninject factory that uses a ninject kernel into your controller using the same ninject kernel so you can inject multiple dependencies without having to inject each one individually.
public class NinjectFactory : IFactory
{
private readonly IKernel kernel;
public Factory(IKernel kernel)
{
this.kernel = kernel;
}
public T Get<T>()