locked
Recursion help RRS feed

  • Question

  • Object Model.

    class Entity

    {

    public Guid Id {get;}

    public Type Type{get; set;}

    public IList<Entity> Collection{get;}

    }

    In another class there is a Dictionary<Guid, Values>, the type of values here is not important. What i am attempting to do is look in this dictionary to see if the id of entity matches the key, if so then copy values to  the collection in entity. Then we need to loop through the collection in the entity and repeat the above process until all the keys in the dictionary have been processed. The collection is nested.


    Anonymous

    Monday, November 26, 2012 6:43 PM

Answers

  • public void Process(Entity entity, Dictionary<Guid, object> lookup)
    {
        entity.Value = lookup[entity.Id];
        foreach (Entity child in entity.Collection)
        {
            Process(child, lookup);
        }
    }

    • Proposed as answer by Norkk Tuesday, November 27, 2012 11:06 AM
    • Marked as answer by Bob Shen Thursday, December 6, 2012 3:29 AM
    Monday, November 26, 2012 7:51 PM