Having output honor ToString


In the example workbook shown below, a simple class Point is defined. Is there a way to get the workbook to display a Point instance using the ToString representation by default? I can of course coerce it to a string as shown by using Console.WriteLine.

It would be nice if the ToString representation were used by default, along with a dropdown option for using the standard object inspector display.

Very nice work so far on the workbooks!



  • SandyArmstrongSandyArmstrong USXamarin Team, Insider Xamurai

    We used to show ToString() by default, and found that in many cases it was beyond useless. Adding it as an option does sound like a good idea, though. I'll add it to the list to consider.

  • dharmatechdharmatech USMember

    Thanks for considering that feature, Sandy.

    The use case I have involves the Symbolism computer algebra library.

    Let's load it up and define a couple of symbols:

    In order to see the result of calling AlgebraicExpand on an expression, we need to use WriteLine:

    It would be nicer if the WriteLine weren't needed:

    But of course, that output isn't quite what we're after. :-)

    Entering expressions and getting their ToString representation back would provide more of a traditional CAS feel.

  • SandyArmstrongSandyArmstrong USXamarin Team, Insider Xamurai

    Thanks for the example; very helpful.

    To clarify what I meant by "beyond useless", it turns out that a lot of view-related types in Xamarin.Android and Xamarin.iOS have very long, very bad ToString representations. This made the Object Members table pretty unpleasant to use.

    But clearly, in cases like yours, the reverse is true.

  • abockabock USXamarin Team, Insider Xamurai

    @dharmatech tomorrow's 0.7.1 release will return with a ToString () renderer. It has priority over the Object Members renderer so will display by default (e.g. without having to pick it from a menu), unless a more specific renderer is available.

    And speaking of more specific renderers, we will look in to adding something even nicer than ToString () for Symbolism. Thank you for the feedback!

  • dharmatechdharmatech USMember



    Omgosh! Can't wait to try it out! :-)

    Regarding more specific renderers, that would be awesome. Symbolism has a parameter MathObject.ToStringForm, which controls the string representation that is output by ToString. Here's an example:

    Miguel's blog post mentioned that an HTML renderer is used for some of the workbook/inspector technology. If that's the case, then perhaps MathJax could be used to render certain math expressions. Symbolism could conceivably offer a ToStringForm of LaTeX to facilitate working with MathJax.

  • abockabock USXamarin Team, Insider Xamurai

    @dharmatech yep - we have plans to allow for pluggable "data shapers" on the agent side (the part that runs in your target app, say in iOS or Android) - whose responsibility is to normalize data that can be serialized and consumed by the clients - and pluggable renderers that can consume normalized/shaped data on the client side. Renderers do target HTML. We went for HTML rendering to make it easy for folks to one day extend Workbooks.

    Unfortunately this pluggability is a little ways off as we must polish up more core aspects of the products. But it's definitely coming - we're very excited to make it happen eventually.

  • MigueldeIcazaMigueldeIcaza USXamarin Team Xamurai

    Aaron, let me know which renderers on Android/iOS are bad, so we can make ToString a little bit better.

  • MigueldeIcazaMigueldeIcaza USXamarin Team Xamurai
    edited April 2016

    Additionally, I think that we could have a peer definition that could annotate types, like:

    RegisterRender ("System.Uri", (dynamic x)=> return $"http://{x.Host}:{x.Port}/{x.Fragment}")

    Or fancier:

     RegisterHtmlRender ("System.Uri", (dynamic x)=> return $"<b>http://{x.Host}:{x.Port}/{x.Fragment}</b>")

    We could load those definitions on startup, so that we could customize poor renderers.

Sign In or Register to comment.