1

假设带有原始 URL 的传入 GET 请求:

/people?includes=family,friends,enemies

从服务端,是否向我的 Request 对象添加一个名为“Includes”的 string[] 属性,并解析数组中的每个项目,然后以正确的方式执行我的业务逻辑?

或者也许,不是去一个字符串 [] 路由,有什么方法可以强输入这个(可能在一个标志枚举中?)所以我的客户和服务可以使它看起来更好?

4

1 回答 1

2

查看ServiceStack.Text.EnumMemberSerializer

public enum ReturnPolicy
{
    NotSet = 0,
    [EnumMember(Value = @"90 Days w/Receipt")]
    _90DayswReceipt = 1,
    [EnumMember(Value = @"15% Restocking Fee")]
    _15RestockingFee = 2,
    [EnumMember(Value = @"Exchange Only")]
    ExchangeOnly = 3,
    [EnumMember(Value = @"As-Is")]
    AsIs = 4,
    ...
}

public class ProductInfo
{
    public string ProductName { get; set; }
    public ReturnPolicy ReturnPolicy { get; set; }
    ...
}

http://myhost/products?returnpolicy=90%20Days%20w%2FReceipt
http://myhost/products?returnpolicy=90%20DaYS%20w%2FReceIPt
http://myhost/products?returnpolicy=_90DayswReceipt
http://myhost/products?returnpolicy=1
于 2013-09-09T16:52:24.667 回答