Archived

This forum has been archived. Please start a new discussion on GitHub.

slice2cs issue with member initialization

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

  • mes
    mes California
    Roman,

    Welcome to the forum, and thanks for the report!

    Regards,
    Mark