title: Inserting code at compile time or any alternative solution
body: <p>I want to make my code cleaner. All my views have a lot of this:</p>
  
  <pre><code>@Html.LabelFor(p =&gt; p.something)
  @Html.EditorFor(p =&gt; p.something)
  @Html.ValidationMessageFor(p =&gt; p.something)
  </code></pre>
  
  <p>So what I have done is define a inline layout in EVERY view:</p>
  
  <pre><code>@helper EditorBlock(Expression&lt;Func&lt; MyModel, string&gt;&gt;   stringExp=null,
          Expression&lt;Func&lt; MyModel,   bool&gt;&gt;     boolExp=null,
  
  @if     (stringExp!= null) {
     @Html.LabelFor(stringExp)
     @Html.EditorFor(stringExp)
     @Html.ValidationMessageFor(stringExp)  
  }
  else if (boolExp!= null) {
     @Html.LabelFor(boolExp)
     @Html.EditorFor(boolExp)
     @Html.ValidationMessageFor(boolExp)
  }
  </code></pre>
  
  <p>Take in account that this inline function is model-dependenting (see "MyModel"). Plus I have needed to define stringExp and boolExp parameters for my model (and sometimes even extra intExp)...</p>
  
  <p>With this I can leave my code like this:</p>
  
  <pre><code>@EditorBlock(p =&gt; p.something) 
  @EditorBlock(p =&gt; p.foo)
  @EditorBlock(p =&gt; p.bar)...
  </code></pre>
  
  <p>Which helps a lot when I need to apply div elements and styles to the views</p>
  
  <p>The problem is that I need to define this inline function in every view. Again, the problem is that LabelFor, EditorFor, ValidationMessageFor... needs a lambda expression at compile time... they can't have the lambda expression in a variable neither anything determined programmatically.</p>
  
  <p>What I would like to do is be able to extract EditorBlock to an external file, this would save me of "copy and paste", and adapt this function in EVERY file (again: the problem is that this function is model and parameter dependenting)... and I have no clue of which approach could help me. If I would be able to define a macro fucntion I think I could handle it, but I have seen that macro functions are not supported on c#. Could someone give me some advice or any other approach?</p>
  
  <p>Thanks in advance</p>