Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all articles
Browse latest Browse all 8156

how to use reflection to find the data type of a class property

$
0
0

I have a C# class called "equipment" with several defined properties with different data types; such as int, bool, string.  I use Reflection to with a variable name to find the property and set its value from a control's value, but before doing so, I would like to know the property's data type.  How can I do that?

The following is an example of how I set the value:

equipment equip = new equipment();
PropertyInfo piInstance;

for (int i = 0; i < pnlEquipmentDetails.Controls.Count; i++) { . . . TextBox tbm = (TextBox)pnlEquipmentDetails.Controls[i]; piInstance = typeof(equipment).GetProperty("equipmentName")); piInstance.SetValue(equip, tbm.Text, null); . . . }


This works well if the type is string, but it the property is of type int, I need to parse tbm.Text.  How can I determine the property's type with Reflection?


Rob E.



Viewing all articles
Browse latest Browse all 8156

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>