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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:31:03+00:00 2026-05-15T15:31:03+00:00

Not sure if this is possible, but here is what I am trying to

  • 0

Not sure if this is possible, but here is what I am trying to do:

I want to have a dictionary that contains a mapping of a column index to a property name used to populate that index.

In my code I will loop through an array if strings and use the dictionary to look up which column it should map to.

My end result code would look like:

for(int index = 0; index < fields.Length)
{
    fieldPropertyMapping[index] = StripQuotes(fields[index]);
}
  • 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-15T15:31:03+00:00Added an answer on May 15, 2026 at 3:31 pm

    To do what you’re asking specifically, you’ll have to use reflection (as you tagged your question) to do this. Have a look at the PropertyInfo class. I’m not entirely certain what your code is doing, but a general example of reflectively setting a property value would be:

    object targetInstance = ...; // your target instance
    
    PropertyInfo prop = targetInstance.GetType().GetProperty(propertyName);
    
    prop.SetValue(targetInstance, null, newValue);
    

    You could, however, pass an Action<T> instead, if you know the property at some point in the code. For example:

    YourType targetInstance = ...;
    
    Action<PropertyType> prop = value => targetInstance.PropertyName = value;
    
    ... // in your consuming code
    
    prop(newValue);
    

    Or, if you know the type when you call it but you don’t have the instance, you could make it an Action<YourType, PropertyType>. This also would prevent creating a closure.

    Action<YourType, PropertyType> prop = (instance, value) => instance.PropertyName = value;
    
    ... // in your consuming code
    
    prop(instance, newValue);
    

    To make this fully generic (“generic” as in “non-specific”, not as in generics), you’ll probably have to make it an Action<object> and cast it to the proper property type within the lambda, but this should work either way.

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

Sidebar

Related Questions

I'm not sure if this is possible but I want to see objects created
Not sure this is possible, but looking to write a script that would return
I'm not sure if what I'm even trying to do is possible but here
Not sure if this is even possible but I am trying to save text
I am not sure if this is possible or not, but I am trying
I'm not sure if this possible but probably is fairly simple. I've made a
I'm not sure this is even possible but I know if it is, the
I'm not sure if this is possible but I'd like to be able to
I'm not sure if this is possible but as I was looking for a
I'm not sure this is possible, but in ruby, you can dynamically call a

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.