I have enum property
public enum MyType
{
House = 0,
Apartment = 1
}
now I want to localize this enum using localized resx strings, so I add
public enum MyType
{
[LocalizedName("House", typeof(LocalizedUIStrings))]
House = 0,
[LocalizedName("Apartment ", typeof(LocalizedUIStrings))]
Apartment = 1
}
and localizedname helper class
public class LocalizedNameAttribute : Attribute
{
private readonly Type _resourceType;
private readonly string _resourceKey;
public LocalizedNameAttribute(string resourceKey, Type resourceType)
{
_resourceType = resourceType;
_resourceKey = resourceKey;
DisplayName = (string)_resourceType
.GetProperty(_resourceKey, BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public)
.GetValue(null, null);
}
public string DisplayName { get; private set; }
}
in the view I'm trying to use this localized property like this
@Html.DisplayFor(modelItem => item.MyType)
It still returns non localized string, no errors (either on compile or runtime). What I'm doing wrong here?