我已经实施了一个Swashbuckle.Swagger.IOperationFilter
按照此处所述处理自定义属性:https://stackoverflow.com/a/52948376/13087 https://stackoverflow.com/a/52948376/13087
我现在想做类似的事情Swashbuckle.AspNetCore 5.0.0
.
看来ApiDescription
类没有扩展方法GetControllerAndActionAttributes
这是在最初的实现中使用的。我尝试通过查看它来重新实现它源代码 https://github.com/domaindrivendev/Swashbuckle/blob/master/Swashbuckle.Core/Swagger/ApiDescriptionExtensions.cs,但它使用成员ApiDescription.ActionDescriptor.ControllerDescriptor
and ApiDescription.ActionDescriptor.GetCustomAttributes<TAttribute>
我似乎不存在于 .NET Core 中。
任何人都可以帮助我开始,向我展示如何从一个对象中获取自定义控制器和操作属性吗?IOperationFilter
?
Update看起来 .NET Framework 实现有一个ActionDescriptor
这实际上是一个反射动作描述符 https://learn.microsoft.com/en-us/previous-versions/aspnet/hh834789(v%3Dvs.118)。这个类有一个构造函数,它需要一个MethodInfo
,用于查找属性。
但我看不出有什么办法可以得到MethodInfo
用于 .NET Core 实现Microsoft.AspNetCore.Mvc.Abstractions.ActionDescriptor https://github.com/dotnet/aspnetcore/blob/master/src/Mvc/Mvc.Abstractions/src/Abstractions/ActionDescriptor.cs.
我找到了答案:有一个扩展方法ApiDescription.TryGetMethodInfo
这将得到MethodInfo
从而允许访问自定义属性。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)