I'm trying to write a strongly typed, localizable DisplayNameAttribute, but I can't get it to even compile. What I'd like to do on my viewmodel properties is something like
[LocalizedDisplayName<HomeResources>(r => r.WelcomeMessage)]
which would basically do the same thing as
[DisplayName("Welcome to my site!")]
except the message is localized. However, I can't get neither the generic constructor working (how do you supply type arguments to a constructor?) nor the choosing of what string to use. The current constructor looks like this
public class LocalizedDisplayNameAttribute<TResource> : DisplayNameAttribute
{
public LocalizedDisplayName(Expression<Func<TResource, string>> resource)
{ // ...
but the compiler complains that the input argument is not a compile time constant, so apparently this way of doing it is not valid.
Is there any way to get a strongly typed, localized attribute for display name? Is there one out there already?