I have a parent class XYZ from which several other child classes inherit (ABC, DEF, GHI, etc.)
This parent class as well as its child classes are all in the same namespace 123.
In a method, from another namespace, I instantiate an object which has, among other things, a string property containing THE NAME of a child class.
This method, in a for loop, calls another method that expects 4 DateTime.
In each iteration of the loop, I have 5 string. The 2 base dates, the 2 reference dates and the name of the child class (which is obviously different in each iteration)
It is easy to convert the first 2 strings to DateTime.
But I would also like, in each iteration, to convert/cast my last two with THE VALUE contained in the variable of the name of the child class.
I tried several things but it always resulted in an error – often a “bad type” error…
for example :
foreach(var item in Items)
{
string className = "namespace.classname" + item.classname;
string startDate = DateTime.Parse(item.txtstartdate.Text);
string endDate = DateTime.Parse(item.txtenddate.Text);
HomeClass[] list = item.Itemslist
// Following is what I wish to accomplish
// I already have 2 strings with the reference dates within the 'list' object of 'item'
string startDateRef = (className)list.startDate;
string endDateRef = (className)list.enddate;
if(!validateDates(startDate, endDate, startDateRef, endDateRef))
return false;
return true;
}
1