设置变量策略:不允许表达式返回类型

问题描述 投票:0回答:1

Azure APIM策略表达式可以访问具有context object属性的Variables,该属性应该是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
1个回答
0
投票

只有一些类型被允许作为APIM表达式中的变量值,对象不是其中之一,这里是目前允许作为变量值的完整列表:

  • System.Boolean
  • 系统销售
  • System.Byte
  • System.UInt16形式
  • System.UInt32
  • System.UInt64形式
  • System.Int16
  • System.Int32
  • System.Int64
  • System.Decimal
  • System.Single
  • System.Double
  • 的System.Guid
  • System.String
  • System.Char
  • System.DateTime的
  • System.TimeSpan
  • System.Byte []
  • IResponse
  • 智威汤逊
  • Newtonsoft.Json.Linq.JToken
© www.soinside.com 2019 - 2024. All rights reserved.