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

C# Union Typing

    XMLWordPrintableJSON

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 0.9.1
    • Component/s: C# - Compiler
    • Labels:
      None
    • Patch Info:
      Patch Available

      Description

      Given the thrift IDL:

      struct A {
        0: i32 value
      }
      
      union AUnion {
        0: A field1,
        1: A field2,
        2: i32 value
      }
      

      We should generate a C# subclassing tree:

      class A : TBase {
        int Value { get;set; }
      }
      
      abstract class AUnion : TBase {
        abstract object Data { get; }
        protected int field;
        abstract void WriteUnionField(TProtocol tprot);
      
        class field1 : AUnion {
          A _data;
          override object Data { get { return _data; } }
          public field1(A data) {
            this._data = data;
            this.field = 0;
          }
        }
      
        class field2 : AUnion {
          A _data;
          override object Data { get { return _data; } }
          public field2(A data) {
            this._data = data;
            this.field = 1;
          }
        }
      
        class value : AUnion {
          int _data;
          override object Data { get { return _data; } }
          public value(int data) {
            this._data = data;
            this.field = 2;
          }
        }
      }
      

      This gives us creation syntax of:

      var aunion = new AUnion.value(10);
      

      This should be an optional parameter to the compiler since it is a breaking change to existing code.

        Attachments

        1. 1786-v2.patch
          16 kB
          Carl Yeksigian
        2. 1786-make-fix.patch
          0.4 kB
          Carl Yeksigian
        3. 1786.patch
          12 kB
          Carl Yeksigian

          Issue Links

            Activity

              People

              • Assignee:
                carlyeks Carl Yeksigian
                Reporter:
                carlyeks Carl Yeksigian
              • Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: