c#

Copy constructor and IClonable

A copy constructor is a constructor that creates a new object by making a copy of an existing object. ICloneable is a standard interface that you can implement, whereby you’ll add a Clone method to your class. The purpose of…Continue Reading →

Adding methods to enums

I used to often find myself creating utility classes to process enums to create markup or carry out particular actions based on the enum value. Since extension methods have been introduced I have started using them to add processing methods…Continue Reading →

Asp.net jQuery like Closest()

Here is a very simple asp.net .Closest() function like the jquery one. public static class ControlExtensions { public static Control Closest(this Control control, Type type ){ Control closest = null; Control parent = control.Parent; while(closest == null && parent != null){ if(parent.GetType().ToString() == type.ToString()){ return parent; } parent = parent.Parent; } return null; } }

c# Coalesce function

When you’ve been working heavily with c# for a few days, coalesce jumps into your head for a lot of c# issues. Heres a little helper to provide coalesce in .net /// <summary> /// Returns the first non null value,…Continue Reading →