Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am passing data back and forth between server and client.
The easy part: In the deserialization, I would like to check to see if the not yet fully deserialized object already exists here. If the object is already here, it could well be referenced by other objects, so all the data in the arriving object has to be copied to the existing one.
Hard part: Once I know the object already exists, I would like to deserialize over the existing object instead of finishing the deserialization on the current object and then moving the data.
So, the question:
Can I hijack the deserialization process and put the data directly into the existing object instead of the one being created by the deserializer?
[edit]
Looking at the IL for ctor, it pushes 'this' onto the stack and calls the base ctor.[^]
While I can not (?) replace 'this' locally, I could intercept the call, and push the old object onto the stack, instead of the new one. All the deserialization would be done on it, instead of the new one. I could just discard the new object after deserialization, since the old one would now have all the values deserialized onto it.
New questions:
Anyone know how to use reflection to intercept a method call, basically substituting one method call for another?
Anyone know of a how to site for using IL in C# methods?
I need a facilitator! :-D
Thanks
[/edit]
Posted
Updated 18-Feb-10 18:48pm
v2

No, you cannot do that, new objects always will be created
 
Share this answer
 
Here is a CodeProject article on [Code Injection].
This looks like a good start for taking over the deserialization process.
 
Share this answer
 
Dmitry. Sorry, but I disbelieve. ;)
Maybe I can intercept the ctor call, and return my object instead of the new one.
This stuff is not rocket science, it is programming. MS may try to hide stuff, but in the end, it is usually there, somewhere.
Thank you, you got me thinking into areas I had not previously thought of.
--------
This may require learning some IL, but from what I have [seen] it looks like the call pushes 'this' onto the stack, then makes the call. If I have 'this', as well as the old one, I can push the old one on, instead of 'this'. That could allow the constructor/deserialiser to unroll onto the old object.
--------
New question: Anyone know how to use IL in C#, and how to use reflection to hijack method calls?
Yeah, yeah, I know. :( Google it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900