Groups | Blog | Home
all groups > dotnet xml > november 2003 >

dotnet xml : Serializing "Type" class



Maersa
11/21/2003 3:42:39 PM
Hi All,

Was anybody able to serialize the "Type" class properly using
XmlSerializer()....
Want to serialize and deserialze the Type in a string form, but can this be
done ?

myobj.Type = typeof(System.String) as <type>System.String</type>

thanks a ton.

Oleg Tkachenko
11/23/2003 12:23:11 PM
[quoted text, click to view]

AFAIK that's impossible due to security reasons.
--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog
Dino Chiesa [Microsoft]
11/24/2003 1:54:32 PM
If all you want is the type name, can you use a buddy member that depends on
the actual type?

public class MyType {
[XmlIgnore] // this is not serialized
public System.Type ActualTypeInstance;

public System.String TypeName {
get {
return ActualTypeInstance.FullName;
}
set {
ActualTypeInstance= System.Type.GetType(value);
}
}
}

-Dino


[quoted text, click to view]

Christoph Schittko [MVP]
11/28/2003 3:53:08 PM
The XmlSerializer is not really intended for anything but binding XML to
simple data classes, check [0] for a more detailed discussion.

Why do you want to serialize a Type object to a string anyway? There isn't
much state information in a Type object that's interesting to serialize. If
you need to store information about what Type you were dealing with, then
storing the Type's FullName property will suffice.

--
HTH
Christoph Schittko [MVP]
Software Architect, .NET Mentor

[0] http://www.topxml.com/xmlserializer/serializable_classes.asp

[quoted text, click to view]

AddThis Social Bookmark Button