帮助翻译反射解构到编译code [英] Help translating Reflector deconstruction into compilable code
问题描述
所以我反射-ING一些框架2.0 code和具有以下解构结束
So I am Reflector-ing some framework 2.0 code and end up with the following deconstruction
fixed (void* voidRef3 = ((void*) &_someMember))
{
...
}
这不会编译由于 fixed语句赋值的右侧可能不是一个施法前pression
据我所知,反射器只能近似,一般我可以看到一个清晰的路径,但是这是我经历过的外面了一下。
I understand that Reflector can only approximate and generally I can see a clear path but this is a bit outside my experience.
问:什么是反射器试图给我描述
Question: what is Reflector trying to describe to me?
更新:
我也看到以下
fixed (IntPtr* ptrRef3 = ((IntPtr*) &this._someMember))
更新:
所以,作为米奇说,它不是一个位操作符,而是一个AddressOf运算
So, as Mitch says, it is not a bitwise operator, but an addressOf operator.
问题现在是:
fixed (IntPtr* ptrRef3 = &_someMember)
失败,XXX *'到'System.IntPtr *的无法隐式转换类型'。一个显式转换存在(是否缺少强制转换?)
'编译错误。
所以,我似乎如果我这样做,如果我不给该死该死。任何想法?
So I seemed to be damned if I do and damned if I dont. Any ideas?
更新:
我想我已经想通。一次偶然的机会我又回到了使用无效*
除权pression并取消了管型和VS停止抱怨,因为我从参加该谈话聚集了无效*
和 IntPtr的*
是等价的,我只是换出来,造成这样的:
I think i have it figured. By chance I went back to the expression that was using void*
and removed the casts and VS stopped complaining and since I gathered from the participants in this conversation that void*
and intptr*
are equivalent I simply swapped them out, resulting in this:
fixed (void* ptrRef3 = &_someMember)
和VS停止抱怨。有人可以验证
and VS stopped complaining. Can someone verify that
fixed (void* ptrRef3 = &_someMember)
等同于
fixed (IntPtr* ptrRef3 = &_someMember)
推荐答案
据正在 _someMember
的地址,并将其转换为(无效* )
(即指针地址),然后设置到该地址的位置。
It is taking the address of _someMember
and casting it to (void *)
(i.e. a pointer address), and then setting a location to that address.
的固定
语句'销'的对象,$ P $来自移动它pvents的GC。
The fixed
statement 'pins' the object, and prevents the GC from moving it around.
在'&放大器;'在这方面采用的是地址中'操作,不按位与。
The '&' used in that context is the 'Address Of' operator, not Bitwise And.
在回应更新的问题:
你试过:
fixed (void* voidRef3 = &_someMember)
{
...
}
这篇关于帮助翻译反射解构到编译code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!