-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved member resolution for parameterized content (#428)
- Loading branch information
1 parent
02adccc
commit 9d372a3
Showing
12 changed files
with
171 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/ExtendedXmlSerializer/ContentModel/Members/MemberContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System.Collections.Immutable; | ||
using System.Reflection; | ||
|
||
namespace ExtendedXmlSerializer.ContentModel.Members | ||
{ | ||
readonly struct MemberContext | ||
{ | ||
public MemberContext(TypeInfo reflectedType, ImmutableArray<IMember> members) | ||
{ | ||
ReflectedType = reflectedType; | ||
Members = members; | ||
} | ||
|
||
public TypeInfo ReflectedType { get; } | ||
|
||
public ImmutableArray<IMember> Members { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/ExtendedXmlSerializer/ExtensionModel/Types/IActivationContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
using ExtendedXmlSerializer.Core.Sources; | ||
using System.Reflection; | ||
|
||
namespace ExtendedXmlSerializer.ExtensionModel.Types | ||
{ | ||
interface ITypeAware : ISource<TypeInfo> {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue427Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
using ExtendedXmlSerializer.Configuration; | ||
using ExtendedXmlSerializer.Tests.ReportedIssues.Support; | ||
using FluentAssertions; | ||
using System.Linq; | ||
using Xunit; | ||
// ReSharper disable UnusedAutoPropertyAccessor.Local | ||
|
||
namespace ExtendedXmlSerializer.Tests.ReportedIssues | ||
{ | ||
public sealed class Issue427Tests | ||
{ | ||
[Fact] | ||
public void Verify() | ||
{ | ||
var instance = new Subject("Hello World", 123); | ||
var serializer = new ConfigurationContainer().EnableParameterizedContent().Create().ForTesting(); | ||
|
||
serializer.Cycle(instance).Should().BeEquivalentTo(instance); | ||
|
||
var element = new Base[] {instance}; | ||
serializer.Cycle(element).Should().BeEquivalentTo(element.Cast<Subject>()); | ||
|
||
} | ||
|
||
[Fact] | ||
public void VerifyBasic() | ||
{ | ||
var instance = new BasicSubject{Name = "Hello World", Number = 123}; | ||
var serializer = new ConfigurationContainer().Create().ForTesting(); | ||
|
||
serializer.Cycle(instance).Should().BeEquivalentTo(instance); | ||
|
||
var element = new Basic[] {instance}; | ||
serializer.Cycle(element).Should().BeEquivalentTo(element.Cast<Basic>()); | ||
|
||
} | ||
|
||
[Fact] | ||
public void VerifyReported() | ||
{ | ||
var config = new NewFieldInfo(FieldType.Int) | ||
{ | ||
Name = "abc", | ||
TargetName = "edf" | ||
}; | ||
|
||
var serializer = new ConfigurationContainer().EnableParameterizedContentWithPropertyAssignments() | ||
.Create() | ||
.ForTesting(); | ||
|
||
var instance = new NewTypeInfo[] {config}; | ||
serializer.Cycle(instance).Should().BeEquivalentTo(instance.Cast<NewFieldInfo>()); | ||
} | ||
|
||
class BasicSubject : Basic | ||
{ | ||
public string Name { get; set; } | ||
} | ||
|
||
class Basic | ||
{ | ||
public int Number { get; set; } | ||
} | ||
|
||
class Subject : Base | ||
{ | ||
public Subject(string name, int number) : base(number) => Name = name; | ||
|
||
public string Name { get; } | ||
} | ||
|
||
class Base | ||
{ | ||
public Base(int number) => Number = number; | ||
|
||
public int Number { get; } | ||
} | ||
|
||
public enum FieldType | ||
{ | ||
Int, | ||
Bool | ||
} | ||
|
||
public class NewFieldInfo : NewTypeInfo | ||
{ | ||
public NewFieldInfo(FieldType type) : base(type) {} | ||
|
||
public string Description { get; set; } = null; | ||
|
||
public bool IsRequired { get; set; } | ||
|
||
public string TargetName { get; set; } | ||
} | ||
|
||
public class NewTypeInfo | ||
{ | ||
public NewTypeInfo(FieldType type) | ||
{ | ||
Type = type; | ||
} | ||
|
||
public FieldType Type { get; } | ||
|
||
public string Name { get; set; } | ||
} | ||
} | ||
} |