I have the following code located in a Swashbuckle.Swagger.IOperationFilter
class.
List<CustomAttributeData> controllerAttributes = apiDescription
.ActionDescriptor
.ControllerDescriptor
.ControllerType
.CustomAttributes
.Where(a => a.AttributeType == typeof(SwaggerFileInFormDataAttribute))
.ToList();
I am obtaining the collection successfully. I want to convert the collection List<CustomAttributeData>
into a collection of my custom attribute List<SwaggerFileInFormDataAttribute>
.
I want to convert the System.Reflection.CustomAttributeData
class to my custom attribute SwaggerFileInFormDataAttribute
.
Edit 1:
Here is how my SwaggerFileInFormDataAttribute
attribute looks like.
[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;
}
}
After successfully converting the List<CustomAttributeData>
to List<SwaggerFileInFormDataAttribute>
I'll be using the property shown in the class SwaggerFileInFormDataAttribute
named DisplayNames
.