O GoConqr está de visual novo! Conte para nós o que você achou.

Flashcards

Serialization

Thiago Avelino Português 20 flashcards

Flashcards do conjunto (20)

  1. 1What is Serialization?Serialization is the process of transforming an object into a form that can either be persisted to
    storage or transferred from one application domain to another.
  2. 2What are the types of serialization that the .NET Framework supports?Binary, XML, and JSON. Or you can customize one to yourself.
  3. 3What are the serialization namespace?Binary: System.Runtime.Serialization.Formatters.Binary
    XML:
    System.Xml.Serialization
    JSON:
    System.Runtime.Serialization
  4. 4What does the class attribute [Serializable] sinalize? Where that can be used?For a class to be serialized, you must add the [Serializable] attribute to the top of the class. That can be used on a class, struct and enum.
  5. 5How to serialize on binary format?IFormatter formatter = new BinaryFormatter();
    Stream stream = new FileStream("Person.bin", FileMode.Create, FileAccess.Write,
    FileShare.None);
    formatter.Serialize(stream, person);
    stream.Close();
  6. 6Are the private fields serialized?Yes
  7. 7How to deserialize on binary format?IFormatter formatter = new BinaryFormatter();
    stream = new FileStream("Person.bin",FileMode.Open,FileAccess.Read,FileShare.Read);
    Person person2 = (Person)formatter.Deserialize(stream);
    stream.Close();
  8. 8How to exclude a field from being serialized(binary)?It's required to use the attribute [NonSerialized].
  9. 9How to serialize to XML?XmlSerializer xmlSerializer = new XmlSerializer(typeof(Person));
    StreamWriter streamWriter = new StreamWriter("Person.xml");
    xmlSerializer.Serialize(streamWriter, person);
  10. 10How to deserialize from XML?XmlSerializer xmlSerializer = new XmlSerializer(typeof(Person));
    FileStream fs = new FileStream("Person.xml", FileMode.Open);
    Person person = (Person)xmlSerializer.Deserialize(fs);
  11. 11How to exclude a field from being serialized(xml)?It's required the [XmlIgnore] attribute.
  12. 12What is the difference between binary and xml serialization?Binary: You need the [Serializable] attribute and private fields are serialized.
    XML: You don't need the [Serializable] attribute and only the public properties and fields are serialized.
  13. 13How to serialize to JSON?Put an attribute before each property or field that you want to be serialized - [DataMember]. In addition you need to add the [DataContract] attribute before the declaration of the class. Then:
    var ser = new DataContractJsonSerializer(typeof(P));
    ser.WriteObject(stream, person);
  14. 14How to deserialize from JSON?DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Person));
    person = (Person)ser.ReadObject(stream);
  15. 15What are the two forms of customize the serialization process?The first is to add an attribute
    before a custom method that manipulates the object’s data during and upon completion of serialization
    and deserialization.
    The second option for customizing the serialization process is to implement the ISerializable interface.
  16. 16What are the xml serialization attributes and what do they stand for?XmlIgnore: Ignore property on Ser/Des XmlAttribute: set property as XML attribute
    XmlElement: set property as XML element XmlArray: Control how the array is Ser/Des
    XmlArrayItem: It defines the supported types of an array
  17. 17Does Binary Formatter have another way of deserialize an object? If yes, what are the pro and cons?Yes. It's called the UnsafeDeserialization. It has improved performance when comparing to Deserialization method.But, do not use this method if your code can be called from partially trusted code
  18. 18What are the interface callbacks?IDeserializationCallback that implements IDeserializationCallback.OnDeserialization(Object sender)
    ISerializable
  19. 19What is the XPathNavigator?The XPathNavigator offers an easy way to navigate through an XML document. It uses a XPath query for elements navigation and filter.
  20. 20What is the basic syntax of the XPath query?// - All elements in the document.
    [@firstName=’Jane’] - attribute filter

Informações

Descrição
FlashCards sobre Serialization, criado por Thiago Avelino em 08-01-2016.
Criado por
Thiago Avelino
Visualizações
2
Avaliação

Fale Conosco

Sobre o que é sua mensagem?

O que você acha do novo visual?

Você gostou?