Sam Stephens: Free-spirited Software
Learnings, ponderings, and questions from my life as a software developer
Browse: Home / .NET

Mocking ASP.NET providers

By SamStephens on May 13, 2012

When playing around with ASP.NET membership, I found myself in a situation where I wanted to mock the ASP.NET Providers. This is something the design of providers makes non-trivial. Mark Seemann summarises: “Since a Provider creates instances of interfaces based on XML configuration and Activator.CreateInstance, there’s no way to inject a dynamic mock.”. See Provider is not a pattern.

Posted in .NET | Tagged .NET, ASP.NET, ASP.NET Providers, C#, Mocking, Testing | Leave a response

Generating multiple files from one T4 template

By SamStephens on January 28, 2012

I extend my previous T4 work to be able to “Duck Type” using a number of interfaces, generating a file per interface.

Posted in .NET | Tagged C#, Code Generation, Entity Framework, T4 | 1 Response

Duck typing Entity Framework classes using T4 Templates

By SamStephens on November 23, 2011

Duck typing is an interesting concept, and alien to C# generally. But using the techniques of my previous post about T4 and Entity Framework, it is possible to have your entities implement interfaces if they have the required properties, resulting in behaviour similar to duck typing. Please read the previous blog post before reading this one.

Posted in .NET | Tagged C#, Code Generation, Duck Typing, Entity Framework, T4 | 1 Response

Using T4 Templates to extend your Entity Framework classes

By SamStephens on November 5, 2011

All my entities for a current project have a UserName column. I used T4 templating to generate a common interface and an implementation for each entity class.

Posted in .NET | Tagged C#, Code Generation, Entity Framework, T4 | Leave a response

Updating the registry using .NET and LogParser

By SamStephens on December 13, 2010

I have discovered a need to be able to search and replace registry values. I originally thought about using Powershell but after reading this blog post about Powershell performance with the registry, I decided to use .NET. I quickly encountered the idea of using LogParser to read the registry at high speed, and decided this was a fruitful avenue.

Posted in .NET, C# | Tagged .NET, C#, COM Interop, LogParser, Registry | Leave a response

Tidy IEqualityComparer with GenericEqualityComparer

By SamStephens on December 6, 2010

Whilst looking through a codebase, I saw implementations of IEqualityComparer<>. After thinking to myself that the need to create an entire implementation of IEqualityComparer<> per use creates quite a bit of boilerplate for such a small amount of signal, I realised that creating a generic implementation of IEqualityComparer<> that takes a definition of equality in its constructor would be very simple.

Posted in .NET, C# | Tagged .NET, C#, Generics, Lambas | 4 Responses

IEnumerable, ReadOnlyCollection, and the missing interface

By SamStephens on November 22, 2010

I’ve been thinking on and off about the appropriate return signature for a method that returns an immutable list of objects, sparked off by reading Eric Lippert’s article, Arrays considered somewhat harmful, and my belief that the value of functional program and growth of parallelism means that immutability is desirable most of the time.

However, once you decide to return an immutable collection, what type do you return?

Posted in .NET, C# | Tagged .NET, C#, Immutable | 2 Responses

Parsing Event Logs using System.Diagnostics.Eventing.Reader

By SamStephens on October 11, 2010

I’ve just had to analyse a bunch of Event Logs that contain exceptions, produced from a load testing exercise. I needed to turn them into a summary of the counts of each class of exception that occurred. After a little research, I found out about the existence of the System.Diagnostics.Eventing.Reader class, which will parse event logs from either the local or a remote computer, or from an EVTX file.

Posted in .NET, C# | Tagged .NET, C#, Event logs, XML | 1 Response

Subscribe

Search

Categories

  • .NET
  • Android
  • C#
  • Javascript
  • Meta
  • MSBuild
  • Opinion
  • Ruby
    • Rails
  • Shell scripting
  • Wordpress

Archives

  • December 2012
  • May 2012
  • March 2012
  • February 2012
  • January 2012
  • November 2011
  • October 2011
  • May 2011
  • February 2011
  • January 2011
  • December 2010
  • November 2010
  • October 2010

Websites

  • A List Apart
  • The Daily WTF
  • Ars Technica

My other sites

  • On Twitter
  • On LinkedIn
  • On Stack Overflow

Blogroll

  • charlie.collins's blog
  • The Radioactive Yak
  • Android Developers Blog
  • Scott Hanselman's Computer Zen
  • ScottGu's Blog
  • Mark's Blog
  • Dare Obasanjo aka Carnage4Life
  • Ayende @ Rahien
  • The WHATWG Blog
  • Fabulous Adventures In Coding
  • Ajaxian
  • Tatham Oddie
  • Marcin On ASP.NET
  • Object Mentor Blog: Category Uncle Bob's Blatherings
  • Schneier on Security
  • CommonsWare

Copyright © 2013 Sam Stephens: Free-spirited Software.

Powered by WordPress and Hybrid.

The opinions expressed on this site are my own and do not necessarily represent those of my employer. Contact me.