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> _generic;
- public static AllowedAssignedInstanceValues Default { get; } = new AllowedAssignedInstanceValues();
-
- AllowedAssignedInstanceValues()
- : this(ActivatingTypeSpecification.Default, TypeMemberDefaults.Default,
+ public AllowedAssignedInstanceValues(ITypeMemberDefaults defaults)
+ : this(ActivatingTypeSpecification.Default, defaults,
new Generic>(typeof(Specification<>))) {}
public AllowedAssignedInstanceValues(ISpecification specification, ITypeMemberDefaults defaults,
diff --git a/src/ExtendedXmlSerializer/ContentModel/Reflection/DefaultTypeDefaults.cs b/src/ExtendedXmlSerializer/ContentModel/Reflection/DefaultTypeDefaults.cs
new file mode 100644
index 000000000..9dbc2ed33
--- /dev/null
+++ b/src/ExtendedXmlSerializer/ContentModel/Reflection/DefaultTypeDefaults.cs
@@ -0,0 +1,13 @@
+using ExtendedXmlSerializer.Core.Sources;
+using ExtendedXmlSerializer.ReflectionModel;
+using System.Reflection;
+
+namespace ExtendedXmlSerializer.ContentModel.Reflection
+{
+ sealed class DefaultTypeDefaults : DecoratedSource, ITypeDefaults
+ {
+ public static DefaultTypeDefaults Default { get; } = new DefaultTypeDefaults();
+
+ DefaultTypeDefaults() : base(new TypeDefaults(DefaultConstructedActivators.Default)) {}
+ }
+}
\ No newline at end of file
diff --git a/src/ExtendedXmlSerializer/ContentModel/Reflection/TypeDefaults.cs b/src/ExtendedXmlSerializer/ContentModel/Reflection/TypeDefaults.cs
index 8fb207998..ac719c27b 100644
--- a/src/ExtendedXmlSerializer/ContentModel/Reflection/TypeDefaults.cs
+++ b/src/ExtendedXmlSerializer/ContentModel/Reflection/TypeDefaults.cs
@@ -1,23 +1,22 @@
-using System.Reflection;
using ExtendedXmlSerializer.Core.Sources;
using ExtendedXmlSerializer.ReflectionModel;
+using System.Reflection;
namespace ExtendedXmlSerializer.ContentModel.Reflection
{
sealed class TypeDefaults : ReferenceCacheBase, ITypeDefaults
{
- public static TypeDefaults Default { get; } = new TypeDefaults();
+ public static IParameterizedSource Defaults { get; }
+ = new ReferenceCache(key => new TypeDefaults(key));
+
+ /*public static TypeDefaults Default { get; } = new TypeDefaults();
- TypeDefaults() : this(DefaultActivators.Default) {}
+ TypeDefaults() : this(DefaultActivators.Default) {}*/
readonly IActivators _activators;
- public TypeDefaults(IActivators activators)
- {
- _activators = activators;
- }
+ public TypeDefaults(IActivators activators) => _activators = activators;
- protected override object Create(TypeInfo parameter) => _activators.Get(parameter.AsType())
- .Get();
+ protected override object Create(TypeInfo parameter) => _activators.Get(parameter.AsType()).Get();
}
}
\ No newline at end of file
diff --git a/src/ExtendedXmlSerializer/ContentModel/Reflection/TypeMemberDefaults.cs b/src/ExtendedXmlSerializer/ContentModel/Reflection/TypeMemberDefaults.cs
index 5ef98e8e7..245eeff84 100644
--- a/src/ExtendedXmlSerializer/ContentModel/Reflection/TypeMemberDefaults.cs
+++ b/src/ExtendedXmlSerializer/ContentModel/Reflection/TypeMemberDefaults.cs
@@ -1,22 +1,19 @@
-using System;
-using System.Reflection;
using ExtendedXmlSerializer.ContentModel.Members;
using ExtendedXmlSerializer.Core.Sources;
+using System;
+using System.Reflection;
namespace ExtendedXmlSerializer.ContentModel.Reflection
{
sealed class TypeMemberDefaults : ReferenceCacheBase>, ITypeMemberDefaults
{
- public static TypeMemberDefaults Default { get; } = new TypeMemberDefaults();
+ /*public static TypeMemberDefaults Default { get; } = new TypeMemberDefaults();
- TypeMemberDefaults() : this(TypeDefaults.Default) {}
+ TypeMemberDefaults() : this(TypeDefaults.Default) {}*/
readonly ITypeDefaults _defaults;
- public TypeMemberDefaults(ITypeDefaults defaults)
- {
- _defaults = defaults;
- }
+ public TypeMemberDefaults(ITypeDefaults defaults) => _defaults = defaults;
protected override Func Create(TypeInfo parameter)
=> new MemberDefaults(_defaults.Get(parameter)).Get;
diff --git a/src/ExtendedXmlSerializer/ExtensionMethodsForExtensionModel.cs b/src/ExtendedXmlSerializer/ExtensionMethodsForExtensionModel.cs
index 6dbe09bc0..75b6a392e 100644
--- a/src/ExtendedXmlSerializer/ExtensionMethodsForExtensionModel.cs
+++ b/src/ExtendedXmlSerializer/ExtensionMethodsForExtensionModel.cs
@@ -127,6 +127,19 @@ public static IConfigurationContainer EnableMarkupExtensions(this IConfiguration
public static IConfigurationContainer EnableAllConstructors(this IConfigurationContainer @this)
=> @this.Extend(AllConstructorsExtension.Default);
+ ///
+ /// Enables the use of types found in the `System.Collections.Immutable` namespace.
+ ///
+ /// The configuration container to configure.
+ /// The configured configuration container.
+ ///
+ public static IConfigurationContainer EnableImmutableTypes(this IConfigurationContainer @this)
+ => @this.Extend(ImmutableListExtension.Default)
+ .Extend(ImmutableHashSetExtension.Default)
+ .Extend(ImmutableSortedSetExtension.Default)
+ .Extend(ImmutableDictionariesExtension.Default)
+ .Extend(ImmutableSortedDictionariesExtension.Default);
+
#region Obsolete
///
@@ -217,7 +230,7 @@ public static IConfigurationContainer AllowExistingInstances(this IConfiguration
///
///
[Obsolete(
- "This method is being deprecated. Please use ConfigurationContainer.WithUnknownContent.Call instead.")]
+ "This method is being deprecated. Please use ConfigurationContainer.WithUnknownContent.Call instead.")]
public static IConfigurationContainer EnableUnknownContentHandling(this IConfigurationContainer @this,
Action onMissing)
=> @this.WithUnknownContent().Call(onMissing);
diff --git a/src/ExtendedXmlSerializer/ExtensionMethodsForSerialization.cs b/src/ExtendedXmlSerializer/ExtensionMethodsForSerialization.cs
index 3b61eb283..97a745729 100644
--- a/src/ExtendedXmlSerializer/ExtensionMethodsForSerialization.cs
+++ b/src/ExtendedXmlSerializer/ExtensionMethodsForSerialization.cs
@@ -17,7 +17,7 @@ namespace ExtendedXmlSerializer
///
public static class ExtensionMethodsForSerialization
{
- readonly static Func New = DefaultActivators.Default.New;
+ readonly static Func New = DefaultConstructedActivators.Default.New;
readonly static IXmlWriterFactory WriterFactory
= new XmlWriterFactory(CloseSettings.Default.Get(ExtensionModel.Xml.Defaults.WriterSettings));
diff --git a/src/ExtendedXmlSerializer/ExtensionModel/Content/ImplicitlyDefinedDefaultValueAlteration.cs b/src/ExtendedXmlSerializer/ExtensionModel/Content/ImplicitlyDefinedDefaultValueAlteration.cs
index a835a02bd..436ea6190 100644
--- a/src/ExtendedXmlSerializer/ExtensionModel/Content/ImplicitlyDefinedDefaultValueAlteration.cs
+++ b/src/ExtendedXmlSerializer/ExtensionModel/Content/ImplicitlyDefinedDefaultValueAlteration.cs
@@ -1,8 +1,8 @@
-using System;
-using ExtendedXmlSerializer.ContentModel.Conversion;
+using ExtendedXmlSerializer.ContentModel.Conversion;
using ExtendedXmlSerializer.ContentModel.Reflection;
using ExtendedXmlSerializer.Core.Parsing;
using ExtendedXmlSerializer.Core.Sources;
+using System;
namespace ExtendedXmlSerializer.ExtensionModel.Content
{
@@ -15,7 +15,7 @@ sealed class ImplicitlyDefinedDefaultValueAlteration : IAlteration
public IConverter Get(IConverter parameter)
{
- var @default = TypeDefaults.Default.Get(parameter.Get());
+ var @default = DefaultTypeDefaults.Default.Get(parameter.Get());
var parser = new Parser(parameter.Parse, @default);
var result = new Converter(parameter, parser.Get, parameter.Format);
return result;
diff --git a/src/ExtendedXmlSerializer/ExtensionModel/Content/Members/AllMembersParameterizedActivators.cs b/src/ExtendedXmlSerializer/ExtensionModel/Content/Members/AllMembersParameterizedActivators.cs
index 5ba133aa3..af66b9ea0 100644
--- a/src/ExtendedXmlSerializer/ExtensionModel/Content/Members/AllMembersParameterizedActivators.cs
+++ b/src/ExtendedXmlSerializer/ExtensionModel/Content/Members/AllMembersParameterizedActivators.cs
@@ -1,4 +1,5 @@
using ExtendedXmlSerializer.ContentModel.Members;
+using ExtendedXmlSerializer.ContentModel.Reflection;
using ExtendedXmlSerializer.Core;
using ExtendedXmlSerializer.Core.Sources;
using ExtendedXmlSerializer.ExtensionModel.Types;
@@ -16,18 +17,27 @@ sealed class AllMembersParameterizedActivators : IActivators
readonly IQueriedConstructors _constructors;
readonly IMemberAccessors _accessors;
readonly ITypeMembers _typeMembers;
+ readonly ITypeDefaults _defaults;
readonly IConstructorMembers _members;
// ReSharper disable once TooManyDependencies
public AllMembersParameterizedActivators(IActivators activators, IQueriedConstructors constructors,
IConstructorMembers members, IMemberAccessors accessors,
ITypeMembers typeMembers)
+ : this(activators, constructors, members, accessors, typeMembers,
+ new ParameterizedAwareTypeDefaults(TypeDefaults.Defaults.Get(activators), constructors)) {}
+
+ // ReSharper disable once TooManyDependencies
+ public AllMembersParameterizedActivators(IActivators activators, IQueriedConstructors constructors,
+ IConstructorMembers members, IMemberAccessors accessors,
+ ITypeMembers typeMembers, ITypeDefaults defaults)
{
_activators = activators;
_constructors = constructors;
_members = members;
_accessors = accessors;
_typeMembers = typeMembers;
+ _defaults = defaults;
}
public IActivator Get(Type parameter)
@@ -46,7 +56,7 @@ ActivationContextActivator Activator(ConstructorInfo constructor, ImmutableArray
{
var activator = new Source(constructor).ToSelectionDelegate();
var context = new MemberContext(constructor.ReflectedType.GetTypeInfo(), members);
- var contexts = new ActivationContexts(_accessors, context, activator);
+ var contexts = new ActivationContexts(_accessors, context, activator, _defaults);
var defaults = constructor.GetParameters()
.Where(x => x.IsOptional)
.Select(x => Pairs.Create(x.Name, x.DefaultValue))
@@ -65,7 +75,10 @@ public IActivator Get(Func parameter)
{
var arguments = new Enumerable(_constructor.GetParameters()
.Select(x => x.Name)
- .Select(parameter));
+ .Select(parameter)
+ .Select(x => x is IActivationAware aware
+ ? aware.Get()
+ : x));
var result = new ConstructedActivator(_constructor, arguments);
return result;
}
diff --git a/src/ExtendedXmlSerializer/ExtensionModel/Content/Members/DefaultValueTypeDefaults.cs b/src/ExtendedXmlSerializer/ExtensionModel/Content/Members/DefaultValueTypeDefaults.cs
new file mode 100644
index 000000000..edcd01161
--- /dev/null
+++ b/src/ExtendedXmlSerializer/ExtensionModel/Content/Members/DefaultValueTypeDefaults.cs
@@ -0,0 +1,20 @@
+using ExtendedXmlSerializer.ContentModel.Reflection;
+using ExtendedXmlSerializer.Core.Sources;
+using ExtendedXmlSerializer.ReflectionModel;
+using System.Reflection;
+
+namespace ExtendedXmlSerializer.ExtensionModel.Content.Members
+{
+ sealed class DefaultValueTypeDefaults : ITypeDefaults
+ {
+ public static DefaultValueTypeDefaults Default { get; } = new DefaultValueTypeDefaults();
+
+ DefaultValueTypeDefaults() : this(new Generic>(typeof(DefaultValues<>))) {}
+
+ readonly IGeneric> _generic;
+
+ public DefaultValueTypeDefaults(IGeneric> generic) => _generic = generic;
+
+ public object Get(TypeInfo parameter) => _generic.Get(parameter)().Get();
+ }
+}
\ No newline at end of file
diff --git a/src/ExtendedXmlSerializer/ExtensionModel/Content/Members/ParameterizedActivators.cs b/src/ExtendedXmlSerializer/ExtensionModel/Content/Members/ParameterizedActivators.cs
index 553967bde..e84476960 100644
--- a/src/ExtendedXmlSerializer/ExtensionModel/Content/Members/ParameterizedActivators.cs
+++ b/src/ExtendedXmlSerializer/ExtensionModel/Content/Members/ParameterizedActivators.cs
@@ -1,4 +1,5 @@
using ExtendedXmlSerializer.ContentModel.Members;
+using ExtendedXmlSerializer.ContentModel.Reflection;
using ExtendedXmlSerializer.Core;
using ExtendedXmlSerializer.Core.Sources;
using ExtendedXmlSerializer.ExtensionModel.Types;
@@ -15,16 +16,24 @@ sealed class ParameterizedActivators : IActivators
readonly IActivators _activators;
readonly IQueriedConstructors _constructors;
readonly IMemberAccessors _accessors;
+ readonly ITypeDefaults _defaults;
readonly IConstructorMembers _members;
// ReSharper disable once TooManyDependencies
public ParameterizedActivators(IActivators activators, IQueriedConstructors constructors,
IConstructorMembers members, IMemberAccessors accessors)
+ : this(activators, constructors, members, accessors,
+ new ParameterizedAwareTypeDefaults(TypeDefaults.Defaults.Get(activators), constructors)) {}
+
+ // ReSharper disable once TooManyDependencies
+ public ParameterizedActivators(IActivators activators, IQueriedConstructors constructors,
+ IConstructorMembers members, IMemberAccessors accessors, ITypeDefaults defaults)
{
_activators = activators;
_constructors = constructors;
_members = members;
_accessors = accessors;
+ _defaults = defaults;
}
public IActivator Get(Type parameter)
@@ -42,7 +51,7 @@ ActivationContextActivator Activator(ConstructorInfo constructor, ImmutableArray
{
var activator = new Source(constructor).ToSelectionDelegate();
var context = new MemberContext(constructor.ReflectedType.GetTypeInfo(), members);
- var contexts = new ActivationContexts(_accessors, context, activator);
+ var contexts = new ActivationContexts(_accessors, context, activator, _defaults);
var defaults = constructor.GetParameters()
.Where(x => x.IsOptional)
.Select(x => Pairs.Create(x.Name, x.DefaultValue))
@@ -61,7 +70,10 @@ public IActivator Get(Func parameter)
{
var arguments = new Enumerable(_constructor.GetParameters()
.Select(x => x.Name)
- .Select(parameter));
+ .Select(parameter)
+ .Select(x => x is IActivationAware aware
+ ? aware.Get()
+ : x));
var result = new ConstructedActivator(_constructor, arguments);
return result;
}
diff --git a/src/ExtendedXmlSerializer/ExtensionModel/Content/Members/ParameterizedAwareTypeDefaults.cs b/src/ExtendedXmlSerializer/ExtensionModel/Content/Members/ParameterizedAwareTypeDefaults.cs
new file mode 100644
index 000000000..1142a0195
--- /dev/null
+++ b/src/ExtendedXmlSerializer/ExtensionModel/Content/Members/ParameterizedAwareTypeDefaults.cs
@@ -0,0 +1,31 @@
+using ExtendedXmlSerializer.ContentModel.Reflection;
+using ExtendedXmlSerializer.ExtensionModel.Types;
+using System.Reflection;
+
+namespace ExtendedXmlSerializer.ExtensionModel.Content.Members
+{
+ sealed class ParameterizedAwareTypeDefaults : ITypeDefaults
+ {
+ readonly ITypeDefaults _previous;
+ readonly IQueriedConstructors _constructors;
+ readonly ITypeDefaults _defaults;
+
+ public ParameterizedAwareTypeDefaults(ITypeDefaults previous, IQueriedConstructors constructors)
+ : this(previous, constructors, DefaultValueTypeDefaults.Default) {}
+
+ public ParameterizedAwareTypeDefaults(ITypeDefaults previous, IQueriedConstructors constructors,
+ ITypeDefaults defaults)
+ {
+ _previous = previous;
+ _constructors = constructors;
+ _defaults = defaults;
+ }
+
+ public object Get(TypeInfo parameter)
+ {
+ var defaults = _constructors.Get(parameter) != null ? _defaults : _previous;
+ var result = defaults.Get(parameter);
+ return result;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/ExtendedXmlSerializer/ExtensionModel/Markup/MarkupExtensionPartsEvaluator.cs b/src/ExtendedXmlSerializer/ExtensionModel/Markup/MarkupExtensionPartsEvaluator.cs
index 31c0f494b..cdb0a2944 100644
--- a/src/ExtendedXmlSerializer/ExtensionModel/Markup/MarkupExtensionPartsEvaluator.cs
+++ b/src/ExtendedXmlSerializer/ExtensionModel/Markup/MarkupExtensionPartsEvaluator.cs
@@ -2,6 +2,7 @@
using ExtendedXmlSerializer.ContentModel.Identification;
using ExtendedXmlSerializer.ContentModel.Members;
using ExtendedXmlSerializer.ContentModel.Properties;
+using ExtendedXmlSerializer.ContentModel.Reflection;
using ExtendedXmlSerializer.Core;
using ExtendedXmlSerializer.Core.Parsing;
using ExtendedXmlSerializer.Core.Sources;
@@ -33,17 +34,21 @@ sealed class MarkupExtensionPartsEvaluator
readonly IConstructors _constructors;
readonly System.IServiceProvider _provider;
readonly IFormatter _formatter;
+ readonly ITypeDefaults _defaults;
readonly object[] _services;
- public MarkupExtensionPartsEvaluator(IParser parser, IEvaluator evaluator, ITypeMembers members,
+ public MarkupExtensionPartsEvaluator(IActivators activators,
+ IParser parser, IEvaluator evaluator, ITypeMembers members,
IMemberAccessors accessors, IConstructors constructors,
- System.IServiceProvider provider, params object[] services)
+ System.IServiceProvider provider,
+ params object[] services)
: this(parser, evaluator, members, accessors, constructors, provider, TypePartsFormatter.Default,
- services) {}
+ TypeDefaults.Defaults.Get(activators), services) {}
public MarkupExtensionPartsEvaluator(IParser parser, IEvaluator evaluator, ITypeMembers members,
IMemberAccessors accessors, IConstructors constructors,
System.IServiceProvider provider, IFormatter formatter,
+ ITypeDefaults defaults,
params object[] services)
{
_parser = parser;
@@ -53,6 +58,7 @@ public MarkupExtensionPartsEvaluator(IParser parser, IEvaluator eval
_constructors = constructors;
_provider = provider;
_formatter = formatter;
+ _defaults = defaults;
_services = services;
}
@@ -81,9 +87,10 @@ protected override object Create(MarkupExtensionParts parameter)
.ToArray();
var activator = new ConstructedActivator(constructor, arguments);
var context = new MemberContext(constructor.ReflectedType.GetTypeInfo(), members);
- var extension = new ActivationContexts(_accessors, context, activator).Get(dictionary)
- .Get()
- .AsValid();
+ var extension = new ActivationContexts(_accessors, context, activator, _defaults)
+ .Get(dictionary)
+ .Get()
+ .AsValid();
var result = extension.ProvideValue(new Provider(_provider, _services.Appending(parameter)
.ToArray()));
return result;
diff --git a/src/ExtendedXmlSerializer/ExtensionModel/Markup/MarkupExtensions.cs b/src/ExtendedXmlSerializer/ExtensionModel/Markup/MarkupExtensions.cs
index a29f0fd5e..6538bdd33 100644
--- a/src/ExtendedXmlSerializer/ExtensionModel/Markup/MarkupExtensions.cs
+++ b/src/ExtendedXmlSerializer/ExtensionModel/Markup/MarkupExtensions.cs
@@ -10,6 +10,7 @@ sealed class MarkupExtensions
: ReferenceCacheBase,
IMarkupExtensions
{
+ readonly IActivators _activators;
readonly IEvaluator _evaluator;
readonly ITypeMembers _members;
readonly IMemberAccessors _accessors;
@@ -17,9 +18,11 @@ sealed class MarkupExtensions
readonly System.IServiceProvider _provider;
// ReSharper disable once TooManyDependencies
- public MarkupExtensions(IEvaluator evaluator, ITypeMembers members, IMemberAccessors accessors,
- IConstructors constructors, System.IServiceProvider provider)
+ public MarkupExtensions(IActivators activators, IEvaluator evaluator, ITypeMembers members,
+ IMemberAccessors accessors, IConstructors constructors,
+ System.IServiceProvider provider)
{
+ _activators = activators;
_evaluator = evaluator;
_members = members;
_accessors = accessors;
@@ -28,7 +31,7 @@ public MarkupExtensions(IEvaluator evaluator, ITypeMembers members, IMemberAcces
}
protected override IMarkupExtensionPartsEvaluator Create(IFormatReader parameter)
- => new MarkupExtensionPartsEvaluator(parameter, _evaluator, _members, _accessors, _constructors, _provider,
- parameter);
+ => new MarkupExtensionPartsEvaluator(_activators, parameter, _evaluator, _members, _accessors,
+ _constructors, _provider, parameter);
}
}
\ No newline at end of file
diff --git a/src/ExtendedXmlSerializer/ExtensionModel/Types/ActivationContexts.cs b/src/ExtendedXmlSerializer/ExtensionModel/Types/ActivationContexts.cs
index 522998604..3a094c714 100644
--- a/src/ExtendedXmlSerializer/ExtensionModel/Types/ActivationContexts.cs
+++ b/src/ExtendedXmlSerializer/ExtensionModel/Types/ActivationContexts.cs
@@ -15,27 +15,39 @@ sealed class ActivationContexts : IActivationContexts
readonly MemberContext _members;
readonly ITableSource _table;
readonly Func, IActivator> _activator;
+ readonly ITypeDefaults _defaults;
- public ActivationContexts(IMemberAccessors accessors, MemberContext members, IActivator activator)
- : this(accessors, members, activator.Accept) {}
+ // ReSharper disable once TooManyDependencies
+ public ActivationContexts(IActivators activators, IMemberAccessors accessors, MemberContext members,
+ IActivator activator)
+ : this(accessors, members, activator, TypeDefaults.Defaults.Get(activators)) {}
+
+ // ReSharper disable once TooManyDependencies
+ public ActivationContexts(IMemberAccessors accessors, MemberContext members, IActivator activator,
+ ITypeDefaults defaults)
+ : this(accessors, members, activator.Accept, defaults) {}
+ // ReSharper disable once TooManyDependencies
public ActivationContexts(IMemberAccessors accessors, MemberContext members,
- Func, IActivator> activator)
+ Func, IActivator> activator, ITypeDefaults defaults)
: this(accessors, members,
new TableSource(members.Members
.ToDictionary(x => x.Name,
StringComparer.InvariantCultureIgnoreCase)),
- activator) {}
+ activator, defaults) {}
// ReSharper disable once TooManyDependencies
public ActivationContexts(IMemberAccessors accessors, MemberContext members,
ITableSource table,
- Func, IActivator> activator)
+ Func, IActivator> activator,
+ ITypeDefaults defaults
+ )
{
_accessors = accessors;
_members = members;
_table = table;
_activator = activator;
+ _defaults = defaults;
}
public IActivationContext Get(IDictionary parameter)
@@ -46,7 +58,7 @@ public IActivationContext Get(IDictionary parameter)
source),
new AddItemsCommand(list));
var alteration = new ConfiguringAlteration(command);
- var activator = new AlteringActivator(alteration, _activator(new Store(source, _table).Get));
+ var activator = new AlteringActivator(alteration, _activator(new Store(source, _table, _defaults).Get));
var result = new ActivationContext(_members.ReflectedType, source, activator.Singleton().Get, list);
return result;
}
@@ -57,9 +69,6 @@ sealed class Store : IParameterizedSource
readonly IParameterizedSource _members;
readonly ITypeDefaults _defaults;
- public Store(ITableSource store, IParameterizedSource members)
- : this(store, members, TypeDefaults.Default) {}
-
public Store(ITableSource store, IParameterizedSource members,
ITypeDefaults defaults)
{
diff --git a/src/ExtendedXmlSerializer/ExtensionModel/Types/Activators.cs b/src/ExtendedXmlSerializer/ExtensionModel/Types/Activators.cs
index c061da8f1..31a174722 100644
--- a/src/ExtendedXmlSerializer/ExtensionModel/Types/Activators.cs
+++ b/src/ExtendedXmlSerializer/ExtensionModel/Types/Activators.cs
@@ -1,15 +1,14 @@
-using System;
using ExtendedXmlSerializer.Core;
using ExtendedXmlSerializer.Core.Sources;
using ExtendedXmlSerializer.ReflectionModel;
+using System;
namespace ExtendedXmlSerializer.ExtensionModel.Types
{
sealed class Activators : ReferenceCacheBase, IActivators
{
- public static Activators Default { get; } = new Activators();
-
- Activators() : this(ActivatingTypeSpecification.Default, DefaultActivators.Default, SingletonLocator.Default) {}
+ public Activators(IActivators activators)
+ : this(ActivatingTypeSpecification.Default, activators, SingletonLocator.Default) {}
readonly IActivatingTypeSpecification _specification;
readonly IActivators _activators;
diff --git a/src/ExtendedXmlSerializer/ExtensionModel/Types/IActivationAware.cs b/src/ExtendedXmlSerializer/ExtensionModel/Types/IActivationAware.cs
new file mode 100644
index 000000000..0cabf7c00
--- /dev/null
+++ b/src/ExtendedXmlSerializer/ExtensionModel/Types/IActivationAware.cs
@@ -0,0 +1,9 @@
+using ExtendedXmlSerializer.Core.Sources;
+
+namespace ExtendedXmlSerializer.ExtensionModel.Types
+{
+ ///
+ /// Convenience interface for activating components.
+ ///
+ public interface IActivationAware : ISource {}
+}
\ No newline at end of file
diff --git a/src/ExtendedXmlSerializer/ExtensionModel/Types/ImmutableDictionariesExtension.cs b/src/ExtendedXmlSerializer/ExtensionModel/Types/ImmutableDictionariesExtension.cs
new file mode 100644
index 000000000..8ad070d42
--- /dev/null
+++ b/src/ExtendedXmlSerializer/ExtensionModel/Types/ImmutableDictionariesExtension.cs
@@ -0,0 +1,112 @@
+using ExtendedXmlSerializer.ContentModel;
+using ExtendedXmlSerializer.ContentModel.Content;
+using ExtendedXmlSerializer.ContentModel.Format;
+using ExtendedXmlSerializer.ContentModel.Identification;
+using ExtendedXmlSerializer.ContentModel.Reflection;
+using ExtendedXmlSerializer.Core;
+using ExtendedXmlSerializer.Core.Specifications;
+using ExtendedXmlSerializer.ReflectionModel;
+using JetBrains.Annotations;
+using System;
+using System.Collections.Generic;
+using System.Collections.Immutable;
+using System.Reflection;
+
+namespace ExtendedXmlSerializer.ExtensionModel.Types
+{
+ sealed class ImmutableDictionariesExtension : ISerializerExtension
+ {
+ public static ImmutableDictionariesExtension Default { get; } = new ImmutableDictionariesExtension();
+
+ ImmutableDictionariesExtension() : this(new IsAssignableGenericSpecification(typeof(ImmutableDictionary<,>))) {}
+
+ readonly ISpecification _specification;
+
+ public ImmutableDictionariesExtension(ISpecification specification) => _specification = specification;
+
+ public IServiceRepository Get(IServiceRepository parameter)
+ => parameter.DecorateContentsWith()
+ .When(_specification)
+ .Decorate()
+ .Decorate(Register);
+
+ IConstructorLocator Register(IServiceProvider arg1, IConstructorLocator previous)
+ => new ConstructorLocator(_specification, previous);
+
+ void ICommand.Execute(IServices parameter) {}
+
+ sealed class ConstructorLocator : DictionaryConstructorLocator, IConstructorLocator
+ {
+ public ConstructorLocator(ISpecification specification, IConstructorLocator previous)
+ : base(specification, previous, typeof(Adapter<,>)) {}
+ }
+
+ sealed class Adapter : Dictionary, IActivationAware
+ {
+ public object Get() => this.ToImmutableDictionary();
+ }
+
+ sealed class GenericTypes : IGenericTypes
+ {
+ readonly static TypeInfo Check = typeof(ImmutableDictionary).GetTypeInfo();
+ readonly static ImmutableArray Type = typeof(ImmutableDictionary<,>).GetTypeInfo()
+ .Yield()
+ .ToImmutableArray();
+
+ readonly IGenericTypes _types;
+
+ public GenericTypes(IGenericTypes types) => _types = types;
+
+ public ImmutableArray Get(IIdentity parameter)
+ {
+ var type = _types.Get(parameter);
+ var result = type.Only()?.Equals(Check) ?? false ? Type : type;
+ return result;
+ }
+ }
+
+ sealed class Contents : IContents
+ {
+ readonly IContents _contents;
+ readonly IGeneric _readers;
+ readonly Type _type;
+
+ [UsedImplicitly]
+ public Contents(IContents contents) : this(contents, Readers.Instance, typeof(Dictionary<,>)) {}
+
+ public Contents(IContents contents, IGeneric readers, Type type)
+ {
+ _contents = contents;
+ _readers = readers;
+ _type = type;
+ }
+
+ public ISerializer Get(TypeInfo parameter)
+ {
+ var types = DictionaryPairTypesLocator.Default.Get(parameter).GetValueOrDefault();
+ var type = _type.MakeGenericType(types.KeyType, types.ValueType);
+ var serializer = _contents.Get(type);
+ var result = new Serializer(_readers.Get(types.KeyType, types.ValueType)(serializer), serializer);
+ return result;
+ }
+
+ sealed class Readers : Generic
+ {
+ public static Readers Instance { get; } = new Readers();
+
+ Readers() : base(typeof(Reader<,>)) {}
+ }
+
+ sealed class Reader : IReader
+ {
+ readonly IReader _reader;
+
+ [UsedImplicitly]
+ public Reader(IReader reader) => _reader = reader;
+
+ public object Get(IFormatReader parameter)
+ => _reader.Get(parameter).AsValid>().ToImmutableDictionary();
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/ExtendedXmlSerializer/ExtensionModel/Types/ImmutableHashSetExtension.cs b/src/ExtendedXmlSerializer/ExtensionModel/Types/ImmutableHashSetExtension.cs
new file mode 100644
index 000000000..15d322881
--- /dev/null
+++ b/src/ExtendedXmlSerializer/ExtensionModel/Types/ImmutableHashSetExtension.cs
@@ -0,0 +1,110 @@
+using ExtendedXmlSerializer.ContentModel;
+using ExtendedXmlSerializer.ContentModel.Collections;
+using ExtendedXmlSerializer.ContentModel.Content;
+using ExtendedXmlSerializer.ContentModel.Format;
+using ExtendedXmlSerializer.ContentModel.Identification;
+using ExtendedXmlSerializer.ContentModel.Reflection;
+using ExtendedXmlSerializer.Core;
+using ExtendedXmlSerializer.Core.Specifications;
+using ExtendedXmlSerializer.ReflectionModel;
+using JetBrains.Annotations;
+using System.Collections.Generic;
+using System.Collections.Immutable;
+using System.Collections.ObjectModel;
+using System.Reflection;
+
+namespace ExtendedXmlSerializer.ExtensionModel.Types
+{
+ sealed class ImmutableHashSetExtension : ISerializerExtension
+ {
+ public static ImmutableHashSetExtension Default { get; } = new ImmutableHashSetExtension();
+
+ ImmutableHashSetExtension() : this(new IsAssignableGenericSpecification(typeof(ImmutableHashSet<>))) {}
+
+ readonly ISpecification _specification;
+
+ public ImmutableHashSetExtension(ISpecification specification) => _specification = specification;
+
+ public IServiceRepository Get(IServiceRepository parameter)
+ => parameter.DecorateContentsWith()
+ .When(_specification)
+ .Decorate()
+ .Decorate(Register);
+
+ IConstructorLocator Register(IServiceProvider arg1, IConstructorLocator previous)
+ => new ConstructorLocator(_specification, previous);
+
+ void ICommand.Execute(IServices parameter) {}
+
+ sealed class ConstructorLocator : ListConstructorLocator, IConstructorLocator
+ {
+ public ConstructorLocator(ISpecification specification, IConstructorLocator previous)
+ : base(specification, previous, typeof(Adapter<>)) {}
+ }
+
+ sealed class Adapter : List, IActivationAware
+ {
+ public object Get() => this.ToImmutableHashSet();
+ }
+
+ sealed class GenericTypes : IGenericTypes
+ {
+ readonly static TypeInfo Check = typeof(ImmutableHashSet).GetTypeInfo();
+ readonly static ImmutableArray Type = typeof(ImmutableHashSet<>).GetTypeInfo()
+ .Yield()
+ .ToImmutableArray();
+
+ readonly IGenericTypes _types;
+
+ public GenericTypes(IGenericTypes types) => _types = types;
+
+ public ImmutableArray Get(IIdentity parameter)
+ {
+ var type = _types.Get(parameter);
+ var result = type.Only()?.Equals(Check) ?? false ? Type : type;
+ return result;
+ }
+ }
+
+ sealed class ImmutableHashSets : Collections
+ {
+ public ImmutableHashSets(RuntimeSerializers serializers, Contents contents) : base(serializers, contents) {}
+ }
+
+ sealed class Contents : ICollectionContents
+ {
+ readonly IInnerContentServices _contents;
+ readonly IEnumerators _enumerators;
+
+ public Contents(IInnerContentServices contents, IEnumerators enumerators)
+ {
+ _contents = contents;
+ _enumerators = enumerators;
+ }
+
+ public ISerializer Get(CollectionContentInput parameter)
+ => new Serializer(Readers.Instance.Get(parameter.ItemType)(_contents, parameter.Item),
+ new EnumerableWriter(_enumerators, parameter.Item).Adapt());
+
+ sealed class Readers : Generic
+ {
+ public static Readers Instance { get; } = new Readers();
+
+ Readers() : base(typeof(Reader<>)) {}
+ }
+
+ sealed class Reader : IReader
+ {
+ readonly IReader> _reader;
+
+ [UsedImplicitly]
+ public Reader(IInnerContentServices services, IReader item)
+ : this(services.CreateContents>(new CollectionInnerContentHandler(item, services))) {}
+
+ Reader(IReader> reader) => _reader = reader;
+
+ public object Get(IFormatReader parameter) => _reader.Get(parameter).ToImmutableHashSet();
+ }
+ }
+ }
+}
diff --git a/src/ExtendedXmlSerializer/ExtensionModel/Types/ImmutableListExtension.cs b/src/ExtendedXmlSerializer/ExtensionModel/Types/ImmutableListExtension.cs
new file mode 100644
index 000000000..8c5252272
--- /dev/null
+++ b/src/ExtendedXmlSerializer/ExtensionModel/Types/ImmutableListExtension.cs
@@ -0,0 +1,110 @@
+using ExtendedXmlSerializer.ContentModel;
+using ExtendedXmlSerializer.ContentModel.Collections;
+using ExtendedXmlSerializer.ContentModel.Content;
+using ExtendedXmlSerializer.ContentModel.Format;
+using ExtendedXmlSerializer.ContentModel.Identification;
+using ExtendedXmlSerializer.ContentModel.Reflection;
+using ExtendedXmlSerializer.Core;
+using ExtendedXmlSerializer.Core.Specifications;
+using ExtendedXmlSerializer.ReflectionModel;
+using JetBrains.Annotations;
+using System.Collections.Generic;
+using System.Collections.Immutable;
+using System.Collections.ObjectModel;
+using System.Reflection;
+
+namespace ExtendedXmlSerializer.ExtensionModel.Types
+{
+ sealed class ImmutableListExtension : ISerializerExtension
+ {
+ public static ImmutableListExtension Default { get; } = new ImmutableListExtension();
+
+ ImmutableListExtension() : this(new IsAssignableGenericSpecification(typeof(ImmutableList<>))) {}
+
+ readonly ISpecification _specification;
+
+ public ImmutableListExtension(ISpecification specification) => _specification = specification;
+
+ public IServiceRepository Get(IServiceRepository parameter)
+ => parameter.DecorateContentsWith()
+ .When(_specification)
+ .Decorate()
+ .Decorate(Register);
+
+ IConstructorLocator Register(IServiceProvider arg1, IConstructorLocator previous)
+ => new ConstructorLocator(_specification, previous);
+
+ void ICommand.Execute(IServices parameter) {}
+
+ sealed class ConstructorLocator : ListConstructorLocator, IConstructorLocator
+ {
+ public ConstructorLocator(ISpecification specification, IConstructorLocator previous)
+ : base(specification, previous, typeof(Adapter<>)) {}
+ }
+
+ sealed class Adapter : List, IActivationAware
+ {
+ public object Get() => this.ToImmutableList();
+ }
+
+ sealed class GenericTypes : IGenericTypes
+ {
+ readonly static TypeInfo Check = typeof(ImmutableList).GetTypeInfo();
+ readonly static ImmutableArray Type = typeof(ImmutableList<>).GetTypeInfo()
+ .Yield()
+ .ToImmutableArray();
+
+ readonly IGenericTypes _types;
+
+ public GenericTypes(IGenericTypes types) => _types = types;
+
+ public ImmutableArray Get(IIdentity parameter)
+ {
+ var type = _types.Get(parameter);
+ var result = type.Only()?.Equals(Check) ?? false ? Type : type;
+ return result;
+ }
+ }
+
+ sealed class ImmutableLists : Collections
+ {
+ public ImmutableLists(RuntimeSerializers serializers, Contents contents) : base(serializers, contents) {}
+ }
+
+ sealed class Contents : ICollectionContents
+ {
+ readonly IInnerContentServices _contents;
+ readonly IEnumerators _enumerators;
+
+ public Contents(IInnerContentServices contents, IEnumerators enumerators)
+ {
+ _contents = contents;
+ _enumerators = enumerators;
+ }
+
+ public ISerializer Get(CollectionContentInput parameter)
+ => new Serializer(Readers.Instance.Get(parameter.ItemType)(_contents, parameter.Item),
+ new EnumerableWriter(_enumerators, parameter.Item).Adapt());
+
+ sealed class Readers : Generic
+ {
+ public static Readers Instance { get; } = new Readers();
+
+ Readers() : base(typeof(Reader<>)) {}
+ }
+
+ sealed class Reader : IReader
+ {
+ readonly IReader> _reader;
+
+ [UsedImplicitly]
+ public Reader(IInnerContentServices services, IReader item)
+ : this(services.CreateContents>(new CollectionInnerContentHandler(item, services))) {}
+
+ Reader(IReader> reader) => _reader = reader;
+
+ public object Get(IFormatReader parameter) => _reader.Get(parameter).ToImmutableList();
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/ExtendedXmlSerializer/ExtensionModel/Types/ImmutableSortedDictionariesExtension.cs b/src/ExtendedXmlSerializer/ExtensionModel/Types/ImmutableSortedDictionariesExtension.cs
new file mode 100644
index 000000000..b91d8c5f1
--- /dev/null
+++ b/src/ExtendedXmlSerializer/ExtensionModel/Types/ImmutableSortedDictionariesExtension.cs
@@ -0,0 +1,115 @@
+using ExtendedXmlSerializer.ContentModel;
+using ExtendedXmlSerializer.ContentModel.Content;
+using ExtendedXmlSerializer.ContentModel.Format;
+using ExtendedXmlSerializer.ContentModel.Identification;
+using ExtendedXmlSerializer.ContentModel.Reflection;
+using ExtendedXmlSerializer.Core;
+using ExtendedXmlSerializer.Core.Specifications;
+using ExtendedXmlSerializer.ReflectionModel;
+using JetBrains.Annotations;
+using System;
+using System.Collections.Generic;
+using System.Collections.Immutable;
+using System.Reflection;
+
+namespace ExtendedXmlSerializer.ExtensionModel.Types
+{
+ sealed class ImmutableSortedDictionariesExtension : ISerializerExtension
+ {
+ public static ImmutableSortedDictionariesExtension Default { get; }
+ = new ImmutableSortedDictionariesExtension();
+
+ ImmutableSortedDictionariesExtension()
+ : this(new IsAssignableGenericSpecification(typeof(ImmutableSortedDictionary<,>))) {}
+
+ readonly ISpecification _specification;
+
+ public ImmutableSortedDictionariesExtension(ISpecification specification)
+ => _specification = specification;
+
+ public IServiceRepository Get(IServiceRepository parameter)
+ => parameter.DecorateContentsWith()
+ .When(_specification)
+ .Decorate()
+ .Decorate(Register);
+
+ IConstructorLocator Register(IServiceProvider arg1, IConstructorLocator previous)
+ => new ConstructorLocator(_specification, previous);
+
+ void ICommand.Execute(IServices parameter) {}
+
+ sealed class ConstructorLocator : DictionaryConstructorLocator, IConstructorLocator
+ {
+ public ConstructorLocator(ISpecification specification, IConstructorLocator previous)
+ : base(specification, previous, typeof(Adapter<,>)) {}
+ }
+
+ sealed class Adapter : Dictionary, IActivationAware
+ {
+ public object Get() => this.ToImmutableSortedDictionary();
+ }
+
+ sealed class GenericTypes : IGenericTypes
+ {
+ readonly static TypeInfo Check = typeof(ImmutableSortedDictionary).GetTypeInfo();
+ readonly static ImmutableArray Type = typeof(ImmutableSortedDictionary<,>).GetTypeInfo()
+ .Yield()
+ .ToImmutableArray();
+
+ readonly IGenericTypes _types;
+
+ public GenericTypes(IGenericTypes types) => _types = types;
+
+ public ImmutableArray Get(IIdentity parameter)
+ {
+ var type = _types.Get(parameter);
+ var result = type.Only()?.Equals(Check) ?? false ? Type : type;
+ return result;
+ }
+ }
+
+ sealed class Contents : IContents
+ {
+ readonly IContents _contents;
+ readonly IGeneric _readers;
+ readonly Type _type;
+
+ [UsedImplicitly]
+ public Contents(IContents contents) : this(contents, Readers.Instance, typeof(Dictionary<,>)) {}
+
+ public Contents(IContents contents, IGeneric readers, Type type)
+ {
+ _contents = contents;
+ _readers = readers;
+ _type = type;
+ }
+
+ public ISerializer Get(TypeInfo parameter)
+ {
+ var types = DictionaryPairTypesLocator.Default.Get(parameter).GetValueOrDefault();
+ var type = _type.MakeGenericType(types.KeyType, types.ValueType);
+ var serializer = _contents.Get(type);
+ var result = new Serializer(_readers.Get(types.KeyType, types.ValueType)(serializer), serializer);
+ return result;
+ }
+
+ sealed class Readers : Generic
+ {
+ public static Readers Instance { get; } = new Readers();
+
+ Readers() : base(typeof(Reader<,>)) {}
+ }
+
+ sealed class Reader : IReader
+ {
+ readonly IReader _reader;
+
+ [UsedImplicitly]
+ public Reader(IReader reader) => _reader = reader;
+
+ public object Get(IFormatReader parameter)
+ => _reader.Get(parameter).AsValid>().ToImmutableSortedDictionary();
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/ExtendedXmlSerializer/ExtensionModel/Types/ImmutableSortedSetExtension.cs b/src/ExtendedXmlSerializer/ExtensionModel/Types/ImmutableSortedSetExtension.cs
new file mode 100644
index 000000000..84a490e79
--- /dev/null
+++ b/src/ExtendedXmlSerializer/ExtensionModel/Types/ImmutableSortedSetExtension.cs
@@ -0,0 +1,112 @@
+using ExtendedXmlSerializer.ContentModel;
+using ExtendedXmlSerializer.ContentModel.Collections;
+using ExtendedXmlSerializer.ContentModel.Content;
+using ExtendedXmlSerializer.ContentModel.Format;
+using ExtendedXmlSerializer.ContentModel.Identification;
+using ExtendedXmlSerializer.ContentModel.Reflection;
+using ExtendedXmlSerializer.Core;
+using ExtendedXmlSerializer.Core.Specifications;
+using ExtendedXmlSerializer.ReflectionModel;
+using JetBrains.Annotations;
+using System.Collections.Generic;
+using System.Collections.Immutable;
+using System.Collections.ObjectModel;
+using System.Reflection;
+
+namespace ExtendedXmlSerializer.ExtensionModel.Types
+{
+ sealed class ImmutableSortedSetExtension : ISerializerExtension
+ {
+ public static ImmutableSortedSetExtension Default { get; } = new ImmutableSortedSetExtension();
+
+ ImmutableSortedSetExtension() : this(new IsAssignableGenericSpecification(typeof(ImmutableSortedSet<>))) {}
+
+ readonly ISpecification _specification;
+
+ public ImmutableSortedSetExtension(ISpecification specification) => _specification = specification;
+
+ public IServiceRepository Get(IServiceRepository parameter)
+ => parameter.DecorateContentsWith()
+ .When(_specification)
+ .Decorate()
+ .Decorate(Register);
+
+ IConstructorLocator Register(IServiceProvider arg1, IConstructorLocator previous)
+ => new ConstructorLocator(_specification, previous);
+
+ void ICommand.Execute(IServices parameter) {}
+
+ sealed class ConstructorLocator : ListConstructorLocator, IConstructorLocator
+ {
+ public ConstructorLocator(ISpecification specification, IConstructorLocator previous)
+ : base(specification, previous, typeof(Adapter<>)) {}
+ }
+
+ sealed class Adapter : List, IActivationAware
+ {
+ public object Get() => this.ToImmutableSortedSet();
+ }
+
+ sealed class GenericTypes : IGenericTypes
+ {
+ readonly static TypeInfo Check = typeof(ImmutableSortedSet).GetTypeInfo();
+ readonly static ImmutableArray Type = typeof(ImmutableSortedSet<>).GetTypeInfo()
+ .Yield()
+ .ToImmutableArray();
+
+ readonly IGenericTypes _types;
+
+ public GenericTypes(IGenericTypes types) => _types = types;
+
+ public ImmutableArray Get(IIdentity parameter)
+ {
+ var type = _types.Get(parameter);
+ var result = type.Only()?.Equals(Check) ?? false ? Type : type;
+ return result;
+ }
+ }
+
+ sealed class ImmutableSortedSets : Collections
+ {
+ public ImmutableSortedSets(RuntimeSerializers serializers, Contents contents)
+ : base(serializers, contents) {}
+ }
+
+ sealed class Contents : ICollectionContents
+ {
+ readonly IInnerContentServices _contents;
+ readonly IEnumerators _enumerators;
+
+ public Contents(IInnerContentServices contents, IEnumerators enumerators)
+ {
+ _contents = contents;
+ _enumerators = enumerators;
+ }
+
+ public ISerializer Get(CollectionContentInput parameter)
+ => new Serializer(Readers.Instance.Get(parameter.ItemType)(_contents, parameter.Item),
+ new EnumerableWriter(_enumerators, parameter.Item).Adapt());
+
+ sealed class Readers : Generic
+ {
+ public static Readers Instance { get; } = new Readers();
+
+ Readers() : base(typeof(Reader<>)) {}
+ }
+
+ sealed class Reader : IReader
+ {
+ readonly IReader> _reader;
+
+ [UsedImplicitly]
+ public Reader(IInnerContentServices services, IReader item)
+ : this(services.CreateContents>(new CollectionInnerContentHandler(item, services))) {}
+
+ Reader(IReader> reader) => _reader = reader;
+
+ public object Get(IFormatReader parameter) => _reader.Get(parameter).ToImmutableSortedSet();
+ }
+ }
+ }
+
+}
diff --git a/src/ExtendedXmlSerializer/ExtensionModel/Types/TypeModelExtension.cs b/src/ExtendedXmlSerializer/ExtensionModel/Types/TypeModelExtension.cs
index 590c9a6f3..c0c8368b6 100644
--- a/src/ExtendedXmlSerializer/ExtensionModel/Types/TypeModelExtension.cs
+++ b/src/ExtendedXmlSerializer/ExtensionModel/Types/TypeModelExtension.cs
@@ -20,9 +20,10 @@ public sealed class TypeModelExtension : ISerializerExtension
public IServiceRepository Get(IServiceRepository parameter)
=> parameter.Register()
.Register()
- .Register()
+ .Register()
.Register()
.Register()
+ .Decorate()
.Register()
.Register()
.RegisterInstance(DictionaryEnumerators.Default)
diff --git a/src/ExtendedXmlSerializer/ExtensionModel/Xml/InstanceFormatter.cs b/src/ExtendedXmlSerializer/ExtensionModel/Xml/InstanceFormatter.cs
index fd092fcbd..b237d44eb 100644
--- a/src/ExtendedXmlSerializer/ExtensionModel/Xml/InstanceFormatter.cs
+++ b/src/ExtendedXmlSerializer/ExtensionModel/Xml/InstanceFormatter.cs
@@ -1,12 +1,12 @@
+using ExtendedXmlSerializer.ReflectionModel;
using System;
using System.IO;
-using ExtendedXmlSerializer.ReflectionModel;
namespace ExtendedXmlSerializer.ExtensionModel.Xml
{
class InstanceFormatter : IInstanceFormatter
{
- readonly static Func Stream = DefaultActivators.Default.New;
+ readonly static Func Stream = DefaultConstructedActivators.Default.New;
readonly IExtendedXmlSerializer _serializer;
readonly IXmlWriterFactory _factory;
diff --git a/src/ExtendedXmlSerializer/ReflectionModel/CollectionAwareConstructorLocator.cs b/src/ExtendedXmlSerializer/ReflectionModel/CollectionAwareConstructorLocator.cs
new file mode 100644
index 000000000..8b4515700
--- /dev/null
+++ b/src/ExtendedXmlSerializer/ReflectionModel/CollectionAwareConstructorLocator.cs
@@ -0,0 +1,21 @@
+using ExtendedXmlSerializer.Core.Specifications;
+using System.Collections.Generic;
+using System.Reflection;
+
+namespace ExtendedXmlSerializer.ReflectionModel
+{
+ sealed class CollectionAwareConstructorLocator : ListConstructorLocator, IConstructorLocator
+ {
+ readonly static ISpecification Specification = IsInterface.Default.And(IsCollectionType.Instance);
+
+ public CollectionAwareConstructorLocator(IConstructorLocator previous) : base(Specification, previous) {}
+
+ sealed class IsCollectionType : AnySpecification
+ {
+ public static IsCollectionType Instance { get; } = new IsCollectionType();
+
+ IsCollectionType() : base(IsCollectionTypeSpecification.Default,
+ new IsAssignableGenericSpecification(typeof(IReadOnlyCollection<>))) {}
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/ExtendedXmlSerializer/ReflectionModel/DefaultActivators.cs b/src/ExtendedXmlSerializer/ReflectionModel/ConstructedActivators.cs
similarity index 54%
rename from src/ExtendedXmlSerializer/ReflectionModel/DefaultActivators.cs
rename to src/ExtendedXmlSerializer/ReflectionModel/ConstructedActivators.cs
index 8a8447bba..b1970a353 100644
--- a/src/ExtendedXmlSerializer/ReflectionModel/DefaultActivators.cs
+++ b/src/ExtendedXmlSerializer/ReflectionModel/ConstructedActivators.cs
@@ -1,76 +1,62 @@
-using ExtendedXmlSerializer.Core.Sources;
-using ExtendedXmlSerializer.Core.Specifications;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Linq.Expressions;
-using System.Reflection;
-
-namespace ExtendedXmlSerializer.ReflectionModel
-{
- sealed class DefaultActivators : ReferenceCacheBase, IActivators
- {
- readonly static Func Selector = DefaultParameters.Instance.Get;
-
- public static DefaultActivators Default { get; } = new DefaultActivators();
-
- DefaultActivators() : this(ConstructorLocator.Default) {}
-
- readonly IConstructorLocator _locator;
-
- public DefaultActivators(IConstructorLocator locator) => _locator = locator;
-
- protected override IActivator Create(Type parameter)
- {
- var typeInfo = parameter.GetTypeInfo();
- var expression = parameter == typeof(string)
- ? (Expression)Expression.Default(parameter)
- : typeInfo.IsValueType
- ? Expression.New(parameter)
- : Reference(parameter, typeInfo);
- var convert = Expression.Convert(expression, typeof(object));
- var lambda = Expression.Lambda>(convert);
- var result = new Activator(lambda.Compile());
- return result;
- }
-
- NewExpression Reference(Type parameter, TypeInfo typeInfo)
- {
- var accounted = typeInfo.IsInterface && IsCollectionType.Instance.IsSatisfiedBy(parameter)
- ? typeof(List<>).MakeGenericType(CollectionItemTypeLocator.Default.Get(typeInfo))
- : typeInfo;
- var constructor = _locator.Get(accounted) ?? _locator.Get(typeInfo);
- var parameters = constructor.GetParameters();
- var result = parameters.Length > 0
- ? Expression.New(constructor, parameters.Select(Selector))
- : Expression.New(accounted);
- return result;
- }
-
- sealed class DefaultParameters : IParameterizedSource
- {
- readonly static IEnumerable Initializers = Enumerable.Empty();
-
- public static DefaultParameters Instance { get; } = new DefaultParameters();
-
- DefaultParameters() {}
-
- public Expression Get(ParameterInfo parameter)
- => parameter.IsDefined(typeof(ParamArrayAttribute))
- ? (Expression)Expression.NewArrayInit(
- parameter.ParameterType.GetElementType() ??
- throw new
- InvalidOperationException("Element Type not found."),
- Initializers)
- : Expression.Default(parameter.ParameterType);
- }
-
- sealed class IsCollectionType : AnySpecification
- {
- public static IsCollectionType Instance { get; } = new IsCollectionType();
-
- IsCollectionType() : base(IsCollectionTypeSpecification.Default,
- new IsAssignableGenericSpecification(typeof(IReadOnlyCollection<>))) {}
- }
- }
+using ExtendedXmlSerializer.Core.Sources;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Linq.Expressions;
+using System.Reflection;
+
+namespace ExtendedXmlSerializer.ReflectionModel
+{
+ sealed class ConstructedActivators : ReferenceCacheBase, IActivators
+ {
+ readonly static Func Selector = DefaultParameters.Instance.Get;
+
+ /*public static DefaultActivators Default { get; } = new DefaultActivators();
+
+ DefaultActivators() : this(ConstructorLocator.Default) {}*/
+
+ readonly IConstructorLocator _locator;
+
+ public ConstructedActivators(IConstructorLocator locator) => _locator = locator;
+
+ protected override IActivator Create(Type parameter)
+ {
+ var expression = parameter == typeof(string)
+ ? (Expression)Expression.Default(parameter)
+ : parameter.IsValueType
+ ? Expression.New(parameter)
+ : Reference(parameter);
+ var convert = Expression.Convert(expression, typeof(object));
+ var lambda = Expression.Lambda>(convert);
+ var result = new Activator(lambda.Compile());
+ return result;
+ }
+
+ NewExpression Reference(Type parameter)
+ {
+ var constructor = _locator.Get(parameter);
+ var parameters = constructor.GetParameters();
+ var result = parameters.Length > 0
+ ? Expression.New(constructor, parameters.Select(Selector))
+ : Expression.New(constructor);
+ return result;
+ }
+
+ sealed class DefaultParameters : IParameterizedSource
+ {
+ readonly static IEnumerable Initializers = Enumerable.Empty();
+
+ public static DefaultParameters Instance { get; } = new DefaultParameters();
+
+ DefaultParameters() {}
+
+ public Expression Get(ParameterInfo parameter)
+ => parameter.IsDefined(typeof(ParamArrayAttribute))
+ ? (Expression)Expression.NewArrayInit(parameter.ParameterType.GetElementType() ??
+ throw new
+ InvalidOperationException("Element Type not found."),
+ Initializers)
+ : Expression.Default(parameter.ParameterType);
+ }
+ }
}
\ No newline at end of file
diff --git a/src/ExtendedXmlSerializer/ReflectionModel/DefaultConstructedActivators.cs b/src/ExtendedXmlSerializer/ReflectionModel/DefaultConstructedActivators.cs
new file mode 100644
index 000000000..4f6498463
--- /dev/null
+++ b/src/ExtendedXmlSerializer/ReflectionModel/DefaultConstructedActivators.cs
@@ -0,0 +1,12 @@
+using ExtendedXmlSerializer.Core.Sources;
+using System;
+
+namespace ExtendedXmlSerializer.ReflectionModel
+{
+ sealed class DefaultConstructedActivators : DecoratedSource, IActivators
+ {
+ public static DefaultConstructedActivators Default { get; } = new DefaultConstructedActivators();
+
+ DefaultConstructedActivators() : base(new ConstructedActivators(ConstructorLocator.Default)) {}
+ }
+}
\ No newline at end of file
diff --git a/src/ExtendedXmlSerializer/ReflectionModel/DictionaryConstructorLocator.cs b/src/ExtendedXmlSerializer/ReflectionModel/DictionaryConstructorLocator.cs
new file mode 100644
index 000000000..153a712fd
--- /dev/null
+++ b/src/ExtendedXmlSerializer/ReflectionModel/DictionaryConstructorLocator.cs
@@ -0,0 +1,42 @@
+using ExtendedXmlSerializer.Core.Sources;
+using ExtendedXmlSerializer.Core.Specifications;
+using System;
+using System.Collections.Generic;
+using System.Reflection;
+
+namespace ExtendedXmlSerializer.ReflectionModel
+{
+ class DictionaryConstructorLocator : IParameterizedSource
+ {
+ readonly ISpecification _specification;
+ readonly IConstructorLocator _previous;
+ readonly Type _baseType;
+
+ public DictionaryConstructorLocator(ISpecification specification, IConstructorLocator previous)
+ : this(specification, previous, typeof(Dictionary<,>)) {}
+
+ public DictionaryConstructorLocator(ISpecification specification, IConstructorLocator previous,
+ Type baseType)
+ {
+ _specification = specification;
+ _previous = previous;
+ _baseType = baseType;
+ }
+
+ public ConstructorInfo Get(TypeInfo parameter)
+ {
+ var accounted = _specification.IsSatisfiedBy(parameter)
+ ? MakeGenericType(parameter)
+ : parameter;
+ var result = _previous.Get(accounted);
+ return result;
+ }
+
+ Type MakeGenericType(TypeInfo parameter)
+ {
+ var types = DictionaryPairTypesLocator.Default.Get(parameter);
+ var result = _baseType.MakeGenericType(types?.KeyType, types?.ValueType);
+ return result;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/ExtendedXmlSerializer/ReflectionModel/IsInterface.cs b/src/ExtendedXmlSerializer/ReflectionModel/IsInterface.cs
new file mode 100644
index 000000000..26069d3c7
--- /dev/null
+++ b/src/ExtendedXmlSerializer/ReflectionModel/IsInterface.cs
@@ -0,0 +1,12 @@
+using ExtendedXmlSerializer.Core.Specifications;
+using System.Reflection;
+
+namespace ExtendedXmlSerializer.ReflectionModel
+{
+ sealed class IsInterface : DelegatedSpecification
+ {
+ public static IsInterface Default { get; } = new IsInterface();
+
+ IsInterface() : base(x => x.IsInterface) {}
+ }
+}
diff --git a/src/ExtendedXmlSerializer/ReflectionModel/ListConstructorLocator.cs b/src/ExtendedXmlSerializer/ReflectionModel/ListConstructorLocator.cs
new file mode 100644
index 000000000..dd0bcb7e2
--- /dev/null
+++ b/src/ExtendedXmlSerializer/ReflectionModel/ListConstructorLocator.cs
@@ -0,0 +1,35 @@
+using ExtendedXmlSerializer.Core.Sources;
+using ExtendedXmlSerializer.Core.Specifications;
+using System;
+using System.Collections.Generic;
+using System.Reflection;
+
+namespace ExtendedXmlSerializer.ReflectionModel
+{
+ class ListConstructorLocator : IParameterizedSource
+ {
+ readonly ISpecification _specification;
+ readonly IConstructorLocator _previous;
+ readonly Type _baseType;
+
+ public ListConstructorLocator(ISpecification specification, IConstructorLocator previous)
+ : this(specification, previous, typeof(List<>)) {}
+
+ public ListConstructorLocator(ISpecification specification, IConstructorLocator previous,
+ Type baseType)
+ {
+ _specification = specification;
+ _previous = previous;
+ _baseType = baseType;
+ }
+
+ public ConstructorInfo Get(TypeInfo parameter)
+ {
+ var accounted = _specification.IsSatisfiedBy(parameter)
+ ? _baseType.MakeGenericType(CollectionItemTypeLocator.Default.Get(parameter))
+ : parameter;
+ var result = _previous.Get(accounted);
+ return result;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/ExtendedXmlSerializer/ReflectionModel/Support.cs b/src/ExtendedXmlSerializer/ReflectionModel/Support.cs
index e364a0222..8ca6494a4 100644
--- a/src/ExtendedXmlSerializer/ReflectionModel/Support.cs
+++ b/src/ExtendedXmlSerializer/ReflectionModel/Support.cs
@@ -10,8 +10,8 @@ static class Support
public static TypeInfo Metadata { get; } = typeof(T).GetTypeInfo();
- public static Func New { get; } = DefaultActivators.Default.New;
+ public static Func New { get; } = DefaultConstructedActivators.Default.New;
- public static Func NewOrSingleton { get; } = Activators.Default.New;
+ public static Func NewOrSingleton { get; } = new Activators(DefaultConstructedActivators.Default).New;
}
}
\ No newline at end of file
diff --git a/test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue485Tests.cs b/test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue485Tests.cs
new file mode 100644
index 000000000..cce2f09fc
--- /dev/null
+++ b/test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue485Tests.cs
@@ -0,0 +1,417 @@
+using ExtendedXmlSerializer.Configuration;
+using ExtendedXmlSerializer.Tests.ReportedIssues.Support;
+using FluentAssertions;
+using System;
+using System.Collections.Generic;
+using System.Collections.Immutable;
+using Xunit;
+// ReSharper disable All
+
+namespace ExtendedXmlSerializer.Tests.ReportedIssues
+{
+ public sealed class Issue485Tests
+ {
+ [Fact]
+ public void Verify()
+ {
+ var instance = new[] { 1, 2, 3, 4 }.ToImmutableList();
+
+ var serializer = new ConfigurationContainer().UseAutoFormatting()
+ .UseOptimizedNamespaces()
+ .EnableImmutableTypes()
+ .EnableParameterizedContent()
+ .Create()
+ .ForTesting();
+ serializer.Assert(instance,
+ @"1 2 3 4 ");
+ serializer.Cycle(instance).Should().BeEquivalentTo(instance);
+ }
+
+ [Fact]
+ public void VerifyHashSet()
+ {
+ var instance = new[] { 1, 2, 3, 4 }.ToImmutableHashSet();
+
+ var serializer = new ConfigurationContainer().UseAutoFormatting()
+ .UseOptimizedNamespaces()
+ .EnableImmutableTypes()
+ .EnableParameterizedContent()
+ .Create()
+ .ForTesting();
+ serializer.Assert(instance,
+ @"1 2 3 4 ");
+ serializer.Cycle(instance).Should().BeEquivalentTo(instance);
+ }
+
+ [Fact]
+ public void VerifySortedSet()
+ {
+ var instance = new[] { 1, 2, 3, 4 }.ToImmutableSortedSet();
+
+ var serializer = new ConfigurationContainer().UseAutoFormatting()
+ .UseOptimizedNamespaces()
+ .EnableImmutableTypes()
+ .EnableParameterizedContent()
+ .Create()
+ .ForTesting();
+ serializer.Assert(instance,
+ @"1 2 3 4 ");
+ serializer.Cycle(instance).Should().BeEquivalentTo(instance);
+ }
+
+ [Fact]
+ public void VerifyDictionary()
+ {
+ var instance = new Dictionary
+ {
+ ["Hello"] = "World"
+ }.ToImmutableDictionary();
+
+ var serializer = new ConfigurationContainer().UseAutoFormatting()
+ .UseOptimizedNamespaces()
+ .EnableImmutableTypes()
+ .EnableParameterizedContent()
+ .Create()
+ .ForTesting();
+
+ serializer.Assert(instance,
+ @" ");
+
+ var dictionary = serializer.Cycle(instance);
+ dictionary.Should().BeEquivalentTo(instance);
+
+ dictionary["Hello"].Should().Be(instance["Hello"]);
+ }
+
+ [Fact]
+ public void VerifySortedDictionary()
+ {
+ var instance = new Dictionary
+ {
+ ["First"] = "Value1",
+ ["Hello"] = "World",
+ ["Second"] = "Value2",
+ ["Last"] = "Value2",
+ }.ToImmutableSortedDictionary();
+
+ var serializer = new ConfigurationContainer().UseAutoFormatting()
+ .UseOptimizedNamespaces()
+ .EnableImmutableTypes()
+ .EnableParameterizedContent()
+ .Create()
+ .ForTesting();
+
+ serializer.Assert(instance,
+ @" ");
+
+ var dictionary = serializer.Cycle(instance);
+ dictionary.Should().BeEquivalentTo(instance);
+
+ dictionary["Hello"].Should().Be(instance["Hello"]);
+ }
+
+ [Fact]
+ public void VerifyWithPropertyAssignments()
+ {
+ var instance = new[] { 1, 2, 3, 4 }.ToImmutableList();
+
+ var serializer = new ConfigurationContainer().UseAutoFormatting()
+ .UseOptimizedNamespaces()
+ .EnableImmutableTypes()
+ .EnableParameterizedContentWithPropertyAssignments()
+ .Create()
+ .ForTesting();
+ serializer.Assert(instance,
+ @"1 2 3 4 ");
+ serializer.Cycle(instance).Should().BeEquivalentTo(instance);
+ }
+
+ [Fact]
+ public void VerifyHashSetWithPropertyAssignments()
+ {
+ var instance = new[] { 1, 2, 3, 4 }.ToImmutableHashSet();
+
+ var serializer = new ConfigurationContainer().UseAutoFormatting()
+ .UseOptimizedNamespaces()
+ .EnableImmutableTypes()
+ .EnableParameterizedContentWithPropertyAssignments()
+ .Create()
+ .ForTesting();
+ serializer.Assert(instance,
+ @"1 2 3 4 ");
+ serializer.Cycle(instance).Should().BeEquivalentTo(instance);
+ }
+
+ [Fact]
+ public void VerifySortedSetWithPropertyAssignments()
+ {
+ var instance = new[] { 1, 2, 3, 4 }.ToImmutableSortedSet();
+
+ var serializer = new ConfigurationContainer().UseAutoFormatting()
+ .UseOptimizedNamespaces()
+ .EnableImmutableTypes()
+ .EnableParameterizedContentWithPropertyAssignments()
+ .Create()
+ .ForTesting();
+ serializer.Assert(instance,
+ @"1 2 3 4 ");
+ serializer.Cycle(instance).Should().BeEquivalentTo(instance);
+ }
+
+ [Fact]
+ public void VerifyDictionaryWithPropertyAssignments()
+ {
+ var instance = new Dictionary
+ {
+ ["Hello"] = "World"
+ }.ToImmutableDictionary();
+
+ var serializer = new ConfigurationContainer().UseAutoFormatting()
+ .UseOptimizedNamespaces()
+ .EnableImmutableTypes()
+ .EnableParameterizedContentWithPropertyAssignments()
+ .Create()
+ .ForTesting();
+
+ serializer.Assert(instance,
+ @" ");
+
+ var dictionary = serializer.Cycle(instance);
+ dictionary.Should().BeEquivalentTo(instance);
+
+ dictionary["Hello"].Should().Be(instance["Hello"]);
+ }
+
+ [Fact]
+ public void VerifySortedDictionaryWithPropertyAssignments()
+ {
+ var instance = new Dictionary
+ {
+ ["First"] = "Value1",
+ ["Hello"] = "World",
+ ["Second"] = "Value2",
+ ["Last"] = "Value2",
+ }.ToImmutableSortedDictionary();
+
+ var serializer = new ConfigurationContainer().UseAutoFormatting()
+ .UseOptimizedNamespaces()
+ .EnableImmutableTypes()
+ .EnableParameterizedContentWithPropertyAssignments()
+ .Create()
+ .ForTesting();
+
+ serializer.Assert(instance,
+ @" ");
+
+ var dictionary = serializer.Cycle(instance);
+ dictionary.Should().BeEquivalentTo(instance);
+
+ dictionary["Hello"].Should().Be(instance["Hello"]);
+ }
+
+ [Fact]
+ public void VerifyListEmpty()
+ {
+ var serializer = new ConfigurationContainer().UseAutoFormatting()
+ .UseOptimizedNamespaces()
+ .EnableImmutableTypes()
+ .EnableParameterizedContent()
+ .Create()
+ .ForTesting();
+ var instance = new SubjectList("Hello World!", ImmutableList.Empty);
+
+ serializer.Cycle(instance).Should().BeEquivalentTo(instance);
+ }
+
+ [Fact]
+ public void VerifyHashSetEmpty()
+ {
+ var serializer = new ConfigurationContainer().UseAutoFormatting()
+ .UseOptimizedNamespaces()
+ .EnableImmutableTypes()
+ .EnableParameterizedContent()
+ .Create()
+ .ForTesting();
+ var instance = new SubjectHashSet("Hello World!", ImmutableHashSet.Empty);
+
+ serializer.Cycle(instance).Should().BeEquivalentTo(instance);
+ }
+
+ [Fact]
+ public void VerifySortedSetEmpty()
+ {
+ var serializer = new ConfigurationContainer().UseAutoFormatting()
+ .UseOptimizedNamespaces()
+ .EnableImmutableTypes()
+ .EnableParameterizedContent()
+ .Create()
+ .ForTesting();
+ var instance = new SubjectSortedSet("Hello World!", ImmutableSortedSet.Empty);
+
+ serializer.Cycle(instance).Should().BeEquivalentTo(instance);
+ }
+
+ [Fact]
+ public void VerifyDictionaryEmpty()
+ {
+ var serializer = new ConfigurationContainer().UseAutoFormatting()
+ .UseOptimizedNamespaces()
+ .EnableImmutableTypes()
+ .EnableParameterizedContent()
+ .Create()
+ .ForTesting();
+ var instance = new SubjectDictionary("Hello World!", ImmutableDictionary.Empty);
+
+ serializer.Cycle(instance).Should().BeEquivalentTo(instance);
+ }
+
+ [Fact]
+ public void VerifySortedDictionaryEmpty()
+ {
+ var serializer = new ConfigurationContainer().UseAutoFormatting()
+ .UseOptimizedNamespaces()
+ .EnableImmutableTypes()
+ .EnableParameterizedContent()
+ .Create()
+ .ForTesting();
+ var instance = new SubjectSortedDictionary("Hello World!", ImmutableSortedDictionary.Empty);
+
+ serializer.Cycle(instance).Should().BeEquivalentTo(instance);
+ }
+
+ [Fact]
+ public void VerifyListEmptyWithPropertyAssignments()
+ {
+ var serializer = new ConfigurationContainer().UseAutoFormatting()
+ .UseOptimizedNamespaces()
+ .EnableImmutableTypes()
+ .EnableParameterizedContentWithPropertyAssignments()
+ .Create()
+ .ForTesting();
+ var instance = new SubjectList("Hello World!", ImmutableList.Empty);
+
+ serializer.Cycle(instance).Should().BeEquivalentTo(instance);
+ }
+
+ [Fact]
+ public void VerifyHashSetEmptyWithPropertyAssignments()
+ {
+ var serializer = new ConfigurationContainer().UseAutoFormatting()
+ .UseOptimizedNamespaces()
+ .EnableImmutableTypes()
+ .EnableParameterizedContentWithPropertyAssignments()
+ .Create()
+ .ForTesting();
+ var instance = new SubjectHashSet("Hello World!", ImmutableHashSet.Empty);
+
+ serializer.Cycle(instance).Should().BeEquivalentTo(instance);
+ }
+
+ [Fact]
+ public void VerifySortedSetEmptyWithPropertyAssignments()
+ {
+ var serializer = new ConfigurationContainer().UseAutoFormatting()
+ .UseOptimizedNamespaces()
+ .EnableImmutableTypes()
+ .EnableParameterizedContentWithPropertyAssignments()
+ .Create()
+ .ForTesting();
+ var instance = new SubjectSortedSet("Hello World!", ImmutableSortedSet.Empty);
+
+ serializer.Cycle(instance).Should().BeEquivalentTo(instance);
+ }
+
+ [Fact]
+ public void VerifyDictionaryEmptyWithPropertyAssignments()
+ {
+ var serializer = new ConfigurationContainer().UseAutoFormatting()
+ .UseOptimizedNamespaces()
+ .EnableImmutableTypes()
+ .EnableParameterizedContentWithPropertyAssignments()
+ .Create()
+ .ForTesting();
+ var instance = new SubjectDictionary("Hello World!", ImmutableDictionary.Empty);
+
+ serializer.Cycle(instance).Should().BeEquivalentTo(instance);
+ }
+
+ [Fact]
+ public void VerifySortedDictionaryEmptyWithPropertyAssignments()
+ {
+ var serializer = new ConfigurationContainer().UseAutoFormatting()
+ .UseOptimizedNamespaces()
+ .EnableImmutableTypes()
+ .EnableParameterizedContentWithPropertyAssignments()
+ .Create()
+ .ForTesting();
+ var instance = new SubjectSortedDictionary("Hello World!", ImmutableSortedDictionary.Empty);
+
+ serializer.Cycle(instance).Should().BeEquivalentTo(instance);
+ }
+
+ class SubjectList
+ {
+ public SubjectList(string name, ImmutableList list)
+ {
+ Name = name;
+ List = list;
+ }
+
+ public string Name { get; }
+
+ public ImmutableList List { get; }
+ }
+
+ class SubjectHashSet
+ {
+ public SubjectHashSet(string name, ImmutableHashSet list)
+ {
+ Name = name;
+ List = list;
+ }
+
+ public string Name { get; }
+
+ public ImmutableHashSet List { get; }
+ }
+
+ class SubjectSortedSet
+ {
+ public SubjectSortedSet(string name, ImmutableSortedSet list)
+ {
+ Name = name;
+ List = list;
+ }
+
+ public string Name { get; }
+
+ public ImmutableSortedSet List { get; }
+ }
+
+ class SubjectDictionary
+ {
+ public SubjectDictionary(string name, ImmutableDictionary list)
+ {
+ Name = name;
+ List = list;
+ }
+
+ public string Name { get; }
+
+ public ImmutableDictionary List { get; }
+ }
+
+ class SubjectSortedDictionary
+ {
+ public SubjectSortedDictionary(string name, ImmutableSortedDictionary list)
+ {
+ Name = name;
+ List = list;
+ }
+
+ public string Name { get; }
+
+ public ImmutableSortedDictionary List { get; }
+ }
+ }
+}
\ No newline at end of file
diff --git a/test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue485Tests_Extended.cs b/test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue485Tests_Extended.cs
new file mode 100644
index 000000000..8c1392c6d
--- /dev/null
+++ b/test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue485Tests_Extended.cs
@@ -0,0 +1,71 @@
+using ExtendedXmlSerializer.Configuration;
+using FluentAssertions;
+using LightInject;
+using System.Xml;
+using Xunit;
+// ReSharper disable All
+
+namespace ExtendedXmlSerializer.Tests.ReportedIssues
+{
+#nullable enable
+ public sealed class Issue485Tests_Extended
+ {
+ [Fact]
+ public void Verify()
+ {
+ var serializer = new ConfigurationContainer().UseAutoFormatting()
+ .EnableImmutableTypes()
+ .EnableParameterizedContent()
+ .Create();
+ var settings = new XmlWriterSettings { Indent = true };
+
+ var instance = new U("ciao", null);
+ var xml = serializer.Serialize(settings, instance);
+
+ var deserialized = serializer.Deserialize(xml);
+ deserialized.Member.Should().BeNull();
+ }
+
+ [Fact]
+ public void VerifyAlternate()
+ {
+ var serializer = new ConfigurationContainer().UseAutoFormatting()
+ .EnableImmutableTypes()
+ .EnableParameterizedContentWithPropertyAssignments()
+ .Create();
+ var settings = new XmlWriterSettings { Indent = true };
+
+ var instance = new U("ciao", null);
+ var xml = serializer.Serialize(settings, instance);
+
+ var deserialized = serializer.Deserialize(xml);
+ deserialized.Member.Should().BeNull();
+ }
+
+ class U
+ {
+ public string Id { get; }
+ public T? Member { get; }
+
+ public U(string id, T? member)
+ {
+ Id = id;
+ Member = member;
+ }
+ }
+
+ class T
+ {
+ public string Name { get; }
+ public ImmutableList List { get; }
+
+ public T(string name, ImmutableList list)
+ {
+ Name = name;
+ List = list;
+ }
+ }
+
+ }
+ #nullable restore
+}