SoFunction
Updated on 2025-03-06

Tips for using reflection to traverse an object's properties and values ​​in C#

//Get PropertyInfo[] and then you can use foreach to traverse it
foreach (PropertyInfo pi in ())
{
object value1 = (tc, null));//Get the value with
string name = ;// Obtain the name of the attribute, and then you can judge the name to perform some operations you want based on the name.
//Get the type of the attribute, make a judgment and then perform subsequent operations, for example, determine that the obtained attribute is an integer
   if(() == typeof(int))
   {
//Perform what you want
   }
}