2009-11-24 10 views
0

Je n'arrive pas à trouver comment désérialiser un fichier binaire. Je ne peux surtout pas comprendre comment utiliser le second argument de SerializationInfo.GetValue(); - Si je mets juste un mot-clé type là-bas, il est invalide, et si j'utilise le TypeCode, il est également invalide. C'est ma tentative actuelle (évidemment, elle ne se construit pas).Comment désérialiser un fichier binaire

 protected GroupMgr(SerializationInfo info, StreamingContext context) { 
     Groups = (Dictionary<int, Group>) info.GetValue("Groups", (Type) TypeCode.Object); 
     Linker = (Dictionary<int, int>) info.GetValue("Linker", (Type) TypeCode.Object); 
     } 

Répondre

3

Le deuxième argument est SerializationInfo.GetValue le type d'objet:

 protected GroupMgr(SerializationInfo info, StreamingContext context) { 
      Groups = (Dictionary<int, Group>) info.GetValue("Groups", typeof(Dictionary<int, Group>)); 
      Linker = (Dictionary<int, int>) info.GetValue("Linker", typeof(Dictionary<int, int>)); 
      } 
0
typeof(object) 

ou

instance.GetType() 

instance est un object. Bien sûr, remplacez par les types réels dans votre cas.

0

instancier variables temporaires:

 
Dictionary<int, Group> tmpDict = new Dictionary<int, Group>(); 
Dictionary<int, int> tmpLinker = new Dictionary<int, int>(); 

puis dans vos lignes ci-dessous:

 
Groups = (Dictionary<int, Group>) info.GetValue("Groups", tmpDict.GetType()); 
Linker = (Dictionary<int, int>) info.GetValue("Linker", tmpLinker.GetType()); 

Hope this helps Meilleures salutations, Tom.

Questions connexes