0

All C# types have the ToString() method inherited from the object base class. Sometimes, it returns a valuable string representation of the data, and sometimes something like the name of the type.

Is there a way to know if the ToString() method will return a string representation of the value data of the class ?


The context of my work about a custom serializer, that will use the string representation of the type if it is valuable, and if not a base 64 string of the byte[] values from the class.

Sylvain B.
  • 719
  • 5
  • 31
  • 1
    You should deserialize complex type-members as well – Stefan Mar 29 '18 at 11:40
  • You might be able to compare the output of the instance's `ToString()` method with the output `.Type().ToString()` to determine whether it's just outputting the type name instead of something useful. Not sure how useful using ToString() for serialization is, but that's probably something for you to decide depending on your requirements :-) – Diado Mar 29 '18 at 11:42
  • @Felipe : thanks for showing the duplicate question, with good answers. – Sylvain B. Mar 29 '18 at 11:45
  • @Diado : yes it is the trick. – Sylvain B. Mar 29 '18 at 11:45
  • @Stefan : thanks you helped me anticipate a bug, I will add a flag – Sylvain B. Mar 29 '18 at 11:45

0 Answers0