/// <summary> /// Converts the given value according to the mappings and id-refs in /// this codec and uses writeAttribute to write the attribute into the /// given node. /// </summary> /// <param name="enc">Codec that controls the encoding process.</param> /// <param name="obj">Object whose member is going to be encoded.</param> /// <param name="fieldname"></param> /// <param name="value">Value of the property to be encoded.</param> /// <param name="node">XML node that contains the encoded object.</param> protected void EncodeValue(mxCodec enc, Object obj, string fieldname, Object value, XmlNode node) { if (value != null && !IsExcluded(obj, fieldname, value, true)) { if (IsReference(obj, fieldname, value, true)) { Object tmp = enc.GetId(value); if (tmp == null) { Trace.WriteLine("mxObjectCodec.encode: No ID for " + GetName() + "." + fieldname + "=" + value); return; // exit } value = tmp; } Object defaultValue = GetFieldValue(template, fieldname); if (fieldname == null || enc.IsEncodeDefaults || defaultValue == null || !defaultValue.Equals(value)) { WriteAttribute(enc, obj, GetAttributeName(fieldname), value, node); } } }
/// <summary> /// Encodes the value of each member in then given obj /// into the given node using encodeFields and encodeElements. /// </summary> /// <param name="enc">Codec that controls the encoding process.</param> /// <param name="obj">Object to be encoded.</param> /// <param name="node">XML node that contains the encoded object.</param> protected virtual void EncodeObject(mxCodec enc, Object obj, XmlNode node) { mxCodec.SetAttribute(node, "id", enc.GetId(obj)); EncodeFields(enc, obj, node); EncodeElements(enc, obj, node); }