, 3.5
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)]
public class DisplayNameLocalizedAttribute : DisplayNameAttribute
{
public DisplayNameLocalizedAttribute(Type resourceType, string resourceKey)
: base(LookupResource(resourceType, resourceKey)) { }
internal static string LookupResource(Type resourceType, string resourceKey)
{
PropertyInfo property = resourceType.GetProperties().FirstOrDefault(p => p.PropertyType == typeof(System.Resources.ResourceManager));
if (property != null)
{
return ((ResourceManager)property.GetValue(null, null)).GetString(resourceKey);
}
return resourceKey;
}
}