Page 1 of 1

initialize the repository at runtime based on a string

Posted: Fri Nov 30, 2012 1:45 am
by jude.sqa
I have two Repositories IntegrationRepo and OtherEnvironmentRepo. I am trying to initialize the repository at runtime based on a string (domain where I am running), but getting error:
************************************************************
//code snippet sample:
// declare the repo with base class
RepoGenBaseFolder repo;

//initialize the Repo based on the string strDomain

repo = strDomain == "integration.testdomain.com" ? IntegrationRepo.Instance : OtherEnvironmentRepo.Instance;

Type of conditional expression cannot be determined because there is no implicit conversion between 'IntegrationRepo' and 'OtherEnvironmentRepo' (CS0173)

How can I solve this?

Re: initialize the repository at runtime based on a string

Posted: Fri Nov 30, 2012 12:00 pm
by Support Team
Hello,

Please try out the following code:
repo = strDomain == "integration.testdomain.com" ? (RepoGenBaseFolder)IntegrationRepo.Instance : (RepoGenBaseFolder)OtherEnvironmentRepo.Instance;
I would use a if-statement as shown below:
if (strDomain == "integration.testdomain.com")
	repo = IntegrationRepo.Instance;
else
	repo = OtherEnvironmentRepo.Instance;
Regards,
Markus (T)