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

Rename constructor argument 'numericalValue' to 'value' #705

Merged
merged 2 commits into from
Sep 20, 2019

Conversation

rohahn
Copy link
Contributor

@rohahn rohahn commented Sep 19, 2019

In a project we would like to serialize quantity objects (e.g. Pressure) with MessagePack for inter-process communication. We don't want to persist the data and all processes will use the same version of Units.NET.

Aligning the name of the constructor argument with the property 'Value' allows MessagePack deserialization of types generated by QuantityGenerator (with some minor changes to MessagePack). MessagePack can deserialize immutable types by passing the deserialized values of properties without a setter to an appropriate constructor.

I did not regenerate the classes in GeneratedCode to keep the changes as small as possible.

@codecov-io
Copy link

codecov-io commented Sep 19, 2019

Codecov Report

Merging #705 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #705   +/-   ##
=======================================
  Coverage   58.25%   58.25%           
=======================================
  Files         166      166           
  Lines       37766    37766           
=======================================
  Hits        22001    22001           
  Misses      15765    15765

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update db95ddf...7a408bb. Read the comment docs.

@angularsen
Copy link
Owner

angularsen commented Sep 19, 2019

@tmilnthorp I don't see any problems with this, do you? If it helps some reflection libraries auto-map ctor params to properties then I guess that is a benefit.

@rohahn Just a word of caution that you might be better off mapping to your own types for serialization. We are very likely to introduce breaking changes without increasing the major version, and this PR reflects that situation perfectly (renaming ctor params). See UnitsNet.Serialization.JsonNet project for how we added support for JSON.net serialization by introducing separate, simpler types intended for future proof serialization.

@rohahn
Copy link
Contributor Author

rohahn commented Sep 20, 2019

@angularsen Thanks for the warning. I read some of the discussions about this topic and I am aware of the potential problems. Our current workaround is quite similar and based on a custom resolver and formatter for MessagePack. But since MessagePack is optimized for performance (code generation instead of reflection), we would prefer a solution without custom code in the serialization pipeline. In our case the problem of breaking changes is mitigated, since we control all parts of the system and the serialization is not part of a the public API.

@angularsen
Copy link
Owner

angularsen commented Sep 20, 2019

Very well. This PR needs to merge in latest origin/master to resolve the conflicts.
Also, you should run generate-code.bat to include the changes in generated code in the PR.

Aligning the name of the constructor argument with the property 'Value' allows MessagePack deserialization of types generated by QuantityGenerator. MessagePack can deserialize immutable types by passing the deserialized values of properties without a setter to an appropriate constructor.
- Rename constructor parameter 'numericalValue' to 'value'
- Fix some typos in comments
- Rename some abbreviations
@rohahn rohahn force-pushed the msgpack-serialization branch from eaa8e60 to 7a408bb Compare September 20, 2019 08:04
@angularsen angularsen merged commit 5179332 into angularsen:master Sep 20, 2019
@angularsen
Copy link
Owner

Looks good to me! Nuget on the way out.

Release UnitsNet/4.37.0 · angularsen/UnitsNet

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

Successfully merging this pull request may close these issues.

3 participants