//根据Node 的节点给每个属性赋值。 private void fillSingleProperty(QueryParameterInfo entity, XmlNode xmlNode) { PropertyInfo[] pros = entity.GetType().GetProperties(); foreach (PropertyInfo info in pros) { if (info.IsSpecialName || !info.CanWrite) { continue; } DataMemberAttribute att = Attribute.GetCustomAttribute(info, typeof(DataMemberAttribute)) as DataMemberAttribute; if (att == null) { continue; } //非查询需要的参数属性去除掉 if (Array.IndexOf(PARAM_EXCEPTION_PROS_NAME, info.Name) >= 0) { continue; } XmlNode propertyNode = getNodeByNodeName(xmlNode.ChildNodes, info.Name); if (propertyNode == null) { continue; } if (string.IsNullOrEmpty(propertyNode.InnerText)) { continue; } object val = propertyNode.InnerText.Trim(); //考虑到Enum 的值都是通过描述来配置的,所以这里需要特殊处理一下。 if (info.PropertyType.IsEnum) { val = Enum.Parse(info.PropertyType, val.ToString()); } MB.Util.MyReflection.Instance.InvokePropertyForSet(entity, info.Name, val); } }
//系列化单的对象 private void serializeSingleObject(StringBuilder sXml, QueryParameterInfo val) { Type t = val.GetType(); PropertyInfo[] pros = t.GetProperties(); foreach (PropertyInfo info in pros) { if (info.IsSpecialName) { continue; } object[] att = info.GetCustomAttributes(typeof(DataMemberAttribute), true); if (att == null || att.Length == 0) { continue; } //非查询需要的参数属性去除掉 if (Array.IndexOf(PARAM_EXCEPTION_PROS_NAME, info.Name) >= 0) { continue; } Type proType = info.PropertyType; object v = info.GetValue(val, null); if (v != null) { writeFirstMarker(sXml, info.Name); if (info.Name == "Value" || info.Name == "Value2") { valueToXmlString(sXml, v, proType); } //sXml.Append(string.Format("<![CDATA[{0}]]>",v.ToString().Trim())); else { sXml.Append(v.ToString()); } writeLastMarker(sXml, info.Name); } } }