public static void GetProps(ObjectWrapper wrapper, XmlElement parent_elem) { ClassDescriptor klass = wrapper.ClassDescriptor; foreach (ItemGroup group in klass.ItemGroups) { foreach (ItemDescriptor item in group) { PropertyDescriptor prop = item as PropertyDescriptor; if (prop == null) { continue; } if (!prop.VisibleFor(wrapper.Wrapped) || !prop.CanWrite || prop.Name == "Name") // Name is written in the id attribute { continue; } object value = prop.GetValue(wrapper.Wrapped); // If the property has its default value, we don't need to write it if (value == null || (prop.HasDefault && prop.IsDefaultValue(value))) { continue; } string val = prop.ValueToString(value); if (val == null) { continue; } XmlElement prop_elem = parent_elem.OwnerDocument.CreateElement("property"); prop_elem.SetAttribute("name", prop.Name); if (val.Length > 0) { prop_elem.InnerText = val; } if (prop.Translatable && prop.IsTranslated(wrapper.Wrapped)) { prop_elem.SetAttribute("translatable", "yes"); string tcx = prop.TranslationContext(wrapper.Wrapped); if (tcx != null && tcx.Length > 0) { prop_elem.SetAttribute("context", "yes"); prop_elem.InnerText = tcx + "|" + prop_elem.InnerText; } string tcm = prop.TranslationComment(wrapper.Wrapped); if (tcm != null && tcm.Length > 0) { prop_elem.SetAttribute("comments", prop.TranslationComment(wrapper.Wrapped)); } } parent_elem.AppendChild(prop_elem); } } }
protected virtual string GetValueText() { if (obj == null) { return(""); } object val = property.GetValue(obj); if (val == null) { return(""); } else { return(property.ValueToString(val)); } }