Im sorry for my bad english. There is a problem that I cannot solve because I am new to generics.
When the constructor method is running, How can I detect the incoming class. I have to continue the process by accessing the class properties. Can you help me about the way I should follow?
public class IslemeBasla<T> where T : class, IEntity
{
private string _profilName;
public int _processCount;
private IWebDriver _driver;
private ChromeDriverService _cService;
private string _arguments;
public T _hEntity;
public IslemeBasla()
{
Type type = typeof(T);
switch (type.Name)
{
// I want to do something like this.
case "Facebook": _hEntity = (facebook)T;
break;
case "Twitter":
break;
case "Youtube":
break;
case "Instagram":
break;
default:
break;
}
}
}
Update ; All classes have the same characteristics. they inherit from a single class. but some classes have their own characteristics.
The method I have created for this is as follows. It's a not good example, but that's how I came to the solution.
public class IslemeBasla<T> where T : class, IEntity
{
private Facebook _fbHesap;
private Youtube _ytHesap;
private Instagram _insHesap;
private Twitter _twHesap;
public T _hEntity;
private string _browserLoc;
public void SetConfigs()
{
Type type = typeof(T);
switch (type.Name)
{
_fbHesap = _hEntity as Facebook;
_browserLoc = _fbHesap.Mail;
break;
case "Twitter": _twHesap = _hEntity as Twitter;
_browserLoc = _twHesap.Mail;
break;
case "Youtube": _ytHesap = _hEntity as Youtube;
_browserLoc = _ytHesap.Mail;
break;
case "Instagram": _insHesap = _hEntity as Instagram;
_browserLoc = _insHesap .Mail;
break;
default:
break;
}
}
}