C#: DataTable conversion row-by-row <p>In an abstract class (<strong>C# 3</strong>), there is a virtual method named <code>GetData</code> which returns a DataTable. The algorithm of the method is as following:</p> <ol> <li>Get SQL query string from the class.</li> <li>Get DataTable from database using above query.</li> <li>Do transformations on DataTable and return it.</li> </ol> <p>In the 3rd point, I clone the original DataTable in order to change the Type of column (I can't do that on populated table and can't setup this at the 2nd point) and enumerate every row in which I copy and transform data from the original one. Transformations depends on the class, every one has private methods which transforms data on its own.</p> <p>The question is: How to make a method in a base class which will be based on the following three params: column name which will be converted, Type of new column and action during the transformation. Two first are quite simple but I'm not sure about the third one. I thought about designing a new class which will store these three parameters, and the action will be stored as following delegate:</p> <pre><code>public delegate object Convert(object objectToConvert); </code></pre> <p>The conversion would look something like that:</p> <pre><code>int rowCounter = 0; foreach(DataRow row in dt.Rows) { foreach(var item in Params) { row[item.ColumnIndex] = item.Convert(originalDataTable.Rows[rowCounter].ItemArray[item.ColumnIndex]); } ++rowCounter; } </code></pre> <p>For now, I have to override the method <code>GetData()</code> in every class I want to have a transformations which causes a large duplication of code. The point I want to achieve is to make a base class which will be based on params I mentioned above. Is the above solution good for this problem or is it any other way to do that? </p>