-
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.
Added support for
System.Collections.Immutable
Types (#486)
- Loading branch information
1 parent
90345c7
commit f74f8c3
Showing
33 changed files
with
1,416 additions
and
137 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
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
13 changes: 13 additions & 0 deletions
13
src/ExtendedXmlSerializer/ContentModel/Reflection/DefaultTypeDefaults.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,13 @@ | ||
using ExtendedXmlSerializer.Core.Sources; | ||
using ExtendedXmlSerializer.ReflectionModel; | ||
using System.Reflection; | ||
|
||
namespace ExtendedXmlSerializer.ContentModel.Reflection | ||
{ | ||
sealed class DefaultTypeDefaults : DecoratedSource<TypeInfo, object>, ITypeDefaults | ||
{ | ||
public static DefaultTypeDefaults Default { get; } = new DefaultTypeDefaults(); | ||
|
||
DefaultTypeDefaults() : base(new TypeDefaults(DefaultConstructedActivators.Default)) {} | ||
} | ||
} |
17 changes: 8 additions & 9 deletions
17
src/ExtendedXmlSerializer/ContentModel/Reflection/TypeDefaults.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 |
---|---|---|
@@ -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<TypeInfo, object>, ITypeDefaults | ||
{ | ||
public static TypeDefaults Default { get; } = new TypeDefaults(); | ||
public static IParameterizedSource<IActivators, ITypeDefaults> Defaults { get; } | ||
= new ReferenceCache<IActivators, ITypeDefaults>(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(); | ||
} | ||
} |
13 changes: 5 additions & 8 deletions
13
src/ExtendedXmlSerializer/ContentModel/Reflection/TypeMemberDefaults.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
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
20 changes: 20 additions & 0 deletions
20
src/ExtendedXmlSerializer/ExtensionModel/Content/Members/DefaultValueTypeDefaults.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,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<ISource<object>>(typeof(DefaultValues<>))) {} | ||
|
||
readonly IGeneric<ISource<object>> _generic; | ||
|
||
public DefaultValueTypeDefaults(IGeneric<ISource<object>> generic) => _generic = generic; | ||
|
||
public object Get(TypeInfo parameter) => _generic.Get(parameter)().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
31 changes: 31 additions & 0 deletions
31
src/ExtendedXmlSerializer/ExtensionModel/Content/Members/ParameterizedAwareTypeDefaults.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,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; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.