views:

18

answers:

1

I making a method that generate a unique string key for some parameters. But the same key if call with same values.

I just accept primitive types, string, DateTime, Guid, and Nullable(since I append types together, I can distinguish who is int and who is int?), because I can convert all to string without lost values or precision.(for float and double a use ToString("R"), to DateTime ToString("O")).

Exists a easy way to know which types I can transform in strings without conflict? And how do this transform(how I said before, float, double and datetime have specific ways)

Thanks

A: 

It is important to make sure that culture-invariant strings are used for roundtripping.

Therefore I usually use the XmlConvert.ToXxx() methods to convert to and parse from strings; those are using the standard XML formats which are designed to be used for roundtripping. Looking at the types supported there also gives you an idea of types which do work out of the box.

For a more generic approach, you can use the IConvertible interface methods, which all accept a IFormatProvider which can be for instance the invariant culture (CultureInfo.InvariantCulture), but that doesn't really warrant a roundtrip functionality.

Lucero