• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 155
  • Last Modified:

C# How to perform macro substitution

Hi..
I have a customer object with properties like this

CUSTOMER.NAME
CUSTOMER.ADDRESS

How can I pass a NAME or ADDRESS to the object (CUSTOMER) and SET the value of NAME and Address

Pass in  and set
NAME
Value = 'BOB'

// Something like this?

var n = "NAME"
var val = 'BOB'

CUSTOMER[N] = val;
0
JElster
Asked:
JElster
1 Solution
 
ste5anSenior DeveloperCommented:
Macro? Under most circumstances you wouldn't do that, cause it's basically a violation of good and clean OOP design principles.

But when there is a good reason: You would use reflection to find the property named 'NAME' and assign the value (PropertyInfo.SetValue Method).

btw, while a name is often a string, an adress is a reference type to it's own class.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now