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 2013/04/24 19:35:18 UTC

[jira] [Comment Edited] (THRIFT-1742) Optionally implement hashcode and equals in c#

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

Jens Geyer edited comment on THRIFT-1742 at 4/24/13 5:35 PM:
-------------------------------------------------------------

I really would like to commit this, but ...

1. I had some Problems applying to the current trunc, because of the Union patch (not your fault, but I want to mention that). 

2. The "hashcode" Option is missing in the help text at the end of the C# Generator. That's quite simple to fix, so not a big problem either.

3. What is really annoying is that I get warnings at generated lines like these:

{code}
    public override int GetHashCode() {
      int hashcode = 0;
      unchecked {
        hashcode = (hashcode * 397) ^(Value == null ? 0 : (Value.GetHashCode()));      }
      return hashcode;
    }
{code}

If Value is a basic type like i32, double or an enum, then the Compiler emits a "Warning: The result of the expression is always 'false' since a value of type 'int' is never equal to 'null' of type 'int?'".

I used the following Options:

{code}
thrift  -v --gen csharp:serial,asyncctp,hashcode  somefile.thrift
{code}

4. It seems that there should be an additional eol emitted by the Generator. In some cases the hashcode = ... lines are added at the end of the previous line instead on a new line. Happens only in some cases. I can provide a test case, if needed.


                
      was (Author: jensg):
    I really would like to commit this, but ...

1. I had some Problems applying to the current trunc, because of the Union patch (not your fault, but I want to mention that). 

2. The "hashcode" Option is missing in the help text at the end of the C# Generator. That's quite simple to fix, so not a big problem either.

3. What is really annoying is that I get warnings at generated lines like these:

{code}
    public override int GetHashCode() {
      int hashcode = 0;
      unchecked {
        hashcode = (hashcode * 397) ^(Value == null ? 0 : (Value.GetHashCode()));      }
      return hashcode;
    }
{code}

If Value is a basic type like i32, double or an enum, then the Compiler emits a "Warning: The result of the expression is always 'false' since a value of type 'int' is never equal to 'null' of type 'int?'".

I used the following Options:

{code}
thrift  -v --gen csharp:serial,asyncctp,hashcode  somefile.thrift
{code}



                  
> Optionally implement hashcode and equals in c#
> ----------------------------------------------
>
>                 Key: THRIFT-1742
>                 URL: https://issues.apache.org/jira/browse/THRIFT-1742
>             Project: Thrift
>          Issue Type: Improvement
>          Components: C# - Compiler
>            Reporter: T Jake Luciani
>            Assignee: Carl Yeksigian
>         Attachments: 1742.patch, 1742-v2.patch, 1742-v3.patch, 1742-v4.patch, 1742-v5.patch, 1742-v6.patch
>
>
> It would be very helpful to have a compiler flag that implements hashCode and equals for c# generated structs.  Java has this capability.

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