代码之家  ›  专栏  ›  技术社区  ›  Thomas Levesque

使用P/Invoke编组结构时,如何忽略字段

  •  15
  • Thomas Levesque  · 技术社区  · 16 年前

    NonSerialized 用于序列化,但它似乎不存在。..

    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;
    }
    

    3 回复  |  直到 4 年前
        1
  •  7
  •   Mattias S    16 年前

    struct MyNativeStructure 
    { 
        public int foo; 
        public int bar; 
    } 
    
    struct MyStructure 
    { 
        public MyNativeStruct native; 
        public int ignored; 
    } 
    
        2
  •  0
  •   g t Omri Btian    8 年前

    1. doThis(ref myStruct) doThis([In, Out] myClass)

        3
  •  -1
  •   Vladislav Sorokin    6 年前

    private int marshaled { get; set; }
    

    Marshal.SizeOf

    private int skipped
    {
        get { return 0; }
        set { }
    }