Repository: dotnet/aspnetcore
File: src/Components/Forms/src/FieldIdentifier.cs (C#)

Code before:
            accessorBody = unaryExpression.Operand;
        }

        switch (accessorBody)
        {
            case MemberExpression memberExpression:
                // Identify the field name. We don't mind whether it's a property or field, or even something else.
                fieldName = memberExpression.Member.Name;
                // Get a reference to the model object
                // i.e., given a value like "(something).MemberName", determine the runtime value of "(something)",
                switch (memberExpression.Expression)
                {
                    case ConstantExpression constant when constant.Value == null:
                        throw new ArgumentException("The provided expression must evaluate to a non-null value.");
                    case ConstantExpression constant when constant.Value != null:
                        model = constant.Value;
                        break;
                    case MemberExpression member when member.Expression is ConstantExpression:
                        model = GetModelFromMemberAccess(member);
                        break;
                    case not null:
                        // It would be great to cache this somehow, but it's unclear there's a reasonable way to do
                        // so, given that it embeds captured values such as "this". We could consider special-casing
                        // for "() => something.Member" and building a cache keyed by "something.GetType()" with values
                        // of type Func<object, object> so we can cheaply map from "something" to "something.Member".
                        var modelLambda = Expression.Lambda(memberExpression.Expression);
                        var modelLambdaCompiled = (Func<object?>)modelLambda.Compile();
                        var result = modelLambdaCompiled() ??
                            throw new ArgumentException("The provided expression must evaluate to a non-null value.");

                        model = result;
                        break;
                    default:
                        throw new ArgumentException($"The provided expression contains a {accessorBody.GetType().Name} which is not supported. {nameof(FieldIdentifier)} only supports simple member accessors (fields, properties) of an object.");
                }
                break;
            case MethodCallExpression methodCallExpression when ExpressionFormatter.IsSingleArgumentIndexer(accessorBody):
                fieldName = ExpressionFormatter.FormatIndexArgument(methodCallExpression.Arguments[0]);
                model = GetModelFromIndexer(methodCallExpression.Object!);
                break;
            case BinaryExpression binaryExpression when binaryExpression.NodeType == ExpressionType.ArrayIndex:
                fieldName = ExpressionFormatter.FormatIndexArgument(binaryExpression.Right);
                model = GetModelFromIndexer(binaryExpression.Left);
                break;
            default:
                throw new ArgumentException($"The provided expression contains a {accessorBody.GetType().Name} which is not supported. {nameof(FieldIdentifier)} only supports simple member accessors (fields, properties) of an object.");
        }
    }

    internal static object GetModelFromMemberAccess(
        MemberExpression member,

Review comment (suggestion):
```suggestion
                        var modelLambda = Expression.Lambda(typeof(Func<object?>), memberExpression.Expression);
```

Code after:
            accessorBody = unaryExpression.Operand;
        }

        switch (accessorBody)
        {
            case MemberExpression memberExpression:
                // Identify the field name. We don't mind whether it's a property or field, or even something else.
                fieldName = memberExpression.Member.Name;
                // Get a reference to the model object
                // i.e., given a value like "(something).MemberName", determine the runtime value of "(something)",
                switch (memberExpression.Expression)
                {
                    case ConstantExpression constant when constant.Value == null:
                        throw new ArgumentException("The provided expression must evaluate to a non-null value.");
                    case ConstantExpression constant when constant.Value != null:
                        model = constant.Value;
                        break;
                    case MemberExpression member when member.Expression is ConstantExpression:
                        model = GetModelFromMemberAccess(member);
                        break;
                    case not null:
                        // It would be great to cache this somehow, but it's unclear there's a reasonable way to do
                        // so, given that it embeds captured values such as "this". We could consider special-casing
                        // for "() => something.Member" and building a cache keyed by "something.GetType()" with values
                        // of type Func<object, object> so we can cheaply map from "something" to "something.Member".
                        var modelLambda = Expression.Lambda(typeof(Func<object?>), memberExpression.Expression);
                        var modelLambdaCompiled = (Func<object?>)modelLambda.Compile();
                        var result = modelLambdaCompiled() ??
                            throw new ArgumentException("The provided expression must evaluate to a non-null value.");

                        model = result;
                        break;
                    default:
                        throw new ArgumentException($"The provided expression contains a {accessorBody.GetType().Name} which is not supported. {nameof(FieldIdentifier)} only supports simple member accessors (fields, properties) of an object.");
                }
                break;
            case MethodCallExpression methodCallExpression when ExpressionFormatter.IsSingleArgumentIndexer(accessorBody):
                fieldName = ExpressionFormatter.FormatIndexArgument(methodCallExpression.Arguments[0]);
                model = GetModelFromIndexer(methodCallExpression.Object!);
                break;
            case BinaryExpression binaryExpression when binaryExpression.NodeType == ExpressionType.ArrayIndex:
                fieldName = ExpressionFormatter.FormatIndexArgument(binaryExpression.Right);
                model = GetModelFromIndexer(binaryExpression.Left);
                break;
            default:
                throw new ArgumentException($"The provided expression contains a {accessorBody.GetType().Name} which is not supported. {nameof(FieldIdentifier)} only supports simple member accessors (fields, properties) of an object.");
        }
    }

    internal static object GetModelFromMemberAccess(
        MemberExpression member,