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

  • Home
  • SEARCH
  • 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 3931908
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:23:55+00:00 2026-05-19T23:23:55+00:00

I have a WPF-mvvm application. I need to read an excel file..and create a

  • 0

I have a WPF-mvvm application.

I need to read an excel file..and create a list of Dto (data transfer objects).

EX:
If below are two types of DTOs
Class A{ // Some properties here} Class B{// Some other properties here}

On run time, I will pass the reference to an excel file…and depending upon from which window I am calling this function I need list of that particular DTO (That means -> List(A) or List(B)).

Can I use function like below (with generics)..?
But How would I know what are the properties in each class at run time ?

 private static IList<T> CreateLookupList<T>(string currentFileName)
        {
            List<T> items = new List<T>();

            Workbook internalWorkBook = Workbook.Load(currentFileName);
                //Create data table for each worksheet
                foreach (Worksheet curWorksheet in internalWorkBook.Worksheets)
            {
            }

            return items;
        }
  • 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-19T23:23:55+00:00Added an answer on May 19, 2026 at 11:23 pm

    Your suggested approach would only work if ClassA and ClassB both implemented the same interface, or both descended from the same superclass. If that were the case, you could do something like this:

    public interface IWorksheetHandler
    {
        void LoadFromWorksheet(Worksheet worksheet);
    }
    
    public class DtoLoader
    {
         public static IList<T> CreateLookupList<T>(string currentFileName) where T:IWorksheetHandler, new()
         {
              List<T> items = new List<T>();
              Workbook internalWorkBook = Workbook.Load(currentFileName);
              foreach (Worksheet worksheet in internalWorkBook.Worksheets)
              {
                  T dto = new T();
                  dto.LoadFromWorksheet(worksheet );
                  items.Add(dto);
              }
              return items;
          }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am coding a WPF application using MVVM pattern. I don't need to have
In my WPF MVVM application my model is a complex tree of Model objects
I have a wpf application in mvvm pattern. In main view, I have few
In my MVVM based WPF application I have a lot of different ViewModel types
I have an application which I am developing using WPF\Prism\MVVM. All is going well
I'm working on my first true WPF MVVM pattern application. Currently I have a
I have a WPF application that mostly follows MVVM, which I am trying to
I have a WPF application which is built on the MVVM design pattern. I
Considering you have an MVVM Architecture in WPF like Josh Smith's examples How would
I have a WPF application in VS 2008 with some web service references. For

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.