That's all, I have a method that returns a list. This method is used to return SQL StoredProcedures parameters, views and functions based on the name. I want to create a list of objects and return this list to the caller. Method below
private List<T> GetInputParameters<T>(string spFunViewName) { string strSql = String.Format( "SELECT PARAMETER_NAME, DATA_TYPE FROM INFORMATION_SCHEMA.PARAMETERS " + "WHERE SPECIFIC_NAME = '{0}' AND PARAMETER_MODE = 'IN';", spFunViewName); List<string[]> paramInfoList = new List<string[]>(); DataTable paramDt = Utilities.DTFromDB(conn, "InputParmaters", strSql); if (paramDt != null) { Converter<DataRow, string[]> rowConverter = new Converter<DataRow, string[]>(Utilities.RowColConvert); paramInfoList = Utilities.ConvertRowsToList<string[]>(paramDt, rowConverter); } else return null;
I obviously cannot create an instance of T via new and go to the constructor, but it should be clear what I'm trying to do. Is there a way to do what I want using three additional methods?
Note. The main problem is that the number of parameters that I pass to T can be either two OR three.
Thank you for your time.
Edit: struct I use the following
public struct Database { public string name { get; set; } public string filename { get; set; } public List<Table> tables { get; set; } public List<StoredProcedure> sps { get; set; } public List<Function> funcs { get; set; } public List<View> views { get; set; } public Database(string name, string filename) { this.name = name; this.filename = filename; } } protected internal struct StoredProcedure { public string name { get; set; } public List<string[]> parameters { get; set; } public StoredProcedure(string name, List<string[]> parameters) { this.name = name; this.parameters = parameters; } } protected internal struct Function { public string name { get; set; } public string output { get; set; } public List<string[]> parameters { get; set; } public Function(string name, string output, List<string[]> parameters) { this.name = name; this.output = output; this.parameters = parameters; } } protected internal struct View { public string name {get; set;} public List<string[]> parameters { get; set; } public View(string name, List<string[]> parameters) { this.name = name; this.parameters = parameters; } }
Moonknight
source share