c# - Serialize property of type object -


I have a serializable class that contains some properties, which contains a variable of type object. I want my class to be able to individually (definitely serial) objects. The problem is, I get an exception during serialization:

  Use the XmlInclude or the SoapInclude feature to specify those types that are not known to be statically  < / pre> 

I have a small sample for this problem:

  class program {static zero main (string [] args) {serialcable test class testclass = new serializablet class (); Testclass.Params = New Extended Mercury (); Memorystream ms = new memorystream (); XmlSerializer xmlf = New XmlSerializer (testClass.GetType ()); Xmlf.Serialize (MS, Test Class); Ms.Cacity = (int) ms.Length; Ms.Close (); Byte [] array = m. Gatebuffer (); }} [Serialable] public class serializablet class {[XmlElement (Elementname = "Ultimate")] Public Object Ultimate; } [Serialable] public class paramagebase {[XmlElement (element name = "some value")] Public Int32 SomeValue; } [Serialable] Public class Extended Param: Paramabase ({XMLAlement (Elementname = "Some NewView")) Public Int 32 Some NewWeiwy; }   

Is there any possibility of serialising and deorizing this class without specifying the "ultimate" type of arbitrary type?

Best Relationship

Is it possible to include all possible types in the class? (This means that the message means no information is included for extended paramas .)

You can call it in XmlSerializeritself Can include or include in the main category: [serialable] [XmlInclude (typebase) [XmlInclude (typef (extended Perm)) public class serializablet class {[XmlElement (Elementname = "Ultimate")] Public Object is absolute; }

But if you do not know all types of information, to dynamically serialize:

  // Fixed: XmlSerializer xmlf = New XmlSerializer (Testclass.GetType (), new type [] {typef (Extended Perm)}); // dynamic: type [extratypes = testClass.Params == tap? Null: new type [] {testClass.Params.GetType ()}; XmlSerializer xmlf = New XmlSerializer (testClass.GetType (), Extras);    

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -