c# - DeSerialize XML into Class, Subclass & Properties making SubClass not null -


I have some XML that I am de-serialing and all works fine except for one of my properties in a serialized class For example a class; Person.Address.Postcode

The person in the know is a property but the address is a property that has properties like postcode.

If the incoming XML does not contain address information and deserialization, place when I see the person. The address is empty.

What I would like to do is for the person. The address is not empty and does not have zero like postcode, but empty strings.

I have tried the IsNullable = false attribute on the property, but it does not work.

How is this possible?

You can create a codec in a code that gives a string. If this is not set, otherwise the value. Or make it impossible to set it in a set block to make a null addition, apart from this, you can become null by making the address in a structure. In that case you can set the postcode in the string. Empty in the manufacturer with no parameters. Or you can apply your class eDescierization callback and make the law on diasisation your address anytime you want.

  Private string _posted; Public string postcode {get {return _postcode ?? String.Empty; } Set {_postcode = value; }}  

or

  private string _postcode = String.Empty; Public string postcode {get {return_postcode; } Set {_postcode = value ?? String.Empty; }}  

I prefer the option first because even the address sets something to clear it from inside the square, it will never be blank.


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -