Skip to content

Commit

Permalink
Added check for "unspeakable" types.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike-E-angelo committed Nov 3, 2020
1 parent d9c07ef commit afd61d4
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 6 deletions.
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
}
}
}
}

0 comments on commit afd61d4

Please sign in to comment.