I have two auto-generated classes, say Type1 and Type2. Each of these classes deals with other related auto-generated classes. Since they are auto-generated, I cannot change them to use either abstract classes or interfaces. I have two methods, one return Type1 and the other return Type2. Type1 and Type2 are almost the same, so I wanted to call them like below to avoid code duplication on my side, of course it did not work as the type needs to be known in compile time.
var response = string.IsNullOrWhiteSpace(inputObject.HistoricYear) ? Type1: Type2;
if (string.IsNullOrWhiteSpace(inputObject.HistoricYear))
{
response = TsiService.GetAccountTransactionsList(inputObject);
} else
{
response = TsiService.GetAccountTransactionsHist(inputObject);
}
I also tried using object and then I get this error object does not contain a definition for MEMBER_1 and MEMBER_2, etc.:
var response = null;
if (string.IsNullOrWhiteSpace(inputObject.HistoricYear))
{
response = TsiService.GetAccountTransactionsList(inputObject);
} else
{
response = TsiService.GetAccountTransactionsHist(inputObject);
}
CustomObject.member1 = response.MEMBER_1;
CustomObject.member2 = response.MEMBER_2;
Any idea how to do it?