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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:35:13+00:00 2026-05-18T08:35:13+00:00

have a look at this code please: public void BindElements<T>(IEnumerable<T> dataObjects) { Paragraph para

  • 0

have a look at this code please:

public void BindElements<T>(IEnumerable<T> dataObjects)
{
    Paragraph para = new Paragraph();

    foreach (T item in dataObjects)
    {
        InlineUIContainer uiContainer =
            this.CreateElementContainer(item.FirstName ????? )              
        para.Inlines.Add(uiContainer);
    }                         

    FlowDocument flowDoc = new FlowDocument(para);
    this.Document = flowDoc;
}

When in write in Visual Studio “item.XXX” I should get the properties from my entitiy like .FirstName or .LastName. I do not know wether dataObjects is an IEnumerable or IOrder etc… it must be generic!

How can I get the real properties form item ? Only with Reflection?

  • 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-18T08:35:14+00:00Added an answer on May 18, 2026 at 8:35 am

    Oded is right, it doesn’t seem (to him or me) to make any sense to try and make this method generic. You are trying to genericize a method whose functionality is actually specific to a few types.

    Now, that said, it seems the bulk of the function is independent of this property you want to access. So why not split it into two parts: that which can be genericized, and that which can’t:

    Something like this:

    void BindElements<T, TProperty>(IEnumerable<T> dataObjects,
                                    Func<T, TProperty> selector)
    {
        Paragraph para = new Paragraph();
    
        foreach (T item in dataObjects)
        {
           // Notice: by delegating the only type-specific aspect of this method
           // (the property) to (fittingly enough) a delegate, we are able to 
           // package MOST of the code in a reusable form.
           var property = selector(item);
    
           InlineUIContainer uiContainer = this.CreateElementContainer(property)
           para.Inlines.Add(uiContainer);
        }
    
        FlowDocument flowDoc = new FlowDocument(para);
        this.Document = flowDoc;
    }
    

    Then your overloads dealing with specific types, e.g., IPerson, can reuse this code (which I suspect may be what you were after all along—code reuse):

    public void BindPeople(IEnumerable<IPerson> people)
    {
        BindElements(people, p => p.FirstName);
    }
    

    …then for IOrder:

    public void BindOrders(IEnumerable<IOrder> orders)
    {
        BindElements(orders, o => p.OrderNumber);
    }
    

    …and so on.

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

Sidebar

Related Questions

am new here. i have a slight problem; PLease look at the following code
Please have a look at following code : import java.util.ArrayList; import java.util.List; class Main{
Please take a look at the code. It shouldn't take long to have a
This is a pretty newbie question- please know I'm aware of that. I have
Edit: This code is fine. I found a logic bug somewhere that doesn't exist
I have created a class library called AddServiceLibrary in which I have a method
I've been struggling with this for 2 days now so i thought i would
i 'm trying the hibernate tutorials from their main site and wanted to change
I am using a timer with interval 1 second. But in the timer's tick
I am writing a parser for csv-files, and sometimes I get NumberFormatException. Is there

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.