Extend a Class

S

shapper

Hello,

I have the following code:

public static class HtmlHelperExtensions {

public static string ToolTip(this HtmlHelper helper, string name)
{
return ToolTip(helper, name, null, null);
}
...

HtmlHelper is a class in System.Web.MVC.

Instead of having the ToolTip inside a new class named
HtmlHelperExtenstions can I make my ToolTip method to some how extend
the HtmlHelper, i.e., to be also inside "HtmlHelper'?

And if yes, should I do this?

Thanks,
Miguel
 
M

Marc Gravell

If you don't control HtmlHelper, then no. However, if you ensure that
HtmlHelperExtensions is in the sample namespace as HtmlHelper, then
the extension method will be available (assuming you have a "using"
for that namespace).

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top