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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:25:00+00:00 2026-05-23T06:25:00+00:00

If I have an object public class Car { public List<UpdatePart> updatePartList {get; set;}

  • 0

If I have an object

public class Car {
  public List<UpdatePart> updatePartList {get; set;}

}

public class UpdatePart {
  public PartToModify PartToModify {get; set;}
  public string NewValue {get;set}
}

And the PartToModify is an enum:

public enum PartToModify {
   Engine,
   Tire, 
}

And I have a Part object:

public class Part {
  public string Engine {get;set;}
  public string Tire   {get;set;}
  public decimal price {get;set;}

}

How can I use reflection and for every property on Part that matches a enum in PartToModify, create a new UpdatePart object and select the correct enum where PartToModify == Part.Property and assigns the UpdatePart.NewValue the value of Part.Property.

I would something like:

var partProperties = partObj.GetType().GetProperties();
foreach (var property on updatePartProperties) {
  UpdatePartList.Add(MapProperties(partProperties, part));
}

 public UpdatePart MapProperties(PropertyInfo partProperties, Part partObj){
   //pseudo code
   var updatePart = new UpdatePart();
   foreach(var property on partProperties) {
      if (property.Name == <iterate through enum values until one is found>)
         updatePart.PartToModify = PartToModify.<somehow select value that matches property.name>
          updatePart.NewValue = property.GetValue(partObj, null);
   }

   return updatePart;
 }

Obviously you get the jiff of what I am trying to do, any thoughts? And no, this is not a school project. The whole “car” example was the quickest closest example I came up with to the actual objects, since I didn’t want to just write out what I was trying to accomplish, wanted to provide an example.

  • 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-23T06:25:01+00:00Added an answer on May 23, 2026 at 6:25 am
    var partNames=Enum.GetNames(typeof(PartToModify));
    var parts = from pi in partObj.GetType.GetProperties()
                where partNames.Contains(pi.Name)
                select new UpdatePart { 
                             PartToModify = (partToModify)Enum.Parse(typeof(PartToModify),pi.Name),
                             NewValue=pi.GetValue(partObj,null)
                           };
    foreach (var part in parts) UpdateList.Add(part);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class public class Car { public string Name {get;set;} public int
I have an object model like this: class Car { public string Manufacturer; public
I have a class : public class Car { public string Name { get;
public class Car { public string SomeProperty { get; set; } public Manufacturer Manufacturer
If I have a list of objects called Car: public class Car { public
Let's say I have an object: public class CustomObj { DateTime Date { get;
I have this object: class a { public string Application; public DateTime From, To;
I have two classes Car and Drivers : public class Car { public string
I use Spring MVC 3.0 and JSP. I have an object: public class ObjectWrapper
I'm just wondering .. I have and object like this public class Entry{ public

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.