We have third party Test class,which has a method "Convert" which only accepts arrays of DataSample.
public class Test{
public class DataSample{
public int testVar{get;set;}
public int testVar2{get;set;}
}
//some methods
public static List<someType> Convert(DataSample[] data)
{
//execute some steps
}
}
We have a stored procedure which gives below output.it basically stored the object creation structure in col1 field
Id col1
1 new Test.DataSample{ testVar=24,testVar=11}
2 new Test.DataSample{ testVar=26,testVar=15}
3 null
4 null
5 new Test.DataSample{ testVar=28,testVar=11}
I am trying to create a class and invoke Convert method of Test class by providing array of DataSample type object. the Data type objects are stored on col1 field as above .
Public class ImplementTest{
public void CallConvert(){
var inputs = new Test.DataSample[] { };
// get the data from DB in list
List<object> InputList = new List<object>();
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.CommandText = "dbo.ReadAll_Input";
con.Open();
using (SqlDataReader dr = cmd.ExecuteReader())
{
while (dr.Read())
{
InputList.Add(dr["col1"]);
}
}
}
}
//remove null
InputList.RemoveAll(x => x == DBNull.Value);
//create an array of Test.DataSample type
??
//call third party class
var ourput = Test.Convert(inputs).ToArray();
}
}
How to pass all objects of InputList to inputs array so that it can passed to third party method Convert() which only accepts array of DataSample type ?
or is there a direct way we can create an array of DataSample type while fetching objects from stored procedure.
any hints on this please?
Thanks!
"new Test.DataSample{ testVar=24,testVar=11}"to an array of type DataSample?