将自定义参数添加到休息回调操作
Adding custom argument to rest callback action
我 运行 在编写一个非常基本的工具时遇到了问题,该工具用于列出 WPF 视频游戏中的一些 'items'(以及它们在 ingame 拍卖行的相应价格) -Window.
我从 REST 服务获取了过去 30 天特定商品 (id) 的价格趋势,该服务为我提供了如下信息:
[{"timestamp":"1453892281000","buy":"3411","sell":"3791"},{...},...]
我一次请求大约 100 件商品的价格趋势(全部异步),在处理 responseData 时,我通过 RestSharp 得到一个包含所有响应字段的 Class。
现在的问题是我无法将 ResponseData 与项目匹配,因为 Rest-Response 没有给我一个。
有没有办法将 ID(整数)添加到 Action/Callback?
public static void getItemPriceHistory(int itemId, ListingsView view)
{
var request = new RestRequest("itemPriceTrend/" + itemId);
Action<List<RestItemPriceHistory>> ariph = view.processItemPriceHistory;
executeAsync(request, ariph);
}
public static void executeAsync<T>(RestRequest request, Action<T> callback) where T : new()
{
var client = new RestClient();
client.BaseUrl = BaseUrl;
var asyncHandle = client.ExecuteAsync<T>(request, aresp => {
callback(aresp.Data);
});
}
我希望我的问题是可以理解的,如果不是,请这样说,我会尽力提供不同的解释:)
我刚刚知道我该怎么做:
通过简单地向 Action 添加第二个参数:
Action<List<RestItemPriceHistory>, int> ariph = view.processItemPriceHistory;
因此当然也在回调中:
callback(aresp.Data, itemId);
现在看起来很简单,不知道为什么我没有早点尝试 :)
我 运行 在编写一个非常基本的工具时遇到了问题,该工具用于列出 WPF 视频游戏中的一些 'items'(以及它们在 ingame 拍卖行的相应价格) -Window.
我从 REST 服务获取了过去 30 天特定商品 (id) 的价格趋势,该服务为我提供了如下信息:
[{"timestamp":"1453892281000","buy":"3411","sell":"3791"},{...},...]
我一次请求大约 100 件商品的价格趋势(全部异步),在处理 responseData 时,我通过 RestSharp 得到一个包含所有响应字段的 Class。 现在的问题是我无法将 ResponseData 与项目匹配,因为 Rest-Response 没有给我一个。 有没有办法将 ID(整数)添加到 Action/Callback?
public static void getItemPriceHistory(int itemId, ListingsView view)
{
var request = new RestRequest("itemPriceTrend/" + itemId);
Action<List<RestItemPriceHistory>> ariph = view.processItemPriceHistory;
executeAsync(request, ariph);
}
public static void executeAsync<T>(RestRequest request, Action<T> callback) where T : new()
{
var client = new RestClient();
client.BaseUrl = BaseUrl;
var asyncHandle = client.ExecuteAsync<T>(request, aresp => {
callback(aresp.Data);
});
}
我希望我的问题是可以理解的,如果不是,请这样说,我会尽力提供不同的解释:)
我刚刚知道我该怎么做: 通过简单地向 Action 添加第二个参数:
Action<List<RestItemPriceHistory>, int> ariph = view.processItemPriceHistory;
因此当然也在回调中:
callback(aresp.Data, itemId);
现在看起来很简单,不知道为什么我没有早点尝试 :)