I have a variant for initializing DbRecordData
public class DbRecordData : IList<DbFieldValue>, ICollection<DbFieldValue>, IEnumerable<DbFieldValue>, IEnumerable
{
public DbRecordData(DataRow row);
public DbRecordData(int countValues);
public int Count { get; }
public DbFieldValue this[int index] { get; set; }
public int Add(DbFieldValue item);
public int Add(string fieldName, object value);
public int Add(DataRow row, string fieldName, SqlDbType dataType);
public int Add(string fieldName, SqlDbType dataType, object value);
public void Clear();
public void FillSqlParameters(SqlParameter[] parameters, int fromIndex);
}
This is initializing:
DbRecordData dbRecord = new DbRecordData(2)
{
{"VehMarkName", SqlDbType.NVarChar, vehMarkName},
{"refVehTypeId", SqlDbType.Int, refVehTypeId}
};
This works and does not create warnings, but i haven’t found same examples in msdn.
is this variant correct? or is it hack?
It certainly works, yes. It’s the equivalent of:
If that’s basically the code you’d have written otherwise, then I’d prefer your object initializer version. If you want different code to that, then you may want to rethink things.