c# - Why are some HtmlHelper methods implemented as extension methods -
i'm creating custom helper classes, similar asp.net mvc's standard htmlhelper
. when looked @ implementation of htmlhelper
, noticed most/all of html generating methods (such actionlink()
, beginform()
, textbox()
, , on) not implemented directly inside htmlhelper class, extension methods in separate classes (e.g. in class linkextensions
).
apart nicer source-code organisation, there advantage when implementing such methods extension methods instead of normal methods?
when creating own helper classes, should follow pattern?
update: when wrote wanted create own helper class, did mean extend existing htmlhelper class. instead created custom base class views (derived viewpage) , want add there additional helper class similar html , url helper classes of viewpage.
the reason is: wanted provide ability opt-out of built-in html helpers in case preferred write own or use other 3rd party helpers instead. if weren't extension methods in special namespace, wouldn't able ignore them.
Comments
Post a Comment