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

Michael Fischer edited comment on THRIFT-1026 at 2/2/11 10:53 PM:
------------------------------------------------------------------

This is actually one of the many issues I ran into yesterday while trying to 
build the entire stack on a Windows 7 based system. It looks like someone has 
built update the code in the trunk to work better.  Line 464 of the 
t_csharp_generator.cc class was updated from:

{noformat}
print_const_value(out, "this." + (*m_iter)->get_name(), t, 
(*m_iter)->get_value(), true, true);
{noformat}

to: 

{noformat}
print_const_value(out, "this." + (*m_iter)->get_name(), t, 
(*m_iter)->get_value(), true, true);
{noformat}

However, I don't think that is the correct fix.  Instead it should be updated 
to:

{noformat}
print_const_value(out, "this." + prop_name((*m_iter)), t, 
(*m_iter)->get_value(), true, true);
{noformat}

This would generate the correct C# code, which in the case above would look 
like:

{code:none}
public DateTimeZone() 
{
      this.TimeZone = "UTC";
}
{code}

Michael Fischer

      was (Author: mkfischer):
    This is actually one of the many issues I ran into yesterday while trying 
to build the entire stack on a Windows 7 based system. It looks like someone 
has built update the code in the trunk to work better.  Line 464 of the 
t_csharp_generator.cc class was updated from:

print_const_value(out, "this." + (*m_iter)->get_name(), t, 
(*m_iter)->get_value(), true, true);

to: 

print_const_value(out, "this." + (*m_iter)->get_name(), t, 
(*m_iter)->get_value(), true, true);

However, I don't think that is the correct fix.  Instead it should be updated 
to:

print_const_value(out, "this." + prop_name((*m_iter)), t, 
(*m_iter)->get_value(), true, true);

This would generate the correct C# code, which in the case above would look 
like:

{code:none}
public DateTimeZone() 
{
      this.TimeZone = "UTC";
}
{code}

Michael Fischer
  
> C# default value code generation problem
> ----------------------------------------
>
>                 Key: THRIFT-1026
>                 URL: https://issues.apache.org/jira/browse/THRIFT-1026
>             Project: Thrift
>          Issue Type: Bug
>          Components: C# - Compiler
>    Affects Versions: 0.5
>         Environment: Windows, Mac
>            Reporter: William Blinn
>
> I have a thrift file that looks like this:
> {code}
> // Time stamp with a timezone specification for normalization.
> struct DateTimeZone
> {
>     1: i64 ticks,
>     2: optional string timeZone = "UTC",
> }
> {code}
> When I generate C#, it produces code like this:
> {code}
>   [Serializable]
>   public partial class DateTimeZone : TBase
>   {
>     private long _ticks;
>     private string _timeZone;
>     public long Ticks
>     {
>       get
>       {
>         return _ticks;
>       }
>       set
>       {
>         __isset.ticks = true;
>         this._ticks = value;
>       }
>     }
>     public string TimeZone
>     {
>       get
>       {
>         return _timeZone;
>       }
>       set
>       {
>         __isset.timeZone = true;
>         this._timeZone = value;
>       }
>     }
>     public Isset __isset;
>     [Serializable]
>     public struct Isset {
>       public bool ticks;
>       public bool timeZone;
>     }
>     public DateTimeZone() {
>       this.timeZone = "UTC";
>     }
> ...
> {code}
> The constructor, which sets the default value should be this.TimeZone = "UTC" 
> because the property is TimeZone, not timeZone. The constructor should set 
> the property rather than the field so that __isset is marked properly.
> The compile error I get when I try to compile the code that thrift generates 
> is like this:
> {code}
>       [csc] d:\code\Thrift\Generated\DateTimeZone.cs(59,12): error CS1061: 
> 'Thrift.Generated.DateTimeZone' does not contain a definition for 'timeZone' 
> and no extension method 'timeZone' accepting a first argument of type 
> 'Thrift.Generated.DateTimeZone' could be found (are you missing a using 
> directive or an assembly reference?)
> {code}

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to