Skip to content

Commit

Permalink
Fix parsing of generic arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
jjonescz committed Aug 22, 2023
1 parent 0ed8965 commit bb23e26
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.
#line default
#line hidden
#nullable disable
, -1, global::Microsoft.AspNetCore.Components.EventCallback.Factory.Create<global::TItem[]>(this,
, -1, global::Microsoft.AspNetCore.Components.EventCallback.Factory.Create(this,
global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.CreateInferredEventCallback(this, __value => Selected = __value, Selected)), -1, () => Selected);
#pragma warning disable BL0005
__typeInference_CreateMyComponent_0.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ Generated Location: (1072:25,26 [8] )

Source Location: (19:0,19 [5] x:\dir\subdir\Test\TestComponent.cshtml)
|Value|
Generated Location: (1610:36,19 [5] )
Generated Location: (1593:36,19 [5] )
|Value|

Source Location: (49:2,7 [64] x:\dir\subdir\Test\TestComponent.cshtml)
|
string[] Selected { get; set; } = Array.Empty<string>();
|
Generated Location: (2025:54,7 [64] )
Generated Location: (2008:54,7 [64] )
|
string[] Selected { get; set; } = Array.Empty<string>();
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.
#line default
#line hidden
#nullable disable
, 2, global::Microsoft.AspNetCore.Components.EventCallback.Factory.Create<global::TItem[]>(this, global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.CreateInferredEventCallback(this, __value => Selected = __value, Selected)), 3, () => Selected);
, 2, global::Microsoft.AspNetCore.Components.EventCallback.Factory.Create(this, global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.CreateInferredEventCallback(this, __value => Selected = __value, Selected)), 3, () => Selected);
}
#pragma warning restore 1998
#nullable restore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
|
string[] Selected { get; set; } = Array.Empty<string>();
|
Generated Location: (1232:28,7 [64] )
Generated Location: (1215:28,7 [64] )
|
string[] Selected { get; set; } = Array.Empty<string>();
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,45 @@ public override IReadOnlyList<string> ParseTypeParameters(string typeName)
}

var parsed = SyntaxFactory.ParseTypeName(typeName);

if (parsed is IdentifierNameSyntax identifier)
{
return Array.Empty<string>();
}
else if (parsed is ArrayTypeSyntax array)

if (TryParseCore(parsed) is { } list)
{
return new[] { array.ElementType.ToString() };
return list;
}
else if (parsed is TupleTypeSyntax tuple)

return parsed.DescendantNodesAndSelf()
.OfType<TypeArgumentListSyntax>()
.SelectMany(arg => arg.Arguments)
.SelectMany(ParseCore).ToArray();

static IReadOnlyList<string> TryParseCore(TypeSyntax parsed)
{
return tuple.Elements.Select(a => a.ToString()).ToList();
if (parsed is ArrayTypeSyntax array)
{
return new[] { array.ElementType.ToString() };
}

if (parsed is TupleTypeSyntax tuple)
{
return tuple.Elements.Select(a => a.ToString()).ToList();
}

return null;
}
else

static IReadOnlyList<string> ParseCore(TypeSyntax parsed)
{
return parsed.DescendantNodesAndSelf()
.OfType<TypeArgumentListSyntax>()
.SelectMany(arg => arg.Arguments)
.Select(a => a.ToString()).ToList();
if (TryParseCore(parsed) is { } list)
{
return list;
}

return new[] { parsed.ToString() };
}
}

Expand Down

0 comments on commit bb23e26

Please sign in to comment.