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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:26:04+00:00 2026-06-11T16:26:04+00:00

What alternatives are there to property.setvalue()? I’ve read that it is very slow. I’m

  • 0

What alternatives are there to property.setvalue()? I’ve read that it is very slow. I’m using it to map IDataReader to POCO objects.

This is a truncated version of the code. Everything here is very new to me. I know there a lot of frameworks that accomplish this task. However, we can’t use them.

public class DbAutoMapper<T>
{
    public IEnumerable<T> MapToList(IDataReader reader)
    {
        var list = new List<T>();

        while (reader.Read())
        {                
            var obj = Activator.CreateInstance<T>();

            foreach (PropertyInfo prop in obj.GetType().GetProperties())
            {
                foreach (var attribute in prop.GetCustomAttributes(true))
                {                        
                    prop.SetValue(obj, value, null);                        
                }
            }

            list.Add(obj);
        }
        return list;
    }
}
  • 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-06-11T16:26:05+00:00Added an answer on June 11, 2026 at 4:26 pm

    Firstly: why are you repeating the reflection for every attribute, when you don’t use the attribute?

    Second: assuming you intended to map this by name, column-to-property (which isn’t what the code currently does), consider a tool like dapper, which does all this for you, including cached high-performance reflection-emit. It’ll also handle the command itself for you. For example:

    string region = "North";
    var customers = conn.Query<Customer>(
        @"select * from Customers where Region = @region",
        new { region } // full parameterization, the easy way
    ).ToList();
    

    If you need more control, consider FastMember, which provides fast member-access (again, reflection-emit), but without being specific to data access:

    var accessor = TypeAccessor.Create(typeof(T)); 
    string propName = // something known only at runtime 
    while( /* some loop of data */ ) {
        var obj = new T();
        foreach(var col in cols) {
            string propName = // ...
            object cellValue = // ...
            accessor[obj, propName] = cellValue;
        }
        yield return obj;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Are there alternatives to gitosis that are easier to use? I currently run gitosis
When using Entity Framework 4.1, are there alternatives to the naming conventions for Navigation
Trying to bind a field to a map of objects I got this error
Generally if there is a property that gets/sets a value for state, I use
I'm using System.IO.Stream.Read(byte[] buffer, int offset, int count) . Is there an alternative to
Is there any alternative to use like tag to property of UIView? The thing
WinJS.UI.getControl is not defined in VS 11 Ultimate. Is there any alternatives there to
Are there any alternatives to the Open Source Job Scheduler ? I'm looking for
Are there any alternatives to py2exe?
Are there any alternatives to stat (which is found on most Unix systems) which

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.