本文整理匯總了C#中System.Dynamic.ExpandoObject.Flatten方法的典型用法代碼示例。如果您正苦於以下問題:C# ExpandoObject.Flatten方法的具體用法?C# ExpandoObject.Flatten怎麽用?C# ExpandoObject.Flatten使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Dynamic.ExpandoObject
的用法示例。
在下文中一共展示了ExpandoObject.Flatten方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Request
internal dynamic Request(string method, string serviceUrl, ExpandoObject postData)
{
if (string.IsNullOrEmpty(serviceUrl))
throw new ArgumentNullException("serviceUrl");
string url = string.Format("{0}{1}", _baseUrl, serviceUrl);
WebRequest request = WebRequest.Create(url);
request.Method = method;
request.ContentType = "application/json";
request.Headers["X-Auth-Token"] = _authToken;
//Write post data
if (method == "POST" && postData != null || method == "PUT" && postData != null)
{
string json = postData.Flatten();
var bytes = Encoding.ASCII.GetBytes(json);
request.ContentLength = bytes.Length;
var requestStream = request.GetRequestStream();
requestStream.Write(bytes, 0, bytes.Length);
requestStream.Close();
}
string response;
using (var webResponse = request.GetResponse())
{
using (var streamReader = new StreamReader(webResponse.GetResponseStream()))
{
response = streamReader.ReadToEnd();
}
}
if (string.IsNullOrEmpty(response))
{
return null;
}
else
{
return response.ToExpando();
}
}