【发布时间】:2019-08-03 03:50:44
【问题描述】:
Azure APIM 策略表达式可以访问具有Variables 属性的context object,该属性应该是IReadOnlyDictionary<string, object> 类型。我应该能够通过set-variable policy 向该字典添加值。我希望能够将任何对象添加到字典中,但是当我尝试添加字符串以外的任何对象时遇到了错误。
例如,当我尝试将其保存到入站策略定义中时:
<set-variable name="regexGroups" value="@(Regex.Match("inputString","regex").Groups)" />
我收到一条错误消息:
X 行 Y 列的元素“set-variable”出错:不允许表达式返回类型“System.Text.RegularExpressions.GroupCollection, System”。
GroupCollection 继承自 object,因此它应该是 Variables 字典中的有效值。为什么这不起作用?
如果我尝试将其显式转换为对象:
<set-variable name="regexGroups" value="@((object)Regex.Match("inputString","regex").Groups)" />
我收到一条错误消息:
X 行 Y 列的元素“set-variable”出错:不允许表达式返回类型“System.Object”
我的语法错了吗?
【问题讨论】:
标签: azure azure-api-management