C# Conditional Question

Class library usage, coding and language questions.
Fergal
Certified Professional
Certified Professional
Posts: 298
Joined: Tue Feb 18, 2014 2:14 pm
Location: Co Louth, Ireland
Contact:

C# Conditional Question

Post by Fergal » Tue Aug 09, 2016 3:12 pm

TC1
-- CodeModuleA

TC2
-- CodeModuleA

I'd like to place a C# conditional statement in CodeModuleA, that is based on which TC the module is being run from. Something along the lines of:

if (TC1)
{
...
}
else if (TC2)
{
...
}

Basically I want to do one thing if the code module is being run as part of TC1 and do something else if the code module is being run as part of TC2.

How can I write that condition?

Thanks!

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: C# Conditional Question

Post by krstcs » Tue Aug 09, 2016 3:52 pm

If you are doing different things, you should split your current module into different modules. Each module should do one thing.

If there is a portion of the module that you want to use in both places, take it out and make it its own module.

For example, say you want to do actions A and B in TC1, and A and C in TC2. Right now you have module A that does it all. Instead, make a module for A, a module for B, and a module for C. Then just put them where you need them.

This is why it is recommended to make the modules as small as possible. It is much easier to manage and manipulate them if they are only doing one thing.

To answer your actual question, I think it is possible, but I believe it uses an internal, non-public API that could change in the future without warning, and it is not recommended to use those.
Shortcuts usually aren't...

Fergal
Certified Professional
Certified Professional
Posts: 298
Joined: Tue Feb 18, 2014 2:14 pm
Location: Co Louth, Ireland
Contact:

Re: C# Conditional Question

Post by Fergal » Fri Aug 12, 2016 10:53 am

Thanks for your helpful reply krstcs, I am currently considering your suggestions and the best option for doing this.