WebExtras provides a general purpose object cloner which performs a deep clone of the given object. However, in order for the cloning to work, all objects (including any child object of the class) to be cloned must be marked as serializable using the [Serializable] decorator attribute.
Markup
SomeClass object1 = new SomeClass();
SomeClass object2 = object1.DeepClone();
WebExtras provides two enum extension methods viz., ToTitleCase() and GetStringValue()
// Enum definition
public enum TestEnum
{
[StringValue("My great Enum")]
enumvalue = 0,
[StringValue(typeof(MyCustomStringValueDecider))]
customEnumValue = 1
}
// Invocation of ToTitleCase
TestEnum.enumvalue.ToTitleCase()
// Output
Enumvalue
// Invocation of GetStringValue
TestEnum.enumvalue.GetStringValue()
// Output
My great Enum
// This is how MyCustomStringValueDecider class looks
class MyCustomStringValueDecider : IStringValueDecider
{
public string Decide()
{
// Let us say we evaluated some condition here
// and our result was "my decided value"
return "my decided value";
}
}
// Invocation of GetStringValue on a value that has a
// custom string value decider
TestEnum.customEnumValue.GetStringValue()
// Output
my decided value
WebExtras provides two string extension methods viz., ToTitleCase() and ContainsIgnoreCase()
// String definition
string str = "basic"
// Invocation of ToTitleCase
str.ToTitleCase()
// Output
Basic
// String definition
string str = "basic"
// Invocation of ContainsIgnoreCase
str.ContainsIgnoreCase("BAS")
// Output
true
// String definition
string str = "basically basic"
// Invocation of Remove
str.Remove("bas")
// Output
ically ic
WebExtras provides ability to convert JavaScript ticks to a .NET DateTime object by using the ToDateTime() extension method available to all double values
double ticks = 1356998400000;
DateTime dt = ticks.ToDateTime(); // Parsed date time is 01/01/2013 12:00:00 AM
As with doubles, WebExtras also provides ability to convert a .NET DateTime object to it's equivalent JavaScript timestamp by using the ToJavaScriptDate() extension method available to all DateTime values
DateTime dt = DateTime.Parse("2013-01-01 00:00:00");
double ticks = dt.ToJavaScriptDate(); // Parsed JavaScript ticks are 1356998400000
In order to create and return custom JavaScript functions for the DataTables and Flot hooks, WebExtras provides the WebExtras.Core.JsFunc class.
Markup
JsFunc foo = new JsFunc
{
Name = "foo",
ParameterNames = new string[] { "myParam1", "myParam2" },
Body = "alert(myParam1 + '...' + myParam2);",
OnDocumentReady = true
};
And the serialised output will be
// You MUST use the Json.NET serialiser in order to serialise properly
$(document).ready(function() {
function foo(myParam1, myParam2) {
alert(myParam1 + '...' + myParam2);
};
});