internal static bool TestCase() { MemberMap value = new MemberMap { Value1 = 1, Value2 = 2, Value3 = 3 }; //成员位图初始化代价比较大,应该根据需求重用该对象 AutoCSer.Metadata.MemberMap <MemberMap> serializeMemberMap = AutoCSer.Metadata.MemberMap <MemberMap> .NewEmpty(); #if DOTNET2 serializeMemberMap.SetMember("Value1"); //添加成员 Value1 serializeMemberMap.SetMember("Value2"); //添加成员 Value2 #else serializeMemberMap.SetMember(member => member.Value1); //添加成员 Value1 serializeMemberMap.SetMember(member => member.Value2); //添加成员 Value2 #endif AutoCSer.Xml.SerializeConfig serializeMemberMapConfig = new AutoCSer.Xml.SerializeConfig { MemberMap = serializeMemberMap }; string xml = AutoCSer.XmlSerializer.Serialize(value, serializeMemberMapConfig); MemberMap newValue = AutoCSer.XmlDeSerializer.DeSerialize <MemberMap>(xml); return(newValue != null && newValue.Value1 == 1 && newValue.Value2 == 2 && newValue.Value3 == 0); }
/// <summary> /// API请求XML数据 /// </summary> /// <typeparam name="valueType">数据类型</typeparam> /// <typeparam name="formType">表单数据类型</typeparam> /// <param name="url">请求地址</param> /// <param name="formValue">POST表单</param> /// <param name="xml">输出XML字符串</param> /// <param name="config">XML序列化配置</param> /// <returns>数据对象,失败放回null</returns> public valueType RequestXml <valueType, formType>(string url, formType formValue, out string xml, AutoCSer.Xml.SerializeConfig config = null) where valueType : class, IReturn { return(parseXml <valueType>(xml = request.Request(url, encoding, null, Encoding.UTF8.GetBytes(AutoCSer.Xml.Serializer.Serialize(formValue, config))), url, true)); }
/// <summary> /// API请求XML返回文本数据 /// </summary> /// <typeparam name="formType">表单数据类型</typeparam> /// <param name="url">请求地址</param> /// <param name="formValue">POST表单</param> /// <param name="config">XML序列化配置</param> /// <returns>数据对象,失败放回null</returns> public string RequestXml <formType>(string url, formType formValue, AutoCSer.Xml.SerializeConfig config = null) { return(request.Request(url, encoding, null, Encoding.UTF8.GetBytes(AutoCSer.Xml.Serializer.Serialize(formValue, config)))); }
/// <summary> /// API请求XML数据 /// </summary> /// <typeparam name="valueType">数据类型</typeparam> /// <typeparam name="formType">表单数据类型</typeparam> /// <param name="url">请求地址</param> /// <param name="formValue">POST表单</param> /// <param name="config">XML序列化配置</param> /// <param name="isValue">是否验证数据</param> /// <returns>数据对象,失败放回null</returns> public valueType RequestXml <valueType, formType>(string url, formType formValue, AutoCSer.Xml.SerializeConfig config = null, bool isValue = true) where valueType : class, IReturn { string xml; return(RequestXml <valueType, formType>(url, formValue, out xml, config)); }