Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net core 大摇大摆地树立榜样_Asp.net Core_Swagger_Swashbuckle - Fatal编程技术网

Asp.net core 大摇大摆地树立榜样

Asp.net core 大摇大摆地树立榜样,asp.net-core,swagger,swashbuckle,Asp.net Core,Swagger,Swashbuckle,我正在使用swashback.AspNetCore.Swagger(1.0.0)和swashback.AspNetCore.SwaggerGen(1.0.0)。我试图在下面的API中添加默认示例。我创建了一个新的类文件并添加 public class SwaggerDefaultValue : Attribute { public string ParameterName { get; set; } public string Value { get; set; } p

我正在使用swashback.AspNetCore.Swagger(1.0.0)和swashback.AspNetCore.SwaggerGen(1.0.0)。我试图在下面的API中添加默认示例。我创建了一个新的类文件并添加

public class SwaggerDefaultValue : Attribute
{
    public string ParameterName { get; set; }
    public string Value { get; set; }

    public SwaggerDefaultValue(string parameterName, string value)
    {
        this.ParameterName = parameterName;
        this.Value = value;
    }
}

public class AddDefaultValues : IOperationFilter
{
    public void Apply(Operation operation, DataTypeRegistry dataTypeRegistry, ApiDescription apiDescription)
    {
        foreach (var param in operation.Parameters)
        {
            var actionParam = apiDescription.ActionDescriptor.GetParameters().First(p => p.ParameterName == param.Name);

            if (actionParam != null)
            {
                var customAttribute = actionParam.ActionDescriptor.GetCustomAttributes<SwaggerDefaultValue>().FirstOrDefault();
                if (customAttribute != null)
                {
                    param.DefaultValue = customAttribute.Value;
                }
            }
        }
    }
}
public类SwaggerDefaultValue:Attribute
{
公共字符串参数名称{get;set;}
公共字符串值{get;set;}
public-SwaggerDefaultValue(字符串参数名称、字符串值)
{
this.ParameterName=ParameterName;
这个。值=值;
}
}
公共类AddDefaultValues:IOperationFilter
{
public void Apply(操作操作,DataTypeRegistry DataTypeRegistry,ApiDescription ApiDescription)
{
foreach(操作中的var param.Parameters)
{
var actionParam=apiscription.ActionDescriptor.GetParameters().First(p=>p.ParameterName==param.Name);
if(actionParam!=null)
{
var customAttribute=actionParam.ActionDescriptor.GetCustomAttributes().FirstOrDefault();
if(customAttribute!=null)
{
param.DefaultValue=customAttribute.Value;
}
}
}
}
}

但是我得到了这个错误-
AddDefaultValues没有实现接口成员IOperationFilter.Apply(操作,操作FilterContext)

您下面的链接不适用于该版本

在正确的项目中查找适当的示例: