I have 2 objects, both of which I want to convert to dictionarys. I use toDictionary<>().
The lambda expression for one object to get the key is (i => i.name). For th
If these are two distinct (reference) types then you can test them using the is or as keywords:
i => {
var x = i as TypeThatHasNameProperty;
return (x != null) ? x.name : i.inner.name;
}
If you can't test for specific types then you can use reflection to test for the name
property itself:
i => {
var pi = i.GetType().GetProperty("name");
return (pi != null) ? pi.GetValue(i, null) : i.inner.name;
}