Reflection question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

is it faster to access the fields from an object directly by using
reflection than accessing them by their properties using reflection?

Thanks Christian
 
Hi,

is it faster to access the fields from an object directly by using
reflection than accessing them by their properties using reflection?

Direct access is always faster than reflection.
 
(e-mail address removed) says...

By the time you get through the machinery of Reflection, accessing a
property versus a field won't make much difference. You should
probably read and write the property, not the field, because that way
the object in question can make guarantees about its state. Messing
with an object's private fields is not good .NETiquette. :-)
 
Hi Bruce,

thanks for your response. I know, that the field access should always be
realized by using a property. I had only a "developer discussion" if an
application will be faster if the access is faster by properties or directly
to the fields (both using reflection).

Bye
Christian
 
Hi Patrick,

thanks for your response.

My problem was not clearly described. The access to the fields is realized
with reflection, too.
 
Logically it should be a smidgen slower via the property, but
preferring to go after the field for that reason is like ordering Diet
Coke with your triple cheeseburger. After the triple cheeseburger, the
"Diet" part of "Diet Coke" doesn't really matter, and makes one look
silly, if you catch my drift.

Translated, if one does all of the work to ramp up the machinery of
Reflection, and then says, "Oh, I prefer to read the field rather than
the property, because it's faster," one sounds like a fool, IMHO.
 
Back
Top