C#, Software Developement »

[11 Oct 2008 | 0 Comments]

I was told about a new feature in C# 3.0 called extension methods back in 2007 sometime by the technical architect at my old company. He explained that Microsoft had created it to enable LINQ and that it allows you extend base classes with your own functions, which is pretty cool. But what's a useful example?

Peter (my TA) said [more] that creating a StartOfDay and EndOfDay function for the .Net DateTime class might be useful and today I needed those functions so I have decided to write them blog how I did it.

 

   1:  public static class ExtensionMethods   {
   2:   
   3:          public static DateTime EndOfDay(this DateTime input)
   4:          {
   5:              return new DateTime(input.Year, input.Month, input.Day, 23, 59, 59, 59);
   6:          }
   7:   
   8:          public static DateTime StartOfDay(this DateTime input)
   9:          {
  10:              return new DateTime(input.Year, input.Month, input.Day, 00, 00, 00, 00);
  11:          }
  12:    }
 

So now I can write the following code as the .Net DateTime class now has my new functions included:

 

   1:  private static FieldBetweenPredicate AvailabilityFilter(DateTime selectedDate)   {
   2:        return new FieldBetweenPredicate(PersonAppointmentsFields.StartDate, selectedDate.StartOfDay(), selectedDate.EndOfDay());
   3:  }

Thanks to David Hayden's blog for reminding me how to write them!

http://www.davidhayden.com/blog/dave/archive/2006/11/30/ExtensionMethodsCSharp.aspx

New note 02/Jan/2010: Just found another useful extension method for randomising a list: http://www.vbforums.com/showthread.php?s=51020c99595a4e123140a61ff2b00007&t=585855

Technorati Tags: ,,

Excel »

[11 Oct 2008 | 0 Comments]

My brother-in-law popped round a couple of weeks ago to see how I was recovering from my knee surgery. We got onto the topic of IT (as always) and how his department at a large financial company were in the process of coming up with their own adhoc financial system [more] because their IT department were:

a) To restrictive
b) To slow to respond to change requests

I shook my head as always saying they were just creating trouble for themselves later down the road, but if they were going to do it they should look into using Excel 2007 and the new Excel services it provides as they already have a MOSS installation to play with.

I touched on Excel services in Moss at a Crm training course I did at Microsoft earlier in the year and it looked pretty good, especially in an iFrame dashboard layout with a bunch of PKI showing, but that's as far as I've used them. I was going to spend some time at some point to learn some more. As luck would have it I'm subscribed to the blog of an old manager of mine from Capgemini, Joel Jeffery, and he's written an article on just this subject.

http://joelj.spaces.live.com/blog/cns!493B225BAB0E6A61!431.entry

Thanks Joel for the article nice introduction to some of the features and what you can do and some of the pain you might experience it also clarifies some of the can's and cannot's of Excel services.

Joel now runs JFDI Phoenix and is offering training that covers this as well as the rest of WSS and MOSS:

http://www.jfdiphoenix.co.uk/sharepoint+training.aspx?language=en-GB

I've forwarded the link onto my brother-in-law so hopefully they create something half decent for future dev teams to unravel!