Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

c#: Add ToString() implementations for compiled bond objects #1171

Open
mgrandi opened this issue Sep 20, 2022 · 1 comment
Open

c#: Add ToString() implementations for compiled bond objects #1171

mgrandi opened this issue Sep 20, 2022 · 1 comment

Comments

@mgrandi
Copy link

mgrandi commented Sep 20, 2022

Bond version: 10.0.0

it seems that when compiling bond objects for c# (and possibly other languages) that there is no ToString() override, so when printing out a bond object in a logger, it just prints the object's name, which is not desirable.

Example:


PS C:\Users\mgrandi\Downloads\gbc-10.0.0-amd64> cat C:\Users\mgrandi\Temp\record.bond
struct Record
{
    0: string Name;
    1: vector<double> Constants;
}
PS C:\Users\mgrandi\Downloads\gbc-10.0.0-amd64>
PS C:\Users\mgrandi\Downloads\gbc-10.0.0-amd64> .\gbc-10.0.0-amd64.exe c# C:\Users\mgrandi\Temp\record.bond
PS C:\Users\mgrandi\Downloads\gbc-10.0.0-amd64> ls


    Directory: C:\Users\mgrandi\Downloads\gbc-10.0.0-amd64


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----          3/7/2022   6:53 PM       53646880 gbc-10.0.0-amd64.exe
-a----         9/20/2022   1:13 PM           1484 record_types.cs


PS C:\Users\mgrandi\Downloads\gbc-10.0.0-amd64> cat .\record_types.cs

//------------------------------------------------------------------------------
// This code was generated by a tool.
//
//   Tool : Bond Compiler 0.12.1.0
//   Input filename:  C:\Users\mgrandi\Temp\record.bond
//   Output filename: record_types.cs
//
// Changes to this file may cause incorrect behavior and will be lost when
// the code is regenerated.
// <auto-generated />
//------------------------------------------------------------------------------


// suppress "Missing XML comment for publicly visible type or member"
#pragma warning disable 1591


#region ReSharper warnings
// ReSharper disable PartialTypeWithSinglePart
// ReSharper disable RedundantNameQualifier
// ReSharper disable InconsistentNaming
// ReSharper disable CheckNamespace
// ReSharper disable UnusedParameter.Local
// ReSharper disable RedundantUsingDirective
#endregion

namespace test
{
    using System.Collections.Generic;

    [global::Bond.Schema]
    [System.CodeDom.Compiler.GeneratedCode("gbc", "0.12.1.0")]
    public partial class Record
    {
        [global::Bond.Id(0)]
        public string Name { get; set; }

        [global::Bond.Id(1)]
        public List<double> Constants { get; set; }

        public Record()
            : this("test.Record", "Record")
        {}

        protected Record(string fullName, string name)
        {
            Name = "";
            Constants = new List<double>();
        }
    }
} // test
@chwarr
Copy link
Member

chwarr commented Sep 20, 2022

Adding this sounds reasonable at first blush. A design before implementing would be appreciated. Some questions that I foresee needing to address at the design stage:

  • How are collections handled?
  • How is inheritance handled?
  • How do type converters come into play?
  • What if someone wants to customize/override the generation/library's ToString implementation?
  • Is there a way to add this in that doesn't break existing users that have manually implemented ToString? (The generated classes are partial.)
  • An initial proposal for what a ToString representation of a Bond object should look like. Is this representation parsable? Roundtrip-able?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants