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

Added check for "unspeakable" types. #471

Merged
merged 1 commit into from
Nov 3, 2020
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 @@ -23,7 +23,8 @@ public AssemblyTypePartitions(IPartitionedTypeSpecification specification, IType
: this(specification, formatter.Get) {}

public AssemblyTypePartitions(ISpecification<TypeInfo> specification, Func<TypeInfo, string> formatter)
: this(specification.IsSatisfiedBy, formatter, ApplicationTypes, x => x.Namespace) {}
: this(specification.And(ApplicationTypeSpecification.Default).IsSatisfiedBy, formatter, ApplicationTypes,
x => x.Namespace) {}

// ReSharper disable once TooManyDependencies
public AssemblyTypePartitions(Func<TypeInfo, bool> specification, Func<TypeInfo, string> formatter,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System.Collections.Immutable;
using System.Reflection;
using ExtendedXmlSerializer.ContentModel.Identification;
using ExtendedXmlSerializer.Core.Sources;
using ExtendedXmlSerializer.Core.Specifications;
using ExtendedXmlSerializer.ReflectionModel;
using JetBrains.Annotations;
using System.Collections.Immutable;
using System.Reflection;

namespace ExtendedXmlSerializer.ContentModel.Reflection
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
using ExtendedXmlSerializer.Core.Specifications;
using System.Reflection;
using System.Runtime.CompilerServices;
using ExtendedXmlSerializer.Core.Specifications;

namespace ExtendedXmlSerializer.ReflectionModel
{
class ApplicationTypeSpecification : InverseSpecification<TypeInfo>
sealed class ApplicationTypeSpecification : InverseSpecification<TypeInfo>
{
public static ApplicationTypeSpecification Default { get; } = new ApplicationTypeSpecification();

ApplicationTypeSpecification() : base(IsDefinedSpecification<CompilerGeneratedAttribute>.Default) {}
ApplicationTypeSpecification()
: base(IsDefinedSpecification<CompilerGeneratedAttribute>.Default.Or(IsUnspeakable.Default)) {}
}
}
15 changes: 15 additions & 0 deletions src/ExtendedXmlSerializer/ReflectionModel/IsUnspeakable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using ExtendedXmlSerializer.Core.Specifications;
using System.Reflection;

namespace ExtendedXmlSerializer.ReflectionModel
{
/// <summary>
/// Reference: https://stackoverflow.com/a/9256695/10340424
/// </summary>
sealed class IsUnspeakable : DelegatedSpecification<TypeInfo>
{
public static IsUnspeakable Default { get; } = new IsUnspeakable();

IsUnspeakable() : base(x => x.Name.StartsWith("<")) {}
}
}
34 changes: 34 additions & 0 deletions test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue470Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using ExtendedXmlSerializer.Configuration;
using ExtendedXmlSerializer.Tests.ReportedIssues.Support;
using FluentAssertions;
using JetBrains.Annotations;
using System;
using System.Threading.Tasks;
using Xunit;

namespace ExtendedXmlSerializer.Tests.ReportedIssues
{
public sealed class Issue470Tests
{
[Fact]
public void Verify()
{
var instance = new Foo();
new ConfigurationContainer().Create().ForTesting().Cycle(instance).Should().BeEquivalentTo(instance);
}

public class Foo
{
public string Bar { get; set; }
}

public class Something
{
[UsedImplicitly]
Func<object, Task> Check<T>(Func<T, Task> data)
{
return async o => await data((T)o); // this causes it to bomb out
}
}
}
}