Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-1127

C# should not generate default constructor

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 0.5
    • None
    • C# - Compiler
    • None

    Description

      The C# code generator should not produce a default constructor.

      Thrift generates partial classes for thrift structs, meaning that the class may be spread across multiple files and csc will link them to be a separate file. When the thrift generated class has the partial constructor, it cannot be added in other files. This is a problem if you want to implement a default constructor that does some initialization to the data in the class.

      For example, this thrift code:

      struct DateTime
      {
          1: required i64 ticks,
      }
      

      produces

      /**
       * Autogenerated by Thrift
       *
       * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
       */
      using System;
      using System.Collections;
      using System.Collections.Generic;
      using System.Text;
      using System.IO;
      using Thrift;
      using Thrift.Collections;
      using Thrift.Protocol;
      using Thrift.Transport;
      namespace Thrift.Generated
      {
      
        [Serializable]
        public partial class DateTime : TBase
        {
          private long _ticks;
      
          public long Ticks
          {
            get
            {
              return _ticks;
            }
            set
            {
              __isset.ticks = true;
              this._ticks = value;
            }
          }
      
      
          public Isset __isset;
          [Serializable]
          public struct Isset {
            public bool ticks;
          }
      
          public DateTime() {
          }
      
          public void Read (TProtocol iprot)
      ...
      

      It would be great if it instead produced code like this:

      /**
       * Autogenerated by Thrift
       *
       * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
       */
      using System;
      using System.Collections;
      using System.Collections.Generic;
      using System.Text;
      using System.IO;
      using Thrift;
      using Thrift.Collections;
      using Thrift.Protocol;
      using Thrift.Transport;
      namespace Thrift.Generated
      {
      
        [Serializable]
        public partial class DateTime : TBase
        {
          private long _ticks;
      
          public long Ticks
          {
            get
            {
              return _ticks;
            }
            set
            {
              __isset.ticks = true;
              this._ticks = value;
            }
          }
      
      
          public Isset __isset;
          [Serializable]
          public struct Isset {
            public bool ticks;
          }
      
          public void Read (TProtocol iprot)
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            wtftc William Blinn
            Votes:
            2 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated: