C# Reflection: Fastest Way to Update a Property Value?

前端 未结 3 1511
醉梦人生
醉梦人生 2020-12-08 17:11

Is this the fastest way to update a property using reflection? Assume the property is always an int:

PropertyInfo counterPropertyInfo = GetProperty();
int va         


        
3条回答
  •  轮回少年
    2020-12-08 17:26

    Just be sure that you are caching the PropertyInfo somehow, so that you aren't repeatably calling type.GetProperty. Other than that it would probably be faster if you created a delegate to a method on the type that performed the increment, or like Teoman suggested make the type implement an interface and use that.

提交回复
热议问题