EnableImplicitTypingFromAll breaks EnableReferences
See original GitHub issueI’m new to this library so still playing around with how ConfigurationContainer works. Apologies if this is the intended behavior.
Here’s a simplified version of my data structures:
public class MainDTO
{
public SubDTO Sub1 { get; set; } = new SubDTO();
public SubDTO Sub2 { get; set; } = new SubDTO();
public SubDTO Sub3 { get; set; } = new SubDTO();
}
public class SubDTO
{
public SubSubDTO SubSub1 { get; set; } = SubSubDTO.NullObject;
}
public class SubSubDTO
{
public static SubSubDTO NullObject { get; } = new SubSubDTO();
public string Id { get; set; } = Guid.NewGuid().ToString();
}
And here is my container
var serializer = new ConfigurationContainer()
.UseAutoFormatting()
.UseOptimizedNamespaces()
.EnableImplicitTyping(new[] {
typeof(MainDTO), // <-- this causes assertion error
typeof(SubDTO),
typeof(SubSubDTO)
})
.Type<SubSubDTO>()
.EnableReferences(definition => definition.Id)
.Create();
I would expect all SubDTO
objects in MainDTO
to be different objects that hold a reference to the same SubSubDTO
object.
Here is the output
<?xml version="1.0" encoding="utf-8"?>
<SerializerPlayground-MainDTO xmlns="clr-namespace:UnitTests.RecipeTests;assembly=UnitTests">
<Sub1>
<SubSub1 Id="78238952-0d09-48dd-8725-4a7326fa897b" />
</Sub1>
<Sub2>
<SubSub1 xmlns:exs="https://extendedxmlserializer.github.io/v2" exs:entity="78238952-0d09-48dd-8725-4a7326fa897b" />
</Sub2>
<Sub3>
<SubSub1 xmlns:exs="https://extendedxmlserializer.github.io/v2" exs:entity="78238952-0d09-48dd-8725-4a7326fa897b" />
</Sub3>
</SerializerPlayground-MainDTO>
This looks right, at least they reference the correct ids. But when I deserialize it, Sub1
is correct but the other two have new Guids.
I tracked down the culprit to this line:
.EnableImplicitTyping(typeof(MainDTO))
If I take this out, all works as expected.
Another strange thing, if MainDTO
references SubSubDTO directly (instead of the middle object) it works fine, even when enabling implicit typing for all types.
Issue Analytics
- State:
- Created 3 years ago
- Comments:22 (16 by maintainers)
Top Results From Across the Web
How to enable implicit type conversion from non-const ...
That is, I have a non-const pointer that I'd like to pass into a function that accept a const pointer by reference. All...
Read more >Allow chained member references in implicit ...
When the type of an expression is implied by the context, Swift allows developers to use what is formally referred to as an...
Read more >Code Syntax Style: Implicit/Explicit Typing ('var' Keyword)
Configure preferences of using 'var' keyword in the Options dialog · Go to the Code Editing | C# | Syntax Style page of...
Read more >Implicit Using Statements In .NET 6 - NET Core Tutorials
When enabled, implicit usings are actually a hidden auto generated file, inside your obj folder, that declares global using statements behind the scenes....
Read more >Implicit none and carry on. Fortran ...
Fortran has an interesting historic feature called implicit typing: Undeclared variables whose name begins with letters i, j, k, l, m, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey @Mike-E-wins I’m doing my own reference resolving after deserialization, so I likely won’t come back to this. Just FYI in case you want to close the issue.
Hi @Mike-E-wins , works on my end. Thanks for updating the documentation!