public static string ToJSON(ContractValue contract, object value) { var sb = new StringBuilder(); var sw = new StringWriter(sb); using (var writer = new Newtonsoft.Json.JsonTextWriter(sw)) { writer.WriteStartObject(); var datacontract = ServicesFactory.GetDataContract(contract.Type); if (datacontract != null) { foreach (var p in datacontract.Properties) { var v = p.Property.GetValue(value, new object[0]); writer.WritePropertyName(p.Name); writer.WriteValue(ValueConverter.ToString(p, v)); } } else { writer.WritePropertyName("result"); writer.WriteValue(ValueConverter.ToString(contract, value)); } writer.WriteEndObject(); } return(sb.ToString()); }
public static object FromString(ContractValue contract, string value) { if (stringtovalue.TryGetValue(contract.GetTypeFromTask(), out ConvertFromString function)) { return(function(value)); } throw new InvokeException($"no value-converter for {contract.Name}"); }
private static string ToString(ContractValue contract, object value) { if (valuetostring.TryGetValue(contract.GetTypeFromTask(), out ConvertToString function)) { return(function(value)); } throw new InvokeException($"no value-converter for {contract.Name}"); }
private static void GetValues(ContractValue contract, object value, NameValueCollection parms, string header) { var datacontract = ServicesFactory.GetDataContract(contract.Type); if (datacontract != null) { foreach (var p in datacontract.Properties) { object vv = p.Property.GetValue(value, new object[0]); GetValues(p, vv, parms, $"{header}_{p.Name}"); } return; } parms[$"{header}"] = ToString(contract, value); }
private static object FromValues(ContractValue contract, NameValueCollection parms, string header) { var datacontract = ServicesFactory.GetDataContract(contract.Type); if (datacontract != null) { var result = Activator.CreateInstance(datacontract.Type); foreach (var p in datacontract.Properties) { p.Property.SetValue(result, FromValues(p, parms, $"{header}_{p.Name}"), new object[0]); } return(result); } return(FromString(contract, parms[$"{header}"])); }
internal static object FromJson(ContractValue contract, JObject data) { var datacontract = ServicesFactory.GetDataContract(contract.Type); if (datacontract != null) { // var obj = data[contract.Name].Value<object>(); var result = Activator.CreateInstance(datacontract.Type); foreach (var p in datacontract.Properties) { p.Property.SetValue(result, data[p.Name].ToObject(p.Type)); } return(result); } else { var obj = data["result"].Value <JValue>(); return(obj.ToObject(contract.GetTypeFromTask())); } }
public static Type GetTypeFromTask(this ContractValue contract) { return(GetTypeFromTask(contract.Type)); }
public static object FromValues(ContractValue contract, NameValueCollection parms) { return(FromValues(contract, parms, contract.Name)); }
public static void GetValues(ContractValue contract, object value, NameValueCollection parms) { GetValues(contract, value, parms, contract.Name); }