Is it somehow possible for properties to reference each other during the creation of a dynamic object an anonymously-typed object (i.e. inside the object initializer)? My simplified example below needs to reuse the Age
property without making a second heavy call to GetAgeFromSomewhere()
. Of course it doesn't work. Any suggestion on how to accomplish this?
var profile = new {
Age = GetAgeFromSomewhere(id),
IsLegal = (Age>18)
};
Is something like this possible or not possible with dynamic objects anonymously-typed object initializers?
GetAgeFromSomewhere
to a variable in a separate statement beforehand. – YordanIsLegal
a derivative property:public bool IsLegal { get { return Age > 18; } }
– Yordandynamic
keyword and the DLR (which is something very different). – Diminution