c#

Mvc Helpers – HtmlAttributes Extension

Just a quick not on how to pass and render HtmlAttributes in a helper: public HtmlString Add(YourObject yourObject, object htmlAttributes = null) { var attributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes); //process you markup etc. attributes.ToHtmlAttributes() } public static class RouteValueDictionaryExtensions { public static…Continue Reading →

MVC – Create a separate DbCompiledModel – Fix

When using a CE database for constructing MVC 3 Controllers you get the following error if using providerName=”System.Data.SqlServerCe.4.0″. “Unable to retreive metadata for ‘X.Y.Z’. Using the same DbCompiledModel to create contexts against different types of database servers is not supported….Continue Reading →

Checking events have fired in Unit Tests

When writing unit test to check events have fired you need to add an extra delegate that also gets called back. I was refactoring my PropertyChanged system and came up with the following: List<string> EventTracking = new List</string><string>(); [TestInitialize] public void Init()…Continue Reading →

Generic default or null

extension method to compare generics for default public static bool IsDefaultOrNull(this T value) { return EqualityComparer.Default.Equals(value, default(T)); }