GoXMLTransformer: Saving sublist of objects

Hi,

I use "Go.Xml" to save the objects in my diagram. I need to change an object field ("ObjPhase") in an object list field in one of my object ("MyObj") like the code below:
internal class MyObj : GoGroup
{
public Phase ObjPhase { get; set; } //Old code
//public List ObjPhase { get; set; } //New code
...
}

[Serializable]
public class Phase
{
public int PhaseMinimum { get; set; }
public int PhaseMaximum { get; set; }
public Color PhaseColor { get; set; } public Phase()
{
PhaseMinimum = 0;
PhaseMaximum = 100;
PhaseColor = Color.Black;
}
}
I can't figure how to save the new object list, is it possible to save it with your xml function?
The code to save "MyObj" in saving function of GoDocument (working ok with my single object):
private static void InitReaderWriter(GoXmlReaderWriterBase rw, ...)
{
GoXmlBindingTransformer t;
...
MyObj myobj = new MyObj();
t = new GoXmlBindingTransformer("MyObj", myobj);
...
t.AddBinding("PhaseMin", "ObjPhase.PhaseMinimum");
t.AddBinding("PhaseMax", "ObjPhase.PhaseMaximum");
t.AddBinding("PhaseColor", "ObjPhase.PhaseColor");
rw.AddTransformer(t);
}
Thank you for any help you can provide.

Define a transformer for the Phase class.

Define a custom transformer class inheriting from GoXmlBindingTransformer for reading/writing instances of your MyObj class.

Override GenerateBody and iterate over your list of Phases, calling this.Writer.GenerateObject on each one.

Set BodyConsumesChildElements to true and override ConsumeChild to add the new instance of a Phase to your list of Phases.

Thanks a lot!

This works great, your support team is very helpful.
I still have a small question, in my "custom transformer class inheriting from GoXmlBindingTransformer" a need to pass a "proto" object in the constructor. My main class ("MyObj") have many others class which was derived from it and this class do not have default constructor. So, my custom transformer look like this:
public class XmlTransformMyObj : GoXmlBindingTransformer
{
public XmlTransformMyObj :base(new MyObj(... , ...))
{
...
}
My question, even if i use specific (default) parameter in this constructor, the class seems to works with every parameter i can use, is my "proto" object ok or i need to make a default constructor for "MyObj" to be clean?

Do I understand correctly that you never create an object of the base class? Then you should be fine.



If you need a class without a default constructor, you can override the Allocate method, as Walter mentions here:


Good read between the lines, i never create an object of the base class.

Thanks for the precision.

I have another question related to this development:

I use undomanager in my program and i do not want my subobject to use the undo/redo functionnality but i want them to set the Dirty flag if some subobject was modified in my document.
I try "Document.IsModified = true;" in my main object containing subobject but this not works (seems the value cannot be set to true cause nothing was modified for him and no record for undo/redo). So, what i need to do to set the Dirty flag of document without messing with my current undo/redo which works great.
Maybe using a new bool value in my GoDocument class which indicates the Dirty status of subobject (like IsSubObjectModified) and check the status of both IsModified and IsSubObjectModified to check if the document have modification. It is correct or do you have better option?

The API Reference for IsModified says:



When using an UndoManager, you should be making all changes within a transaction.

After finishing or aborting a transaction, you can set GoDocument.IsModified

to false, and then it will remain false until another change is made to the document.




but… if you set it to true, and you’re using the undo manager, it just returns the state of the undo engine.



I think your solution of tracking changes to your special subobjects separately sounds like the right thing to do.