-
-
Notifications
You must be signed in to change notification settings - Fork 51
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
Add fs_preserveFieldCasing attribute #306
Add fs_preserveFieldCasing attribute #306
Conversation
This enables overriding the behavior of --normalize-field-names at the field, struct, or table level.
@jamescourtney I don't seem to have permission to add reviewer but FYI. cc @vvuk |
Thanks for this! I always appreciate contributions. I'll try to figure out how to get @vvuk added as a contributor. In the meantime, I will take a look at this, but I'll need you to be a little patient as real-life obligations prevent me from spending too much time on FlatSharp these days. Thanks again for the contribution -- I'll get back to you with my feedback in a few days. |
Codecov Report
@@ Coverage Diff @@
## main #306 +/- ##
==========================================
- Coverage 95.75% 95.73% -0.03%
==========================================
Files 114 114
Lines 7806 7816 +10
Branches 740 746 +6
==========================================
+ Hits 7475 7483 +8
Misses 229 229
- Partials 102 104 +2
Continue to review full report at Codecov.
|
bool? preserveFieldCasing = field.Attributes != null ? preserveFieldCasing = new FlatSharpAttributes(field.Attributes).PreserveFieldCasing : default; | ||
|
||
var preserve = (preserveFieldCasing ?? preserveFieldCasingParent) switch | ||
{ | ||
false or null => false, | ||
true => true, | ||
}; |
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.
This seems odd, why bool?
and default
instead of just bool
and false
? Would also get rid of the switch, especially if PreserveFieldCasing
on the attributes did a ?? false
to explicitly specify the default there.
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.
I did it this way to match similar logic for NonVirtual
here:
string @virtual = (this.Attributes.NonVirtual ?? this.Parent.Attributes.NonVirtual) switch |
I initially had something simpler, but it didn't properly handle field overriding struct/table setting case. There may indeed be a simpler check than I have though.
@jamescourtney thanks -- @joncham and I work together, so you may see PRs for Unity integration coming from both of us over the next little while. |
}; | ||
|
||
if (!preserve) | ||
field.Name = NormalizeFieldName(field.Name); |
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.
Nitpick: Please use curly braces.
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.
Overall looks good. I think we need a different name than just fs_preserveFieldCasing
. Maybe fs_nonNormalizedName
or something? Naming things is hard.
@jamescourtney do you want a followup PR with different naming? |
@joncham -- I think it's fine. I may change it to |
This enables overriding the behavior of --normalize-field-names at the field, struct, or table level.
This PR attempts to implements a solution for issue #305 . I did make the attribute a bit more verbose as
fs_preserveFieldCasing
but am happy to use the original suggestion offs_preserveCase
as well.