コード例 #1
0
        private static IDictionary <string, object> BuildDocumentFor(IApiResponse apiResponse)
        {
            var response = new Dictionary <string, object>();

            var links    = apiResponse.GetLinks().ToList();
            var forms    = apiResponse.GetForms().ToList();
            var embedded = new Dictionary <string, IEnumerable <IDictionary <string, object> > >();

            foreach (var child in apiResponse.GetChildren())
            {
                embedded[child.Key] = child.Value.Select(BuildDocumentFor);
            }

            response["_links"] = BuildLinks(links);

            if (forms.Any())
            {
                response["_forms"] = BuildForms(forms);
            }

            foreach (var item in BuildState(apiResponse))
            {
                response[item.Key] = item.Value;
            }

            if (embedded.Any())
            {
                response["_embedded"] = embedded;
            }

            return(response);
        }