Parameterless constructor - why?

Class library usage, coding and language questions.
dankod
Posts: 1
Joined: Thu Nov 12, 2015 1:31 pm

Parameterless constructor - why?

Post by dankod » Thu Nov 12, 2015 1:43 pm

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?

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Parameterless constructor - why?

Post by Support Team » Thu Nov 12, 2015 10:46 pm

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