R – Localization of attribute values in .NET

asp.netattributesinternationalizationlocalizationnet

How can I localize/internationalize attribute values in .NET?

My specific example is for ASP.NET web parts such as WebDisplayName, WebDescription, etc. where I inherit from the base class that uses these attributes.

Also, is there any difference to doing this with attributes declared in my own classes?

Thanks!

Best Answer

Have you had a look at Localizing the Property Grid?

This seems pretty much the same thing, except you're inheriting from WebDescriptionAttribute (et al) instead of DescriptionAttribute. All of the important properties in the Web classes, like Description, are still overridable.

The example on that page calls out to a static SR class, which retrieves string resources from a specific type. If you need to support multiple languages at the same time - and obviously take a minor performance hit in the process - then you would have to adjust the attribute itself to take the Type of the resource you expect, and use the appropriate constructor for the ResourceManager class.

I can go into more detail if you want to expand a little on the intended uses.