With the DLR, i would like to do something like this:
class MyClass {
int MyProperty { get; set; }
}
In razor, I would do something like this. (InstanceOfMyClass is some dynamic object that looks at an instance of MyClass)
@InstanceOfMyClass.MyProperty
This would output the string representation of MyProperty.
Now if I do this.
@InstanceOfMyClass.MyMissingProperty
I would like it to output “Missing: MyMissingProperty”. I would love to capture the whole expression, like so.
@InstanceOfMyClass.MyMissingProperty.MoreMissing
Could potentially output “Missing: MyMissingProperty.MoreMissing”, but that might be asking a lot of the DLR.
Will the ExpandoObject allow me to do this? If not, what do I have to do to implement this?
Extend DynamicObject.TryGetMember in this way:
If the member exists, return the value. If the member doesn’t exist, return a new instance of a class that will handle both the string representation of the missing property and also the chain. Something like this
I didn’t try it, but I think it will give you the idea of how to solve the problem.
Hope it helps.