Page 1 of 1

Parameterless constructor - why?

Posted: Thu Nov 12, 2015 1:43 pm
by dankod
Why exactly do you need a parameterless constructor in code modules?

Code: Select all

  
        public UserModule()
        {
            // Do not delete - a parameterless constructor is required!
        }
I've run some test and they're working just fine without one. In C#, if you don't have any other constructors, you shouldn't have to define a parameterless constructor - it is automatically provided.

So, is there another reason Ranorex requires an explicit default constructor?

Re: Parameterless constructor - why?

Posted: Thu Nov 12, 2015 10:46 pm
by Support Team
You are right, there is always an implicit parameterless constructor if (and only if) no other constructor (with parameters) is defined.
dankod wrote:So, is there another reason Ranorex requires an explicit default constructor?
No, Ranorex just needs a parameterless constructor to create the module at runtime. So the code for the parameterless constructor is there in case you define a second constructor with parameters. You can safely delete the parameterless constructor if you make sure, you don't create a constructor with parameters.

Regards,
Alex
Ranorex Team