Skip to content

Is there any way to generate a non-wrap csharp struct for POD in cpp? #1897

Open
@ThraceShah

Description

@ThraceShah

For this cpp struct:

struct MyStruct {
  int x;
  float y;
};

I hope to get a csharp struct like this:

struct MyStruct {
  int x;
  float y;
}

But actually i get a struct or class like this:

    public unsafe partial struct MyStruct
    {
        [StructLayout(LayoutKind.Sequential, Size = 8)]
        public partial struct __Internal
        {
            internal int x;
            internal float y;

            [SuppressUnmanagedCodeSecurity, DllImport("MyModule", EntryPoint = "??0MyStruct@@QEAA@AEBU0@@Z", CallingConvention = __CallingConvention.Cdecl)]
            internal static extern __IntPtr cctor(__IntPtr __instance, __IntPtr _0);
        }

        private MyStruct.__Internal __instance;
        internal ref MyStruct.__Internal __Instance => ref __instance;

        internal static MyStruct __CreateInstance(__IntPtr native, bool skipVTables = false)
        {
            return new MyStruct(native.ToPointer(), skipVTables);
        }

        internal static MyStruct __CreateInstance(__Internal native, bool skipVTables = false)
        {
            return new MyStruct(native, skipVTables);
        }

        private MyStruct(__Internal native, bool skipVTables = false)
            : this()
        {
            __instance = native;
        }

        private MyStruct(void* native, bool skipVTables = false) : this()
        {
            __instance = *(global::MyModule.MyStruct.__Internal*) native;
        }

        public MyStruct(global::MyModule.MyStruct _0)
            : this()
        {
            var ____arg0 = _0.__Instance;
            var __arg0 = new __IntPtr(&____arg0);
            fixed (__Internal* __instancePtr = &__instance)
            {
                __Internal.cctor(new __IntPtr(__instancePtr), __arg0);
            }
        }

        public int X
        {
            get
            {
                return __instance.x;
            }

            set
            {
                __instance.x = value;
            }
        }

        public float Y
        {
            get
            {
                return __instance.y;
            }

            set
            {
                __instance.y = value;
            }
        }
    }

Even though there is no export symbol for MyStruct in cpp

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions