Could someone please clarify something for me. In my ASP.NET MVC 2 app, I\'ve got a BaseViewModel class which includes the following method:
pu
In your example, the compiler has no way of knowing what type should TModel be. You could do something close to what you are probably trying to do with an extension method.
static class ModelExtensions
{
public static IDictionary GetHtmlAttributes
(this TModel model, Expression> propertyExpression)
{
return new Dictionary();
}
}
But you wouldn't be able to have anything similar to virtual, I think.
EDIT:
Actually, you can do virtual, using self-referential generics:
class ModelBase
{
public virtual IDictionary GetHtmlAttributes
(Expression> propertyExpression)
{
return new Dictionary();
}
}
class FooModel : ModelBase
{
public override IDictionary GetHtmlAttributes
(Expression> propertyExpression)
{
return new Dictionary { { "foo", "bar" } };
}
}