PropertyDescriptor.GetValue() => Huh?

Hello All, 

  I am trying to write out the properties for the controls placed on my form to an XML file. I think that the following code is close but the line with p.GetValue() does not work. This is not really shocking as GetValue() is defined as "abstract". Fine, but the online help says something like "if you override this class you need a MyPropertyValues method." I have no idea what to put in the method, where it should go, or anything like that.

  I looked online for samples or tutorials but could not find anything that made sense to me. Does anyone know of a source of information or examples for this sort of thing

XmlTextWriter writer = new XmlTextWriter();
// set up the writer here...

foreach(Control c in myControl.Controls)
{
writer.WriteStartElement("Item");
writer.WriteAttributeString("Name", c.Name);
PropertyDescriptorCollection props = c.GetProperties();
foreach(PropertyDescriptor p in props)
{
writer.WriteStartElement(p.DisplayName);
writer.WriteString(p.GetValue()); // MESSED UP HERE!
writer.WriteEndElement(); 
}
writer.WriteEndElement(); // Item
}
writer.WriteEndElement(); // Dialog


 Thanks in advance.
Steve


Answer this question

PropertyDescriptor.GetValue() => Huh?

  • Nick Doty

    I actually already wrote a class to do this...it's pretty simple and doesn't cover every situation, but you might find it useful!  :) 

    <a href="http://www.gotdotnet.com/Community/UserSamples/Details.aspx SampleGuid=de5858f1-db75-4a1e-a86d-b31cb93b0ab1">UISerializer</a>

  • PropertyDescriptor.GetValue() =&gt; Huh?