How do I cast a parameter passed into a function at runtime?
private object PopulateObject(object dataObj, System.Data.DataRow dataRow, string query)
{
object = DataAccess.Retriever.RetrieveArray<dataObj.GetType()>(query);
i’d like to know how to get dataObj.GetType() inside the type declaration at runtime.
Try something like this:
This will allow you to avoid any reflection in this method as the type argument supplied to
PopulateObjectwill also be the type argument forRetrieveArray. By calling this method the compiler will be able to infer the type ofT, allowing you to avoid writing runtime type checking.