Level: 100
 

Sitecore Extension method competition

Trophy

In .NET 3.5 extension methods were introduced. Extension methods are great for extending API’s, where you either think something is missing or if you just want something extended so it fits into your custom solution. LearnSitecore wants to know your favorite extension methods to the Sitecore API and therefore we are hosting a Sitecore Extension Method Competition.

Written by: Jens Mikkelsen
Wed, Oct 12 2011
One of the great things about extension methods are, that you can group your functionality where it belongs. For instance if you have extensions to the Sitecore.Data.Items.Item class, you can just create an extension method, and it will now appear as if it is part of the Item class. No more Util classes!

If you don’t know much about the extension methods you can read more about them here.  

About the competition

If you want to participate in the competition, you must submit your extension method in a mail to learnsitecore@gmail.com no later than the 12th of November, which means you have a whole month to come up with your best idea. 
 
All entries will be published here on LearnSitecore, so that we can all benefit from it.

What will the winner get? Well… Besides being the coolest extension developer on LearnSitecore, the winner will receive an official LearnSitecore mug! Wuuuhoooo!

An example

I have developed quite a few extensions especially for the Item class and one of the most simple are a method called bool IsStandardValue(), which indicates whether an item is a standard value item or not. Here is the code:

public static bool IsStandardValues(this Item item)

{

  if (item == null)

    return false;

  bool isStandardValue = false;

         

  if (item.Template.StandardValues != null)

    isStandardValue = (item.Template.StandardValues.ID == item.ID);

         

  return isStandardValue;

}


This can then be called like this:

Sitecore.Context.Item.IsStandardValues()

So please share your favorite extensions!






 

Please rate this article


2 rates / 4,5 avg.

  • About the author:

    Jens Mikkelsen

    Jens Mikkelsen is a partner at Inmento Solutions a Sitecore consulting firm. He works as a Sitecore specialist and consulting helping clients architect and build quality Sitecore solutions using the newest modules and tools. 

    Further he has been deeply envolved in various complex solutions and has built up a strong knowledge of Sitecore architecture and best practices. He has especially focused on and is specialized in debugging and analyzing Sitecore solutions.

     

    Jens is very interested in the technical mechanisms in the new marketing products such as Sitecore DMS and Sitecore ECM.

    My Sitecore Freelance CV

3 responses to "Sitecore Extension method competition"

Cool contest! - and I like the nice and fluent syntax that extensions methods provides. I also think that it is lack of functional cohesion and the static modifier rather than the actual name that is the code smell of util classes.. Of course, naming a class util class makes it obvious.

Extension classes are static and type centric by nature which makes them prone to be used as util classes.

But you can count on my contributions to this contest. I want that mug!
Posted: Wednesday, October 19, 2011 9:41 AM
Hello Jens Mikkelsen,

Please keep organizing such events on regular basis..
Thanks!
VNS
Posted: Tuesday, November 15, 2011 1:41 AM
Say when will you announce the winner and when do you publish all those really cool extension methods that we are all dying to see.

Ohh yeah and I think you need to consider a new captcha solution - might I suggest recaptcha ;o)
Posted: Wednesday, December 07, 2011 8:50 PM

Leave a reply


Notify me of follow-up comments via email.
 
 
#nbsp;