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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T16:26:12+00:00 2026-05-12T16:26:12+00:00

I need a little help. I am fairly new to reflection. We’re using a

  • 0

I need a little help. I am fairly new to reflection. We’re using a 3rd party api and it returns a class called “AddressList”. It has public properties within it literally called Address1, Address1Name, Address1Desc, Address2, Address2Name, Address2Desc, Address3, Address3Name, Address3Desc,… Address99, Address99Name, Address99Desc.. There are also a couple of other properties. I have a class called “SimpleAddress” that has just the 3 properties (Address, Name, Description). What I want to do is when I get the “AddressList” class returned, I would like to loop AddressDesc1… through AddressDesc99… and whichever ones are not null or empty, I would like to create an instance of “SimpleAddress”, populate it’s properties, and add it to a List… Can someone point me in the right direction? Obviously this would have been better if “AddressList” was some sort of collection, but unfortunately it is not. It is generated from a return string from a mainframe.

Thanks for any help,
~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-12T16:26:12+00:00Added an answer on May 12, 2026 at 4:26 pm

    Ick. You could do something like this:

    List<SimpleAddress> addresses = new List<SimpleAddress>();
    
    string addressPropertyPattern = "Address{0}";
    string namePropertyPattern = "Address{0}Name";
    string descPropertyPattern = "Address{0}Desc";
    
    for(int i = 1; i <= MAX_ADDRESS_NUMBER; i++)
    {
        System.Reflection.PropertyInfo addressProperty = typeof(AddressList).GetProperty(string.Format(addressPropertyPattern, i));
        System.Reflection.PropertyInfo nameProperty = typeof(AddressList).GetProperty(string.Format(namePropertyPattern, i));
        System.Reflection.PropertyInfo descProperty = typeof(AddressList).GetProperty(string.Format(descPropertyPattern, i));
    
        SimpleAddress address = new SimpleAddress();
    
        address.Address = (string)addressProperty.GetValue(yourAddressListObject, null);
        address.Name = (string)nameProperty.GetValue(yourAddressListObject, null);
        address.Description = (string)descProperty.GetValue(yourAddressListObject, null);
    
        addresses.Add(address);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm fairly new to programming and new to java, but I'd like to jump
Hey guys I'm fairly green when it comes to wpf, so I need a
I am a little confused on the logic of how to write this SQL
I am in the processes of replacing the framework for a fairly complex business
This question might seem very specific but I am in need of some ideas
I'm sure this is fairly simple, however I have a major mental block on
I don't intend this to be subjective, but if the answers can be seasoned
UPDATE: In trying to replicate this problem one more time to answer your questions
Firstly, I'm not against Opera. It just seems when I encounter cross browser issues,

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.