Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #142 #143

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private static async Task ValidateField(EditContext editContext,
{
var properties = new[] { fieldIdentifier.FieldName };
var context = new ValidationContext<object>(fieldIdentifier.Model, new PropertyChain(), new MemberNameValidatorSelector(properties));

validator ??= GetValidatorForModel(serviceProvider, fieldIdentifier.Model, disableAssemblyScanning);

if (validator is not null)
Expand Down Expand Up @@ -148,7 +148,7 @@ private static FieldIdentifier ToFieldIdentifier(in EditContext editContext, in

var obj = editContext.Model;
var nextTokenEnd = propertyPath.IndexOfAny(Separators);

// Optimize for a scenario when parsing isn't needed.
if (nextTokenEnd < 0)
{
Expand All @@ -168,15 +168,15 @@ private static FieldIdentifier ToFieldIdentifier(in EditContext editContext, in
// It's an indexer
// This code assumes C# conventions (one indexer named Item with one param)
nextToken = nextToken.Slice(0, nextToken.Length - 1);
var prop = obj.GetType().GetProperty("Item");
var prop = obj.GetType().GetProperties().SingleOrDefault(p => p.Name == "Item" && p.CanWrite);

if (prop is not null)
{
// we've got an Item property
var indexerType = prop.GetIndexParameters()[0].ParameterType;
var indexerValue = Convert.ChangeType(nextToken.ToString(), indexerType);
newObj = prop.GetValue(obj, new [] { indexerValue });

newObj = prop.GetValue(obj, new[] { indexerValue });
}
else
{
Expand Down Expand Up @@ -211,7 +211,7 @@ private static FieldIdentifier ToFieldIdentifier(in EditContext editContext, in
}

obj = newObj;

nextTokenEnd = propertyPathAsSpan.IndexOfAny(Separators);
if (nextTokenEnd < 0)
{
Expand Down