将反序列化到现有对象上[编辑] IL&拦截方法调用 [英] Deserialization onto existing objects [edit] IL & Intercepting Method Calls

查看:129
本文介绍了将反序列化到现有对象上[编辑] IL&拦截方法调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在服务器和客户端之间来回传递数据.
简单的部分:在反序列化中,我想检查此处是否已经存在尚未完全反序列化的对象.如果该对象已经存在,则很可能被其他对象引用,因此到达的对象中的所有数据都必须复制到现有对象中.
困难的部分:一旦我知道对象已经存在,我想对现有对象进行反序列化,而不是对当前对象完成反序列化,然后再移动数据.
所以,问题是:
我可以劫持反序列化过程并将数据直接放入现有对象中,而不是由反序列化器创建的对象吗?
[edit]
查看IL的ctor,它将"this"压入堆栈并调用基本ctor.[ 新问题:
任何人都知道如何使用反射来拦截方法调用,基本上是将一个方法调用替换为另一个方法调用吗?
有谁知道如何在C#方法中使用IL的网站?
我需要一个主持人! :-D
谢谢
[/edit]

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]

推荐答案

不,您不能这样做,总是会创建新对象
No, you cannot do that, new objects always will be created


此处是CodeProject的文章在[代码注入]上.
这似乎是接管反序列化过程的良好起点.
Here is a CodeProject article on [Code Injection].
This looks like a good start for taking over the deserialization process.


Dmitry.抱歉,但我不相信. ;)
也许我可以拦截ctor调用,然后返回我的对象​​而不是新对象.
这些东西不是火箭科学,而是编程. MS可能会尝试隐藏东西,但最后,它通常在某个地方.
谢谢,您让我开始思考以前从未想过的领域.
--------
这可能需要学习一些IL,但是根据我的经验[ --------
新问题:有人知道如何在C#中使用IL,以及如何使用反射来劫持方法调用吗?
是的,是的,我知道. :( Google搜索.
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.


这篇关于将反序列化到现有对象上[编辑] IL&拦截方法调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆