jeudi 20 décembre 2018

Improve object.GetType().GetProperties() and PropertyInfo.GetValue(object) performance

private static int GenerateKey(T requestParams)
{
    foreach (PropertyInfo property in requestParams.GetType().GetProperties())
    {
            var propertyValue = property.GetValue(requestParams);
            // Do stuff with propertyValue
    }
    // ...
}

I have this code snippet that iterates through generic type properties and extracts each property's value. I know that Reflection can be a huge performance bottleneck and that it could be improved using delegates / DynamicMethod / ILGenerator. However its quite difficult for to grasp these. Example on how to utilize one of these methods would be awesome.





Aucun commentaire:

Enregistrer un commentaire