C# is statically typed language which requires explicit handling for runtime inspection.
Reflection is what allows C# developers to inspect data structures by looking up:
- The type of an object
- Properties
- Methods, etc.
var user = new UserData()
{
Id = 1,
Name = "Mirza",
Age = 30
};
var keys = user.GetType().GetProperties().Select(prop => prop.Name).ToList(); // [Id, Name, Age]
var values = user.GetType().GetProperties().Select(prop => prop.GetValue(user, null)).ToList(); // [1, Mirza, 30]