I am writing a class library where i need to extend System.DateTime to have a property called VendorSpecificDay such that
DateTime txnDate = DateTime.Today;
VendorSpecificDayEnum vendorDay = txnDate.VendorSpecificDay;
public enum VendorSpecificDayEnum
{
Monday, Tuesday, ShoppingDay, HolidayDay
}
I realize that this is a perfect candidate for a System.Core Extension method, but the class library is in .net 2.0 ( i know i am living in dark ages )
Given that Extension methods are syntactical sugar, is there anyway i can achieve this without them ?
Many Thanks
If you have access to the C# 3.0 compiler in VS 2008, you can use extension methods even if your project targets .NET 2.0. Just define your own
ExtensionAttribute:As long as that type exists in a referenced assembly, you can use the
thiskeyword to define extension methods, and can consume them like normal.