public static T PostWithConverter<T>(string function, JsonConverter converter, params object[] postData) { if (string.IsNullOrWhiteSpace(AuthToken) && WebAddress.Equals("https://compute.rhino3d.com")) throw new UnauthorizedAccessException("AuthToken must be set for compute.rhino3d.com"); for( int i=0; i<postData.Length; i++ ) { if( postData[i]!=null && postData[i].GetType().IsGenericType && postData[i].GetType().GetGenericTypeDefinition() == typeof(Remote<>) ) { var mi = postData[i].GetType().GetMethod("JsonObject"); postData[i] = mi.Invoke(postData[i], null); } } string json = converter == null ? JsonConvert.SerializeObject(postData, Formatting.None) : JsonConvert.SerializeObject(postData, Formatting.None, converter); var response = DoPost(function, json); using (var streamReader = new StreamReader(response.GetResponseStream())) { var result = streamReader.ReadToEnd(); if (converter == null) return JsonConvert.DeserializeObject<T>(result); return JsonConvert.DeserializeObject<T>(result, converter); } }
public static T0 Post<T0, T1>(string function, out T1 out1, params object[] postData) { if (string.IsNullOrWhiteSpace(AuthToken) && WebAddress.Equals("https://compute.rhino3d.com")) throw new UnauthorizedAccessException("AuthToken must be set for compute.rhino3d.com"); string json = Newtonsoft.Json.JsonConvert.SerializeObject(postData); var response = DoPost(function, json); using (var streamReader = new StreamReader(response.GetResponseStream())) { var jsonString = streamReader.ReadToEnd(); object data = Newtonsoft.Json.JsonConvert.DeserializeObject(jsonString); var ja = data as Newtonsoft.Json.Linq.JArray; out1 = ja[1].ToObject<T1>(); return ja[0].ToObject<T0>(); } }