private static void PersistInnerProperty(PropertyDescriptor prop, object value, HtmlTextWriter writer, IDesignerHost host, bool isDefault)
{
//newline and indent
writer.WriteLine();
//trivial case
if (value == null) {
if (!isDefault) {
writer.WriteBeginTag (prop.Name);
writer.Write (HtmlTextWriter.SelfClosingTagEnd);
}
return;
}
//A collection? Persist individual objects.
if (value is ICollection) {
if (((ICollection) value).Count > 0) {
//if default property needs no surrounding tags
if(!isDefault) {
writer.WriteFullBeginTag (prop.Name);
writer.Indent++;
}
foreach (object o in (ICollection)value)
PersistObject (writer, o, host, false);
if(!isDefault) {
writer.Indent--;
writer.WriteEndTag (prop.Name);
}
}
}
//default but not collection: just write content
else if (isDefault) {
if (prop.Converter.CanConvertTo (typeof (string))){
writer.Write (prop.Converter.ConvertToString (value));
return;
}
}
//else: a tag of property name, with sub-properties as attribs
else {
//only want to render tag if it has any attributes
writer.WriteBeginTag (prop.Name);
foreach (PropertyDescriptor p in TypeDescriptor.GetProperties(value))
ProcessAttribute (p, value, writer, string.Empty);
writer.Write (HtmlTextWriter.SelfClosingTagEnd);
}
}