Seemingly not :(
The DisplayTemplates are generic, eg.:
@Html.DisplayFor(model => model.Foo)
To use [Obsolete]
, you'd have to mark the DisplayFor method, which would apply to them all. I tried to create a "more specific" version, to see if it would pick that up (since you could then mark that as [Obsolete]
, like this:
public static class MyExtensions
{
[Obsolete]
public static MvcHtmlString DisplayFor<TModel, DateTime>(this HtmlHelper<TModel> html, Expression<Func<TModel, DateTime>> expression)
{
return html.DisplayFor(expression);
}
}
Sadly, this didn't work - it gives the following error:
Compiler Error Message: CS0121: The call is ambiguous between the
following methods or properties:
'MvcApplication11.Models.MyExtensions.DisplayFor(System.Web.Mvc.HtmlHelper,
System.Linq.Expressions.Expression>)'
and
'System.Web.Mvc.Html.DisplayExtensions.DisplayFor(System.Web.Mvc.HtmlHelper,
System.Linq.Expressions.Expression>)'
So I don't think you can achieve what you need with [Obsolete]
. If you really can't pick through the calls to DisplayFor in the IDE, you could try logging the stack trace inside the template (since you can execute any C# inside it) and then running through the app. This won't be bullet-proof, but might help a little.