Skip to content

Instantly share code, notes, and snippets.

View rdingwall's full-sized avatar

Richard Dingwall rdingwall

View GitHub Profile
@rdingwall
rdingwall / InMemoryHostWithCustomResolver.cs
Created September 1, 2011 10:08
OpenRasta InMemoryHost that allows setting a custom resolver. Workaround for openrasta-stable issue 24
using System;
using System.Linq;
using System.Reflection;
using OpenRasta.Configuration;
using OpenRasta.DI;
// ReSharper disable CheckNamespace
namespace OpenRasta.Hosting.InMemory
// ReSharper restore CheckNamespace
{
@rdingwall
rdingwall / gist:1316612
Created October 26, 2011 15:01
Visual Studio Regex to remove Code Contracts and replace with standard if/throw
Find / replace
Contract.Requires\<ArgumentNullException\>\(!String.IsNullOr(Empty|WhiteSpace)\({:i}\)\);
if (String.IsNullOrWhiteSpace(\1)) throw new ArgumentException("\1 was null or empty.", "\1");
Contract\.Requires\<ArgumentNullException\>\({:i} \!\= null, .+\)\;
if (\1 == null) throw new ArgumentNullException("\1");
@rdingwall
rdingwall / ConnectionStringSettingsCollectionExtensions.cs
Created November 3, 2011 14:08
Rich's handy C# Extension Methods
// ReSharper disable CheckNamespace
namespace System.Configuration
// ReSharper restore CheckNamespace
{
public static class ConnectionStringSettingsCollectionExtensions
{
// Connection strings by default just return null. We want something
// a bit more snappy.
public static string GetOrThrow(this ConnectionStringSettingsCollection connectionStrings, string name)
{
@rdingwall
rdingwall / FtpClientTests.cs
Created November 14, 2011 21:14
Tests for my URI ctor patch for System.Net.FtpClient
using System;
using System.Net.FtpClient;
using NUnit.Framework;
namespace System.Net.FtpClient.Tests
{
public class FtpClientTests
{
[TestFixture]
public class when_constructing
@rdingwall
rdingwall / FileHelpersTypeExtensions.cs
Created November 24, 2011 14:07
Set FileHelper's FileHelperEngine.HeaderText via reflection
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
// see http://stackoverflow.com/questions/3975741/column-headers-in-csv-using-filehelpers-library/8258420#8258420
// ReSharper disable CheckNamespace
namespace FileHelpers
// ReSharper restore CheckNamespace
@rdingwall
rdingwall / gist:1514426
Created December 23, 2011 15:05
Devart Oracle home debugging
using System;
using System.Reflection;
using Devart.Data.Oracle;
void PrintDevartOracleHome()
{
// SUPER HACKY
// Get internal property OracleHomeCollection.SingletonInstance
var homes = (OracleHomeCollection)typeof(OracleHomeCollection)
.GetProperties(BindingFlags.Static | BindingFlags.NonPublic)
@rdingwall
rdingwall / FindCctors.cs
Created December 29, 2011 13:24
Find types with static ctors (.cctor)
[TestFixture]
public class FindStaticCtors
{
[Test]
public void Foo()
{
var typesWithCctors = new[]
{
Assembly.GetAssembly(typeof(xyz)),
@rdingwall
rdingwall / CompositePresentationEventExtensions.cs
Created February 9, 2012 17:04
AsObservable() extension method for Prism's event aggregator
using System;
using Microsoft.Practices.Prism.Events;
// ReSharper disable CheckNamespace
namespace Microsoft.Practices.Prism.Events
// ReSharper restore CheckNamespace
{
public static class CompositePresentationEventExtensions
{
public static IObservable<TEventArgs> AsObservable<TEventArgs>(this CompositePresentationEvent<TEventArgs> @event)
@rdingwall
rdingwall / DynamicJsonDeserializer.cs
Created February 22, 2012 12:22
RestSharp deserialize JSON to dynamic
// ReSharper disable CheckNamespace
namespace RestSharp.Deserializers
// ReSharper restore CheckNamespace
{
public class DynamicJsonDeserializer : IDeserializer
{
public string RootElement { get; set; }
public string Namespace { get; set; }
public string DateFormat { get; set; }
@rdingwall
rdingwall / DropAllRavenDatabases.bat
Created February 29, 2012 13:15
Fast Raven DB sandbox database helpers
@echo off
rem Warning: this batch file deletes ALL Raven DB data and databases, leaving you with a totally empty (but ready to use) Raven DB instance.
net stop RavenDB
rd /S /Q C:\RavenDB\Server\Data
rd /S /Q C:\RavenDB\Server\Tenants
net start RavenDB