ant-design-blazor/components/table/Internal/ColumnExpressionHelper.cs
Zonciu Liang 3bf616b735 fix(module: table): fix DataIndex Column with incorrect sorting and filter (#1295)
* refactor(module: table): Unify the behavior of Field and DataIndex

* fix(module: table): Fix DataIndex Column doesn't refresh

* doc(module: table): add DataIndex column filter demo

* doc(module: table): fix Blazor table

Co-authored-by: James Yeung <shunjiey@hotmail.com>
2021-04-02 15:54:56 +00:00

38 lines
1.3 KiB
C#

// 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;
using System.Linq.Expressions;
using System.Reflection;
namespace AntDesign.Internal
{
internal static class ColumnExpressionHelper
{
internal static MemberInfo GetReturnMemberInfo(LambdaExpression expression)
{
var accessorBody = expression.Body;
if (accessorBody is UnaryExpression unaryExpression
&& unaryExpression.NodeType == ExpressionType.Convert
&& unaryExpression.Type == typeof(object))
{
accessorBody = unaryExpression.Operand;
}
if (accessorBody is ConditionalExpression conditionalExpression)
{
accessorBody = conditionalExpression.IfTrue;
}
if (!(accessorBody is MemberExpression memberExpression))
{
throw new ArgumentException($"The type of the provided expression {accessorBody.GetType().Name} is not supported, it should be {nameof(MemberExpression)}.");
}
return memberExpression.Member;
}
}
}