Assign Property Values via String Variables?

J

Joe Cool

Using VB.NET 2005.

I will not go into detail on a problem I can't figure out, but I will
describe it simple terms that should convey the underlying issue.

I have a class called ClassA. It has two properties, Property1 and
Property2. Both properties are string datatypes. This class is a
member of a class library.

I have some code in an application that imports the class library that
ClassA is a member of. In this code I have DIMmed a variable called
myClassA that is a New ClassA datatype. I have a string array of two
elements who values are "Property1" and "Property2". I would like to
assign values to the two properties utilizing the myClassA instance
but referring to the properties by means of the values of the string
array. Is that possible?

TIA,
 
P

Patrick Steele [MVP]

Using VB.NET 2005.

I will not go into detail on a problem I can't figure out, but I will
describe it simple terms that should convey the underlying issue.

I have a class called ClassA. It has two properties, Property1 and
Property2. Both properties are string datatypes. This class is a
member of a class library.

I have some code in an application that imports the class library that
ClassA is a member of. In this code I have DIMmed a variable called
myClassA that is a New ClassA datatype. I have a string array of two
elements who values are "Property1" and "Property2". I would like to
assign values to the two properties utilizing the myClassA instance
but referring to the properties by means of the values of the string
array. Is that possible?

Yes. Use Reflection. See:

http://tinyurl.com/n0cp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top