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 6901255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:39:01+00:00 2026-05-27T07:39:01+00:00

I have 5 classes which represent a row of a grid of data. All

  • 0

I have 5 classes which represent a row of a grid of data. All of these classes inherit from an abstract class of CoreGrid.

I have an export mechanism, which uses reflection to figure out the columns to export. At the minute, I have a method for each type of grid (ExportOrganisations, ExportPeople, ExportEvents) however this is horrible, as the only thing different between them is the part where it looks up the type. Example code is shown below:

public string ExportEvents(List<EventGrid> events)
{
    DataTable report = new DataTable();

    EventGrid ev = new EventGrid();

    Type t = ev.GetType();

    PropertyInfo[] props = t.GetProperties();

    foreach (PropertyInfo prop in props)
    {
        if (!prop.Name.Contains("ID"))
        {
            report.Columns.Add(prop.Name);
        }
    }

    foreach (var item in events)
    {
        DataRow dr = report.NewRow();

        Type itemType = item.GetType();

        PropertyInfo[] itemProps = itemType.GetProperties();

        foreach (PropertyInfo prop in itemProps)
        {
            if (report.Columns.Contains(prop.Name))
            {
                if (prop.GetValue(item, null) != null)
                {
                    dr[prop.Name] = prop.GetValue(item, null).ToString().Replace(",", string.Empty);
                }
            }
        }

        report.Rows.Add(dr);
    }

    return GenerateCSVExport(report, ExportType.Events);
}

My question is, how would I condense these methods into one method where the method accepts a list which inherits from CoreGrid?

  • 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-27T07:39:02+00:00Added an answer on May 27, 2026 at 7:39 am
    public string ExportEvents<T>(List<T> events) where T : CoreGrid
    {
        DataTable report = new DataTable();
    
        Type t = typeof(T);
    
        //your magic here
    }
    

    And then use

    var result = ExportEvents<EventGrid>(eventList);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider I have some abstract Vehicle class and car, truck, motorcycle abstract classes which
I have various classes which all contain address details, i.e. AddressLine1, AddressLine2, AddressLine3, Suburb,
i have two data classes which hold only data members(no functions). One is CallTask
I have two classes one of which inherits from the other. Im trying to
I have two classes which represent a special kind of numeric value. Let's call
I have a number of classes that represent various computer components, each of which
I have crosstab which has row columns indicating different classes, and then peoples names
I have my own classes that represent image data. They have various underlying structure
I have 2 classes which represent a matrix: 1. RegularMatrix - O(n^2) representation 2.
I have following classes: public abstract class CustomerBase { public long CustomerNumber { get;

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.