Max,
Yes, you can use reflection to do this:
// Get the type of c first.
Type pobjTypeOfC = c.GetType();
// Now get the property on that type.
PropertyInfo pobjPropInfo = pobjTypeOfC.GetProperty(s);
// Now get the value for that property.
string pobjText = (string) pobjPropInfo.GetValue(c, null);
Basically, you are getting the type information for the instance of c in
the first line. Then, you are getting the property information in the
second, finally invoking the property in the third.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
-
ni**************@exisconsulting.com
"Max Sandman" <sa*********@yahoo.com> wrote in message
news:uo**************@TK2MSFTNGP11.phx.gbl...
Say I've got a control c = textBox1 and a string that is a property of
c, say string s = "Text". Is there a way in C# to use c and s to get
the contents of textbox1.Text?
sandman
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!