Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to add custom resource types to a .NET .resx file?

In Visual Studio .NET projects you can create .resx files that contain resources which can be localized. Out of the box Visual Studio recognizes Strings, Images, Icons, Audio, Files and something called "Other" which I don't really understand.

What I want to know - can I extend Visual Studio and add a custom type here - say "Messages" (where a message would contain not only text, but also severity and other flags)? Naturally I would need to provide Visual Studio with my own editor and handle the necessary codebehind genereation, etc - but that's all doable. That is, if Visual Studio allows this sort of extensibility at all. Does it? And if yes, where can I find any documentation on it?

P.S. I'm using Visual Studio 2012.

like image 804
Vilx- Avatar asked Nov 11 '22 19:11

Vilx-


1 Answers

Yes, this is entirely possible. In order to do this, the type you want to include has to have a TypeConverter that can convert to and from InstanceDescriptor. There is an example of this on MSDN.

Once you have the TypeConverter created, you adorn the type with a TypeConverterAttribute to tell the framework to use that type converter.

For example:

[TypeConverter(typeof(MyTypeConverter)]
public class MyType
{
   ...
}

Then you can persist values of that type into and out of the resx files.

like image 129
Jeff Yates Avatar answered Dec 01 '22 04:12

Jeff Yates