Project DescriptionThe Extension Toolkit project provides a collection of useful extension methods for all kind of types (e.g. String class extensions).
SamplesThe String.Replace extension method:
string mailTemplate = "Dear ${Name}, how are you? .... Creation date: ${CreatedOn}";
...
string mail = mailTemplate.Replace(new { Name = "Billy", CreatedOn = DateTime.Now });
The string variable mail will contain the following text:
Dear Billy, how are you? .... Creation date: 01/25/2007
The String.ToNameValueCollection and NameValueCollection.Join extension method:
string prefFromDb = "ShowList=1|Type=Premium|DefaultTheme=Green";
...
NameValueCollection options = prefFromDb.ToNameValueCollection();
...
if(options["Type"] == "Premium){
...
}
...
prefFromDb = options.Join();
The List<string>.ToDataTableStructure extension method:
List<string> columns = new List<string>();
columns.Add("ID");
columns.Add("Name");
DataTable dt = columns.ToDataTableStructure();
The NameValueCollection.ToXml extension method:
NameValueCollection c = new NameValueCollection();
c.Add("Host", "codeplex.com");
c.Add("Port", "80");
xml = c.ToXml("Server", new { Active = "true" });
The created XML snippet will look like this:
<Server Active="true">
<Host>codeplex.com</Host>
<Port>80</Port>
</Server>
Help wantedIf you want to contribute to this project or have ideas for new extension methods, please feel free to contact me.