Xamarin.Forms 服务 return 列表<T> 加上状态码

Xamarin.Forms Service return List<T> plus Status Code

这是来自服务的代码,我 generated.Everything 工作正常。我得到了照片列表,但我想得到 status_code 并在 ViewModel 中创建逻辑并向用户显示消息。

 public async Task<IList<Photo>> GetAllPosts()
        {
            try
            {
                if (CrossConnectivity.Current.IsConnected)
                {
                    instagramCloneClient.DefaultRequestHeaders.Clear();
                    instagramCloneClient.DefaultRequestHeaders.Add("Accept", "application/json");
                    var response = await instagramCloneClient.GetAsync($"/photos");
                    var status_code=(int)response.StatusCode;
                    if (response.IsSuccessStatusCode)
                    {
                        string jsonMessage;
                        using (Stream responseStream = await response.Content.ReadAsStreamAsync())
                        {
                            jsonMessage = new StreamReader(responseStream).ReadToEnd();
                        }

                        IList<Photo> photos = JsonConvert.DeserializeObject<IList<Photo>>(jsonMessage);
                        return photos;
                    }
                    else
                    {
                        return null;
                    }
                }
                else
                {

                    return null;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                string error = ex.Message;
                return null;
            }
        } 

我return照片列表。我还想要 response.StatusCodeViewModel,我从中调用 function.I 必须 return IList,如何包含一些 int status_code?最佳做法是什么?

您有多种选择。您可以使用您的列表和 StatusCode 的 integer/enum 创建一个新模型。另一种选择是 return ArrayList 的列表。