You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
AddModelError extension method does not work for expressions that ends with indexer (e.g. m => m.Numbers[0]).
The problem is that every expression that do not directly returns object is wrapped by Convert expression and IsConversionToObject method returns true only if NodeType equals to ExpressionType.MemberAccess.
I think it should return true also for ExpressionType.Call or ExpressionType.ArrayIndex.
If I run this code in C# Interactive concole in Visual Studio:
#r "c:\Program Files\dotnet\shared\Microsoft.AspNetCore.App\8.0.7\Microsoft.AspNetCore.Mvc.ViewFeatures.dll"
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
class Model
{
public List<int> Numbers { get; set; }
}
var state = new ModelStateDictionary();
state.AddModelError<Model>(m => m.Numbers[0], "Error");
state.Keys.First()
it returns empty string:
""
Expected Behavior
It should return:
"Numbers[0]"
Steps To Reproduce
No response
Exceptions (if any)
No response
.NET Version
No response
Anything else?
No response
The text was updated successfully, but these errors were encountered:
Is there an existing issue for this?
Describe the bug
AddModelError extension method does not work for expressions that ends with indexer (e.g.
m => m.Numbers[0]
).The problem is that every expression that do not directly returns
object
is wrapped byConvert
expression and IsConversionToObject method returnstrue
only ifNodeType
equals toExpressionType.MemberAccess
.I think it should return
true
also forExpressionType.Call
orExpressionType.ArrayIndex
.If I run this code in C# Interactive concole in Visual Studio:
it returns empty string:
Expected Behavior
It should return:
Steps To Reproduce
No response
Exceptions (if any)
No response
.NET Version
No response
Anything else?
No response
The text was updated successfully, but these errors were encountered: