You can use reflections if you don't mind losing security of a static type. I don't mind, so I just use your first squirrel cage design. You can mention a feature like Eric :)
I have thought about this issue several times. Lisp has macros that solve the problem as you mentioned, as they allow you to customize your score.
I also tried using extension methods to solve this problem, but nothing is less ugly than the source code.
Edit: (Answers do not allow me to insert blocks of code, so editing my post)
Oops, didn't keep up with that. Sorry for this:)
You can use reflections to search and evaluate an element or property through a string. One class from my friends wrote syntax like:
new ReflectionHelper(obj)["Parameters"]["UserSettings"]
It worked through a chain of methods, returning a ReflectionHelper at each level. I know that NullReferenceException is the problem in this example. I just wanted to demonstrate how an evaluation can be delayed until runtime.
An example is a bit closer to utility:
public class Something { public static object ResultOrDefault(object baseObject, params string[] chainedFields) {
Again, this syntax stinks. But this demonstrates the use of lines + reflections to defer evaluation to runtime.
source share