-
-
Notifications
You must be signed in to change notification settings - Fork 961
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
[Serialization] Fix diverging rules for editor and runtime serialization of fields and properties #1875
Conversation
…ion of fields and properties
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.
Note that anything in Stride.Core.Assets and Design wasn't running with binary serialization.
[Fact] | ||
public void TestImplicitMemberType() | ||
{ | ||
var settings = new SerializerSettings() {LimitPrimitiveFlowSequence = 0}; | ||
|
||
var text = @"!ClassWithImplicitMemberType | ||
Test: | ||
String: test | ||
"; | ||
|
||
settings.RegisterTagMapping("ClassWithImplicitMemberType", typeof(ClassWithImplicitMemberType)); | ||
settings.RegisterTagMapping("ClassWithImplicitMemberTypeInner", typeof(ClassWithImplicitMemberTypeInner)); | ||
SerialRoundTrip(settings, text); | ||
} | ||
|
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 test has been removed as omitting object type when they match the type at initialization but diverge from the member's return type has been deprecated in a previous pr.
You'll see more changes related to this in other tests.
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'm surprised there's so many places which use private setters and are serializable, nice work! - Being explicit about it seems better.
sources/core/Stride.Core.Reflection/TypeDescriptors/ObjectDescriptor.cs
Outdated
Show resolved
Hide resolved
There's a fair amount members in the engine that don't conform with the binary's rules, i.e.: a bunch of [DataMember]
public float MyVal { get; private set; } But if they did end up at runtime they would have been broken before this change anyway since binary never supported private or protected members. I've looked at a couple and they seem to be used for either the |
this is an invalid case and is not allowed.. atleast it should be and my diagnostics count that as error but i only found around 8 cases with invalid combinations |
Yes, as I said, those are only in our source and used only in the editor, right now yaml still allows them through to avoid breaking everything until we take care of them. If you have an easy way to detect them feel free to share, what I was using for internal doesn't scale to private/protected. |
https://gist.github.com/IXLLEGACYIXL/b311896965b67af082eafde723619b54 |
We've discussed a bit more on discord and ended up agreeing on a less restrictive rule, there's a document covering it over here. Last PR fixed the issue Joreyk logged. |
sources/core/Stride.Core.Reflection/TypeDescriptors/ObjectDescriptor.cs
Outdated
Show resolved
Hide resolved
Will merge this one once #1694 is merged to avoid more merge conflicts over there. |
i have one last thing. // Member is not displayed if there is a YamlIgnore attribute on it
if (AttributeRegistry.GetAttribute<DataMemberIgnoreAttribute>(memberInfo) != null)
return false; the comment is wrong, probably its a leftover from yamldotnet migration like manio said in discord |
PR Details
Prevent serializing get-only properties without backing field.
The idea here is that they aren't safe enough to serialize by default since they are functions, getting the value may throw, and since they do not provide a setter to create a value if the getter ever throws, we decided to only include them if the user decorates them with a
[DataMember]
Diverging rules between runtime and editor serialization
Yaml can now serialize internal fields if decorated with
DataMember
, reflecting how serialization and filtering works for properties.Binary includes properties with internal getters, as long as they are decorated with
DataMember
as well.Those two changes were required to ensure that both serializer behaved in the same way.
Related Issue
Didn't find any ?
Types of changes
Checklist
Pinging @IXLLEGACYIXL and @manio143 to take a look into this.