Thabane
Thabane

Reputation: 48

TFS - How do I loop through a LinkCollection object?

I have this nested LinkCollection object which has Results which is a list but I am unable to iterate through this list because it sees this object as a single object (I am 100% sure there is a list embedded in there).

This LinkCollection class is nested within this structure Changeset[].WorkItem[].Links - I am able to loop through the upper classes but have a problem when I get to the Links object.

This is my code

    public Changeset CheckForDuplicateChangeset(Changeset cs)
    {
        foreach (WorkItem wi in cs.WorkItems)
        {
            foreach (var link in wi.Links)
            {
                //Here I cannot access the link properties 
                //from the "link" within my foreach loop
            }
        }

        //This this the property I want to access within the Links object
        if (cs.WorkItems[0].Links[0].BaseType == BaseLinkType.ExternalLink)
        {                
        }
        return null;
    }

The fully qualified name for the Changeset class is Microsoft.TeamFoundation.Client.Changeset

Upvotes: 0

Views: 348

Answers (1)

Thabane
Thabane

Reputation: 48

I struggled until I found the answer. Basically I need to specify the type of the object within the LinkCollection. The type is Link. So this is how my nested loop looks now.

foreach (WorkItem wi in cs.WorkItems)
{
    foreach (Link link in wi.Links)
    {  
        if (link.BaseType == BaseLinkType.ExternalLink)
        {
            //Implement my logic
        }
    }
}

Upvotes: 1

Related Questions