microsoft / bond

Bond is a cross-platform framework for working with schematized data. It supports cross-language de/serialization and powerful generic mechanisms for efficiently manipulating data. Bond is broadly used at Microsoft in high scale services.
MIT License
2.61k stars 321 forks source link

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

Open mgrandi opened 2 years ago

mgrandi commented 2 years ago

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 commented 2 years ago

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: