35 builder.WriteLine(
"[global::System.Runtime.InteropServices(LayoutKind.Sequential)]");
36 builder.WriteLine($
"public struct {Name}");
37 builder.WriteLine(
"{");
40 if (!_symbol.IsStatic)
41 builder.WriteLine(
"public System.IntPtr __this;");
43 foreach (var parameter
in _symbol.Parameters)
45 var isPrimitive = parameter.Type.IsPrimitives();
47 var type = isPrimitive ? parameter.Type.GetManagedPackedName() :
"System.IntPtr";
48 var name = !isPrimitive || type ==
"unsafe char*" ? $
"__unsafe_{parameter.Name}" : parameter.Name;
50 builder.WriteLine($
"public {type} {name};");
53 if (!_symbol.ReturnsVoid)
54 builder.WriteLine($
"public {_symbol.ReturnType.GetManagedPackedName()} __return;");
56 foreach (var parameter
in _symbol.Parameters)
58 if (parameter.Type.GetFullName() ==
"System::String")
61 builder.WriteLine($
"public string {parameter.Name}");
62 builder.WriteLine(
"{");
64 builder.WriteLine(
"get");
65 builder.WriteLine(
"{");
67 builder.WriteLine($
"return System.Runtime.InteropServices.Marshal.PtrToStringUTF8(__unsafe_{parameter.Name});");
69 builder.WriteLine(
"}");
71 builder.WriteLine(
"}");
73 else if (!parameter.Type.IsPrimitives())
75 var fullname = parameter.Type.GetManagedFullName();
78 builder.WriteLine($
"public {fullname} {parameter.Name}");
79 builder.WriteLine(
"{");
81 builder.WriteLine(
"get");
82 builder.WriteLine(
"{");
84 builder.WriteLine($
"return ({fullname})System.Runtime.InteropServices.GCHandle.FromIntPtr(__unsafe_{parameter.Name}).Target;");
86 builder.WriteLine(
"}");
88 builder.WriteLine(
"}");
93 builder.WriteLine(
"}");