-
Notifications
You must be signed in to change notification settings - Fork 12
Extension Methods
Rock provides several extension methods to various .NET objects. For a developer to take advantage of these, they just need to add a using to the base Rock namespace.
using Rock;Here are a few methods we thought we'd highlight for you (-- just enough to give you some incentive to go read the code.)
TODO - once Sandcastle is building our class reference documentation we'll add a link to the page for the
Rock.ExtensionMethodsclass documentation.
-
Ellipsis(int)- Truncates a string after a max length and adds ellipsis. Truncation will occur at first space prior to maxLength. -
Pluralize()- Pluralizes the specified string. In other words book becomes books and candy becomes candies.
-
ToYesNo()- Returns Yes fortrueand No forfalse.
-
ConvertToString()- Converts to the enum value to it's string value. We even split on the case changes such that an enum of RecordStatus would return "Record Status". -
ConvertToInt()- Vice versa -- for consistency. -
ConvertToEnum()- Converts a string value to an enum value. This one is worth showing...
// Assuming you've got an enum such as:
public enum Status
{
Success,
Fail,
EpicFail,
}
// elsewhere, you can get the proper enum if you've only got the string value:
Status s = "Epic Fail".ConvertToEnum<Status>(); // w00t!-
BindToDefinedType( DefinedTypeCache )- Binds a given DefinedType to your drop down ListControl. Example:
ListControl ddl = new ListControl();
ddl.BindToDefinedType( DefinedTypeCache.Read( myConfiguredDefinedTypeGuid ) );