You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

18 lines
512 B

  1. using System.Runtime.Serialization;
  2. using System.Text;
  3. using System.Xml;
  4. namespace Shentun.Utilities.Data
  5. {
  6. public class DataContractSerializerHelper
  7. {
  8. public static void Write<T>(T instance, string fileName)
  9. {
  10. DataContractSerializer serializer = new DataContractSerializer(typeof(T));
  11. using (XmlWriter writer = new XmlTextWriter(fileName, Encoding.UTF8))
  12. {
  13. serializer.WriteObject(writer, instance);
  14. }
  15. }
  16. }
  17. }