可以从属性中读取FromUri参数吗?

时间:2016-04-27 08:40:28

标签: c#-4.0 asp.net-web-api custom-attributes

我有一个简单的控制器,可以接受来自支付系统的响应。

        public async Task<IHttpActionResult> Pending([FromUri] DepositResponse response)
        {
            Logger.LogInfo(JsonConvert.SerializeObject(response));

            return Ok(response);
        }
然而,存款响应具有非常丑陋和不标准的参数。我无法控制,因为那是支付系统发送的内容。

public class DepositResponse
{
    public string ppp_status { get; set; }

    public string ExErrorCode { get; set; }

    public string PPP_TransactionID { get; set; }

    public string merchant_site_id { get; set; }

    //etc
}

因此,Resharper抱怨所选名称与规则不匹配,我想更改它以匹配项目其余部分中的所有类。

是否有我可以使用的属性,或者我可以创建的属性让FromUri了解响应?

例如

public class DepositResponse
{
    [FromUriName("ppp_status")]
    public string pppStatus { get; set; }

    [FromUriName("ExErrorCode")]
    public string exErrorCode { get; set; }

    [FromUriName("PPP_TransactionID")]
    public string pppTransactionId { get; set; }

    [FromUriName("merchant_site_id")]
    public string merchantSiteId { get; set; }

    //etc
}

我无法在网上找到这样的例子,但我认为在处理发送垃圾的外部系统时它非常有用......

任何想法?

1 个答案:

答案 0 :(得分:0)

您可以使用以下型号

public class DepositResponse
    {

    [JsonProperty(PropertyName="ppp_status")]
    public string pppStatus { get; set; }

    [JsonProperty(PropertyName="ExErrorCode")]
    public string exErrorCode { get; set; }

    [JsonProperty(PropertyName="PPP_TransactionID")]
    public string pppTransactionId { get; set; }

    [PropertyName(PropertyName="merchant_site_id")]
    public string merchantSiteId { get; set; }

    //etc
    }
相关问题