I have a program that loads a web page and walks the DOM creating a HtmlElement to map (using Dictionary).
I then wait for the user to click and element and get the HtmlElement using webBrowser.Document.GetElementFromPoint.
I then try to look up the element in the Dictionary... and fail. It's not found. However, I can find the matching element by walking through the keys and:
elementFromDom.Equals(elementFromPoint) true
elementFromDom.GetHashCode() == elementFromPoint.GetHashCode() false
How can this be? I know it can work the other way around, but I'm stumped what's going on here.
Is .NET creating a new HtmlElement object every time it's asked about the underlying Html Element??
Questions:
- Does anyone have an explanation for the behavior I'm seeing?
- Is there a way of getting the memory address of the HtmlElement in the Visaul Studio 2008 debugger. I'd like to know if I'm looking at two different objects, even though (as far as I can tell), every member seems identical.
- Is there any documentation for the definition of Equals for HtmlElement. The MS documentation is about as helpful as one would expect and the definition of equals for a complicated object like HtmlElement is definitely non-trivial.
- Is there any way to use a hash table when we're dealing with something like this?
Many thanks.