Last post Dec 15, 2005 07:15 AM by Luis Abreu
Dec 14, 2005 08:28 AM|rmprimo|LINK
Custom namespaces for global resources within the Resources namespace is a completely undocumented but nice new feature:
This is an invariant file that gets code-generated into a public class
ResourceName inside the namespace Resources.XXX.YYY.ZZZ
string s= Resources.XXX.YYY.ZZZ.ResourceName.ResKey1;
Before RTM I had a thousand entries which all appeared at once in the intellisense popup and were hard to navigate. Now I can break them up into different resx files and incorporate the naming hierarchy in the file names
rather than the resource key names.
For some quirky reason you cannot put a using statement at the top of the page:
string s= ResourceName.ResKey1;
The above would be defeating the purpose of the namespaces but this wouldn't:
string s= ZZZ.ResourceName.ResKey1;
I'd appreciate if anyone knows the reason.
Dec 14, 2005 09:41 AM|Luis Abreu|LINK
well, i think that is just the way C# works. According to the spec:
"Create a using directive to use the types in a namespace without having to specify the namespace. A
using directive does not give you access to any namespaces that may be nested in the namespace you specify."
so, it looks like using gives you access to the types defined in a namespace but not to other nested namespaces .
Dec 14, 2005 12:15 PM|rmprimo|LINK
We meet again. It does work. The problem was the generated file is outside the project and the IDE cannot see it until you re-build.
The namespace is NOT nested and that is exactly the issue.
The namespce is "Resources.XXX.YYY.ZZZ" It just happens to contain dots. Resources is a poor choice as it can be easily confused with System.Resources but it is what it is.
string s= ResName.ResKey1;
The other culprit is the IDE intellisense which piece-meals the dot-separated parts one by one as though they are nested namepaces.
If I only have one file: "~/App_GlobalResources/XXX.YYY.ZZZ.ResName.resx." I should have have only ONE generated namespace.
So when I start typing using... I should get the next intellisense tip "XXX.YYY.ZZZ". and not just "XXX". Actually, to be exact I should not get a tip at all until I am finished typing the whole thing because it is
all one piece. The IDE is too helpful, misleadingly so.
Nesting the namespaces would have only meant a couple of extra lines of CodeDom, so I don't know why they didn't do it. It is still possible to do a complete hierarchy if you create files like:
"~/App_GlobalResources/ResName1.resx." namepsace is : "Resources"
"~/App_GlobalResources/XXX.ResName2.resx." namepsace is : "Resources.XXX"
"~/App_GlobalResources/XXX.YYY.ResName3.resx." namepsace is : "Resources.XXX.YYY"
"~/App_GlobalResources/XXX.YYY.ZZZ.ResName4.resx." namepsace is : "Resources.XXX.YYY.ZZZ"
Again they wouldn't be nested but it doesn't matter usage-wise, unless you were doing reflection and trying to step up the hierachy of containers. You still get the organizational benefits which is what matters.
Someone should really blog about this.
Dec 15, 2005 07:15 AM|Luis Abreu|LINK
hello again :)
ah...well, i though it generated nested namespaces and din't really bothered to check it out. thanks for the feedback Rob!