openvr icon indicating copy to clipboard operation
openvr copied to clipboard

Make types in the C# API `partial`

Open ericwj opened this issue 2 years ago • 3 comments

Consider declaring the types in /openvr/headers/openvr_api.cs with the partial modifier.

This will greatly simplify integrating the types in applications, because that way the types can be augmented with for example conversion or reinterpret cast operators without touching the autogenerated file.

ericwj avatar Jul 23 '22 22:07 ericwj

Can you provide a small diff as an example so I can be sure to get it correct?

aleiby avatar Aug 16 '22 19:08 aleiby

Making the declarations partial won't hurt, so just do it for every single declaration of struct or class.

Here is how it works:

A minimal diff with the first occurrences of (differently looking) declarations:

-public struct IVRSystem
+public partial struct IVRSystem
-public class Utils
+public partial class Utils
-[StructLayout(LayoutKind.Explicit)] public struct VREvent_Data_t
+[StructLayout(LayoutKind.Explicit)] public partial struct VREvent_Data_t
-public class OpenVR
+public partial class OpenVR
{
-	class COpenVRContext
+	partial class COpenVRContext
}

Maybe the generation should be public? There's lots more to improve, but for that you need people who are really into C#. Don't special case Unity. That can be moved out of the #if and UNITY_METRO can be replaced with standard .NET defines which people on older .NET can mimic easily with $(DefineConstant) and the if inside there can become #if. Etc.

ericwj avatar Aug 17 '22 19:08 ericwj

We've added the scripts used to generate these bindings here: https://github.com/ValveSoftware/openvr/tree/master/codegen

aleiby avatar Aug 19 '22 20:08 aleiby