From f74f8c375c9ce4813cf5f1d6f089a5a38ce1e68c Mon Sep 17 00:00:00 2001
From: Mike-E <2931376+Mike-E-angelo@users.noreply.github.com>
Date: Mon, 7 Dec 2020 16:09:19 -0500
Subject: [PATCH] Added support for `System.Collections.Immutable` Types (#486)
---
.../Configuration/EmitBehaviors.cs | 6 +-
.../Members/AllowedAssignedInstanceValues.cs | 8 +-
.../Reflection/DefaultTypeDefaults.cs | 13 +
.../ContentModel/Reflection/TypeDefaults.cs | 17 +-
.../Reflection/TypeMemberDefaults.cs | 13 +-
.../ExtensionMethodsForExtensionModel.cs | 15 +-
.../ExtensionMethodsForSerialization.cs | 2 +-
...ImplicitlyDefinedDefaultValueAlteration.cs | 6 +-
.../AllMembersParameterizedActivators.cs | 17 +-
.../Members/DefaultValueTypeDefaults.cs | 20 +
.../Members/ParameterizedActivators.cs | 16 +-
.../Members/ParameterizedAwareTypeDefaults.cs | 31 ++
.../Markup/MarkupExtensionPartsEvaluator.cs | 19 +-
.../ExtensionModel/Markup/MarkupExtensions.cs | 11 +-
.../Types/ActivationContexts.cs | 27 +-
.../ExtensionModel/Types/Activators.cs | 7 +-
.../ExtensionModel/Types/IActivationAware.cs | 9 +
.../Types/ImmutableDictionariesExtension.cs | 112 +++++
.../Types/ImmutableHashSetExtension.cs | 110 +++++
.../Types/ImmutableListExtension.cs | 110 +++++
.../ImmutableSortedDictionariesExtension.cs | 115 +++++
.../Types/ImmutableSortedSetExtension.cs | 112 +++++
.../Types/TypeModelExtension.cs | 3 +-
.../ExtensionModel/Xml/InstanceFormatter.cs | 4 +-
.../CollectionAwareConstructorLocator.cs | 21 +
...Activators.cs => ConstructedActivators.cs} | 136 +++---
.../DefaultConstructedActivators.cs | 12 +
.../DictionaryConstructorLocator.cs | 42 ++
.../ReflectionModel/IsInterface.cs | 12 +
.../ReflectionModel/ListConstructorLocator.cs | 35 ++
.../ReflectionModel/Support.cs | 4 +-
.../Issue485Tests.cs | 417 ++++++++++++++++++
.../Issue485Tests_Extended.cs | 71 +++
33 files changed, 1416 insertions(+), 137 deletions(-)
create mode 100644 src/ExtendedXmlSerializer/ContentModel/Reflection/DefaultTypeDefaults.cs
create mode 100644 src/ExtendedXmlSerializer/ExtensionModel/Content/Members/DefaultValueTypeDefaults.cs
create mode 100644 src/ExtendedXmlSerializer/ExtensionModel/Content/Members/ParameterizedAwareTypeDefaults.cs
create mode 100644 src/ExtendedXmlSerializer/ExtensionModel/Types/IActivationAware.cs
create mode 100644 src/ExtendedXmlSerializer/ExtensionModel/Types/ImmutableDictionariesExtension.cs
create mode 100644 src/ExtendedXmlSerializer/ExtensionModel/Types/ImmutableHashSetExtension.cs
create mode 100644 src/ExtendedXmlSerializer/ExtensionModel/Types/ImmutableListExtension.cs
create mode 100644 src/ExtendedXmlSerializer/ExtensionModel/Types/ImmutableSortedDictionariesExtension.cs
create mode 100644 src/ExtendedXmlSerializer/ExtensionModel/Types/ImmutableSortedSetExtension.cs
create mode 100644 src/ExtendedXmlSerializer/ReflectionModel/CollectionAwareConstructorLocator.cs
rename src/ExtendedXmlSerializer/ReflectionModel/{DefaultActivators.cs => ConstructedActivators.cs} (54%)
create mode 100644 src/ExtendedXmlSerializer/ReflectionModel/DefaultConstructedActivators.cs
create mode 100644 src/ExtendedXmlSerializer/ReflectionModel/DictionaryConstructorLocator.cs
create mode 100644 src/ExtendedXmlSerializer/ReflectionModel/IsInterface.cs
create mode 100644 src/ExtendedXmlSerializer/ReflectionModel/ListConstructorLocator.cs
create mode 100644 test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue485Tests.cs
create mode 100644 test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue485Tests_Extended.cs
diff --git a/src/ExtendedXmlSerializer/Configuration/EmitBehaviors.cs b/src/ExtendedXmlSerializer/Configuration/EmitBehaviors.cs
index 584289d53..5b4e6779c 100644
--- a/src/ExtendedXmlSerializer/Configuration/EmitBehaviors.cs
+++ b/src/ExtendedXmlSerializer/Configuration/EmitBehaviors.cs
@@ -1,4 +1,5 @@
using ExtendedXmlSerializer.ContentModel.Members;
+using ExtendedXmlSerializer.ContentModel.Reflection;
using ExtendedXmlSerializer.ExtensionModel.Content.Members;
using ExtendedXmlSerializer.ExtensionModel.Xml.Classic;
using System;
@@ -35,14 +36,13 @@ public static class EmitBehaviors
/// MyProperty {get; set} = true` and `MyProperty` is `false` upon serialization, then the content is emitted.
///
public static IEmitBehavior WhenModified { get; } =
- new EmitBehavior(new AddAlteration(AllowedAssignedInstanceValues.Default));
+ new EmitBehavior(new AddAlteration(new AllowedAssignedInstanceValues(new TypeMemberDefaults(DefaultTypeDefaults.Default))));
#region Obsolete
///
[Obsolete("This is considered deprecated and will be removed in a future release. Use EmitBehaviors.WhenModified instead.")]
- public static IEmitBehavior Assigned { get; } =
- new EmitBehavior(new AddAlteration(AllowedAssignedInstanceValues.Default));
+ public static IEmitBehavior Assigned { get; } = WhenModified;
///
[Obsolete("This is considered deprecated and will be removed in a future release. Use EmitBehaviors.WhenAssigned instead.")]
diff --git a/src/ExtendedXmlSerializer/ContentModel/Members/AllowedAssignedInstanceValues.cs b/src/ExtendedXmlSerializer/ContentModel/Members/AllowedAssignedInstanceValues.cs
index 3efe2778c..c33dd7f76 100644
--- a/src/ExtendedXmlSerializer/ContentModel/Members/AllowedAssignedInstanceValues.cs
+++ b/src/ExtendedXmlSerializer/ContentModel/Members/AllowedAssignedInstanceValues.cs
@@ -7,16 +7,14 @@
namespace ExtendedXmlSerializer.ContentModel.Members
{
- class AllowedAssignedInstanceValues : IAllowedMemberValues
+ sealed class AllowedAssignedInstanceValues : IAllowedMemberValues
{
readonly ISpecification _specification;
readonly ITypeMemberDefaults _defaults;
readonly IGeneric