To achieve what you described, you would have to deserialize the entire object graph from the stream, not knowing the type from which it was serialized. But this is not possible because the serializer does not store such information. AFAIK works as follows. Suppose you have several types:
class A { bool p1 } class B { string p1; string p2; A p3} // instantiate them: var b = new B { p1 = "ppp1", p2 = "ppp2", p3 = new A { p1 = true} };
When the serializer writes this object, it starts to draw a graph of the object in a certain order (I guess in alphabetical order) and writes the type of the object, and then its contents. So your binary stream will look like this:
[B:[string:ppp1][string:ppp2][A:[bool:true]]]
You see, there are only values ββand their types. But the order is implicit - as it is written. So, if you change your object B, suppose that
class B { A p1; string p3; string p3;}
Serialzer will not work because it will try to determine the instance of the string (which was first serialized) for a pointer to A. You can try to reproduce the process of creating a binary serialization, then you can create a dynamic tree of serialized objects. But this will require considerable effort.
For this purpose, I would create a class like this:
class Node { public string NodeType; public List<Node> Children; public object NodeValue; }
Then, while you are reading from the stream, you can create these nodes and recreate the entire serialized tree and analyze it.
source share