Skip to content

Instantly share code, notes, and snippets.

public class Tests
{
[Input(1)]
[Input(true)]
[Input("Cantaloupe Pantaloons")]
public void GenericTestMethod<T>(T input)
{
Console.WriteLine(typeof(T).Name);
}
}
var instance = new Thing();
var method = typeof(Thing).GetMethod("GenericMethod");
var methodOfInt32 = method.MakeGenericMethod(typeof(int));
methodOfInt32.Invoke(instance, new object[] { 1 });
var methodOfBoolean = method.MakeGenericMethod(typeof(bool));
methodOfBoolean.Invoke(instance, new object[] { true });
var instance = new Thing();
var method = typeof(Thing).GetMethod("GenericMethod");
method.Invoke(instance, new object[] { 1 });
method.Invoke(instance, new object[] { true });
method.Invoke(instance, new object[] { "Cantaloupe Pantaloons" });
var instance = new Thing();
instance.GenericMethod(1); //Compile-time type is Int32, so prints "Int32".
instance.GenericMethod(true); //Compile-time type is Boolean, so prints "Boolean".
instance.GenericMethod("Cantaloupe Pantaloons"); //Compile-time type is String, so prints "String".
public class Thing
{
public void GenericMethod<T>(T input)
{
Console.WriteLine(typeof(T).Name);
}
}
[AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = false)]
public class SkipAttribute : Attribute
{
public string ExpirationDate { get; set; }
public bool HasExpired
{
get
{
DateTime expirationDate;
public class CustomConvention : Convention
{
public CustomConvention()
{
Classes
.NameEndsWith("Tests");
Methods
.Where(method => method.IsVoid());
[AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = false)]
public class SkipAttribute : Attribute { }
public class CustomConvention : Convention
{
public CustomConvention()
{
Classes
.NameEndsWith("Tests");
public class ExecuteCases : InstanceBehavior
{
public void Execute(Fixture fixture)
{
foreach (var @case in fixture.Cases)
{
using (var console = new RedirectedConsole())
{
var stopwatch = new Stopwatch();
stopwatch.Start();
public class RedirectedConsole : IDisposable
{
readonly TextWriter outBefore;
readonly TextWriter errBefore;
readonly StringWriter console;
public RedirectedConsole()
{
console = new StringWriter();
outBefore = Console.Out;