Outils pour utilisateurs

Outils du site


lang:csharp:serialisation

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
Prochaine révision
Révision précédente
lang:csharp:serialisation [2019/03/06 11:52] – Ajout de "OnDeserializing" rootlang:csharp:serialisation [2020/04/27 08:39] (Version actuelle) – mhtml -> html root
Ligne 1: Ligne 1:
 +Il faut ajouter la référence ''System.Runtime.Serialization''.
 +
 ====Préparation des classes==== ====Préparation des classes====
 <code csharp> <code csharp>
Ligne 43: Ligne 45:
 </code> </code>
  
-<note important>''IsReference'' ne marche qu'avec la sérialisation au format XML, pas JSON.</note>+<WRAP center round important 60%> 
 +''IsReference'' ne marche qu'avec la sérialisation au format XML, pas JSON. 
 +</WRAP>
  
   * Héritage   * Héritage
Ligne 73: Ligne 77:
   by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.   by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.
  
-[[https://stackoverflow.com/questions/30210393/exception-during-the-serialization-type-with-data-contract-name-is-not-expecte/30214583|Exception during the serialization - Type with data contract name is not expected]] {{ :lang:csharp:serialisation:c_-_exception_during_the_serialization_-_type_with_data_contract_name_is_not_expected_-_stack_overflow.mhtml |Archive du 04/03/2019}}+[[https://stackoverflow.com/questions/30210393/exception-during-the-serialization-type-with-data-contract-name-is-not-expecte/30214583|Exception during the serialization - Type with data contract name is not expected]] {{ :lang:csharp:serialisation:c_-_exception_during_the_serialization_-_type_with_data_contract_name_is_not_expected_-_stack_overflow_2020-04-27_8_18_17_am_.html |Archive du 13/05/2015 le 27/04/2020}}
  
-[[https://blogs.msdn.microsoft.com/youssefm/2009/04/22/understanding-known-types/|Understanding Known Types]] {{ :lang:csharp:serialisation:understanding_known_types_youssef_m_s_blog.mhtml |Archive du 04/03/2019}}+[[https://docs.microsoft.com/en-us/archive/blogs/youssefm/understanding-known-types/|Understanding Known Types]] {{ :lang:csharp:serialisation:understanding_known_types_microsoft_docs_2020-04-27_8_18_33_am_.html |Archive du 22/04/2009 le 27/04/2020}}
  
 ====Sérialisation en XML==== ====Sérialisation en XML====
Ligne 88: Ligne 92:
     using (MemoryStream ms = new MemoryStream())     using (MemoryStream ms = new MemoryStream())
     {     {
-      _batch = (BatchPoco)ser.ReadObject(reader, true);+      try 
 +      { 
 +        _batch = (BatchPoco)ser.ReadObject(reader, true); 
 +      } 
 +      catch (SerializationException) 
 +      { 
 +        // Fichier non valide. 
 +      }
     }     }
   }   }
Ligne 109: Ligne 120:
 </code> </code>
  
-[[https://docs.microsoft.com/fr-fr/dotnet/framework/wcf/samples/datacontractserializer-sample|DataContractSerializer, exemple]] {{ :lang:csharp:serialisation:datacontractserializer_exemple_microsoft_docs.mhtml |Archive du 04/03/2019}}+[[https://docs.microsoft.com/fr-fr/dotnet/framework/wcf/samples/datacontractserializer-sample|DataContractSerializer, exemple]] {{ :lang:csharp:serialisation:datacontractserializer_exemple_-_wcf_microsoft_docs_2020-04-27_8_18_42_am_.html |Archive du 03/30/2017 le 27/04/2020}}
  
 ====Sérialisation en JSON==== ====Sérialisation en JSON====
 C'est la même chose avec ''DataContractJsonSerializer''. C'est la même chose avec ''DataContractJsonSerializer''.
  
-[[https://docs.microsoft.com/fr-fr/dotnet/framework/wcf/feature-details/how-to-serialize-and-deserialize-json-data|Procédure : Sérialiser et désérialiser des données JSON]] {{ :lang:csharp:serialisation:procedure_serialiser_et_deserialiser_des_donnees_json_microsoft_docs.mhtml |Archive du 04/03/2019}}+[[https://docs.microsoft.com/fr-fr/dotnet/framework/wcf/feature-details/how-to-serialize-and-deserialize-json-data|How to use DataContractJsonSerializer]] {{ :lang:csharp:serialisation:comment_utiliser_datacontractjsonserializer_-_wcf_microsoft_docs_2020-04-27_8_19_16_am_.html |Archive du 25/03/2019 le 27/04/2020}} 
 + 
 +<WRAP center round important 60%> 
 +TODO : Cette classe est dépréciée au profit du namespace ''System.Text.Json''
 +</WRAP> 
  
 ====Initialisation dans le constructeur==== ====Initialisation dans le constructeur====
Ligne 145: Ligne 161:
   * ''OnDeserialized'' : fonction exécutée après la désérialisation de l'instance.   * ''OnDeserialized'' : fonction exécutée après la désérialisation de l'instance.
  
 +En cas d'héritage, ''OnSerializing'' est appelée pour le parent, puis pour l'enfant et enfin les ''OnSerialized'' sont appelées. Puis la désérialisation passe à l'objet suivant.
lang/csharp/serialisation.1551869532.txt.gz · Dernière modification : 2019/03/06 11:52 de root