-
-
Notifications
You must be signed in to change notification settings - Fork 152
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
feat: C#12 UnsafeAccessor
for private properties and fields
#732
Conversation
189da7e
to
5ffdea8
Compare
83bf662
to
7092733
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this PR and sorry for the late review... Looks pretty good already 😊 Is it still in a draft state? I didn't do a complete review yet.
What do you think about #600 (comment), I think such an approach would lead to cleaner and improved readability.
Addressing the questions:
Need to check/decide how private set; should be handled.
Would treat them the same as private fields
I suspect it is now possible to assign to init properties after construction. Not sure if this should be explored.
I'd focus on other things for now and see if there is demand / a use case.
Should the generated static class UnsafeAccessor appear before or after the code?
I'd put it after the code, as these are only accessors and seem to be less relevant.
Could the class names/generated extension names be improved?
Probably upper-case the first char of the name of the target property in the accessor name?
SymbolAccessor is initialized before ConfigurationReader so I pass in the MemberVisibility via SetMemberVisibility, this is hacky. I should probably create a AccesibilityContext class (just realied it would have to injected into SymbolAccessor. not sure what to do)
I'll try some things here and come back to you...
Haven't added a .Net 8 constraint, don't know if I can get away with using #if NET8_OR_GREATER preprocessors everywhere, or if I should check the compilation.
I think it should be safe to check whether the UnsafeAccessorAttribute
is available.
It is nearish to completion 😅 I need to add xml comments, docs, review my logic etc. Not a fan of how I've handled
👍
How should a leading underscore
I might create a spearate pr to help this. There are a couple of version specific methods that mapperly will try to use like
Thanks, it was really helpful. |
I'd strip it and capitalise the first letter after _. |
43df4e3
to
b5313a1
Compare
Codecov Report
@@ Coverage Diff @@
## main #732 +/- ##
==========================================
+ Coverage 91.38% 91.45% +0.07%
==========================================
Files 202 214 +12
Lines 6721 7152 +431
Branches 832 868 +36
==========================================
+ Hits 6142 6541 +399
- Misses 388 406 +18
- Partials 191 205 +14
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
I haven't read through my code yet but this PR is near completion.
Unfortunately, the preview is still broken for me, so I;ve never been able to run code containing |
b5313a1
to
649bec5
Compare
src/Riok.Mapperly/Descriptors/Mappings/MemberMappings/UnsafeAccess/UnsafeAccessSetProperty.cs
Outdated
Show resolved
Hide resolved
...k.Mapperly.IntegrationTests/_snapshots/MapperTest.SnapshotGeneratedSource_NET8_0.verified.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Solid work 👍 Thank you!
I added my comments, feel free to discuss any provided feedback points 😊
Please don't forget the documentation updates.
8eba515
to
2880ea6
Compare
Thanks for the review, must have taken some time 😅 Thanks again 😄 |
77926d1
to
8aab15d
Compare
a317bbc
to
e925792
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the updates. Sorry for the slow reviews but this MR is huge 🙈 We should try to split future MR's into smaller ones to be better manageable.
e35e7c4
to
66eadb2
Compare
da68015
to
1102641
Compare
5e85dc7
to
c72a97b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me now 🥳 Thank you!
Can you rebase onto main?
For future PR's we should definitely try to keep them smaller, it makes reviewing and merging easier for everyone involved.
c72a97b
to
9e07d83
Compare
🎉 This PR is included in version 3.3.0-next.2 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
🎉 This PR is included in version 3.3.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
C#12
UnsafeAccessor
for private properties and fieldsDescription
WIP for
UnsafeMemberAccessor
, logic is mostly sound but not cleaned up.Ramblings/Thoughts
MethodMember
successfully 👍MemberVisbility.Accessible
be removed and merged intoPublic
, I have no idea why someone would want to only use it or need to disable it.SetterMemberPath
needs the caller to check ifIsMethod
is true before either assigning to or invoking the result. (target.Set_value(target.Get_value() ?? new())
vstarget.Value ??= new()
) I did consider creating two functions, or overloads. Not sure what is better. Will sleep on it.private set;
should be handled.init
properties after construction. Not sure if this should be explored.SeparateByTrailingLineFeed
not sure if I missed a helper function.Probably need to addusing System.CompilerService;
somewhere.static class UnsafeAccessor
appear before or after the code. Could the class names/generated extension names be improved?SymbolAccessor
is initialized beforeConfigurationReader
so I pass in theMemberVisibility
viaSetMemberVisibility
, this is hacky. I should probably create aAccesibilityContext
class (just realied it would have to injected intoSymbolAccessor
. not sure what to do)#if NET8_OR_GREATER
preprocessors everywhere, or if I should check the compilation.Update
Fixes #600
Checklist