Taking action for all controls with an 'ImageUrl' property
<p>I've got the below piece of code, which iterates through the controls on a webpage and where it is an imagebutton, it modifies the imageUrl property.  What I'd <em>like</em> it to do, is go through each control and, if that control happens to <em>have</em> an imageUrl property, then do the change. Eg normal images etc would be included in the process.  I get the feeling that generics or something might be the key here, but I am not versed in that area to say the least.  Any thoughts?  Thanks!</p>

<pre><code>        public static void AddThemePathToImages(Control Parent)
    {

        foreach (Control c in Parent.Controls)
        {
            ImageButton i = c as ImageButton;
            if (i != null)
            {
                // See if theme specific version of this file exists.  If not, point it to normal images dir.
                if (File.Exists(System.Web.HttpContext.Current.Server.MapPath("~/App_Variants/" + GetUserTheme().ToString() + "/images/" + i.ImageUrl)))
                {
                    i.ImageUrl = "~/App_Variants/" + GetUserTheme().ToString() + "/images/" + i.ImageUrl;
                }
                else
                {
                    i.ImageUrl = "~/images/" + i.ImageUrl;
                }   
            }
            if (c.HasControls())
            {
                AddThemePathToImages(c);
            }
        }
    }
</code></pre>
