Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 963397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:39:53+00:00 2026-05-16T01:39:53+00:00

In an abstract class ( C# 3 ), there is a virtual method named

  • 0

In an abstract class (C# 3), there is a virtual method named GetData which returns a DataTable. The algorithm of the method is as following:

  1. Get SQL query string from the class.
  2. Get DataTable from database using above query.
  3. Do transformations on DataTable and return it.

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.

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:

public delegate object Convert(object objectToConvert);

The conversion would look something like that:

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;
}

For now, I have to override the method GetData() 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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T01:39:54+00:00Added an answer on May 16, 2026 at 1:39 am

    Okay, for now I have a following solution which does fully satisfy me:

    Every convertor implements following interface:

    public interface IConvertor
    {
     object Convert(object item);
    }
    

    Params class is as following:

    Type ColumnType { get; protected set; } // New type
    string[] ColumnNames { get; protected set; }
    IConvertor Convertor { get; protected set; }
    

    Every object have its own Params array property. I’ve got one method for every derived class and all what I have to do is to set up parameters.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 516k
  • Answers 516k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer There is no Python "object" (built-in or in the standard… May 16, 2026 at 6:56 pm
  • Editorial Team
    Editorial Team added an answer If you want to add a new variable (ie some_list),… May 16, 2026 at 6:56 pm
  • Editorial Team
    Editorial Team added an answer You want to get a correct output file for a… May 16, 2026 at 6:55 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Say I have an abstract class class NecessaryDanger { public: virtual void doSomethingDangerous() =0;
I have an abstract base class with a TcpClient field: public abstract class ControllerBase
Why is new/override required on abstract methods but not on virtual methods? Sample 1:
I have the following hierarchy: Graduate.cpp (abstract) College.cpp (abstract) Ecollege.cpp University.cpp (abstract) Tuniversity.cpp Huniversity.cpp
I think virtual alone is generally sufficient. Is there another reason to make it
I've got a class definition similar to the following: class UUID { public: //
(Django 1.x, Python 2.6.x) I have models to the tune of: class Animal(models.Model): pass
My GUI project in Qt has a lot of configuration pages classes which all
Basically, my question is short and sweet: Is the following a bad idea (encapsulating
Given an abstract interface and an implementation derived from that interface, where constructors are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.