Each object in C# has the potential to be streamed to a string as ToString(). Is there a one liner that would reverse the process given the string originally produced?
So:
var stringSomeObject = SomeObject.ToString();
and then to reverse:
var someObjectFromToString = ??????.FromString(stringSomeObject);
Is there a one liner that would reverse the process given the string originally produced?
No. Every type has the option of implementing ToString() in any way is desires. This makes it impossible to arbitrarily round trip the value.
Round tripping objects to and from some other representation is typically handled via the framework's support for Object Serialization.
Specific types within the Framework do implement methods following specific patterns which handle this, however. Many of the default value types (Int32, Double, etc) implement a .Parse and .TryParse method which can be used to "round trip" from a string. This is something that has to be implemented per type, however, and does not work on arbitrary types.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With