This project is read-only.

partial modifier?

Dec 14, 2011 at 9:32 AM

Is it possible to add 'partial' keyword to generated classes? This can be useful in some scenarios, especially in helpers. For example, partial definition allows to add some C# methods, that can be used inside razor code.

Dec 14, 2011 at 6:13 PM
Edited Dec 14, 2011 at 6:13 PM

We generate Mvc helpers as static types, so that you could write your helpers as extension methods to HtmlHelper. Partials wouldn't work here. For views, I guess it would make more sense to simply call a helper rather than have code across pages.

Are there specific scenarios you are trying to address here?

Dec 15, 2011 at 12:04 AM

1) I don't need to extend HtmlHelper, because there is no semantic links to it.

2) Of course, I can create separate static class, but it increases number of classes without any needs and adds explicit class names to razor code.

IMHO, it isn't require too much work to add partial to classes, and I don't see any side effects of this.

For example -


@helper Helper()
  var data = Helper2.LoadData();

With partial

@helper Helper()
  var data = LoadData();
Second sample is cleaner, isn't it?

Dec 15, 2011 at 5:26 PM

Sure. Making sure you are aware of @function blocks. You can write regular C# code inside one of those.

Additionally, assuming you are working with an Mvc app, for partials to work with your helper once we add a directive for partials, you would need to set the generator for the file as  WebPagesHelper (@* Generator : WebPagesHelper). As I said earlier, we modify helpers generated in Mvc applications to be static types.