Reputation: 26051
I'm having some trouble figuring out how to deserialize a binary file. I mostly can't figure out how to use the second argument of SerializationInfo.GetValue(); - if I just put a type keyword there, it's invalid, and if I use the TypeCode, it's invalid as well. This is my current attempt (obviously it doesn't build).
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 );
}
Upvotes: 0
Views: 231
Reputation: 66
The second argument in SerializationInfo.GetValue is the object type:
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>));
}
Upvotes: 3
Reputation: 34592
Instantiate temporary variables:
Dictionary<int, Group> tmpDict = new Dictionary<int, Group>(); Dictionary<int, int> tmpLinker = new Dictionary<int, int>();
then in your lines below:
Groups = (Dictionary<int, Group>) info.GetValue("Groups", tmpDict.GetType()); Linker = (Dictionary<int, int>) info.GetValue("Linker", tmpLinker.GetType());
Hope this helps, Best regards, Tom.
Upvotes: 0
Reputation: 241641
typeof(object)
or
instance.GetType()
where instance
is an object
. Of course, replace by the actual types in your case.
Upvotes: 0