public static XmlDocument Serialize(object obj, int ver, string rootName) { CustomXmlSerializer.SerializationOptions opt = new CustomXmlSerializer.SerializationOptions(); if (obj != null) { Type type = obj.GetType(); object[] customAttributes = type.GetCustomAttributes(typeof(CustomXmlSerializationOptionsAttribute), false); if (customAttributes.Length > 0) { opt = ((CustomXmlSerializationOptionsAttribute)customAttributes[0]).SerializationOptions; } } CustomXmlSerializer customXmlSerializer = new CustomXmlSerializer(opt); XmlElement xmlElement = customXmlSerializer.SerializeCore(rootName, obj); xmlElement.SetAttribute("version", ver.ToString()); xmlElement.SetAttribute("culture", Thread.CurrentThread.CurrentCulture.ToString()); XmlElement typeInfoNode = customXmlSerializer.GetTypeInfoNode(); if (typeInfoNode != null) { xmlElement.PrependChild(typeInfoNode); xmlElement.SetAttribute("hasTypeCache", "true"); } customXmlSerializer.doc.AppendChild(xmlElement); return(customXmlSerializer.doc); }
protected CustomXmlSerializer(CustomXmlSerializer.SerializationOptions opt) { this.options = opt; }