Task IModelBinder.BindModelAsync(ModelBindingContext bindingContext) { if (bindingContext == null) { throw new ArgumentNullException(nameof(bindingContext)); } var modelName = bindingContext.ModelName; // Try to fetch the value of the argument by name var valueProviderResult = bindingContext.ValueProvider.GetValue(modelName); if (valueProviderResult == ValueProviderResult.None) { return(Task.CompletedTask); } bindingContext.ModelState.SetModelValue(modelName, valueProviderResult); var model = MatrixIndicator.Parse(valueProviderResult.FirstValue); bindingContext.Model = model; bindingContext.Result = ModelBindingResult.Success(model); return(Task.CompletedTask); }
public void ConvertFromStringTest(string input) { var array = new[] { new [] { 0, 0, 0, 0, 0, 0, 0 }, // Y = 0 new [] { 0, 0, 1, 0, 1, 1, 1 }, // Y = 1 new [] { 0, 0, 0, 0, 0, 0, 0 }, // Y = 2 new [] { 0, 0, 1, 0, 0, 0, 0 }, // Y = 3 new [] { 0, 0, 1, 0, 0, 0, 0 }, // Y = 4 new [] { 0, 1, 0, 0, 0, 0, 0 }, // Y = 5 new [] { 0, 0, 1, 0, 0, 0, 0 }, // Y = 6 }; var selectFromArray = from j in Enumerable.Range(0, array.Length) from i in Enumerable.Range(0, array[j].Length) where array[j][i] > 0 select(I: i, J: j); var expected = MatrixIndicator.Create(selectFromArray.ToArray(), t => t.I, t => t.J).AsEnumerable(ValueTuple.Create).ToHashSet(); var actual = MatrixIndicator.Parse(input).AsEnumerable(ValueTuple.Create).ToHashSet(); Assert.Equal(expected, actual); }