October 2010
Intermediate to advanced
1920 pages
73h 55m
English
The idea behind extension methods should also be familiar to anyone who has worked with JavaScript (think prototype). By taking advantage of extension methods, you can add new methods to existing classes. For example, you can make up any method you want and add the method to the String class.
I’m constantly HTML-encoding strings because I am paranoid about JavaScript injection attacks. In .NET Framework 2.0, you HTML-encode a string by calling the Server.HtmlEncode() static method, like this:
string evilString = "<script>alert('boom!')<" + "/script>";ltlMessage.Text = Server.HtmlEncode(evilString);
In this statement, the static HtmlEncode() method is called on the Server class. Wouldn’t it be nice if we could ...
Read now
Unlock full access