[
https://issues.apache.org/jira/browse/THRIFT-1127?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13604906#comment-13604906
]
Thunder Stumpges commented on THRIFT-1127:
------------------------------------------
Hi Jens, I put quite a number of hours into this tonight, and ran into several
issues. See below:
1. Use of auto-properties for required members with default values:
I had to change the logic in deciding between private field backed property and
auto-property for Required members. If we use auto-property, we can't do the
field level initialization. Any time we have a default, we need a field backed
property.
This undoes a little bit of the work done in bug THRIFT-1783. What I did was
add the field-backed property if a default value was present, but leave out the
stuff for _isset when it is required. I am somewhat uncomfortable doing this,
though I don't fully understand why the fixing of bug 1783 required removal of
the field-backed properties, or the _isset either. Was it just an optimization?
Does this sound OK?
2. Required Member Constructor (from bug THRIFT-1783):
Bug THRIFT-1783 creates a constructor taking all required members. Not sure if
this is also just a convenience thing, but it also makes the "no-args
constructor" required. I would like to get rid of this constructor. It's easy
enough to just use object initialization syntax. Is this OK?
3. Set initialization with const value:
For some reason (not sure why, do you?) The type name rendered for Set is not
just the .net HashSet<T> but it uses a thrift version called THashSet<T> which
does not have a constructor taking IEnumerable<T> like the List<T>,
Dictionary<K,V>, and HashSet<T> .net versions do. Therefore my code which
initialized the collections defaults fails:
{code}
private List<string> _OptListWDef = new List<string>(Constants.CONSTLIST);
// WORKS
private Dictionary<string, string> _OptMapWDef = new Dictionary<string,
string>(Constants.CONSTMAP); // WORKS
private THashSet<string> _OptSetWDef = new
THashSet<string>(Constants.CONSTSET); // FAILS!
{code}
If I change the type name from THashSet to HashSet, everything compiles fine.
Not sure how you want to handle this.
Let me know about these three things, and I think I can have a patch in to you
tomorrow sometime.
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