[ 
https://issues.apache.org/jira/browse/THRIFT-1127?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13596392#comment-13596392
 ] 

Thunder Stumpges commented on THRIFT-1127:
------------------------------------------

Jens, thanks for taking a look. While I do agree with you about the 
inconsistent behavior, I do have (I think) an issue that I cannot resolve 
without having the constructor for initialization.

I am fairly certain that what Vadim is suggesting is for Thrift to use defaults 
to initialize fields and NEVER write a default constructor (to solve your issue 
of inconsistency). My issue is that I need to perform initialization 
(conditionally or not, but usually not) on Thrift generated members which I 
cannot do from the partial class. The only place I have to even simply 
initialize a struct member to a new instance is in the partial class in a 
constructor.

Please let me know if you have another suggestion for this, or if you're open 
to solving it with Vadim's suggestion of performing Thrift initialization in 
the field defaults, and leaving the constructor to the partial class.

Thanks!
Thunder

                
> C# should not generate default constructor
> ------------------------------------------
>
>                 Key: THRIFT-1127
>                 URL: https://issues.apache.org/jira/browse/THRIFT-1127
>             Project: Thrift
>          Issue Type: Bug
>          Components: C# - Compiler
>    Affects Versions: 0.5
>            Reporter: William Blinn
>         Attachments: DontCreateEmptyDefaultConstructor.patch
>
>
> 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:
> {code}
> struct DateTime
> {
>     1: required i64 ticks,
> }
> {code}
> produces
> {code}
> /**
>  * 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)
> ...
> {code}
> It would be great if it instead produced code like this:
> {code}
> /**
>  * 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)
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to