Skip to content

Commit

Permalink
Fix for 1.6.14
Browse files Browse the repository at this point in the history
Fix for 1.6.14
  • Loading branch information
zzzprojects committed Jan 21, 2018
1 parent 341f2ca commit e2d186d
Showing 1 changed file with 51 additions and 21 deletions.
72 changes: 51 additions & 21 deletions src/HtmlAgilityPack.Shared/HtmlAttributeCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,6 @@ internal HtmlAttributeCollection(HtmlNode ownernode)

#endregion

#region Properties

/// <summary>
/// Gets a given attribute from the list using its name.
/// </summary>
public HtmlAttribute this[string name]
{
get
{
if (name == null)
{
throw new ArgumentNullException("name");
}
HtmlAttribute value;
return Hashitems.TryGetValue(name, out value) ? value : null;
}
set { Append(value); }
}

#endregion

#region IList<HtmlAttribute> Members

Expand All @@ -78,9 +58,53 @@ public bool IsReadOnly
public HtmlAttribute this[int index]
{
get { return items[index]; }
set { items[index] = value; }
set
{
var oldValue = items[index];

items[index] = value;

if (oldValue.Name != value.Name)
{
Hashitems.Remove(oldValue.Name);
}
Hashitems[value.Name] = value;

value._ownernode = _ownernode;
_ownernode.SetChanged();
}
}


/// <summary>
/// Gets a given attribute from the list using its name.
/// </summary>
public HtmlAttribute this[string name]
{
get
{
if (name == null)
{
throw new ArgumentNullException("name");
}

HtmlAttribute value;
return Hashitems.TryGetValue(name, out value) ? value : null;
}
set
{
HtmlAttribute currentValue;

if (!Hashitems.TryGetValue(name, out currentValue))
{
Append(value);
}

this[items.IndexOf(currentValue)] = value;
}
}


/// <summary>
/// Adds supplied item to collection
/// </summary>
Expand Down Expand Up @@ -257,6 +281,7 @@ public bool Contains(string name)
if (String.Equals(items[i].Name, name, StringComparison.OrdinalIgnoreCase))
return true;
}

return false;
}

Expand All @@ -281,11 +306,13 @@ public void Remove(HtmlAttribute attribute)
{
throw new ArgumentNullException("attribute");
}

int index = GetAttributeIndex(attribute);
if (index == -1)
{
throw new IndexOutOfRangeException();
}

RemoveAt(index);
}

Expand Down Expand Up @@ -366,11 +393,13 @@ internal int GetAttributeIndex(HtmlAttribute attribute)
{
throw new ArgumentNullException("attribute");
}

for (int i = 0; i < items.Count; i++)
{
if ((items[i]) == attribute)
return i;
}

return -1;
}

Expand All @@ -386,6 +415,7 @@ internal int GetAttributeIndex(string name)
if (String.Equals((items[i]).Name, name, StringComparison.OrdinalIgnoreCase))
return i;
}

return -1;
}

Expand Down

0 comments on commit e2d186d

Please sign in to comment.