Skip to content

Instantly share code, notes, and snippets.

View ianfnelson's full-sized avatar

Ian Nelson ianfnelson

View GitHub Profile
@ianfnelson
ianfnelson / WCFEH_1.cs
Created September 18, 2014 12:20
Snippets for 2010 blog post "WCF - Global Exception Handling"
using System;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using Castle.Core.Logging;
/// <summary>
/// Being a custom EndpointBehavior added to the WCF services to provide custom error handling functionality.
/// Namely, logging error so it doesn't get ignored.
/// </summary>
@ianfnelson
ianfnelson / WCFLog_1.cs
Created September 18, 2014 12:18
Snippets for 2010 blog post "WCF - Logging Before and After Operation Invocation"
using System;
using System.ServiceModel.Description;
using Castle.Core.Logging;
/// <summary>
/// Being a custom EndpointBehavior added to the WCF services such that each operation outputs
/// a debug log message before and after invocation.
/// </summary>
public class OperationLoggingEndpointBehavior : IEndpointBehavior
{
@ianfnelson
ianfnelson / IoC_1.cs
Created September 18, 2014 12:14
Snippets for 2010 blog post "Testing IoC Registrations"
AutoMapper.Mapper.AssertConfigurationIsValid();
@ianfnelson
ianfnelson / NHAggregates.cs
Created September 18, 2014 09:08
Snippet for 2010 blog post "NHibernate and Mapping Aggregates"
public class IdeaMap : ClassMap<Idea>
{
public IdeaMap()
{
Id(x => x.Id)
.Column("ID")
.GeneratedBy.Identity();
Map(x => x.Summary).Not.Nullable();
Map(x => x.Description).WithMaxSize().Not.Nullable();
@ianfnelson
ianfnelson / EF1_1.cs
Created September 18, 2014 09:05
Snippets for 2011 blog post "Entity Framework Week Part 1: Introduction, Configuration and Initialization"
DbDatabase.SetInitializer<MyAppContext>(null);
@ianfnelson
ianfnelson / EF2_1.cs
Last active April 1, 2024 19:33
Snippets for 2011 blog post "Entity Framework Week Part 2: Conventions and Fluent Mappings"
public class MyAppPrimaryKeyConvention : IConfigurationConvention<PropertyInfo, PrimitivePropertyConfiguration>
{
public void Apply(PropertyInfo memberInfo, Func<PrimitivePropertyConfiguration> configuration)
{
if (memberInfo.Name == "Id")
{
// We need to avoid overriding concrete class mapped using TPH.
if (memberInfo.ReflectedType.IsSubclassOf(typeof(ProductFeature)) ||
memberInfo.ReflectedType.IsSubclassOf(typeof(ProductInsert)))
{
@ianfnelson
ianfnelson / EF3_1.cs
Created September 18, 2014 08:34
Snippets for 2011 blog post "Entity Framework Week Part 3: Runtime Issues Encountered"
public class Order
{
public Order()
{
this.Address = new Address();
}
public virtual Address Address { get; set; }
}
@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
@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 / 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
{