Hello,
I want to have a class that contains only a collection of another class.
For example:
public __gc class Alignment {
public:
Alignment();
...
};
// Probably using XmlIncludeAttribute such as this is wrong...
[System::Xml::Serialization::XmlIncludeAttribute(__ typeof(Alignment))]
public __gc class Alignments : public System::Collections::ArrayList {
public:
Alignments();
...
};
I figured I could use Alignments like this:
Alignment* alignment = new Alignment;
Alignments* alignments = new Alignments;
alignments->Add(alignment);
BTW, I am using XmlSerializer and XmlTextWriter.
But I get exceptions:
--------- Exception Data ---------
Message: There was an error reflecting type 'LX.LandXML'.
Exception Type: System.InvalidOperationException
Source: System.Xml
StrackTrace: at
System.Xml.Serialization.XmlReflectionImporter.Imp ortTypeMapping(TypeModel
model, String ns, ImportContext context, String dataType, Boolean repeats)
at
System.Xml.Serialization.XmlReflectionImporter.Imp ortElement(TypeModel
model, XmlRootAttribute root, String defaultNamespace)
at System.Xml.Serialization.XmlSerializer..ctor(Type type, String
defaultNamespace)
at System.Xml.Serialization.XmlSerializer..ctor(Type type)
at main(Int32 argc, SByte** argv) in c:\documents and
settings\daniel.sbg\my documents\visual studio
projects\managed_test\test1\test1.cpp:line 22
TargetSite: System.Xml.Serialization.TypeMapping
ImportTypeMapping(System.Xml.Serialization.TypeMod el, System.String,
ImportContext, System.String, Boolean)
--------- Exception Data ---------
Message: There was an error reflecting property 'Alignments'.
Exception Type: System.InvalidOperationException
Source: System.Xml
StrackTrace: at
System.Xml.Serialization.XmlReflectionImporter.Imp ortStructLikeMapping(StructModel
model, String ns)
at
System.Xml.Serialization.XmlReflectionImporter.Imp ortTypeMapping(TypeModel
model, String ns, ImportContext context, String dataType, Boolean repeats)
TargetSite: System.Xml.Serialization.StructMapping
ImportStructLikeMapping(System.Xml.Serialization.S tructModel,
System.String)
What is the usual way to serialize a collection of the same type of
objects? The end result I am after is this:
<Alignments>
<Alignment name="Centreline>
</Alignment>
<Alignment name="LeftCatch">
</Alignment>
... arbitrary number of Alignments
</Alignments>
Any pointers or references very much appreciated.
Thanks!
--
Daniel