i'm going to have to pick on a good pal in this post. in hopes, i guess, to point out a nice way of solving programming problems by using (unfortunately through a good pal of mine who totally rocks as a coder, businessman, and architect) a little dose of old-fashioned guesswork. sometimes, following up on “i hate that this class lacks XYZ functionality” with a hefty dose of patience and creativity can help you accomplish precisely what you wanted, all through the process of simple inheritance and extension.
my buddy Robert has one of these rather legitimate complains about certain objects in the framework. or in this case, the old framework. early in my .net development i began to miss the old MSXML property, “Xml.” remember for a moment how this property works - it simply returns all of the XML - similar to the OuterXml property in the XmlDocument object. basically, i extend the XmlDocument object and add an additional property to it. the simplest kind of inheritance-provided functionality is defined below in the code for this discussion:
public class MyXmlDocument : System.Xml.XmlDocument
{
public string Xml
{
get
{
return this.OuterXml;
}
}
}
see, not too difficult, when you see it all in action, eh? so - let's get to the culprit for this whole idea for a post. Robert's desire for there to be a property on the DropDownList object that returned the SelectedItem's Value property. Here ya go:
public class MyDropDownList : System.Web.UI.WebControls.DropDownList
{
public string SelectedValue
{
get
{
if(this.SelectedItem != null)
return this.SelectedItem.Value;
return null;
}
}
}
so, through picking on a money guy, super developer, ingenious architect and land-speed-record-holder-code, i've explained how a little trickery via inheritance can, in a sense, give you just what you asked for (or didn't think to ask for!).
just one more time that sun has completely, totally amazed me with their, well...
badoingas.