Bob said:
Hi Peter,
I'm using ResourceManager.
By convention, my VB apps will all have a resource file that shows up in
Solution Explorer as "strings.resx". I want to write a generic GetString
routine that lives in a library DLL that knows how to find the "strings"
resource in its caller's assembly and, using ResrouceManager, fetch the
value of a specified resource string. My problem is, VB insists on
qualifying "strings.resource" with the root namespace.
In the best possible solution, the routine that calls GetString would not
need to specify the root namespace (either directly or indirectly).
GetString has no problem getting a reference to the caller's assembly. But
there may possibly be more than one resource in that assembly whose name
ends with ".strings.resource".
So... I'm fishing for something that I can look for in the caller's assembly
from whose name I can reliably deduce the root namespace, and thereby
reliably fabricate the full name for <RootNamespace>.strings.resource
I don't think you can reliably deduce the root namespace, other than by
observing the fact that the assembly contains types that always start
with that particular name. This can be true of other assemblies as
well, though.
I'd suggest something along the lines of:
- if "strings.resource" exists, then load it and you're done;
- else, find all the names of the form "*.strings.resource", using
a regular expression, for example. If there's only one then load that
and you're done;
- else, throw an exception, or load the first one in the list, or
load one where the first part of the name matches the assembly name, or
.... What you decide to do in this case depends on a policy that your
generic GetString() method would document.
To handle cases where the default policy doesn't fit a particular user's
situation, overload GetString() to take a 'rootnamespace' parameter.