Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I nest resource identifiers?

Tags:

.net

msdn

resx

The page Names of Resources on MSDN says the following.

Do use the dot separator (".") to nest identifiers with a clear hierarchy.

For example, names such as Menus.FileMenu.Close.Text and Menus.FileMenu.Close.Color conform to this guideline.

How do I do this? When I try to, I'm told a dot is not valid in a resource identifier, like this.

Disappointing.

I can understand why it's not valid[1], which is why I always assumed it wasn't possible to nest resource identifiers, and never tried until now... but MSDN says I can. What am I missing?

[1] From looking at the auto-generated Resource.Designer.cs file.

like image 1000
crdx Avatar asked Nov 04 '22 17:11

crdx


1 Answers

I've seen this too and it looks like it has been around for a few years now.

The strong type generator generates a strong typed class, and maps each resource to a property of that class. The resource name (identifier) will be used as the name of the property. An identifier with a dot character is not valid in C# (as you declared in the question). However, the generator will replace the dot with underscore so you still get a valid strong typed class.

I usually just replace the dot with an underscore. It's strange though that they still haven't changed that in the guidelines. (Or maybe I have missed something?)

like image 144
Mario S Avatar answered Nov 08 '22 04:11

Mario S