<p>I am currently in the process of making a new ASP.net MVC website, and find myself using Html.Encode all over the place, which is good practice, but gets pretty messy. I think a good way to clean this up would be if I could overload an operator to automatically do Html encoding. </p>

<p>Previously:</p>

<pre><code>&lt;%= Html.Encode( ViewData['username'] ) %&gt;
</code></pre>

<p>Would be equivalent to:</p>

<pre><code>&lt;%=h ViewData['username'] %&gt;
</code></pre>

<p>Anyone have any ideas how I could do this, maybe using an extension method or something?</p>

NOTE: This is an ugly and untested hack, I don't think I'd ever do this
```
```
public static String h (this System.Object o, System.Object viewData)
{
    return Html.Encode(viewData);
}
```
```
I'm not sure what type ViewData is, so I used Object here, it would be best to actually change the type in the real code.
this works by hanging an extension method off System.Object, so it is always available on all types...ugly, but it may do the job:
```
```
<%=h(ViewData['username']) %>
```
```