Xml Deserialization with Visual C++ .NET

G

Guest

Hi,

I'm trying to deserialize a VC++ .NET class and am stumped by the following
problem :
In order to create the XmlSerializer you need to pass the type of the object
being created.
The doc shows the example in C# (no C++ available) :[C#]
MySerializableClass myObject;
// Constructs an instance of the XmlSerializer with the type
// of object that is being deserialized.
XmlSerializer mySerializer = new XmlSerializer(typeof(MySerializableClass));
....
<<
How do I get the System::Type for a class in VC++ ?
I tried Class::GetType() but that generates a compile error C2352 (illegal
call of non-static member function) and it doesn't look like 'typeof' exists.

Help and/or VC++ .NET example would be appreciated!
 
P

Paul Wohlhart

Meta-Meta said:
Hi,

I'm trying to deserialize a VC++ .NET class and am stumped by the following
problem :
In order to create the XmlSerializer you need to pass the type of the object
being created.
The doc shows the example in C# (no C++ available) :

[C#]
MySerializableClass myObject;
// Constructs an instance of the XmlSerializer with the type
// of object that is being deserialized.
XmlSerializer mySerializer = new XmlSerializer(typeof(MySerializableClass));
...
<<
How do I get the System::Type for a class in VC++ ?
I tried Class::GetType() but that generates a compile error C2352 (illegal
call of non-static member function) and it doesn't look like 'typeof' exists.

1)
well if the question is how to write the "typeof(...)" statement of
above have a look at

http://msdn.microsoft.com/library/d...serializationxmlserializerclassctortopic2.asp

important line is

XmlSerializer* serializer =
new XmlSerializer(__typeof(OrderedItem));

2)
if you mean that you dont know the type of class you are deserializing
at all, there is a problem: you have to.
anyway if you dont know what it is what you are dealing with, what would
you do with it?

if it was the second, be more explicit about what you want to do


cheers,
paul
 
G

Guest

Paul,

My problem is not with Serializing but deserializing, and not in C# but in
VC++ .NET.
When deserializing, the object does not exist yet, as it will be created as
a result of the deserialization therefore I cannot get the type from the
object (or so argues the compiler ;-) ).
The example supplied in MSDN is in C# and shows the serializer getting the
type from the Class (not object) for deserialization (see C# code snippet in
my first post).
What I do not know how to do in VC++ is to get the type of the Class as
'typeof' does not exist and as I was unable to find an equivalent
method/function for a custon class.

Many thanks,

~Meta-Meta.

Paul Wohlhart said:
Meta-Meta said:
Hi,

I'm trying to deserialize a VC++ .NET class and am stumped by the following
problem :
In order to create the XmlSerializer you need to pass the type of the object
being created.
The doc shows the example in C# (no C++ available) :

[C#]
MySerializableClass myObject;
// Constructs an instance of the XmlSerializer with the type
// of object that is being deserialized.
XmlSerializer mySerializer = new XmlSerializer(typeof(MySerializableClass));
...
<<
How do I get the System::Type for a class in VC++ ?
I tried Class::GetType() but that generates a compile error C2352 (illegal
call of non-static member function) and it doesn't look like 'typeof' exists.

1)
well if the question is how to write the "typeof(...)" statement of
above have a look at

http://msdn.microsoft.com/library/d...serializationxmlserializerclassctortopic2.asp

important line is

XmlSerializer* serializer =
new XmlSerializer(__typeof(OrderedItem));

2)
if you mean that you dont know the type of class you are deserializing
at all, there is a problem: you have to.
anyway if you dont know what it is what you are dealing with, what would
you do with it?

if it was the second, be more explicit about what you want to do


cheers,
paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top