Это моя модель
public class MyModel
{
public string Title { get; set; }
public string Code { get; set; }
public string Description { get; set; }
public Guid InstructorId { get; set; }
}
И вот как я планирую использовать ее со связывателем модели.
public Task BindModelAsync(ModelBindingContext bindingContext)
{
if (bindingContext == null)
{
throw new ArgumentNullException(nameof(bindingContext));
}
var model = new CreateCourseRequestModel();
var properties = typeof(CreateCourseRequestModel).GetProperties();
foreach (var property in properties)
{
var value = bindingContext.ValueProvider.GetValue(property.Name); // prop value
property.SetValue(model, value.FirstValue);
}
bindingContext.Result = ModelBindingResult.Success(model);
return Task.CompletedTask;
}
Если все свойства имеют тип string
, тогдане проблема.
Если какое-либо свойство не относится к строковому типу, тогда возникнет проблема.
Вопрос
Как выполнить синтаксический анализ string
к нужному типу свойства в связывателе модели?
Спасибо