我怎么能忽略一个字段的P / Invoke封送处理的结构时, [英] How can I ignore a field when marshalling a structure with P/Invoke

查看:124
本文介绍了我怎么能忽略一个字段的P / Invoke封送处理的结构时,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要为元帅以P / Invoke的使用结构,但这种结构包含一个字段,只与我的管理code,所以我不希望它被封,因为它不属于在天然结构。它甚至有可能?我一直在寻找的序列相似的属性,以非序列化,但它似乎并不存在...

I want to marshal a structure for use with P/Invoke, but this struct contains a field that is only relevant to my managed code, so I don't want it to be marshaled since it doesn't belong in the native structure. Is it even possible ? I was looking for an attribute similar to NonSerialized for serialization, but it doesn't seem to exist...

struct MyStructure
{
    int foo;
    int bar;

    [NotMarshaled] // This attribute doesn't exist, but that's the kind of thing I'm looking for...
    int ignored;
}

任何建议将AP preciated

Any suggestion would be appreciated

推荐答案

有没有办法让CLR忽视的一个领域。我会转而使用两个结构,或许使一个在另一个的成员。

There's no way to make the CLR ignore a field. I would instead use two structures, and perhaps make one a member of the other.

struct MyNativeStructure 
{ 
    public int foo; 
    public int bar; 
} 

struct MyStructure 
{ 
    public MyNativeStruct native; 
    public int ignored; 
}

这篇关于我怎么能忽略一个字段的P / Invoke封送处理的结构时,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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