-3
PropertyInfo info =currentobject.getType.getproperty (propertychain)
currentobject=info.getvalue (currentobject)

When I put a string instead of getValue it works pretty fast. But if it returns an object it gets so slow?

Why is that, is there a possible solution/workaround for this?

Ekrem Doğan
  • 674
  • 6
  • 13
  • 5
    The work around is probably to work out if you really need reflection, removing reflection is almost guarranteed to speed up whatever you are trying to solve – Sayse Jul 25 '14 at 08:53
  • 2
    This won't compile - can you correct it to C# ? – Ondrej Svejdar Jul 25 '14 at 08:53
  • 1
    Don't use reflection, if you can avoid it. Read this: http://stackoverflow.com/questions/25458/how-costly-is-net-reflection – Florian Gl Jul 25 '14 at 08:54

1 Answers1

1

Assuming you're running this method on a relatively small number of classes you could cache references to property getters to remove some reflection overhead.

evgenyk
  • 51
  • 2