Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET, Why must I use *Specified property to force serialization? Is there a way to not do this?

Tags:

I am using xml-serialization in my project to serialize and deserialize objects based on an xml schema. I used the xsd tool to create classes to use when serializing / deserializing the objects.

When I go to serialize the object before sending, I am forced to set the *Specified property to true in order to force the serializer to serialize all propeties that are not of type string.

Is there a way to force the serialization of all properties without having to set the *Specified property to true?

like image 741
TheDevOpsGuru Avatar asked Jul 15 '11 18:07

TheDevOpsGuru


People also ask

How do you ignore property serializable?

Try marking the field with [NonSerialized()] attribute. This will tell the serializer to ignore the field.

Why do we need to serialize an object in C#?

Serialization allows the developer to save the state of an object and re-create it as needed, providing storage of objects as well as data exchange. Through serialization, a developer can perform actions such as: Sending the object to a remote application by using a web service.

What is the serialization in .NET how is it affecting to .NET programming?

Serialization is a process of converting an object into a stream of data so that it can be is easily transmittable over the network or can be continued in a persistent storage location. This storage location can be a physical file, database or ASP.NET Cache.

What is serialization in .NET with example?

Serialization is the process of converting the state of an object into a form that can be persisted or transported. The complement of serialization is deserialization, which converts a stream into an object. Together, these processes allow data to be stored and transferred. .


1 Answers

The FooSpecified property is used to control whether the Foo property must be serialized. If you always want to serialize the property, just remove the FooSpecified property.

like image 61
Thomas Levesque Avatar answered Oct 15 '22 02:10

Thomas Levesque