Skip to main content

Practice · 1 of 3

Cache the invoke

CHALLENGE
Difficulty: advanced+25 XP

Implement static Func<object?, object?> BuildGetter(Type type, string propertyName) that returns a DELEGATE reading the given instance property via reflection — and the delegate must be CACHED: two calls with the same (type, name) return the SAME delegate instance, and invoking the cached delegate performs the PropertyInfo work already captured, not a fresh resolve. Also implement static object? Read(object target, string prop) => BuildGetter(target.GetType(), prop)(target);.

Back to lesson: Practice: Reflection drills