Is there a .net method that determines whether or not a given method has been previously called for a given object instance?
Sometimes a property getter method has side effects. For instance, a property getter if not called previously may need to create additional objects and perform other work in order to return the value of a backing field. I can't have that happen. If the getter method hasn't been called previously, I don't need the value.
For example...
object item = something;
foreach (PropertyInfo propertyInfoForItem in item.GetProperties(Reflection.BindingFlags.Public)) {
//Need something to avoid calling this if the property getter method has not been previously been called for this item
object itemPropertyValue = nothing;
itemPropertyValue = propertyInfoForItem.GetValue(item, null);
}
I've looked through the MethodInfo class returned from PropertyInfo.GetGetMethod() and didn't spot anything there that would help.
Any ideas?
Aucun commentaire:
Enregistrer un commentaire