Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make types in the C# API partial #1670

Open
ericwj opened this issue Jul 23, 2022 · 3 comments
Open

Make types in the C# API partial #1670

ericwj opened this issue Jul 23, 2022 · 3 comments

Comments

@ericwj
Copy link

ericwj commented Jul 23, 2022

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.

@aleiby
Copy link
Contributor

aleiby commented Aug 16, 2022

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

@ericwj
Copy link
Author

ericwj commented Aug 17, 2022

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.

@aleiby
Copy link
Contributor

aleiby commented Aug 19, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants