Omitting @Model

Jul 26, 2011 at 6:31 AM

Hi team,

I'm looking for a way to shorten the syntax for accessing properties in the Model object. i.e. instead of using @Model.Name, I want to omit the @Model syntax, and leave "@Name" only. If the Name property does not present in the Template class, I want the CodeGenerator to automatically resolve the property from the Model object. Is there an easy way to achieve this?

Cheers,

Qi

Coordinator
Jul 26, 2011 at 3:11 PM
Edited Jul 26, 2011 at 3:12 PM

The simplest way would probably be to create your own BaseTemplate with a property - let's call it M that is a reference to the model. The Shortest you could get it then is @M.Name. Or, you could create a base template for *all* your different models and have all the model properties as properties on the base template and each of those properties would reference the model property of the same name.

Since the RazorParser converts directly to code it wouldn't be very easy to override any specific translation without writing hooks into the parser - not an easy task to be sure.

Take a look at the patch 8914 uploaded by me that gives the project `@model` support. You could probably extend that to do what you want. (though looking at it i don't think it's that feasible)

Jul 27, 2011 at 1:52 AM

Thank you for your reply and @model example. I guess I will use customized templates to resolve my problem at hand for now.

I will post code examples if I figure out a way to hack the code generator.