I am working with a 3rd party web testing API which has a Src property for image.
What I need to do is say:
if (t is HtmlImage) { // Do cast here. } // t is a variable of type T (my generic).
However, my cast does not work. The cast is as follows:
Controls.HtmlImage img = (Controls.HtmlImage)t;
This gives an error stating that I cannot convert Type 'T' to HtmlImage. BUT type T is the base class for all controls, including HtmlImage.
The problem I am trying to solve is I have a utility method to loop through a site's pages, but if I am passing Html Image as the value of T, I get the src property as I need the paths (to identify which images have no alt tags, and the src property can never be null). If T is of another type, I will get another property as an identifier. I am testing if images have alt tags, links have meaningful descriptions, etc. For a possible type total of about 30, is this scalable? Because I will be saying if T is Button, else, etc etc for quite a lot of types (could use table driven method).
HtmlImage inherits from:
public class HtmlImage : ArtOfTest.WebAii.Controls.HtmlControls.HtmlControl
T is of type HtmlControl
Thanks