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.
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!
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!