mirror of
https://gitee.com/ant-design-blazor/ant-design-blazor.git
synced 2024-12-05 05:27:37 +08:00
fix(module: table): exception is thrown when the DataIndex ends with the get_Item method. (#1485)
This commit is contained in:
parent
a7fabae919
commit
d98b402b10
@ -13,18 +13,31 @@ namespace AntDesign.Internal
|
||||
internal static MemberInfo GetReturnMemberInfo(LambdaExpression expression)
|
||||
{
|
||||
var accessorBody = expression.Body;
|
||||
|
||||
if (accessorBody is ConditionalExpression conditionalExpression)
|
||||
while (true)
|
||||
{
|
||||
accessorBody = conditionalExpression.IfTrue;
|
||||
if (accessorBody is UnaryExpression unaryExpression)
|
||||
{
|
||||
accessorBody = unaryExpression.Operand;
|
||||
}
|
||||
else if (accessorBody is ConditionalExpression conditionalExpression)
|
||||
{
|
||||
accessorBody = conditionalExpression.IfTrue;
|
||||
}
|
||||
else if (accessorBody is MethodCallExpression methodCallExpression)
|
||||
{
|
||||
accessorBody = methodCallExpression.Object;
|
||||
}
|
||||
else if (accessorBody is BinaryExpression binaryExpression)
|
||||
{
|
||||
accessorBody = binaryExpression.Left;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (accessorBody is UnaryExpression unaryExpression && unaryExpression.NodeType == ExpressionType.Convert)
|
||||
{
|
||||
accessorBody = unaryExpression.Operand;
|
||||
}
|
||||
|
||||
if (!(accessorBody is MemberExpression memberExpression))
|
||||
if (accessorBody is not MemberExpression memberExpression)
|
||||
{
|
||||
throw new ArgumentException($"The type of the provided expression {accessorBody.GetType().Name} is not supported, it should be {nameof(MemberExpression)}.");
|
||||
}
|
||||
|
46
tests/AntDesign.Tests/table/ColumnExpressionHelperTest.cs
Normal file
46
tests/AntDesign.Tests/table/ColumnExpressionHelperTest.cs
Normal file
@ -0,0 +1,46 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using AntDesign.core.Helpers;
|
||||
using AntDesign.Internal;
|
||||
using Xunit;
|
||||
|
||||
namespace AntDesign.Tests.Table
|
||||
{
|
||||
public class ColumnExpressionHelperTest
|
||||
{
|
||||
[Fact]
|
||||
public void EndsWithGetItem()
|
||||
{
|
||||
var t1 = new T1()
|
||||
{
|
||||
T2 = new()
|
||||
{
|
||||
Arr = new()
|
||||
{
|
||||
5,
|
||||
6,
|
||||
7
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var exp = typeof(T1).BuildAccessPropertyLambdaExpression("T2.Arr[2]");
|
||||
|
||||
var memberInfo = ColumnExpressionHelper.GetReturnMemberInfo(exp);
|
||||
Assert.Equal(nameof(T2.Arr), memberInfo.Name);
|
||||
}
|
||||
|
||||
public class T1
|
||||
{
|
||||
public T2 T2 { get; set; }
|
||||
}
|
||||
|
||||
public class T2
|
||||
{
|
||||
public List<int> Arr { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user