Skip to content

Commit

Permalink
Merge pull request #232 from sungam3r/expressions
Browse files Browse the repository at this point in the history
Fix generic arguments for array types
  • Loading branch information
stakx committed Jan 31, 2022
2 parents 071b807 + 2e16a01 commit 67cd50b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/PublicApiGenerator/CodeTypeReferenceBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ static CodeTypeReference CreateCodeTypeReferenceWithNullabilityMap(TypeReference
{
// ReSharper disable once RedundantEnumerableCastCall
var genericArgs = type is IGenericInstance instance ? instance.GenericArguments : type.HasGenericParameters ? type.GenericParameters.Cast<TypeReference>() : null;
if (genericArgs == null) return null;
if (genericArgs == null)
{
return type is ArrayType arr
? CreateGenericArguments(arr.ElementType, nullabilityMap)
: null;
}

var genericArguments = new List<CodeTypeReference>();
foreach (var argument in genericArgs)
Expand Down
37 changes: 37 additions & 0 deletions src/PublicApiGeneratorTests/Expressions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using PublicApiGeneratorTests.Examples;
using System;
using System.Linq.Expressions;
using Xunit;

namespace PublicApiGeneratorTests
{
public class Expressions : ApiGeneratorTestsBase
{
[Fact]
public void Should_write_expression()
{
AssertPublicApi(typeof(ClassWithExpressions<>),
@"namespace PublicApiGeneratorTests.Examples
{
public class ClassWithExpressions<TSourceType>
{
public ClassWithExpressions(params System.Linq.Expressions.Expression<System.Func<int, object>>[] expr1) { }
public ClassWithExpressions(params System.Linq.Expressions.Expression<System.Func<TSourceType, object?>>[] expr2) { }
public ClassWithExpressions(System.Linq.Expressions.Expression<System.Func<TSourceType, object>?> expr3) { }
public ClassWithExpressions(System.Linq.Expressions.Expression<System.Func<int, object>>? expr4) { }
}
}");
}
}

namespace Examples
{
public class ClassWithExpressions<TSourceType>
{
public ClassWithExpressions(params Expression<Func<int, object>>[] expr1) { }
public ClassWithExpressions(params Expression<Func<TSourceType, object?>>[] expr2) { }
public ClassWithExpressions(Expression<Func<TSourceType, object>?> expr3) { }
public ClassWithExpressions(Expression<Func<int, object>>? expr4) { }
}
}
}

0 comments on commit 67cd50b

Please sign in to comment.