将C#CustomAttributeData类归为属性

问题描述

我在Swashbuckle.Swagger.IOperationFilter类中有以下代码。

List<CustomAttributeData> controllerAttributes = apiDescription
    .ActionDescriptor
    .ControllerDescriptor
    .ControllerType
    .CustomAttributes
    .Where(a => a.AttributeType == typeof(SwaggerFileInFormDataAttribute))
    .ToList();

我正在成功获取收藏集。我想将集合List<CustomAttributeData>转换成我的自定义属性List<SwaggerFileInFormDataAttribute>的集合。

enter image description here

我想将System.Reflection.CustomAttributeData类转换为我的自定义属性SwaggerFileInFormDataAttribute


编辑1:
这是我的SwaggerFileInFormDataAttribute属性的样子。

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method,AllowMultiple = false,Inherited = false)]
public class SwaggerFileInFormDataAttribute : Attribute
{
    private ICollection<string> displayNames;

    public SwaggerFileInFormDataAttribute()
    {
        this.DisplayNames = new List<string> { "File" };
    }

    public SwaggerFileInFormDataAttribute(params string[] displayNames)
    {
        this.DisplayNames = displayNames;
    }

    public ICollection<string> DisplayNames
    {
        get
        {
            if (this.displayNames == null)
                return new List<string> { "File" };
            else
                return this.displayNames;
        }
        set => displayNames = value;
    }
}

成功将List<CustomAttributeData>转换为List<SwaggerFileInFormDataAttribute>后,我将使用名为SwaggerFileInFormDataAttribute的类DisplayNames中显示的属性。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)