There's the DisplayAttribute that has been added in .NET 4.0 which allows you to specify a resource string:
[Display(Name = "UsernameField")]
string Username;
If you can't use .NET 4.0 yet you may write your own attribute:
public class DisplayAttribute : DisplayNameAttribute
{
public DisplayAttribute(Type resourceManagerProvider, string resourceKey)
: base(LookupResource(resourceManagerProvider, resourceKey))
{
}
private static string LookupResource(Type resourceManagerProvider, string resourceKey)
{
var properties = resourceManagerProvider.GetProperties(
BindingFlags.Static | BindingFlags.NonPublic);
foreach (var staticProperty in properties)
{
if (staticProperty.PropertyType == typeof(ResourceManager))
{
var resourceManager = (ResourceManager)staticProperty
.GetValue(null, null);
return resourceManager.GetString(resourceKey);
}
}
return resourceKey;
}
}
which you could use like this:
[Display(typeof(Resources.Resource), "UsernameField"),
string Username { get; set; }