Skip to content

Instantly share code, notes, and snippets.

View ianfnelson's full-sized avatar

Ian Nelson ianfnelson

View GitHub Profile
@ianfnelson
ianfnelson / AspNetCache.cs
Created March 25, 2010 21:35
Caching abstractions for DI and testing purposes
namespace IanFNelson.Utilities.Caching
{
using System;
using System.Web;
using System.Web.Caching;
public class AspNetCache : ICache
{
public object Get(string key)
{
@ianfnelson
ianfnelson / WindsorServiceLocator.cs
Created March 25, 2010 21:38
Windsor implementation of Common Service Locator
using System;
using System.Collections.Generic;
using Castle.Windsor;
using Microsoft.Practices.ServiceLocation;
/// <summary>
/// Adapts the behavior of the Windsor container to the common
/// IServiceLocator
/// </summary>
public class WindsorServiceLocator : ServiceLocatorImplBase
@ianfnelson
ianfnelson / gist:632368
Created October 18, 2010 15:15
Unit of Work
namespace Marshalls.Leads.DataAccess
{
using System;
using System.Collections.Generic;
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using Marshalls.Leads.Facilities;
using Marshalls.Leads.Facilities.Configuration;
using NHibernate;
using NHibernate.Cfg;
@ianfnelson
ianfnelson / TestFixture.cs
Created January 7, 2012 20:53
Test Domain Entities Contain Only Virtual Public Members
/// <summary>
/// This test is designed to catch those instances where we forget to mark public members on entities
/// as virtual - before NH complains at runtime.
///
/// Where classes implement properties from interfaces, the CLR will treat those properties
/// as virtual even when they have not explicitly been set as such (e.g. implementations of IEntity.Id)
/// so this test is not fool-proof. But it should help.
/// </summary>
[Test]
public void Convention_AllDomainEntitiesShouldContainOnlyVirtualMembers()
@ianfnelson
ianfnelson / ControlPropertiesValid.cs
Created March 28, 2014 20:36
Gists for 2004 Blog Post "Inheriting From BaseValidator to Make Custom Validation Controls"
///
/// This method checks whether the control set in the
/// ControlToValidate property is valid.
///
/// Boolean indicating whether we have a valid ControlToValidate
protected override bool ControlPropertiesValid()
{
// Get the control we're trying to validate
Control ctrl = FindControl(ControlToValidate);
if (ctrl == null)
@ianfnelson
ianfnelson / EmailPublisher.cs
Last active August 29, 2015 13:57
Code for 2004 blog post "Custom Email Publisher for Microsoft Exception Management Application Block"
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Reflection;
using System.Text;
using System.Web.Mail;
using Microsoft.ApplicationBlocks.ExceptionManagement;
namespace IanFNelson
{
@ianfnelson
ianfnelson / GenericSorter.cs
Created March 28, 2014 20:57
Code for 2004 blog post A Generic Sorter For Strongly-Typed Collections
using System;
using System.Collections;
using System.Globalization;
using System.Reflection;
namespace IanNelson.Utilities
{
/// <SUMMARY>
/// A generic sorter, inheriting from IComparer,
/// intended to allow for the sorting of
/// strongly-typed collections on any named public property
@ianfnelson
ianfnelson / universalcomparer.cs
Created March 29, 2014 19:56
Code for 2006 blog post "Universal Comparer for .NET"
using System;
using System.Reflection;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Globalization;
namespace IanNelson.Utilities
{
@ianfnelson
ianfnelson / KeyValuePairCollection.cs
Created March 29, 2014 20:14
Snippets for 2006 blog post "A Serializable KeyValuePair Class"
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
namespace IanFNelson
{
[Serializable()]
public class KeyValuePairCollection<TKey, TValue> :
Collection<KeyValuePairThatSerializesProperly<TKey, TValue>>
{
public void Add(TKey key, TValue value)
@ianfnelson
ianfnelson / CodeContracts1.cs
Last active August 29, 2015 13:58
Snippets for 2009 blog post "Code Contracts"
/// <summary>
/// Search for a collection of customers, given a set of criteria.
/// </summary>
/// <param name="queryCriteria" />Query Object defining the search criteria.</param>
/// <returns>Collection of customers matching the specified criteria.</returns>
/// <exception cref="System.ArgumentNullException">Where queryCriteria is null</exception>
/// <exception cref="System.ArgumentException">Where no query criteria have been set (we do not permit searching for all customers)</exception>
public static CustomerCollection Find(CustomerQuery queryCriteria)
{
#region Validate parameters