Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addressed Solution Warnings #596

Merged
merged 2 commits into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace ExtendedXmlSerializer.Samples.Generics
{
public class GenericSerializer
public class GenericSerializer
{
private IExtendedXmlSerializer serializer;

Expand Down Expand Up @@ -46,7 +46,7 @@ public static void SerializeAndDeserialize()


var data = srl.SerializeProject(prj);
var obj = srl.DeserializeProject<IProject>(data);
srl.DeserializeProject<IProject>(data);
}


Expand Down Expand Up @@ -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<ISite<IContext>> Sites { get; } = new List<ISite<IContext>>();
}

public class SpecificClass : SiteBase<Context>
public sealed class SpecificClass : SiteBase<Context>
{
public SpecificClass()
{
this.Name = "Specific class";
this.UserDescription = "Class description";
this.Context = new Context();
Name = "Specific class";
UserDescription = "Class description";
Context = new Context();
}


Expand All @@ -105,6 +105,7 @@ public abstract class SiteBase<TSiteContext> : ISite<TSiteContext> where TSiteCo
{
public string Name { get; set; }
public string UserDescription { get; set; }
// ReSharper disable once MemberHidesStaticFromOuterClass
public abstract TSiteContext Context { get; set; }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace ExtendedXmlSerializer.Samples.Parametrized
{
public static class ParametrizedConstructors
public static class ParametrizedConstructors
{
public static void SerializeAndDeserialize()
{
Expand All @@ -22,7 +22,7 @@ public static void SerializeAndDeserialize()
dt.Data.Add(7);

var data = srl.Serialize(dt);
var obj = dsrl.Deserialize<DataHolder>(data);
dsrl.Deserialize<DataHolder>(data);
}

public class DataHolder
Expand Down
6 changes: 3 additions & 3 deletions samples/ExtendedXmlSerializer.Samples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Reflection;
using ExtendedXmlSerializer.Core;
using System.Reflection;

namespace ExtendedXmlSerializer.ContentModel.Conversion
{
Expand All @@ -11,7 +11,7 @@ sealed class StructureConverter<T> : IConverter<T?> 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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Reflection;
using ExtendedXmlSerializer.Core.Specifications;
using ExtendedXmlSerializer.ReflectionModel;
using System.Reflection;

namespace ExtendedXmlSerializer.ContentModel.Members
{
Expand All @@ -21,7 +21,7 @@ public InstanceMemberSerializations(ISpecification<TypeInfo> specification,

public IInstanceMemberSerialization Get(TypeInfo parameter)
=> _specification.IsSatisfiedBy(parameter)
? (IInstanceMemberSerialization)new InstanceMemberSerialization(parameter, _serializations)
? new InstanceMemberSerialization(parameter, _serializations)
: new FixedInstanceMemberSerialization(_serializations.Get(parameter));
}
}
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -26,7 +26,7 @@ public TypeParts Get(TypeParts parameter)
arguments.HasValue
? arguments.Value.Select(_selector)
.ToImmutableArray
: (Func<ImmutableArray<TypeParts>>)null);
: null);
return result;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<TypeInfo>, ISource<IEnumerable<TypeInfo>>
{
readonly static ReflectionModel.VariableTypeSpecification Specification =
ReflectionModel.VariableTypeSpecification.Default;
readonly static ISpecification<TypeInfo> Specification =
ReflectionModel.VariableTypeSpecification.Default.Or(IsArraySpecification.Default);

readonly ISpecification<TypeInfo> _specification;

Expand Down
2 changes: 1 addition & 1 deletion src/ExtendedXmlSerializer/Core/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public static TValue Get<TKey, TValue>(this IReadOnlyDictionary<TKey, TValue> ta
where TValue : struct
=> AssignedSpecification<TKey>.Default.IsSatisfiedBy(key) && target.TryGetValue(key, out var result)
? result
: (TValue?)null;
: null;

public static IEnumerable<T> Appending<T>(this IEnumerable<T> @this, params T[] items) => @this.Concat(items);

Expand Down
2 changes: 1 addition & 1 deletion src/ExtendedXmlSerializer/Core/Parsing/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static T ParseAsOptional<T>(this Parser<T> @this, string data)
public static Func<T> Build<T>(this IOption<T> @this) => @this.IsDefined ? new Func<T>(@this.Get) : null;

public static T? GetAssigned<T>(this IOption<T> @this) where T : struct
=> @this.IsDefined ? @this.Get() : (T?)null;
=> @this.IsDefined ? @this.Get() : null;

public static T Get<T>(this IParsing<T> @this, string parameter) => @this.Get(Inputs.Default.Get(parameter))
.Value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public ConditionalSource(ISpecification<TParameter> specification, ISpecificatio
/// <exclude />
public ConditionalSource(Func<TParameter, bool> specification, Func<TResult, bool> result,
Func<TParameter, TResult> source)
: this(specification, result, source, x => default) {}
: this(specification, result, source, _ => default) {}

/// <exclude />
public ConditionalSource(Func<TParameter, bool> specification, Func<TResult, bool> result,
Expand Down
4 changes: 2 additions & 2 deletions src/ExtendedXmlSerializer/Core/TypedSortOrder.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System.Reflection;
using ExtendedXmlSerializer.Core.Sources;
using System.Reflection;

namespace ExtendedXmlSerializer.Core
{
sealed class TypedSortOrder : StructureCache<TypeInfo, int>, ITypedSortOrder
{
public TypedSortOrder() : base(info => 1) {}
public TypedSortOrder() : base(_ => 1) {}
}
}
3 changes: 2 additions & 1 deletion src/ExtendedXmlSerializer/ExtendedXmlSerializer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
<Authors>Wojciech Nagórski;Michael DeMond</Authors>
<TargetFramework>netstandard2.0</TargetFramework>
<AssemblyName>ExtendedXmlSerializer</AssemblyName>
<DocumentationFile>$(BaseIntermediateOutputPath)\$(Configuration)\$(TargetFramework)\ExtendedXmlSerializer.xml</DocumentationFile>
<!-- ReSharper disable once UnknownProperty -->
<DocumentationFile>$(BaseIntermediateOutputPath)\$(Configuration)\$(TargetFramework)\ExtendedXmlSerializer.xml</DocumentationFile>
<LangVersion>preview</LangVersion>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public sealed class Contents : ISerializerExtension

/// <inheritdoc />
public IServiceRepository Get(IServiceRepository parameter)
=> parameter.RegisterConstructorDependency<IContents>((provider, info) => provider.Get<DeferredContents>())
=> parameter.RegisterConstructorDependency<IContents>((provider, _) => provider.Get<DeferredContents>())
.Register<IContents, RuntimeContents>()

.DecorateContentsWith<MemberedContents>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ImmutableArray<TypeParts>>)null,
array != null ? array.ToImmutableArray : null,
parameter.Dimensions);
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace ExtendedXmlSerializer.ExtensionModel.References;

sealed class ProcessReference : ICommand<ReferenceSet>
sealed class ProcessReference : ICommand<ProcessReferenceInput>
{
readonly ISpecification<TypeInfo> _allowed;
readonly ITypeMembers _members;
Expand All @@ -29,24 +29,37 @@ public ProcessReference(ISpecification<TypeInfo> 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);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace ExtendedXmlSerializer.ExtensionModel.References;

readonly record struct ProcessReferenceInput(ReferenceSet Results, object Current);
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,10 @@ namespace ExtendedXmlSerializer.ExtensionModel.References;
{
readonly Stack<object> _context;

public ReferenceBoundary(Stack<object> context, object subject)
{
Subject = subject;
_context = context;
}

public object Subject { get; }
public ReferenceBoundary(Stack<object> context) => _context = context;

public void Dispose()
{
_context.Push(ReferenceCompleted.Default);
_context.Pop();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ namespace ExtendedXmlSerializer.ExtensionModel.References;

record ReferenceResult(HashSet<object> Encountered, HashSet<object> Cyclical)
{
public ReferenceResult() : this(new HashSet<object>(), new HashSet<object>()) {}
protected ReferenceResult() : this(new HashSet<object>(), new HashSet<object>()) {}
}
Loading