Characteristics of extension classes:
- Must be public
- Static functions
- Include keyword "this" in the parameter to be extended
- Solution must include the reference System.Core
- Class must be in same namespace
Example of use:
namespace ReportingWebApp
{
public static class SPListItemExtensions // extends the SPListItem class
{
public static string GetStringValue(this SPListItem item, string fieldName)
{
// insert code here
}
}
}
In main application:
SPListItem item = myList.Items[0];
string itemStringValue = item.GetStringValue("Color");
Showing posts with label extension classes. Show all posts
Showing posts with label extension classes. Show all posts
Friday, August 28, 2009
Subscribe to:
Posts (Atom)