I have a need that is a bit similar to this question, except that it requires a deeper exploration of the source object.
Here is a code sample:
public class Target {};
public class Analyzed
{
public Target EasyOne { get; set; }
public IList<Target> ABitMoreTricky { get; set; }
public IList<Tuple<string, Target>> Nightmare { get; set; }
}
From an instance of Analyzed, I want to extract all the Target instances.
In order to ease the exploration, we can assume the following:
- Explore only properties.
- There is no infinite reference loop.
For now, EasyOne is… easy, but I am looking for some strategy to get all the Target instances lost in more tricky structures.
How about something along these lines: