Serialize the class
-
Hi Here is the class structure in which i am facing the problem Class1 : User Properties: Name, Phone No, City Class2 : Address Properties: Street, City Now i am serializing the User class and also add an object of address class in it to serialize it too. the error that I'm gettin is regarding double entry of a property (City) in the file. Is there any method using which i can distinguish between the two properties with same name but from different classes. I and using SOAP for serialization Thanks in advance Parag
-
Hi Here is the class structure in which i am facing the problem Class1 : User Properties: Name, Phone No, City Class2 : Address Properties: Street, City Now i am serializing the User class and also add an object of address class in it to serialize it too. the error that I'm gettin is regarding double entry of a property (City) in the file. Is there any method using which i can distinguish between the two properties with same name but from different classes. I and using SOAP for serialization Thanks in advance Parag
-
Hi Here is the class structure in which i am facing the problem Class1 : User Properties: Name, Phone No, City Class2 : Address Properties: Street, City Now i am serializing the User class and also add an object of address class in it to serialize it too. the error that I'm gettin is regarding double entry of a property (City) in the file. Is there any method using which i can distinguish between the two properties with same name but from different classes. I and using SOAP for serialization Thanks in advance Parag
The problem is that in the XML file, both City properties will have the same exact name. This obviously won't work. So, you have to change the name of one of the City properties in the file, not necessarily in your code. This is easily done if you use the XmlElement attribute on the property definition:
<XmlElement(ElementName = "AddrCity")> \_ Public Property City() As String ...
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
Hi Here is the class structure in which i am facing the problem Class1 : User Properties: Name, Phone No, City Class2 : Address Properties: Street, City Now i am serializing the User class and also add an object of address class in it to serialize it too. the error that I'm gettin is regarding double entry of a property (City) in the file. Is there any method using which i can distinguish between the two properties with same name but from different classes. I and using SOAP for serialization Thanks in advance Parag
ParagGupta wrote:
I and using SOAP for serialization
You could also switch to binary serialization which doesn't have this limitation.... In my experience, SOAP serialization is not very practical. Once you start serializing a realistic number of objects, the size of the output grows very rapidly. You can also tell that Microsoft is moving away from it since it doesn't support generics.
-
ParagGupta wrote:
I and using SOAP for serialization
You could also switch to binary serialization which doesn't have this limitation.... In my experience, SOAP serialization is not very practical. Once you start serializing a realistic number of objects, the size of the output grows very rapidly. You can also tell that Microsoft is moving away from it since it doesn't support generics.
Hi, Well thanks for all your responses. But I cant use any of these as the porblem using these are : 1. I dont know which properties it will use and so i cant change the name. 2. Binary cant be used as it wont support if i made any changes for reading/writing from/in the file. Isn't there any method that can distinguish each into different regions like ......... all the properties in employee....... <\employee>
........ all the properties in address......... <\address> .......