Assume i have a class like this below
class Student
{
public int ID { get; set; }
public string Name { get; set; }
}
Just with 10 more properties. I want to loop through these properties. I can do it through reflection, which will have a performance cost. Is serializing it using Newtonsoft JSON and looping through it better?
Edit: The reason i want to do this is there are many classes like this. Each of these classes also has a Ienumerable object as below
public bool Validation
{
public string PropName { get; set; }
public bool IsRequired { get; set; }
public int? MaxLength { get; set; }
public int? MinLength { get; set; }
public void Validate(object propValue)
{... }
}
I want to loop through each property in student class, take values and supply it to validate method. But i don't want to use reflection. I am not sure if it is even possible. Let me know if u have any thoughts.