diff --git a/samples/ExtendedXmlSerializer.Samples/Generics/GenericSerializer.cs b/samples/ExtendedXmlSerializer.Samples/Generics/GenericSerializer.cs index 81afc4548..c82f79fde 100644 --- a/samples/ExtendedXmlSerializer.Samples/Generics/GenericSerializer.cs +++ b/samples/ExtendedXmlSerializer.Samples/Generics/GenericSerializer.cs @@ -4,7 +4,7 @@ namespace ExtendedXmlSerializer.Samples.Generics { - public class GenericSerializer + public class GenericSerializer { private IExtendedXmlSerializer serializer; @@ -46,7 +46,7 @@ public static void SerializeAndDeserialize() var data = srl.SerializeProject(prj); - var obj = srl.DeserializeProject(data); + srl.DeserializeProject(data); } @@ -78,20 +78,20 @@ public Project(string name, int id) Id = id; } - public string Name { get; set; } = "MY project"; + public string Name { get; set; } public int Id { get; } public string Path => @"C:/my/fake/path"; public IList> Sites { get; } = new List>(); } - public class SpecificClass : SiteBase + public sealed class SpecificClass : SiteBase { public SpecificClass() { - this.Name = "Specific class"; - this.UserDescription = "Class description"; - this.Context = new Context(); + Name = "Specific class"; + UserDescription = "Class description"; + Context = new Context(); } @@ -105,6 +105,7 @@ public abstract class SiteBase : ISite where TSiteCo { public string Name { get; set; } public string UserDescription { get; set; } + // ReSharper disable once MemberHidesStaticFromOuterClass public abstract TSiteContext Context { get; set; } } diff --git a/samples/ExtendedXmlSerializer.Samples/Parametrized/ParametrizedConstructors.cs b/samples/ExtendedXmlSerializer.Samples/Parametrized/ParametrizedConstructors.cs index e816ad476..1f3004b2d 100644 --- a/samples/ExtendedXmlSerializer.Samples/Parametrized/ParametrizedConstructors.cs +++ b/samples/ExtendedXmlSerializer.Samples/Parametrized/ParametrizedConstructors.cs @@ -3,7 +3,7 @@ namespace ExtendedXmlSerializer.Samples.Parametrized { - public static class ParametrizedConstructors + public static class ParametrizedConstructors { public static void SerializeAndDeserialize() { @@ -22,7 +22,7 @@ public static void SerializeAndDeserialize() dt.Data.Add(7); var data = srl.Serialize(dt); - var obj = dsrl.Deserialize(data); + dsrl.Deserialize(data); } public class DataHolder diff --git a/samples/ExtendedXmlSerializer.Samples/Program.cs b/samples/ExtendedXmlSerializer.Samples/Program.cs index 0b3a397bf..8bd169d97 100644 --- a/samples/ExtendedXmlSerializer.Samples/Program.cs +++ b/samples/ExtendedXmlSerializer.Samples/Program.cs @@ -33,9 +33,9 @@ namespace ExtendedXmlSerializer.Samples { - using ExtendedXmlSerializer.Samples.Generics; - using ExtendedXmlSerializer.Samples.Parametrized; - using FluentApi; + using FluentApi; + using Generics; + using Parametrized; public class Program { diff --git a/src/ExtendedXmlSerializer/ContentModel/Conversion/StructureConverter.cs b/src/ExtendedXmlSerializer/ContentModel/Conversion/StructureConverter.cs index cd4e92960..e306c2bf3 100644 --- a/src/ExtendedXmlSerializer/ContentModel/Conversion/StructureConverter.cs +++ b/src/ExtendedXmlSerializer/ContentModel/Conversion/StructureConverter.cs @@ -1,5 +1,5 @@ -using System.Reflection; using ExtendedXmlSerializer.Core; +using System.Reflection; namespace ExtendedXmlSerializer.ContentModel.Conversion { @@ -11,7 +11,7 @@ sealed class StructureConverter : IConverter where T : struct public bool IsSatisfiedBy(TypeInfo parameter) => _converter.IsSatisfiedBy(parameter); - public T? Parse(string data) => data.NullIfEmpty() != null ? _converter.Parse(data) : (T?)null; + public T? Parse(string data) => data.NullIfEmpty() != null ? _converter.Parse(data) : null; public string Format(T? instance) => instance.HasValue ? _converter.Format(instance.Value) : null; } diff --git a/src/ExtendedXmlSerializer/ContentModel/Members/InstanceMemberSerializations.cs b/src/ExtendedXmlSerializer/ContentModel/Members/InstanceMemberSerializations.cs index 53ee2ddbd..6cdef1b2a 100644 --- a/src/ExtendedXmlSerializer/ContentModel/Members/InstanceMemberSerializations.cs +++ b/src/ExtendedXmlSerializer/ContentModel/Members/InstanceMemberSerializations.cs @@ -1,6 +1,6 @@ -using System.Reflection; using ExtendedXmlSerializer.Core.Specifications; using ExtendedXmlSerializer.ReflectionModel; +using System.Reflection; namespace ExtendedXmlSerializer.ContentModel.Members { @@ -21,7 +21,7 @@ public InstanceMemberSerializations(ISpecification specification, public IInstanceMemberSerialization Get(TypeInfo parameter) => _specification.IsSatisfiedBy(parameter) - ? (IInstanceMemberSerialization)new InstanceMemberSerialization(parameter, _serializations) + ? new InstanceMemberSerialization(parameter, _serializations) : new FixedInstanceMemberSerialization(_serializations.Get(parameter)); } } \ No newline at end of file diff --git a/src/ExtendedXmlSerializer/ContentModel/Reflection/TypePartMapper.cs b/src/ExtendedXmlSerializer/ContentModel/Reflection/TypePartMapper.cs index ab1b00edb..3bb5a7d28 100644 --- a/src/ExtendedXmlSerializer/ContentModel/Reflection/TypePartMapper.cs +++ b/src/ExtendedXmlSerializer/ContentModel/Reflection/TypePartMapper.cs @@ -1,9 +1,9 @@ -using System; -using System.Collections.Immutable; -using System.Linq; using ExtendedXmlSerializer.ContentModel.Conversion; using ExtendedXmlSerializer.ContentModel.Identification; using ExtendedXmlSerializer.Core.Sources; +using System; +using System.Collections.Immutable; +using System.Linq; namespace ExtendedXmlSerializer.ContentModel.Reflection { @@ -26,7 +26,7 @@ public TypeParts Get(TypeParts parameter) arguments.HasValue ? arguments.Value.Select(_selector) .ToImmutableArray - : (Func>)null); + : null); return result; } } diff --git a/src/ExtendedXmlSerializer/ContentModel/Reflection/VariableTypeWalker.cs b/src/ExtendedXmlSerializer/ContentModel/Reflection/VariableTypeWalker.cs index bbeb6bc29..1c7acc131 100644 --- a/src/ExtendedXmlSerializer/ContentModel/Reflection/VariableTypeWalker.cs +++ b/src/ExtendedXmlSerializer/ContentModel/Reflection/VariableTypeWalker.cs @@ -1,17 +1,18 @@ -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using ExtendedXmlSerializer.ContentModel.Members; +using ExtendedXmlSerializer.ContentModel.Members; using ExtendedXmlSerializer.Core; using ExtendedXmlSerializer.Core.Sources; using ExtendedXmlSerializer.Core.Specifications; +using ExtendedXmlSerializer.ReflectionModel; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; namespace ExtendedXmlSerializer.ContentModel.Reflection { class VariableTypeWalker : TypeMemberWalkerBase, ISource> { - readonly static ReflectionModel.VariableTypeSpecification Specification = - ReflectionModel.VariableTypeSpecification.Default; + readonly static ISpecification Specification = + ReflectionModel.VariableTypeSpecification.Default.Or(IsArraySpecification.Default); readonly ISpecification _specification; diff --git a/src/ExtendedXmlSerializer/Core/Extensions.cs b/src/ExtendedXmlSerializer/Core/Extensions.cs index 03fc8aa51..f50d08fe7 100644 --- a/src/ExtendedXmlSerializer/Core/Extensions.cs +++ b/src/ExtendedXmlSerializer/Core/Extensions.cs @@ -152,7 +152,7 @@ public static TValue Get(this IReadOnlyDictionary ta where TValue : struct => AssignedSpecification.Default.IsSatisfiedBy(key) && target.TryGetValue(key, out var result) ? result - : (TValue?)null; + : null; public static IEnumerable Appending(this IEnumerable @this, params T[] items) => @this.Concat(items); diff --git a/src/ExtendedXmlSerializer/Core/Parsing/Extensions.cs b/src/ExtendedXmlSerializer/Core/Parsing/Extensions.cs index d6faf07ef..fd0487031 100644 --- a/src/ExtendedXmlSerializer/Core/Parsing/Extensions.cs +++ b/src/ExtendedXmlSerializer/Core/Parsing/Extensions.cs @@ -18,7 +18,7 @@ public static T ParseAsOptional(this Parser @this, string data) public static Func Build(this IOption @this) => @this.IsDefined ? new Func(@this.Get) : null; public static T? GetAssigned(this IOption @this) where T : struct - => @this.IsDefined ? @this.Get() : (T?)null; + => @this.IsDefined ? @this.Get() : null; public static T Get(this IParsing @this, string parameter) => @this.Get(Inputs.Default.Get(parameter)) .Value; diff --git a/src/ExtendedXmlSerializer/Core/Sources/ConditionalSource.cs b/src/ExtendedXmlSerializer/Core/Sources/ConditionalSource.cs index c0ec07866..3a729c7b6 100644 --- a/src/ExtendedXmlSerializer/Core/Sources/ConditionalSource.cs +++ b/src/ExtendedXmlSerializer/Core/Sources/ConditionalSource.cs @@ -26,7 +26,7 @@ public ConditionalSource(ISpecification specification, ISpecificatio /// public ConditionalSource(Func specification, Func result, Func source) - : this(specification, result, source, x => default) {} + : this(specification, result, source, _ => default) {} /// public ConditionalSource(Func specification, Func result, diff --git a/src/ExtendedXmlSerializer/Core/TypedSortOrder.cs b/src/ExtendedXmlSerializer/Core/TypedSortOrder.cs index e4bd45322..5b2d47a74 100644 --- a/src/ExtendedXmlSerializer/Core/TypedSortOrder.cs +++ b/src/ExtendedXmlSerializer/Core/TypedSortOrder.cs @@ -1,10 +1,10 @@ -using System.Reflection; using ExtendedXmlSerializer.Core.Sources; +using System.Reflection; namespace ExtendedXmlSerializer.Core { sealed class TypedSortOrder : StructureCache, ITypedSortOrder { - public TypedSortOrder() : base(info => 1) {} + public TypedSortOrder() : base(_ => 1) {} } } \ No newline at end of file diff --git a/src/ExtendedXmlSerializer/ExtendedXmlSerializer.csproj b/src/ExtendedXmlSerializer/ExtendedXmlSerializer.csproj index 44351e4d3..650df8e61 100644 --- a/src/ExtendedXmlSerializer/ExtendedXmlSerializer.csproj +++ b/src/ExtendedXmlSerializer/ExtendedXmlSerializer.csproj @@ -7,7 +7,8 @@ Wojciech Nagórski;Michael DeMond netstandard2.0 ExtendedXmlSerializer - $(BaseIntermediateOutputPath)\$(Configuration)\$(TargetFramework)\ExtendedXmlSerializer.xml + + $(BaseIntermediateOutputPath)\$(Configuration)\$(TargetFramework)\ExtendedXmlSerializer.xml preview diff --git a/src/ExtendedXmlSerializer/ExtensionModel/Content/Contents.cs b/src/ExtendedXmlSerializer/ExtensionModel/Content/Contents.cs index c3693bafb..00f0ee9f4 100644 --- a/src/ExtendedXmlSerializer/ExtensionModel/Content/Contents.cs +++ b/src/ExtendedXmlSerializer/ExtensionModel/Content/Contents.cs @@ -22,7 +22,7 @@ public sealed class Contents : ISerializerExtension /// public IServiceRepository Get(IServiceRepository parameter) - => parameter.RegisterConstructorDependency((provider, info) => provider.Get()) + => parameter.RegisterConstructorDependency((provider, _) => provider.Get()) .Register() .DecorateContentsWith() diff --git a/src/ExtendedXmlSerializer/ExtensionModel/Content/Members/RuntimeSerializationExceptionMessage.cs b/src/ExtendedXmlSerializer/ExtensionModel/Content/Members/RuntimeSerializationExceptionMessage.cs index 3845823ef..1afbeecc5 100644 --- a/src/ExtendedXmlSerializer/ExtensionModel/Content/Members/RuntimeSerializationExceptionMessage.cs +++ b/src/ExtendedXmlSerializer/ExtensionModel/Content/Members/RuntimeSerializationExceptionMessage.cs @@ -11,7 +11,7 @@ sealed class RuntimeSerializationExceptionMessage = new RuntimeSerializationExceptionMessage(); RuntimeSerializationExceptionMessage() : - base(x => @"Parameterized Content is enabled on the container. By default, the type must satisfy the following rules if a public parameterless constructor is not found: + base(_ => @"Parameterized Content is enabled on the container. By default, the type must satisfy the following rules if a public parameterless constructor is not found: - Each member must not already be marked as an explicit contract - Must be a public fields / property. diff --git a/src/ExtendedXmlSerializer/ExtensionModel/Markup/MarkupExtensionPartsEvaluator.cs b/src/ExtendedXmlSerializer/ExtensionModel/Markup/MarkupExtensionPartsEvaluator.cs index cdb0a2944..4a0eb7545 100644 --- a/src/ExtendedXmlSerializer/ExtensionModel/Markup/MarkupExtensionPartsEvaluator.cs +++ b/src/ExtendedXmlSerializer/ExtensionModel/Markup/MarkupExtensionPartsEvaluator.cs @@ -160,7 +160,7 @@ static TypeParts Copy(TypeParts parameter) var array = parameter.GetArguments() ?.ToArray(); var result = new TypeParts(string.Concat(parameter.Name, Extension), parameter.Identifier, - array != null ? array.ToImmutableArray : (Func>)null, + array != null ? array.ToImmutableArray : null, parameter.Dimensions); return result; } diff --git a/src/ExtendedXmlSerializer/ExtensionModel/References/ProcessReference.cs b/src/ExtendedXmlSerializer/ExtensionModel/References/ProcessReference.cs index f615fe347..9c2da840f 100644 --- a/src/ExtendedXmlSerializer/ExtensionModel/References/ProcessReference.cs +++ b/src/ExtendedXmlSerializer/ExtensionModel/References/ProcessReference.cs @@ -7,7 +7,7 @@ namespace ExtendedXmlSerializer.ExtensionModel.References; -sealed class ProcessReference : ICommand +sealed class ProcessReference : ICommand { readonly ISpecification _allowed; readonly ITypeMembers _members; @@ -29,24 +29,37 @@ public ProcessReference(ISpecification allowed, ITypeMembers members, _store = store; } - public void Execute(ReferenceSet parameter) + public void Execute(ProcessReferenceInput parameter) { - using var boundary = parameter.Get(); - var next = boundary.Subject; - var type = next.GetType(); + var (results, current) = parameter; + results.IsSatisfiedBy(current); + Process(results, current); + } + + void Process(ReferenceSet results, object current) + { + using var boundary = results.Get(current); + var type = current.GetType(); if (_allowed.IsSatisfiedBy(type)) { var members = _members.Get(type); for (var i = 0; i < members.Length; i++) { - var value = _accessors.Get(members[i]).Get(next); - parameter.Execute(value); + var value = _accessors.Get(members[i]).Get(current); + if (results.IsSatisfiedBy(value)) + { + Process(results, value); + } } - var iterator = _store.For(next); + var iterator = _store.For(current); while (iterator?.MoveNext() ?? false) { - parameter.Execute(iterator.Current); + var o = iterator.Current; + if (results.IsSatisfiedBy(o)) + { + Process(results, o); + } } } } diff --git a/src/ExtendedXmlSerializer/ExtensionModel/References/ProcessReferenceInput.cs b/src/ExtendedXmlSerializer/ExtensionModel/References/ProcessReferenceInput.cs new file mode 100644 index 000000000..a81cf2b2b --- /dev/null +++ b/src/ExtendedXmlSerializer/ExtensionModel/References/ProcessReferenceInput.cs @@ -0,0 +1,3 @@ +namespace ExtendedXmlSerializer.ExtensionModel.References; + +readonly record struct ProcessReferenceInput(ReferenceSet Results, object Current); \ No newline at end of file diff --git a/src/ExtendedXmlSerializer/ExtensionModel/References/ReferenceAwareSerializers.cs b/src/ExtendedXmlSerializer/ExtensionModel/References/ReferenceAwareSerializers.cs index d3250dd20..2713cc3b5 100644 --- a/src/ExtendedXmlSerializer/ExtensionModel/References/ReferenceAwareSerializers.cs +++ b/src/ExtendedXmlSerializer/ExtensionModel/References/ReferenceAwareSerializers.cs @@ -84,7 +84,7 @@ public void Write(IFormatWriter writer, object instance) $"{line}{line}Here is a list of found references:{line}{string.Join(line, references.Encountered.Select(x => $"- {x}"))}"; throw new MultipleReferencesDetectedException( - $"The provided instance of type '{type}' contains the same reference multiple times in its graph. While this is technically allowed, it is recommended to instead enable referential support by calling EnableReferences on the ConfigurationContainer. Doing so will ensure that multiple references found in the graph are emitted only once in the serialized document.{message}", + $"The provided instance of type '{type}' contains the same reference multiple times in its graph. While this is technically allowed, it is recommended to instead enable referential support by calling EnableReferences on the ConfigurationContainer. Doing so will ensure that multiple references found in the graph are emitted only once in the serialized document. Additionally, if you do want to allow multiple instances emitted as-is, make use of the `AllowMultipleReferences` method on the ConfigurationContainer.{message}", _container); } } diff --git a/src/ExtendedXmlSerializer/ExtensionModel/References/ReferenceBoundary.cs b/src/ExtendedXmlSerializer/ExtensionModel/References/ReferenceBoundary.cs index 4356e6374..651fd0ae4 100644 --- a/src/ExtendedXmlSerializer/ExtensionModel/References/ReferenceBoundary.cs +++ b/src/ExtendedXmlSerializer/ExtensionModel/References/ReferenceBoundary.cs @@ -7,16 +7,10 @@ namespace ExtendedXmlSerializer.ExtensionModel.References; { readonly Stack _context; - public ReferenceBoundary(Stack context, object subject) - { - Subject = subject; - _context = context; - } - - public object Subject { get; } + public ReferenceBoundary(Stack context) => _context = context; public void Dispose() { - _context.Push(ReferenceCompleted.Default); + _context.Pop(); } } \ No newline at end of file diff --git a/src/ExtendedXmlSerializer/ExtensionModel/References/ReferenceCompleted.cs b/src/ExtendedXmlSerializer/ExtensionModel/References/ReferenceCompleted.cs deleted file mode 100644 index 5f2e4053b..000000000 --- a/src/ExtendedXmlSerializer/ExtensionModel/References/ReferenceCompleted.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace ExtendedXmlSerializer.ExtensionModel.References; - -sealed class ReferenceCompleted -{ - public static ReferenceCompleted Default { get; } = new(); - - ReferenceCompleted() {} -} \ No newline at end of file diff --git a/src/ExtendedXmlSerializer/ExtensionModel/References/ReferenceResult.cs b/src/ExtendedXmlSerializer/ExtensionModel/References/ReferenceResult.cs index 5544daeb4..be2f567ac 100644 --- a/src/ExtendedXmlSerializer/ExtensionModel/References/ReferenceResult.cs +++ b/src/ExtendedXmlSerializer/ExtensionModel/References/ReferenceResult.cs @@ -4,5 +4,5 @@ namespace ExtendedXmlSerializer.ExtensionModel.References; record ReferenceResult(HashSet Encountered, HashSet Cyclical) { - public ReferenceResult() : this(new HashSet(), new HashSet()) {} + protected ReferenceResult() : this(new HashSet(), new HashSet()) {} } \ No newline at end of file diff --git a/src/ExtendedXmlSerializer/ExtensionModel/References/ReferenceSet.cs b/src/ExtendedXmlSerializer/ExtensionModel/References/ReferenceSet.cs index dadde8663..0e9e7403e 100644 --- a/src/ExtendedXmlSerializer/ExtensionModel/References/ReferenceSet.cs +++ b/src/ExtendedXmlSerializer/ExtensionModel/References/ReferenceSet.cs @@ -1,35 +1,31 @@ -using ExtendedXmlSerializer.Core; using ExtendedXmlSerializer.Core.Sources; +using ExtendedXmlSerializer.Core.Specifications; using ExtendedXmlSerializer.ReflectionModel; using System.Collections.Generic; namespace ExtendedXmlSerializer.ExtensionModel.References; -sealed record ReferenceSet : ReferenceResult, ICommand, ISource +sealed record ReferenceSet : ReferenceResult, ISpecification, IParameterizedSource { readonly IReferencesPolicy _policy; - readonly Stack _remaining, _depth = new(); + readonly Stack _depth; readonly HashSet _tracked; - public ReferenceSet(IReferencesPolicy policy) - : this(policy, new Stack(), new HashSet()) {} + public ReferenceSet(IReferencesPolicy policy) : this(policy, new Stack(), new HashSet()) {} - public ReferenceSet(IReferencesPolicy policy, Stack remaining, HashSet tracked) + public ReferenceSet(IReferencesPolicy policy, Stack depth, HashSet tracked) { - _policy = policy; - _remaining = remaining; - _tracked = tracked; + _policy = policy; + _depth = depth; + _tracked = tracked; } - public void Execute(object parameter) + public bool IsSatisfiedBy(object parameter) { if (parameter is not null) { - if (_tracked.Add(parameter)) - { - _remaining.Push(parameter); - } - else + var result = _tracked.Add(parameter); + if (!result) { var info = parameter.GetType(); if (!info.IsValueType && _policy.IsSatisfiedBy(info)) @@ -41,24 +37,15 @@ public void Execute(object parameter) } } } + return result; } + + return false; } - public ReferenceBoundary Get() + public ReferenceBoundary Get(object parameter) { - var subject = _remaining.Pop(); - while (subject is ReferenceCompleted) - { - _depth.Pop(); - subject = Any() ? _remaining.Pop() : null; - } - - if (subject is not null) - { - _depth.Push(subject); - } - return new(_depth, subject); + _depth.Push(parameter); + return new(_depth); } - - public bool Any() => _remaining.Count > 0; } \ No newline at end of file diff --git a/src/ExtendedXmlSerializer/ExtensionModel/References/ReferenceView.cs b/src/ExtendedXmlSerializer/ExtensionModel/References/ReferenceView.cs index b0dea5182..d070df18b 100644 --- a/src/ExtendedXmlSerializer/ExtensionModel/References/ReferenceView.cs +++ b/src/ExtendedXmlSerializer/ExtensionModel/References/ReferenceView.cs @@ -16,9 +16,5 @@ public ReferenceView(IContainsCustomSerialization custom, IReferencesPolicy poli // ReSharper disable once TooManyDependencies ReferenceView(ReferenceWalker walker) => _walker = walker; - public ReferenceResult Get(object parameter) - { - var result = _walker.Get(parameter); - return result; - } + public ReferenceResult Get(object parameter) => _walker.Get(parameter); } \ No newline at end of file diff --git a/src/ExtendedXmlSerializer/ExtensionModel/References/ReferenceWalker.cs b/src/ExtendedXmlSerializer/ExtensionModel/References/ReferenceWalker.cs index 2eba97cbe..07cbc046b 100644 --- a/src/ExtendedXmlSerializer/ExtensionModel/References/ReferenceWalker.cs +++ b/src/ExtendedXmlSerializer/ExtensionModel/References/ReferenceWalker.cs @@ -16,12 +16,7 @@ public ReferenceWalker(IReferencesPolicy policy, ProcessReference process) public ReferenceResult Get(object parameter) { var result = new ReferenceSet(_policy); - result.Execute(parameter); - while (result.Any()) - { - _process.Execute(result); - } - + _process.Execute(new (result, parameter)); return result; } } diff --git a/src/ExtendedXmlSerializer/ExtensionModel/Services.cs b/src/ExtendedXmlSerializer/ExtensionModel/Services.cs index fa20a564e..2f1a3d508 100644 --- a/src/ExtendedXmlSerializer/ExtensionModel/Services.cs +++ b/src/ExtendedXmlSerializer/ExtensionModel/Services.cs @@ -152,7 +152,7 @@ public IServiceRepository Register(Func fa public IServiceRepository RegisterFallback(Func predicate, Func factory) => new Services(_container, - _registry.RegisterFallback((type, s) => predicate(type), + _registry.RegisterFallback((type, _) => predicate(type), request => factory(request.ServiceType))); public IServiceRepository RegisterConstructorDependency( diff --git a/src/ExtendedXmlSerializer/ExtensionModel/Types/Activators.cs b/src/ExtendedXmlSerializer/ExtensionModel/Types/Activators.cs index 31a174722..f099bac04 100644 --- a/src/ExtendedXmlSerializer/ExtensionModel/Types/Activators.cs +++ b/src/ExtendedXmlSerializer/ExtensionModel/Types/Activators.cs @@ -29,7 +29,7 @@ protected override IActivator Create(Type parameter) var result = singleton != null ? activate ? new Activator(_activators.Build(parameter), singleton) - : (IActivator)new ReflectionModel.Activator(singleton.Self) + : new ReflectionModel.Activator(singleton.Self) : activator(); return result; } diff --git a/src/ExtendedXmlSerializer/ExtensionModel/Types/AllConstructorsExtension.cs b/src/ExtendedXmlSerializer/ExtensionModel/Types/AllConstructorsExtension.cs index a87c3bb8d..4f96d2ef3 100644 --- a/src/ExtendedXmlSerializer/ExtensionModel/Types/AllConstructorsExtension.cs +++ b/src/ExtendedXmlSerializer/ExtensionModel/Types/AllConstructorsExtension.cs @@ -10,7 +10,7 @@ sealed class AllConstructorsExtension : ISerializerExtension AllConstructorsExtension() {} public IServiceRepository Get(IServiceRepository parameter) - => parameter.Decorate((provider, constructors) => new AllConstructors(constructors)); + => parameter.Decorate((_, constructors) => new AllConstructors(constructors)); void ICommand.Execute(IServices parameter) {} } diff --git a/src/ExtendedXmlSerializer/ExtensionModel/Xml/Classic/TypeIdentity.cs b/src/ExtendedXmlSerializer/ExtensionModel/Xml/Classic/TypeIdentity.cs index 99a036167..704bc8b3c 100644 --- a/src/ExtendedXmlSerializer/ExtensionModel/Xml/Classic/TypeIdentity.cs +++ b/src/ExtendedXmlSerializer/ExtensionModel/Xml/Classic/TypeIdentity.cs @@ -11,7 +11,7 @@ class TypeIdentity : ITypeIdentity where T : Attribute public TypeIdentity(Func identity) => _identity = identity; public Key? Get(TypeInfo parameter) - => parameter.IsDefined(typeof(T)) ? (Key?)_identity(parameter.GetCustomAttribute()) : null; + => parameter.IsDefined(typeof(T)) ? _identity(parameter.GetCustomAttribute()) : null; } sealed class TypeIdentity : ITypeIdentity diff --git a/src/ExtendedXmlSerializer/ExtensionModel/Xml/XmlWriter.cs b/src/ExtendedXmlSerializer/ExtensionModel/Xml/XmlWriter.cs index 947dcaf6b..acfe26099 100644 --- a/src/ExtendedXmlSerializer/ExtensionModel/Xml/XmlWriter.cs +++ b/src/ExtendedXmlSerializer/ExtensionModel/Xml/XmlWriter.cs @@ -154,7 +154,7 @@ TypeParts Get(TypeParts parameter) arguments.HasValue ? arguments.Value.Select(_selector) .ToImmutableArray - : (Func>)null, parameter.Dimensions); + : null, parameter.Dimensions); return result; } } diff --git a/src/ExtendedXmlSerializer/ReflectionModel/ConstructedActivators.cs b/src/ExtendedXmlSerializer/ReflectionModel/ConstructedActivators.cs index b1970a353..e507cb9c2 100644 --- a/src/ExtendedXmlSerializer/ReflectionModel/ConstructedActivators.cs +++ b/src/ExtendedXmlSerializer/ReflectionModel/ConstructedActivators.cs @@ -52,10 +52,10 @@ sealed class DefaultParameters : IParameterizedSource public Expression Get(ParameterInfo parameter) => parameter.IsDefined(typeof(ParamArrayAttribute)) - ? (Expression)Expression.NewArrayInit(parameter.ParameterType.GetElementType() ?? - throw new - InvalidOperationException("Element Type not found."), - Initializers) + ? Expression.NewArrayInit(parameter.ParameterType.GetElementType() ?? + throw new + InvalidOperationException("Element Type not found."), + Initializers) : Expression.Default(parameter.ParameterType); } } diff --git a/src/ExtendedXmlSerializer/ReflectionModel/Defaults.cs b/src/ExtendedXmlSerializer/ReflectionModel/Defaults.cs index 2711de6ff..538e869e5 100644 --- a/src/ExtendedXmlSerializer/ReflectionModel/Defaults.cs +++ b/src/ExtendedXmlSerializer/ReflectionModel/Defaults.cs @@ -14,6 +14,6 @@ static class Defaults public static Func ExpressionZip { get; } = (expression, type) => type.IsAssignableFrom(expression.Type) ? expression - : (Expression)Expression.Convert(expression, type); + : Expression.Convert(expression, type); } } \ No newline at end of file diff --git a/test/.External/VweCore/Geometry/LeveledRectangle.cs b/test/.External/VweCore/Geometry/LeveledRectangle.cs index 0d92ab47e..6a1411f36 100644 --- a/test/.External/VweCore/Geometry/LeveledRectangle.cs +++ b/test/.External/VweCore/Geometry/LeveledRectangle.cs @@ -38,7 +38,7 @@ public LeveledRectangle(Point2D firstPoint, Point2D secondPoint) public bool IsEmpty => LowerLeft.Equals(UpperRight); - public Point2D Center => new Point2D(LowerLeft.X + (Width / 2), LowerLeft.Y + (Height / 2)); + public Point2D Center => new Point2D(LowerLeft.X + Width / 2, LowerLeft.Y + Height / 2); public bool Equals(LeveledRectangle other) => LowerLeft.Equals(other.LowerLeft) && UpperRight.Equals(other.UpperRight); diff --git a/test/.External/VweCore/Geometry/MathExtensions.cs b/test/.External/VweCore/Geometry/MathExtensions.cs index 9404939c8..24bec65b7 100644 --- a/test/.External/VweCore/Geometry/MathExtensions.cs +++ b/test/.External/VweCore/Geometry/MathExtensions.cs @@ -4,9 +4,9 @@ namespace VweCore.Geometry { public static class MathExtensions { - public static double ToRadians(this double angleInDegrees) => (angleInDegrees * Math.PI) / 180.0; + public static double ToRadians(this double angleInDegrees) => angleInDegrees * Math.PI / 180.0; - public static double ToDegrees(this double angleInRadians) => (angleInRadians * 180) / Math.PI; + public static double ToDegrees(this double angleInRadians) => angleInRadians * 180 / Math.PI; public static double Square(this double value) => value * value; @@ -31,21 +31,21 @@ public static bool TryCalculateSlope(this Point2D point, Point2D other, out doub return true; } - public static double CalculateYIntercept(this Point2D point, double slope) => point.Y - (slope * point.X); + public static double CalculateYIntercept(this Point2D point, double slope) => point.Y - slope * point.X; public static (double xDistance, double yDistance) CalculateDistances(this Point2D point, Point2D other) => (point.X - other.X, point.Y - other.Y); public static double NormalizeAngleInDegrees(this double angleInDegrees) { if (angleInDegrees < 0.0) - return 360.0 + (angleInDegrees % -360.0); + return 360.0 + angleInDegrees % -360.0; if (angleInDegrees < 360.0) return angleInDegrees; return angleInDegrees % 360.0; } - public static double CalculateDotProduct(this Point2D point, Point2D other) => (point.X * other.X) + (point.Y * other.Y); + public static double CalculateDotProduct(this Point2D point, Point2D other) => point.X * other.X + point.Y * other.Y; public static double CalculateDirectionAngle(this Point2D vector) => Math.Atan2(vector.Y, vector.X).ToDegrees(); diff --git a/test/.External/VweCore/Geometry/Point2D.cs b/test/.External/VweCore/Geometry/Point2D.cs index 48cad9d4d..3d5d020e9 100644 --- a/test/.External/VweCore/Geometry/Point2D.cs +++ b/test/.External/VweCore/Geometry/Point2D.cs @@ -64,9 +64,9 @@ public Point2D TranslateToOrigin(Point2D referencePoint) => public Point2D TranslateBackFromOrigin(Point2D referencePoint) => new Point2D(X + referencePoint.X, Y + referencePoint.Y); - public double CalculateRotatedXCoordinate(double angleInRadians) => (X * Math.Cos(angleInRadians)) - (Y * Math.Sin(angleInRadians)); + public double CalculateRotatedXCoordinate(double angleInRadians) => X * Math.Cos(angleInRadians) - Y * Math.Sin(angleInRadians); - public double CalculateRotatedYCoordinate(double angleInRadians) => (X * Math.Sin(angleInRadians)) + (Y * Math.Cos(angleInRadians)); + public double CalculateRotatedYCoordinate(double angleInRadians) => X * Math.Sin(angleInRadians) + Y * Math.Cos(angleInRadians); public static bool operator !=(Point2D left, Point2D right) => !left.Equals(right); diff --git a/test/.External/VweCore/Geometry/SlopeInterceptEquation.cs b/test/.External/VweCore/Geometry/SlopeInterceptEquation.cs index 96e18ed24..807e2e584 100644 --- a/test/.External/VweCore/Geometry/SlopeInterceptEquation.cs +++ b/test/.External/VweCore/Geometry/SlopeInterceptEquation.cs @@ -30,7 +30,7 @@ public override int GetHashCode() public static bool operator !=(SlopeInterceptEquation left, SlopeInterceptEquation right) => !left.Equals(right); - public double CalculateY(double x) => (x * Slope) + YIntercept; + public double CalculateY(double x) => x * Slope + YIntercept; public bool ContainsPoint(Point2D point) => CalculateY(point.X).IsApproximately(point.Y); @@ -73,8 +73,8 @@ public Point2D GetPointByDistance(double x, double distance, AbscissaDirection d var x2 = x + xDistance; var pointX = direction == AbscissaDirection.LeftToRight - ? (x1.IsGreaterThanOrApproximatelyEqualTo(x) ? x1 : x2) - : (x1.IsLessThanOrApproximatelyEqualTo(x) ? x1 : x2); + ? x1.IsGreaterThanOrApproximatelyEqualTo(x) ? x1 : x2 + : x1.IsLessThanOrApproximatelyEqualTo(x) ? x1 : x2; return new Point2D(pointX, CalculateY(pointX)); } diff --git a/test/.External/VweCore/Node.cs b/test/.External/VweCore/Node.cs index 7385cbf80..d6c070f08 100644 --- a/test/.External/VweCore/Node.cs +++ b/test/.External/VweCore/Node.cs @@ -1,6 +1,6 @@ +using Light.GuardClauses; using System; using System.Collections.Generic; -using Light.GuardClauses; using VweCore.Geometry; using VweCore.Translations; @@ -43,7 +43,7 @@ public NodeLink AddLinkedNode(Node node, int nodeLinkId, bool isBidirectional = Node2 = node, Direction = isBidirectional ? NodeLinkDirection.Bidirectional : NodeLinkDirection.FromNode1ToNode2, DrivingDirectionFromNode1 = NodeLinkDrivingDirection.Straight, - DrivingDirectionFromNode2 = isBidirectional ? NodeLinkDrivingDirection.Straight : (NodeLinkDrivingDirection?)null + DrivingDirectionFromNode2 = isBidirectional ? NodeLinkDrivingDirection.Straight : null }; NodeLinks.Add(nodeLink); node.NodeLinks.Add(nodeLink); diff --git a/test/.External/VweCore/StorageRow.cs b/test/.External/VweCore/StorageRow.cs index f5e9ff8f7..144c3c054 100644 --- a/test/.External/VweCore/StorageRow.cs +++ b/test/.External/VweCore/StorageRow.cs @@ -1,6 +1,6 @@ -using System; +using Light.GuardClauses; +using System; using System.Collections.Generic; -using Light.GuardClauses; using VweCore.Abstractions; using VweCore.Geometry; using VweCore.Translations; @@ -72,7 +72,7 @@ public StorageRow Clone(int id) => public Ray2D GetPerpendicularRay() { - var referencePoint = new Point2D(Position.X + (Width / 2), Position.Y).RotateAroundReferencePoint(AngleInDegrees, Position); + var referencePoint = new Point2D(Position.X + Width / 2, Position.Y).RotateAroundReferencePoint(AngleInDegrees, Position); return new Ray2D(referencePoint, AngleInDegrees); } @@ -119,7 +119,7 @@ public StorageRow AddStorageLocationAndAdjustWidthIfNecessary(StorageLocation st minimumWidth += StorageLocations[i].Diameter + StorageLocationPadding + StorageLocationPadding; } - var offsetForNewLocation = -(minimumWidth + StorageLocationPadding + (storageLocation.Diameter / 2)); + var offsetForNewLocation = -(minimumWidth + StorageLocationPadding + storageLocation.Diameter / 2); minimumWidth += storageLocation.Diameter + StorageLocationPadding + StorageLocationPadding; return (minimumWidth, offsetForNewLocation); } diff --git a/test/ExtendedXmlSerializer.Tests.ReportedIssues.Issue502/ExtendedXmlSerializer.Tests.ReportedIssues.Issue502.csproj b/test/ExtendedXmlSerializer.Tests.ReportedIssues.Issue502/ExtendedXmlSerializer.Tests.ReportedIssues.Issue502.csproj index 28031b340..2f8f09896 100644 --- a/test/ExtendedXmlSerializer.Tests.ReportedIssues.Issue502/ExtendedXmlSerializer.Tests.ReportedIssues.Issue502.csproj +++ b/test/ExtendedXmlSerializer.Tests.ReportedIssues.Issue502/ExtendedXmlSerializer.Tests.ReportedIssues.Issue502.csproj @@ -2,6 +2,7 @@ net462 + net6.0; net7.0;$(ClassicFramework) latest $(NoWarn);CS8981 diff --git a/test/ExtendedXmlSerializer.Tests.ReportedIssues.Issue502/Issue502Tests.cs b/test/ExtendedXmlSerializer.Tests.ReportedIssues.Issue502/Issue502Tests.cs index 93e920a2b..6302a2ae7 100644 --- a/test/ExtendedXmlSerializer.Tests.ReportedIssues.Issue502/Issue502Tests.cs +++ b/test/ExtendedXmlSerializer.Tests.ReportedIssues.Issue502/Issue502Tests.cs @@ -7,7 +7,7 @@ namespace ExtendedXmlSerializer.Tests.ReportedIssues.Issue502 { - public sealed class Issue502Tests + public sealed class Issue502Tests { private readonly ITestOutputHelper _output; @@ -48,8 +48,8 @@ public void SerializeMapWithStorageLocationAndStorageRow() { var serializer = XmlSerializer.CreateDefaultSerializer(); - var storageLocation = new StorageLocation() { }; - var storageRow = new StorageRow() { StorageLocations = { storageLocation } }; + var storageLocation = new StorageLocation(); + var storageRow = new StorageRow { StorageLocations = { storageLocation } }; storageLocation.StorageRow = storageRow; var map = new Map(); map.Add(storageRow); @@ -67,10 +67,10 @@ public void SerializeStorageRow() { var serializer = XmlSerializer.CreateDefaultSerializer(); - var markerPoint = new MarkerPoint() { }; - var storageLocation = new StorageLocation() { MarkerPoints = new List(){markerPoint}}; + var markerPoint = new MarkerPoint(); + var storageLocation = new StorageLocation { MarkerPoints = new List {markerPoint}}; markerPoint.StorageLocation = storageLocation; - var storageRow = new StorageRow() {StorageLocations = {storageLocation}}; + var storageRow = new StorageRow {StorageLocations = {storageLocation}}; storageLocation.StorageRow = storageRow; var xml = serializer.SerializeIndented(storageRow); @@ -86,12 +86,12 @@ public void SerializeSmallMap() { var serializer = XmlSerializer.CreateDefaultSerializer(); - var markerPoint = new MarkerPoint() { }; - var storageLocation = new StorageLocation() { MarkerPoints = new List(){markerPoint}}; + var markerPoint = new MarkerPoint(); + var storageLocation = new StorageLocation { MarkerPoints = new List {markerPoint}}; markerPoint.StorageLocation = storageLocation; - var storageRow = new StorageRow() { StorageLocations = { storageLocation } }; + var storageRow = new StorageRow { StorageLocations = { storageLocation } }; storageLocation.StorageRow = storageRow; - var map = new Map(){Name = "test"}; + var map = new Map {Name = "test"}; map.Add(storageRow); map.Add(storageLocation); map.Add(markerPoint); @@ -110,12 +110,12 @@ public void SerializeHomeNodeNotMarkerPoint() { var serializer = XmlSerializer.CreateDefaultSerializer(); - var somePoint = new HallwayNode(){Id = 3}; + var somePoint = new HallwayNode {Id = 3}; var storageLocation = new StorageLocation(); - var markerPoint = new MarkerPoint() { StorageLocation = storageLocation}; + var markerPoint = new MarkerPoint { StorageLocation = storageLocation}; storageLocation.MarkerPoints.Add(markerPoint); - var storageRow = new StorageRow() { StorageLocations = { storageLocation } }; + var storageRow = new StorageRow { StorageLocations = { storageLocation } }; storageLocation.StorageRow = storageRow; var map = new Map(); map.Add(somePoint); diff --git a/test/ExtendedXmlSerializer.Tests.ReportedIssues/ExtendedXmlSerializer.Tests.ReportedIssues.csproj b/test/ExtendedXmlSerializer.Tests.ReportedIssues/ExtendedXmlSerializer.Tests.ReportedIssues.csproj index 6f9c8f495..3409d22e4 100644 --- a/test/ExtendedXmlSerializer.Tests.ReportedIssues/ExtendedXmlSerializer.Tests.ReportedIssues.csproj +++ b/test/ExtendedXmlSerializer.Tests.ReportedIssues/ExtendedXmlSerializer.Tests.ReportedIssues.csproj @@ -1,4 +1,5 @@ - + + net462 diff --git a/test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue199Tests.cs b/test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue199Tests.cs index c8db2109a..468a4cbc7 100644 --- a/test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue199Tests.cs +++ b/test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue199Tests.cs @@ -52,7 +52,7 @@ void AllTypes() @""); } - [System.CodeDom.Compiler.GeneratedCodeAttribute("XmlSchemaClassGenerator", "1.0.0.0"), SerializableAttribute, + [System.CodeDom.Compiler.GeneratedCodeAttribute("XmlSchemaClassGenerator", "1.0.0.0"), Serializable, System.Xml.Serialization.XmlTypeAttribute("PatientVerificationRequest", Namespace = "http://hic.gov.au/hiconline/hiconline/version-4"), System.Diagnostics.DebuggerStepThroughAttribute, System.ComponentModel.DesignerCategoryAttribute("code"), System.Xml.Serialization.XmlRootAttribute( diff --git a/test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue563Tests.cs b/test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue563Tests.cs index 5e64328eb..2e4276fe0 100644 --- a/test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue563Tests.cs +++ b/test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue563Tests.cs @@ -1,6 +1,7 @@ using ExtendedXmlSerializer.Configuration; using ExtendedXmlSerializer.Tests.ReportedIssues.Support; using FluentAssertions; +using JetBrains.Annotations; using System.Collections.Generic; using Xunit; @@ -18,9 +19,11 @@ public void Verify() sealed class Subject { + // ReSharper disable once CollectionNeverUpdated.Local public List ParentKey { get; set; } = new (); - public byte[] Id { get; set; } + public byte[] Id { get; [UsedImplicitly] set; } + [UsedImplicitly] public List Key { get diff --git a/test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue565Tests.cs b/test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue565Tests.cs index 84b97f9f8..14bff2dbe 100644 --- a/test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue565Tests.cs +++ b/test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue565Tests.cs @@ -1,6 +1,7 @@ using ExtendedXmlSerializer.Configuration; using ExtendedXmlSerializer.Tests.ReportedIssues.Support; using FluentAssertions; +using JetBrains.Annotations; using System.Linq; using System.Text; using Xunit; @@ -37,6 +38,7 @@ public void VerifyExclude() sealed class Model { + [UsedImplicitly] public Model(byte[] data, IDispenseEntity entity) : this(Encoding.UTF8.GetString(data), data, entity) {} public Model(string key, IDispenseEntity entity) : this(key, Encoding.UTF8.GetBytes(key), entity) {} diff --git a/test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue583Tests.cs b/test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue583Tests.cs index 3acef1f81..9406e18a0 100644 --- a/test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue583Tests.cs +++ b/test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue583Tests.cs @@ -23,7 +23,7 @@ public void Verify() Action action = () => new ConfigurationContainer().Create().Cycle(subject).Should().BeEquivalentTo(subject); action.Should() .Throw() - .WithMessage("The provided instance of type 'ExtendedXmlSerializer.Tests.ReportedIssues.Issue583Tests+RootObject' contains the same reference multiple times in its graph. While this is technically allowed, it is recommended to instead enable referential support by calling EnableReferences on the ConfigurationContainer. Doing so will ensure that multiple references found in the graph are emitted only once in the serialized document.\r\n\r\nHere is a list of found references:\r\n- ExtendedXmlSerializer.Tests.ReportedIssues.Issue583Tests+InnerObject"); + .WithMessage("The provided instance of type 'ExtendedXmlSerializer.Tests.ReportedIssues.Issue583Tests+RootObject' contains the same reference multiple times in its graph. While this is technically allowed, it is recommended to instead enable referential support by calling EnableReferences on the ConfigurationContainer. Doing so will ensure that multiple references found in the graph are emitted only once in the serialized document. Additionally, if you do want to allow multiple instances emitted as-is, make use of the `AllowMultipleReferences` method on the ConfigurationContainer.\r\n\r\nHere is a list of found references:\r\n- ExtendedXmlSerializer.Tests.ReportedIssues.Issue583Tests+InnerObject"); } [Fact] @@ -39,7 +39,7 @@ public void VerifyOnePropertyAndCollectionThrows() Action action = () => new ConfigurationContainer().Create().Cycle(subject).Should().BeEquivalentTo(subject); action.Should() .Throw() - .WithMessage("The provided instance of type 'ExtendedXmlSerializer.Tests.ReportedIssues.Issue583Tests+RootObjectOneProperty' contains the same reference multiple times in its graph. While this is technically allowed, it is recommended to instead enable referential support by calling EnableReferences on the ConfigurationContainer. Doing so will ensure that multiple references found in the graph are emitted only once in the serialized document.\r\n\r\nHere is a list of found references:\r\n- ExtendedXmlSerializer.Tests.ReportedIssues.Issue583Tests+InnerObject"); + .WithMessage("The provided instance of type 'ExtendedXmlSerializer.Tests.ReportedIssues.Issue583Tests+RootObjectOneProperty' contains the same reference multiple times in its graph. While this is technically allowed, it is recommended to instead enable referential support by calling EnableReferences on the ConfigurationContainer. Doing so will ensure that multiple references found in the graph are emitted only once in the serialized document. Additionally, if you do want to allow multiple instances emitted as-is, make use of the `AllowMultipleReferences` method on the ConfigurationContainer.\r\n\r\nHere is a list of found references:\r\n- ExtendedXmlSerializer.Tests.ReportedIssues.Issue583Tests+InnerObject"); } [Fact] diff --git a/test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue584Tests.cs b/test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue584Tests.cs new file mode 100644 index 000000000..07c0fbf08 --- /dev/null +++ b/test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue584Tests.cs @@ -0,0 +1,65 @@ +using ExtendedXmlSerializer.Configuration; +using ExtendedXmlSerializer.Tests.ReportedIssues.Support; +using FluentAssertions; +using System; +using Xunit; + +namespace ExtendedXmlSerializer.Tests.ReportedIssues +{ + public sealed class Issue584Tests + { + [Fact] + public void Verify() + { + var items = new[] { "Some" }; + var same = new InnerObject { Items = items }; + var instance = new RootObject + { + Item1 = same, + Item2 = new InnerObject2 { Items = items }, + }; + + var action = () => + { + var serializer = new ConfigurationContainer() + .Create() + .ForTesting(); + serializer.Cycle(instance).Should().BeEquivalentTo(instance); + }; + action.Should().Throw().Where(x => x.GetType().Name == "MultipleReferencesDetectedException"); + } + + [Fact] + public void VerifyConfiguration() + { + var items = new[] { "Some" }; + var same = new InnerObject { Items = items }; + var instance = new RootObject + { + Item1 = same, + Item2 = new InnerObject2 { Items = items }, + }; + + var serializer = new ConfigurationContainer().AllowMultipleReferences() + .Create() + .ForTesting(); + serializer.Cycle(instance).Should().BeEquivalentTo(instance); + } + + public class RootObject + { + public InnerObject Item1 { get; set; } + public InnerObject2 Item2 { get; set; } + } + + public class InnerObject + { + public string[] Items { get; set; } + } + + public class InnerObject2 + { + public string[] Items { get; set; } + } + } +} \ No newline at end of file diff --git a/test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue98Tests.cs b/test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue98Tests.cs index ec3ca0acc..06001ce98 100644 --- a/test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue98Tests.cs +++ b/test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue98Tests.cs @@ -14,17 +14,13 @@ void Verify() var instance = new Foo {Bar = new Bar()}; instance.Bar.Foos.Add(instance); - var serializer = new ConfigurationContainer().EnableReferences() - .Create(); + var serializer = new ConfigurationContainer().EnableReferences().Create().ForTesting(); var cycled = serializer.Cycle(instance); - cycled.Should() - .BeSameAs(cycled.Bar.Foos.Only()); + cycled.Should().BeSameAs(cycled.Bar.Foos.Only()); - cycled.Bar.Should() - .BeSameAs(cycled.Bar.Foos.Only() - .Bar); + cycled.Bar.Should().BeSameAs(cycled.Bar.Foos.Only().Bar); } [Fact] diff --git a/test/ExtendedXmlSerializer.Tests/ExtendedXmlSerializer.Tests.csproj b/test/ExtendedXmlSerializer.Tests/ExtendedXmlSerializer.Tests.csproj index 51af3a33a..b56937221 100644 --- a/test/ExtendedXmlSerializer.Tests/ExtendedXmlSerializer.Tests.csproj +++ b/test/ExtendedXmlSerializer.Tests/ExtendedXmlSerializer.Tests.csproj @@ -1,5 +1,5 @@  - + ExtendedXmlSerializer.Tests net462 @@ -10,7 +10,7 @@ $(NoWarn);CS8981 - + $(DefineConstants);CORE diff --git a/test/ExtendedXmlSerializer.Tests/ExtensionModel/Xml/ExtendedXmlSerializerTests.cs b/test/ExtendedXmlSerializer.Tests/ExtensionModel/Xml/ExtendedXmlSerializerTests.cs index 9cbd07a6c..24408bf55 100644 --- a/test/ExtendedXmlSerializer.Tests/ExtensionModel/Xml/ExtendedXmlSerializerTests.cs +++ b/test/ExtendedXmlSerializer.Tests/ExtensionModel/Xml/ExtendedXmlSerializerTests.cs @@ -5,7 +5,6 @@ using JetBrains.Annotations; using System; using System.Collections.Generic; -using System.Drawing; using System.Linq; using Xunit; @@ -376,7 +375,7 @@ public void ClassWithObjectProperty() [Fact] public void Point() { - var expected = new PointProperty { Point = new Point(10, 20) }; + var expected = new PointProperty { Point = new System.Drawing.Point(10, 20) }; var actual = new SerializationSupport().Assert(expected, @"1020"); @@ -447,7 +446,7 @@ class GuidProperty #if !CORE class PointProperty { - public Point Point { get; set; } + public System.Drawing.Point Point { get; set; } }