RicoSuter/NSwag

After upgrade core 2.2=>3.1, class with inheritance is shown as object

Open

#3,141 建立於 2020年11月3日

在 GitHub 查看
 (10 留言) (0 反應) (0 負責人)C# (6,291 star) (1,189 fork)batch import
help wantedproject: NSwag.AspNetCore

描述

In 2.2, the controllers accepting a paramater of DataSourceLoadOptions correctly showed the structure of the inherited DataSourceLoadOptionsBase. This is no longer the case in 3.1 - it is now just shown as an object. Any ideas how I can fix this?

[ModelBinder(BinderType = typeof(DataSourceLoadOptionsBinder))]
public class DataSourceLoadOptions : DataSourceLoadOptionsBase
{
    public IList CustomQueryParams { get; set; }

}

public class DataSourceLoadOptionsBinder : IModelBinder
{
    public Task BindModelAsync(ModelBindingContext bindingContext)
    {
        var loadOptions = new DataSourceLoadOptions();
        DataSourceLoadOptionsParser.Parse(loadOptions, key => bindingContext.ValueProvider.GetValue(key).FirstOrDefault());
        var _customQueryParams = bindingContext.ValueProvider.GetValue("customQueryParams").FirstOrDefault();
        if (_customQueryParams != null)
        {
            loadOptions.CustomQueryParams = JsonConvert.DeserializeObject<IList>(_customQueryParams, new JsonSerializerSettings
            {
                DateParseHandling = DateParseHandling.None
            });
        }
        bindingContext.Result = ModelBindingResult.Success(loadOptions);
        return Task.CompletedTask;
    }
}

貢獻者指南