DataContract serialization of property of “Type”?

Type cannot be expressed in a cross-platform way, so it has no inbuilt representation. Your best bet is to represent it as a string, i.e.

Type cannot be expressed in a cross-platform way, so it has no inbuilt representation. Your best bet is to represent it as a string, i.e. Public Type DeviceType { get; set; } DataMember(Name="DeviceType") private string DeviceTypeName { get { return DeviceType == null?

Null : DeviceType. AssemblyQualifiedName; } set { DeviceType = value == null? Null : Type.

GetType(value); } }.

Mark: I'm surprised you'd say this. DataContractSerializer in . NET 3.5SP1 has support for ISerializable implementations...and System.

RuntimeType implements ISerializable. Adding a KnownType should be sufficient. That said, serializing an AssemblyQualified name instead of using the builtin ISerializable implementation isn't necessarily wrong.

– JeffN825 Sep 20 at 17:06 @JeffN825 that depends entirely on what you want to see on the wire. If ISerializable was added... that is interesting but... meh - still not sure that makes it desirable in terms of what goes on the wire. – Marc Gravell?

Sep 20 at 17:11 Agreed. Far from desirable, but nonetheless, Type (RuntimeType) CAN be serialized over the wire – JeffN825 Sep 20 at 21:40.

To the root class, add the KnownType attribute with System. RuntimeType passed in as a type. In C#, KnownType(typeof(System.

RuntimeType)).

Or do you mean the class I am serializing. – Firoso Sep 20 at 16:37 The class you are serializing. – Daniel A.

White Sep 20 at 16:39 erm... no such type... do you mean System.Dynamic. DynamicMetaObject. RuntimeType?

– Firoso Sep 20 at 16:42 ok then - how are you setting the type. – Daniel A. White Sep 20 at 16:45 which type?

Type DeviceType {get;set;} I'm setting it explicitly in external code... are we on totally different pages? – Firoso Sep 20 at 16:46.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions