Question

Is it possible to use Guids as the identifier in resource files?

In my program the user will be able to chose between some possible types when he creates an item. Which item was chosen is saved via a Guid.

But the hyphens in the Guids seem to be a problem for the resource files. Is there a better solution that to use Replace in order to remove every hyphen from the Guid before looking up the typename in the current language?

Était-ce utile?

La solution

How are you turning the Guids into strings?

You can use Guid.ToString("N") to produce a string guid without any hyphens.

You may have to put a non-digit at the start too - if you do, it's probably easiest to do it with String.Format():

string guidStr = string.Format("X{0:N}", Guid.NewGuid()); // Prefix with "X"
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top