Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click Write("file.xml") End Sub Private Sub Write(ByVal fileName As String) AddHandler diagram.SerializeTag, New SerializeTagEventHandler(AddressOf SerializeTag) diagram.SaveToXml(fileName) End Sub Sub SerializeTag(ByVal sender As Object, ByVal e As SerializeTagEventArgs) e.Handled = True Dim taggedElement As Elem = e.Tag Dim stringRepresentation As String = "" If Not taggedElement Is Nothing Then stringRepresentation = "ID" 'stringRepresentation += ";" stringRepresentation += taggedElement.ID.ToString() End If Dim repElem As XmlElement = e.Context.XmlDocument.CreateElement(stringRepresentation) e.Representation.AppendChild(repElem) 'e.Context.WriteObject(taggedElement, stringRepresentation, repElem) e.Context.WriteString(taggedElement.RandomNumber.ToString(), "RandomNumber", repElem) End Sub
Type type = control.GetType(); string assemblyName = type.Assembly.GetName().Name; string typeName = type.FullName; controlElement.SetAttribute("AssemblyName", assemblyName); controlElement.SetAttribute("TypeName", typeName); XmlElement propertiesElement = context.AddChildElement("Properties", controlElement); // Save control serializable properties PropertyInfo[] props = type.GetProperties(); foreach (PropertyInfo prop in props) { if (!prop.CanRead || !prop.CanWrite) continue; if (FilteredProperty(prop)) continue; object val; try { val = prop.GetValue(control, null); } catch { // Some properties cannot be read continue; } if (val == null) continue; if (!(val.GetType().IsSerializable)) continue; context.WriteObject(val, prop.Name, propertiesElement); }