I have a class hierarchy like the following:
public class Country : MainObj
public class MainObj : BaseEntity
and I have business logic classes like the following:
public class CountryBLL<TEntity> : CountryDLL<TEntity>,IBaseBLL<TEntity> where TEntity : Country
public class MainObjBLL<TEntity> : MainObjDLL<TEntity>, IBaseBLL<TEntity> where TEntity : MainObj
Now the thing I want to implement is a function in that I decide which class and bll should I get for this I added IBaseBLL interfaces for return type of my function
My function is the following:
public static IBaseBLL<T> GetProperBllFromObjName<T>(string entityName)
{
IBaseBLL<T> baseBLL = null;
switch (entityName)
{
case "Country":
CountryBLL<Country> aa = new CountryBLL<Country>();
baseBLL = (IBaseBLL<T>) aa; //error line
break;
}
return baseBLL;
}
when I call the function like this:
IBaseBLL<BaseEntity> mainBll = GetProperBllFromObjName("Country");
But I am unable to cast exception in line where i added comment "error line"
so what should i do in this case. The only thing i want is writing a function to decide which bll should i use. (i dont want to change bll declerations).