Home All Groups Group Topic Archive Search About

Assign Property Values via String Variables?

Author
11 Feb 2006 8:55 PM
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,

Author
12 Feb 2006 3:27 AM
Patrick Steele [MVP]
In article <amjsu1p63h8jqfcf76chogkragpphm2***@4ax.com>,
joec***@home.net says...
Show quoteHide quote
> 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

--
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele