You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Jens Geyer (Jira)" <ji...@apache.org> on 2020/05/25 00:55:00 UTC
[jira] [Commented] (THRIFT-1786) C# Union Typing
[ https://issues.apache.org/jira/browse/THRIFT-1786?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17115610#comment-17115610 ]
Jens Geyer commented on THRIFT-1786:
------------------------------------
I just had another two hours spent on the specialties of this construct, not to mention the and non-existing support of Equals(). The more and often I get stopped by this in sight distance of the goal line, the less I like it.
> C# Union Typing
> ---------------
>
> Key: THRIFT-1786
> URL: https://issues.apache.org/jira/browse/THRIFT-1786
> Project: Thrift
> Issue Type: New Feature
> Components: C# - Compiler
> Reporter: Carl Yeksigian
> Assignee: Carl Yeksigian
> Priority: Major
> Fix For: 0.9.1
>
> Attachments: 1786-make-fix.patch, 1786-v2.patch, 1786.patch
>
>
> Given the thrift IDL:
> {code}
> struct A {
> 0: i32 value
> }
> union AUnion {
> 0: A field1,
> 1: A field2,
> 2: i32 value
> }
> {code}
> We should generate a C# subclassing tree:
> {code}
> 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;
> }
> }
> }
> {code}
> This gives us creation syntax of:
> {code}
> var aunion = new AUnion.value(10);
> {code}
> This should be an optional parameter to the compiler since it is a breaking change to existing code.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)