C# String Assignment Optimization

Tuesday, August 26th, 2008

I happened to come across the following code the other day. string cost = "FR" + "E" + "E"; // bad perf = true J Which, after my performance investigation the other day, got me wondering again. Is there performance really going to be ...

C# Inline Methods and Optimization

Tuesday, August 19th, 2008

Last night I was playing around with a vector class that's part of a scientific computation code I've been working on. It's a long story more on that later but it means I've found some of my own time to write code in. Anyway... The Vector class uses the automatically ...

An xUnit.net Assert.Throws() Code Snippet

Tuesday, June 24th, 2008

I was mucking around with code snippets over the weekend - it killed the time in between feeling sick. As my unit testing framework of choice is XUnit I thought I've have a go at adding a snippet or two around that. xUnit already comes with a nice code snippet for ...

Linq DataContext Logging with the Logging Application Block

Thursday, June 5th, 2008

The System.Data.Linq.DataContext class exposes a TextWriter as the Log property allowing you to monitor the SQL that's getting executed under the covers. The trivial usage of this is to simply set the property to Console.Out and watch the results. Given that I was adding the Enterprise Library 4.0 Logging Block to ...

#region around implemented interfaces and code smell

Friday, April 18th, 2008

Some (not so) random surfing got me to this... How to get rid of the auto-generated #region for implemented interfaces - Daniel Cazzulino's Blog There's a setting in VS that allows you to turn off the #region generation when using VS's implement interface feature (ALT-SHIFT-F10). 99% of the time ...

An alternative to the C# generic new() constraint

Monday, November 12th, 2007

Here's something I came up with other the weekend while playing with some code... I wanted to write a method that ensured that some object of type T was always available. ModelElement element = EnsureElementExists<ModelElement>(_store); Unfortunately in this case the ModelElement class does not have a parameterless constructor. This means I can't use ...

xUnit released

Wednesday, September 26th, 2007

xUnit is the latest greatest unit testing framework from Jim Newkirk, one of the original authors of NUnit. Jim, Brad and the CodePlex team have finally released it on xUnit.net. I went to a talk by Brad on xUnit a while back it's got lots of cool new features and has ...

In praise of ‘_’

Thursday, August 31st, 2006

I was talking to one of my Developers this afternoon about coding styles. This is one of the things we discussed. It's something you see a lot, CamelCased properties with associated pascalCased data members. public class MyClass {     private string myName; This is all well and good but it can lead to some insidious ...