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?

有帮助吗?

解决方案

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"
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top