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

csharp generate identifiers for extensions #5246

Conversation

jswigart
Copy link

@jswigart jswigart commented Oct 11, 2018

the goal of these changes is to allow the csharp code generator to emit named constants for the extensions defined in the proto file so that fetching them in csharp code doesn't need to use literal number constants, which are error prone and not very readable

- added support for type safe identifiers to be written to c# generated file so that an object can be passed in to CustomOptions.TryGet* that is safe to the type of option being passed, so mistakes like passing the wrong extension to the function will be detected at compile time
- updated c# generator to write type safe extension identifiers to an extensions namespace under the package
changed back to simple integer constant so compatibility isn't broken with the custom options api
@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

@jswigart
Copy link
Author

I signed it!

@googlebot
Copy link

CLAs look good, thanks!

@anandolee
Copy link
Contributor

anandolee commented Oct 29, 2018

Not quit understand how this change will be used as no test has been added for the usage. It looks a temp solution which should indeed work in descriptors not generated APIs. We are very serious on generated APIs because once it is published, it will be very hard to change/delete for compatibility reason.

@ObsidianMinor is working on C# proto2 support and extension is one of the major work. I'd prefer a fully extension support instead of a temp solution.

@jswigart
Copy link
Author

This change basically brings the c# generator up to parity with the c++ generator in terms of using your named extension identifiers to create field constants so that you can fetch them with a named variable rather than a literal integer. That make sense?

@jswigart
Copy link
Author

I would think that whatever extension work that is being performed, fetching them by a readable identifier that maps to the field id would be part of it.

@ObsidianMinor
Copy link
Contributor

It is a part of it. Making it type safe is a bigger part of it. This PR would be completely replaced by full support, so what's the point?

@jswigart
Copy link
Author

My first check in was also a type safe variation but I ultimately changed it to be simpler like c++ so as not to totally break the api for existing users. I didn't know about your work or I wouldn't have bothered.

Feel free to close it.

@anandolee anandolee closed this Nov 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants