Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to extend .net framework namespace like one can extend .net framework class?

Tags:

c#

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 ?

like image 392
user310291 Avatar asked Oct 21 '10 19:10

user310291


People also ask

What are extended methods in c#?

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.

Can we define extension method for static class?

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.

When to use extension methods in c#?

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.

Are extension methods good?

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.


1 Answers

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.

like image 102
Peter Lillevold Avatar answered Nov 08 '22 10:11

Peter Lillevold