Based on http://www.thinkingguy.net/2010/01/localizing-labelfor-in-aspnet-mvc-2.html
I’m trying to use reflection to get to a string property in a resx file
var propertyInfo = _resourceType.GetProperty(resourcePropertyName, BindingFlags.Static | BindingFlags.GetField | BindingFlags.NonPublic);
I have a resources folder in my MVC2 project with a resource file that autogenerated a Property
public static string Dagrapport_Datum {
get {
return ResourceManager.GetString("Dagrapport_Datum", resourceCulture);
}
}
Whatever I pass to GetProperty It just stays null….
Any clues as to why this could be?
Your BindingFlags doesn’t match with the signature of the property.
You need BindingFlags.Static | BindingFlags.Public and maybe BindingFlags.GetProperty.
Edit: Its better to set BindingFlags.NonPublic too.
So GetProperty() searches for all Static, Public or NonPublic (internal, private, protected) properties.