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

Jens Geyer edited comment on THRIFT-1780 at 12/9/12 5:56 PM:
-------------------------------------------------------------

Nice!
But ... using your patch I get without nullable:

{code}
    private bool _Visible;

    public bool Visible
    {
      get
      {
        return _Visible;
      }
      set
      {
        __isset.Visible = true;
        this._Visible = value;
      }
    }
{code}


Same with nullable:
{code}
    private bool _Visible;

    public bool? Visible
    {
      get
      {
        return __isset.Visible ? (bool?)_Visible : null;
      }
      set
      {
        __isset.Visible = value.HasValue;
        if (value.HasValue) this._Visible = value.Value;
      }
    }
{code}

Couldn't the value be stored as the nullable, effectively combining both the 
value and the isset flag into one? That way the conversions now introduced in 
the getters could be avoided.

Something like this (not tested!):

{code}
    private bool? _Visible;

    public bool Visible
    {
      get
      {
        return _Visible;
      }
      set
      {
        _Visible = value;
      }
    }
{code}


Maybe if autoprops are mono-comaptible (are they? not sure about that) even 
simpler:

{code}
    public bool? Visible { get; set;}
{code}


                
      was (Author: jensg):
    Nice!
But ... using your patch I get without nullable:

{code}
    private bool _Visible;

    public bool Visible
    {
      get
      {
        return _Visible;
      }
      set
      {
        __isset.Visible = true;
        this._Visible = value;
      }
    }
{code}


Same with nullable:
{code}
    private bool _Visible;

    public bool? Visible
    {
      get
      {
        return __isset.Visible ? (bool?)_Visible : null;
      }
      set
      {
        __isset.Visible = value.HasValue;
        if (value.HasValue) this._Visible = value.Value;
      }
    }
{code}

Couldn't the value be stored as the nullable, effectively combining both the 
value and the isset flag into one? That way the conversions now introduced in 
the getters could be avoided.

Something like this (not tested!):

{code}
    private bool? _Visible;

    public bool Visible
    {
      get
      {
        return _Visible;
      }
      set
      {
        _Visible = value;
      }
    }
{code}


Maybe if autoprops are mono-comaptible (?) even simpler:

{code}
    public bool? Visible { get; set;}
{code}


                  
> Add option to generate nullable values
> --------------------------------------
>
>                 Key: THRIFT-1780
>                 URL: https://issues.apache.org/jira/browse/THRIFT-1780
>             Project: Thrift
>          Issue Type: New Feature
>          Components: C# - Compiler
>            Reporter: Carl Yeksigian
>            Priority: Minor
>         Attachments: 1780.patch
>
>
> There should be an option to generate nullable value types for C#.
> If a value is not set, then it would return as null rather than default 
> value. If a value is updated to null, then it would become unset.

--
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