It is possible to extend a class like string (see http://www.c-sharpcorner.com/uploadfile/mgold/extendingstringclass03162008132109pm/extendingstringclass.aspx) is there a way to extend in a similar way System.Web for example by adding our own classes to this namespace ?
Extension methods enable you to "add" methods to existing types without creating a new derived type, recompiling, or otherwise modifying the original type. Extension methods are static methods, but they're called as if they were instance methods on the extended type.
Extension methods are a special kind of static method, but they are called as if they were instance methods on the extended type." Essentially, an extension method is a special type of a static method and enable you to add functionality to an existing type even if you don't have access to the source code of the type.
In C#, the extension method concept allows you to add new methods in the existing class or in the structure without modifying the source code of the original type and you do not require any kind of special permission from the original type and there is no need to re-compile the original type.
For an application programmer, extension methods are an incredibly powerful and expressive tool. They enable convenience, extensibility, and an improved intellisence experience. However, many of the features that make extension methods so useful for library consumers can be problematic for class library authors.
Sure. Try something like this:
namespace System.Web
{
public class ThisIsMyAdditionToSystemWeb
{
}
}
But obviously, this will not add anything to the actual .Net assemblies, projects that want to utilize your "extension" will have to reference your assembly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With