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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:10:08+00:00 2026-05-29T06:10:08+00:00

I have a csv file where each row is a different type of record.

  • 0

I have a csv file where each row is a different type of record. I am parsing the csv and want to store the rows (varied types of records) in various types of custom classes.

At each row i need to instantiate a different class based on the record type.

So taken from other reflection examples, I have the code below;

      Type type = Type.GetType("myNamespace." + className);
      object recordclass = Activator.CreateInstance(type);

so i have an object named recordclass of the correct type, but how do I use it?

all I really want to do is access the properties of the class and populate the row data, and then later add to a container class.

I guess im missing something about the runtime nature of reflection. Please help me connect the dots!

Hope that all makes sense!

TIA,
Gary

  • 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-29T06:10:10+00:00Added an answer on May 29, 2026 at 6:10 am

    With the example you give you could cast your object to the actual type you need:

    Type type = Type.GetType("myNamespace." + className);
    object recordclass = Activator.CreateInstance(type);
    
    var record = recordClass as ConcreteRecordType;
    if(record != null)
        record.Name = csv["Name"];
    

    Alternatively look into using a Factory to return populated record objects:

    public class RecordFactory
    {
        RecordBase ParseCsvRow(string[] columns)
        {
            const int typeDescriminatorColumn = 0;
            switch (columns[typeDescriminatorColumn])
            {
                case "RecordTypeA":
                    return new RecordTypeA(columns[1], columns[2], ...);
                case "RecordTypeB":
                    return new RecordTypeB(columns[1], columns[2], ...);
                default:
                    throw new InvalidOperationException("Unexpected descriminator: " + columns[typeDescriminatorColumn]);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a csv file with 350,000 rows, each row has about 150 columns.
I want the following functionality using php I have a csv file. Each file
I have a csv file where each row defines a room in a given
I have a csv file which has a word for each row like this
I have a CSV file with a {LF} delimiting each row and a date
I have a csv file where amount and quantity fields are present in each
I have a CSV file with several entries, and each entry has 2 unix
I have CSV file and Macro in VBA. I want to open CSV file
I have a CSV file that holds about 200,000 - 300,000 records. Most of
I have my CSV file imported as such: records = FasterCSV.read(path, :headers => true,

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.