C
C#5mo ago
Evyr

Looking for more performant alternatives to reflection for iterating through properties of a class

I've been using reflection to get the values of each of seventeen properties. I'm generating these values based off of an int seed passed to the constructor and trying to do so for the entire range of int values, so it'll an estimated 10 hours to complete. I was wondering if there were any more elegant solutions than writing out a "sum += <property>" for each property. Thanks!
2 Replies
Pobiega
Pobiega5mo ago
sum += property is the way to go, assuming the properties should indeed be properties alternatively, have the props just be items in a dictionary
Joschi
Joschi5mo ago
Or use a source generator to generate the code for you. But if you create those value of off some seed, why not directly sum them then and there as well?
Want results from more Discord servers?
Add your server