@@ -10,31 +10,43 @@ namespace WebApiClientCore
1010 public class ApiParameterContext : ApiRequestContext
1111 {
1212 /// <summary>
13- /// 参数索引
13+ /// 获取参数描述
1414 /// </summary>
15- private readonly int index ;
15+ public ApiParameterDescriptor Parameter { get ; }
1616
1717 /// <summary>
18- /// 获取参数描述
18+ /// 获取参数名
1919 /// </summary>
20- public ApiParameterDescriptor Parameter => this . ApiAction . Parameters [ index ] ;
20+ public string ParameterName => this . Parameter . Name ;
2121
2222 /// <summary>
2323 /// 获取参数值
2424 /// </summary>
25- public object ? ParameterValue => this . Arguments [ index ] ;
25+ public object ? ParameterValue => this . Arguments [ this . Parameter . Index ] ;
26+
2627
2728 /// <summary>
2829 /// Api参数上下文
2930 /// </summary>
3031 /// <param name="context">上下文</param>
3132 /// <param name="parameterIndex">参数索引</param>
3233 public ApiParameterContext ( ApiRequestContext context , int parameterIndex )
34+ : this ( context , context . ApiAction . Parameters [ parameterIndex ] )
35+ {
36+ }
37+
38+ /// <summary>
39+ /// Api参数上下文
40+ /// </summary>
41+ /// <param name="context">上下文</param>
42+ /// <param name="parameter">参数描述</param>
43+ public ApiParameterContext ( ApiRequestContext context , ApiParameterDescriptor parameter )
3344 : base ( context . HttpContext , context . ApiAction , context . Arguments , context . Properties )
3445 {
35- this . index = parameterIndex ;
46+ this . Parameter = parameter ;
3647 }
3748
49+
3850 /// <summary>
3951 /// 序列化参数值为utf8编码的Json
4052 /// </summary>
@@ -108,7 +120,7 @@ public IList<KeyValue> SerializeToKeyValues()
108120 return this . HttpContext
109121 . ServiceProvider
110122 . GetKeyValueSerializer ( )
111- . Serialize ( this . Parameter . Name , this . ParameterValue , options ) ;
123+ . Serialize ( this . ParameterName , this . ParameterValue , options ) ;
112124 }
113125 }
114126}
0 commit comments