Home Bug Reports

slice2cs issue with member initialization

romankromank Member Roman KiseliovOrganization: PersonalProject: DB facade
Given
module M
{
    ["clr:property"]
    class A
    {
        int f = 1;
    };
};

slice2cs generates
class A
{
   private int f_prop;

   public virtual int f 
   {
        get 
        { 
             return f_prop; 
        }; 

        set 
        { 
             f_prop = value; 
        }; 
   }

   A()
   {
        [COLOR="Red"][B]this.f = 1;[/B][/COLOR]
   }
}

Using virtual property in constructor is a bad practice. slice2cs must generate initialization code by using only data members:
class A
{
   private int f_prop;

   public virtual int f 
   {
        get 
        { 
             return f_prop; 
        }; 

        set 
        { 
             f_prop = value; 
        }; 
   }

   A()
   {
        [COLOR="Green"][B]this.f_prop = 1;[/B][/COLOR]
   }
}

Comments

  • mesmes CaliforniaAdministrators, ZeroC Staff Mark SpruiellOrganization: ZeroC, Inc.Project: Ice Developer ZeroC Staff
    Roman,

    Welcome to the forum, and thanks for the report!

    Regards,
    Mark
Sign In or Register to comment.