-
Notifications
You must be signed in to change notification settings - Fork 77
Conversation
Corresponding JIRA ticket: https://improbableio.atlassian.net/browse/UTY-1970 |
Need to repoint this to |
@@ -60,7 +61,8 @@ public string GetDeserializationExpression(string schemaObject, uint fieldNumber | |||
return | |||
$"{schemaObject}.{SchemaFunctionMappings.GetSchemaFunctionFromType(PrimitiveType.Value)}({fieldNumber})"; | |||
case ValueType.Enum: | |||
return $"({FqnType}) {schemaObject}.GetEnum({fieldNumber})"; | |||
var shifter = UnityEnumDetails.GetEnumMinimum(FqnType); | |||
return $"({FqnType}) ({schemaObject}.GetEnum({fieldNumber}) - {shifter})"; |
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.
Tried a val + 0
on https://sharplab.io/. Compiler ignores +- 0.
...e.gdk.tools/.CodeGenTemplate/CodeGenerationLib/Model/Details/TypeDetails/UnityEnumDetails.cs
Show resolved
Hide resolved
...e.gdk.tools/.CodeGenTemplate/CodeGenerationLib/Model/Details/TypeDetails/UnityEnumDetails.cs
Outdated
Show resolved
Hide resolved
...e.gdk.tools/.CodeGenTemplate/CodeGenerationLib/Model/Details/TypeDetails/UnityEnumDetails.cs
Outdated
Show resolved
Hide resolved
11890ad
to
1edc476
Compare
CHANGELOG.md
Outdated
### Breaking Changes | ||
|
||
- All generated C# enums will now start from 0, being shifted to schema values on serialization and shifted back to C# values on deserialization. [#1412](https://github.com/spatialos/gdk-for-unity/pull/1412) |
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.
Typically we put 'Breaking Changes' at the top as that will be most important to a developer when upgrading
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.
LGTM % moving breaking changes to top of changelog
Move breaking changes to top
Kudos, SonarCloud Quality Gate passed! 0 Bugs |
Description
Shifted all C# enum definition to start from 0 to ensure no invalid enums are generated by default constructors. Serialization is done by
value + min_val
and Deserializationvalue - min_val
. A warning is also generated to advice users to redefine the schema enums to start from 0.Tests
Change the playground schema for
Color
(sorted and unsorted, sequential and non-sequential) and ran the code generator to ensure the enum definition, serialization and deserialization function inColorData
is what's expected.Documentation
Did you remember a changelog entry?
Yes
Primary reviewers
If your change will take a long time to review, you can name at most two primary reviewers who are ultimately responsible for reviewing this request. @ mention them.