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 |
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 |
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 |
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 |
By SamStephens on October 25, 2011
The application I am currently working on has a requirement to audit which application user last created or updated database records. I used the ObjectContext event SavingChanges to keep this concern out of my application code.
Posted in C# | Tagged .NET, C#, Entity Framework |
By SamStephens on February 14, 2011
I recently wanted to build an extensible set of processing classes. Each class can process certain objects it is provided.
I decided the simplest way to do this was to create an processor interface. The set of processing classes then is all classes that implement this interface. I use reflection to then find all the processors: that is, all implementations of the processor interface.
Posted in C# | Tagged .NET, C#, Reflection |
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 |
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 |
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 |
By SamStephens on November 15, 2010
It’s a waste of processor cycles and user time to make web service calls to systems that are not currently functioning. I was involved in building a solution that allows code that depends on non-functioning systems to be skipped entirely. Code simply needs to be attributed with the systems it uses. Then a policy injection handler will throw an exception without even calling that code if a system is known to be unavailable.
Posted in C# | Tagged Aspect-oriented Programming, Attributes, C#, Policy Injection, Unity |