0

I'm currently having 2 wrapper classes to contain DataReader and DataRow, respectively. The wrapper classes implement same interface IIndexer. They are used because I have lots of methods that just indexes the columns to get the values:

Here is the example: How can I read from a DataRow or a DataReader using the same code?

Now I need to have 3rd option for Insert-statements. Now there's no DataTables to get DataRow and no need to read from Db.

This could mayber be done by having IndexerWrapper (or DictionaryWrapper):

public class IndexerWrapper : IIndexer
{
    private readonly Dictionary<string, object> _indexer;

    public DataReaderWrapper(Dictionary<string, object> indexer)
    {
        _indexer = indexer;
    }

    public object this[string index]
    {
        get { return _indexer[index]; }
    }
}

I have the column information of database table already so i would loop the columns and add the column names as keys.

Is there a better way to do it? This is not so handy because I have to initialize it. What about performance? This could be in future used for large masses and now column names are stored for each item. Is there really overhead compared to collection of DataRows?

Thanks -matti

Community
  • 1
  • 1
char m
  • 7,840
  • 14
  • 68
  • 117
  • Have you tried using DataColumn.Ordinal? – gabnaim May 14 '13 at 17:57
  • What do you mean by that? I need an object that can be indexed like mimicsADataRow["NAME"]. – char m May 15 '13 at 06:34
  • Sorry, I misread it. If you want to read your data by column name, you got the right solution. It will not add much overhead, you will only have to add the column names once for each read. However I am surprised you would want to wrap classes to reuse a certain implementation. Your calling classes should not depend on the implementation - instead create a common interface to get your data, and create multiple implementations as needed. – gabnaim May 15 '13 at 14:04

0 Answers0