Click here to Skip to main content
14,971,029 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a read only properties.
JSON are serializing Read only properties but xml are not serializing why ?
C#
public int x
{
get{return xVal;}
}


Please give me answer
Posted
Updated 21-Mar-18 2:16am
v2

XML Serialization has no support for non-public or read-only properties.

Or you can use the BinaryFormatter.
   
Hi,

Declare your class as Serializable...

Example:

C#
[Serializable]
public class Regions
{
     private DateTime _creaDt;
     ....
     ....
     public DateTime CreaDt{ get { return _creaDt; } set { _creaDt = value; } }
     ....
     ....

     public Regions() { }
}


Please vote if could help...


Regards,
   
v2
Comments
lxnitu 10-May-19 6:06am
   
This is not a read-only property.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900