I have 15 string value. For example: excel sheet names: Customers, Products etc. these sheet,s names are the same as db Tables also Ef 4.0 Entities Name. (Products.cs, Customers.cs)
String[] excelSheets = GetExcelSheetNames(String.Format(@"C:\{0}\{1}", UserName, FileUploadForExcel.FileName));
foreach (String excelSheet in excelSheets)
{
GetEntity(excelSheet);
}
protected TModel GetEntity(string ClassNameFromExcelSheetName)
{
return(TModel)Activator.CreateInstance(ClassNameFromExcelSheetName);
}
above code is a kind of simple foresight. NOT real codes. How to create instance only using string value?
you can create instance of class by class name in string representation using .NET Reflection
Check the following article on reflection:
http://www.codeproject.com/KB/dotnet/Reflection.aspx