I have a System.Collections.Generic.Dictionary<System.Web.UI.Control, object>
where all keys can be either type of System.Web.UI.WebControls.HyperLink
or type of System.Web.UI.WebControls.Label
.
I want to change Text
property of each control. Because HyperLink doesn't implement (why??) ITextControl
, I need to cast Label or HyperLink explicitly:
Dictionary<Control,object> dic = ..
dic
.Where(p => p.Key is HyperLink)
.ForEach(c => ((HyperLink)c).Text = "something")
dic
.Where(p => p.Key is Label)
.ForEach(c => ((Label)c).Text = "something")
Are there ways to workaround such approach?