Parameters
- attrname
- an XML attribute name
- proppath
- a .NET property name, or a sequence of properties separated by periods
transformer.AddBinding("label", "Text")
will generate a "label" attribute whose value is the value of the "Text" property on the object being generated. When the element is consumed, the "Text" property of the newly copied object will be set to the value of the "label" attribute.
This mechanism can handle all of the data types for which there are predefined methods in GoXmlTransformer to read and write attribute values. For example, if the data type of the property is Color
, it will read the attribute using the GoXmlTransformer.ColorAttr method and will write the attribute using the GoXmlTransformer.WriteAttrVal method.
To support access to properties that are not defined on the transformer's GoXmlTransformer.TransformerType Type, the proppath can be a "path" of properties, separated by periods. For example: transformer.AddBinding("img", "Image.Name")
where the GoXmlBindingTransformer is defined for a Northwoods.Go.GoIconicNode, will read and write the value of the GoIconicNode.Image.Name
property.
As special cases, there are two property names that provide special behavior. For the Northwoods.Go.GoStroke, Northwoods.Go.GoLabeledLink, Northwoods.Go.GoPolygon, and Northwoods.Go.GoDrawing classes, you can bind to the "Points" property in order to get or set the array of points used to define those shapes. The "Points" property is not treated specially for objects of any other type.
Also as a special case for node classes, the "TreeParentNode" property binding is handled as a reference to another node, where the other node is considered to be the "parent" node in a tree-structured diagram. This supports the definition of XML that only has elements for nodes, with an implicit link from a "parent" node to the node whose element includes the attribute corresponding to the "TreeParentNode" property. The TreeLinkPrototype property of this transformer provides a link that is copied when consuming such an element. The "TreeParentNode" property is not treated specially for objects that are not instances of IGoNode
.
This mechanism has special code to handle Brush
es and Pen
s, because those types must not be modified. Instead, they are cloned, the property is set, and then the brush or pen property is set on the shape object. However, in most cases, you should bind to the Northwoods.Go.GoShape.Northwoods.Go.GoShape.BrushColor and perhaps other GoShape.Brush...
properties, and to the Northwoods.Go.GoShape.PenColor and Northwoods.Go.GoShape.PenWidth properties, since those properties can handle the cases when there is no Northwoods.Go.GoShape.Brush or Northwoods.Go.GoShape.Pen value.