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

The Archive Base Latest Questions

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

I am using c# & .NET 3.5. A vendor gives us an object that

  • 0

I am using c# & .NET 3.5. A vendor gives us an object that has properties of UserVarNbr1, UserVarData1, UserVarNbr2, UserVarData2,… UserVarNbrN, UserVarDataN. Not the way I would have coded it but nonetheless, this is what we have to work with. Another object in the application returns a collection of items used to represent these UserVariables.

The collection items have properties like this

public string VariableName
{
  get { return _VariableName; }
  set { _VariableName = value; }
}


public string VariableData
{
  get { return _VariableData; }
  set { _VariableData = value; }
}

I need to loop through the collection and create an instance of the vendor object and set the correct properties. UserVarNbrN, UserVarDataN needs to be put in the correct place. Note the collection returns a VariableName as a string “03”, this needs to drive VendorObject properties UserVarNbr3, UserVarData3 **notice no “0” in the actual property name. How do I reference the correct property to get/set?

var o = new VendorObj();

I have something like this so far.

foreach (var item in userVars)
        {
            const string propPrefix = "UserVar";
            int varNum;
            var isNum = int.TryParse(item.VariableName, out varNum);

            if(isNum)
            {
                PropertyInfo pi;
                //this is where I am stuck
                // I need to set the corresponding properties on o
                // example if varNum == 38, how do I reference
                // o.(propPrefix+"Nbr"+varNum.ToString())
                // and
                // o.(propPrefix+"Data"+varNum.ToString())
                // so I may set them? 
            }
        }

Any help is appreciated. I am a rookie when it come to reflection.

Thanks,
~ck in San Diego

  • 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-13T08:38:54+00:00Added an answer on May 13, 2026 at 8:38 am

    Try this:

    const string propPrefix = "UserVar";
    
    VendorObj o = new VendorObj();
    foreach (var item in userVars)
    {
        int varNum = 0;
        if (Int32.TryParse(item.VariableName, out varNum))
        {
            string name = String.Format("{0}Nbr{1}", propPrefix, varNum);
            o.GetType().GetProperty(name).SetValue(o, "some value", null);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using C# & .NEt 3.5. What is the difference between the OptionA and
Is there an ASP.NET AJAX framework other than just using UpdatePanel & Friends or
We are using C#, ASP.NET & WCF. I am trying to send form data
I've created an web authentication app using c# & asp.net and want to bounce
The application is planned to be built using ASP.NET, .NET Remoting & MS SQL
Disclaimer: I'm completely clueless about .net and COM. I have a vendor's application that
Using ASP.Net & C# I want to run my web page in the internet
Using ASP.Net & C# I want to use a datetimepicker in my web page,
I'm creating a web application using asp.net & WCF as 3 tier architecture, which
In VB.NET, is there any advantage to using & to concatenate strings instead of

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.