initialize the repository at runtime based on a string

Ask general questions here.
jude.sqa
Posts: 1
Joined: Tue Oct 16, 2012 10:47 pm

initialize the repository at runtime based on a string

Post by jude.sqa » Fri Nov 30, 2012 1:45 am

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?

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

Re: initialize the repository at runtime based on a string

Post by Support Team » Fri Nov 30, 2012 12:00 pm

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