SerializableAttribute () and DesignerCategoryAttribute are not supported in uwp applications.
To create a successful class that can be copied directly to UWP ap, use the following tip:
This is done in the UWP app, so you can just go ahead and do it. Well, XML serialization has some limitations that you should have a default constructor without any parameters.
if you plan to serialize a class that does not have a constructor, Microsoft recommends using the DataContractSerializer for such use cases.
Now the code is pretty simple
- First create an obj instance for serialization.
- Create a new XmlSerializer object.
- Then XmlWriter obj, as it takes in many different writer classes and u It is necessary to create an instance of one of the selected line builders for demonstration purposes.
- Then just just call serialization in the obj serializer passing in your object and xmlwriter, and xml-writer returns op in the obj line builder.
- Then I just turn it into a string .. from here you can do something with xml .. save or play with it ..
The last toUpper method was just added by bcoz. I need a line for the debug point .. I donβt need it at all ...
private void Button_Click( object sender , RoutedEventArgs e ) { Animal a = new Animal("Sheep" , 4); XmlSerializer m = new XmlSerializer(typeof(Animal)); StringBuilder op = new StringBuilder(); var x = XmlWriter.Create(op); m.Serialize(x , a); string s = op.ToString(); var p = s.ToUpper(); } public class Animal { public Animal( string name , int legcount ) { this.name = name; this.legcount = legcount; } public Animal() { this.name = "default"; this.legcount = 10000000; } public string name { get; set; } public int legcount { get; set; } }
Serialized class result
<?xml version="1.0" encoding="utf-16"?> <Animal xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <name>Sheep</name> <legcount>4</legcount> </Animal>
UPDATE: with this method, you can first copy all your serialized classes into the application and deserialize them when necessary inside the application.
Now all you have to do is copy xml into a new application and implement deserialization using the same methods as shown above.
source share