Sometimes on pages I must show some data from attributes of different object properties. A.e. when I have a class
class A
{
[CustomAttribute("See me!")]
public int B{get;set;}
}
and want to show data from my custom attribute, I can use smth like
static string TitleFor<TClass, TProp>(TClass model, Expression<Func<TClass, TProp>> expression)
and it works good. But when I want to turn it into Html helper like
static MvcHtmlString TitleFor<TClass, TProp>(this HtmlHelper htmlHelper, TClass @object, Expression<Func<TClass, TProp>> expression)
and use it
@Html.TitleFor(default(A), (x) => default(A).B)
I'm getting errors like error CS1061: 'HtmlHelper' does not contain a definition for 'TitleFor' and no accessible extension method 'TitleFor' accepting a first argument of type 'HtmlHelper' could be found (are you missing a using directive or an assembly reference?) where CurrentPageModel — class, used as model on this page.
How to do it right?
Update: added public
keyword to my function, but it not helps much — now I'm getting CS0117: 'HtmlHelper' does not contain a definition for 'TitleFor'
Update 2: while .DisplayFor partially served my needs, I'm still unable to do something like that for object another than model. C# not allowing to perform member access like C++ allows with ::
operator and that reduces our abilities in metadata accessing.