IList items are getting replaced

Experiences, small talk, and other automation gossip.
User avatar
testautomator
Posts: 67
Joined: Fri Oct 25, 2013 6:37 am
Location: Bangalore, India

IList items are getting replaced

Post by testautomator » Wed Nov 12, 2014 11:58 am

Hi All,
There is an ilist we are using to hold list of Text objects we want from a table.
Getting them is not an issue but keeping them in the IList is a problem.
See the code below,
IList<Text> ilColumnList = new List<Text>();
IList<Element> ilElements = tblPriorityField().Find("element");
int intColIndex = (penumPriorityField == PriorityField.Values) ? 1 : 2;
foreach (Element eleTemp in ilElements)
{
if (!eleTemp.Visible) eleTemp.EnsureVisible();
ilColumnList.Add(eleTemp.FindSingle("element[" + intColIndex + "]/text"));
}

So, as you can see the IList has a clause that it take Text objects that are visible. Because the table has hidden rows and we cant see the text objects under the element unless they are visible. When it comes to adding the text that was just made visible the 'add' operation is going and replacing the one that has gone invisible because of the scroll operation to make present text object visible.
Example:
IList has these objects for now,
Object1
Object2
Object3
Object4

The other objects are invisible,
Object5
Object6

So, when we make Object5 visible then add it, its replacing the Object1 which has gone invisible now. Like this,
Object5
Object2
Object3
Object4

Now, we know that IList is holding the references and not the copies of the Text objects!

We solved it my taking out the Text values from those texts which were what we wanted.
Text txtTemp = eleTemp.FindSingle("element[" + intColIndex + "]/text");
ilColumnList.Add(txtTemp.TextValue);

Off course with changes made to IList type and all the jazz needed.

My question is why IList is holding the references?

User avatar
testautomator
Posts: 67
Joined: Fri Oct 25, 2013 6:37 am
Location: Bangalore, India

Re: IList items are getting replaced

Post by testautomator » Fri Nov 14, 2014 6:15 am

Can anybody please reply? :|

swmatisa
Posts: 122
Joined: Fri Aug 05, 2011 7:52 am

Re: IList items are getting replaced

Post by swmatisa » Fri Nov 14, 2014 6:56 am

Hello,

Text is a "Reference Type", not a "Value Type": http://msdn.microsoft.com/en-us/library/t63sy5hs.aspx
SW

User avatar
testautomator
Posts: 67
Joined: Fri Oct 25, 2013 6:37 am
Location: Bangalore, India

Re: IList items are getting replaced

Post by testautomator » Fri Nov 14, 2014 10:43 am

@swmatisa : Thanks for that info