For Some debug i need to get the list of SqlDataRecord generated by the method IEnumerator IEnumerable.GetEnumerator() of the class TVPDataCollection
this code :
TVPDataCollection<AttributiDocumento> oAttributiDocumentoList = new TVPDataCollection<AttributiDocumento>();
AttributiDocumento doc1 = new AttributiDocumento();
AttributiDocumento doc2 = new AttributiDocumento();
oAttributiDocumentoList.Add(doc1);
oAttributiDocumentoList.Add(doc2);
var x = oAttributiDocumentoList.GetEnumerator();
x is a list of AttributiDocumento, but i need a list of SqlDataRecord because i want to inspect the values. what's the way to call the GetEnumerator() that returns SqlDataRecord?
public class TVPDataCollection<T> : List<T>, IEnumerable<SqlDataRecord> where T : class
{
IEnumerator<SqlDataRecord> IEnumerable<SqlDataRecord>.GetEnumerator()
{
List<SqlMetaData> records = new List<SqlMetaData>();
var properties = typeof(T).GetProperties();
foreach (var prop in properties)
{
SqlType oSqlType = GetSqlType(prop);
if (oSqlType.UseSize)
records.Add(new SqlMetaData(prop.Name, oSqlType.SqlDbType, oSqlType.Size));
else
records.Add(new SqlMetaData(prop.Name, oSqlType.SqlDbType));
}
SqlDataRecord oSqlDataRecord = new SqlDataRecord(records.ToArray());
foreach (T data in this)
{
for (int i = 0; i < properties.Length; i++)
{
oSqlDataRecord.SetValue(i, properties[i].GetValue(data, null));
}
yield return oSqlDataRecord;
}
}
}
public class AttributiDocumento
{
public int IdProvPart { get; set; }
//uso stringa in quanto con data agigunge 2 ore del fuso orario
public DateTime Data { get; set; }
public int Articolo { get; set; }
public int ExArticolo { get; set; }
public int DocVer { get; set; }
[LenAttribute(255)]
public string Altro { get; set; }
public AttributiDocumento()
{
this.Data = new DateTime(1900, 1, 1);
this.Altro = string.Empty;
}
}