コード例 #1
0
 // Token: 0x06000669 RID: 1641 RVA: 0x00017BF8 File Offset: 0x00015DF8
 public static Exception SerializeToXmlFile(object toSerialize, string fileFullPath)
 {
     return(DataContractSerializeHelper.HandleException(delegate
     {
         string directoryName = Path.GetDirectoryName(fileFullPath);
         if (!Directory.Exists(directoryName))
         {
             Directory.CreateDirectory(directoryName);
         }
         if (File.Exists(fileFullPath))
         {
             File.Delete(fileFullPath);
         }
         using (FileStream fileStream = File.OpenWrite(fileFullPath))
         {
             XmlWriterSettings settings = new XmlWriterSettings
             {
                 Indent = true,
                 IndentChars = "\t",
                 Encoding = Encoding.UTF8
             };
             DataContractSerializer dataContractSerializer = new DataContractSerializer(toSerialize.GetType());
             using (XmlWriter xmlWriter = XmlWriter.Create(fileStream, settings))
             {
                 using (XmlDictionaryWriter xmlDictionaryWriter = XmlDictionaryWriter.CreateDictionaryWriter(xmlWriter))
                 {
                     dataContractSerializer.WriteObject(xmlDictionaryWriter, toSerialize);
                     xmlDictionaryWriter.Flush();
                 }
             }
         }
     }));
 }
コード例 #2
0
        // Token: 0x06000667 RID: 1639 RVA: 0x000179DC File Offset: 0x00015BDC
        public static Exception SerializeToXmlString(object toSerialize, out string xmlString)
        {
            xmlString = null;
            string    tmpStr = null;
            Exception ex     = DataContractSerializeHelper.HandleException(delegate
            {
                XmlWriterSettings settings = new XmlWriterSettings
                {
                    Indent      = true,
                    IndentChars = "\t"
                };
                DataContractSerializer dataContractSerializer = new DataContractSerializer(toSerialize.GetType());
                StringBuilder stringBuilder = new StringBuilder();
                using (XmlWriter xmlWriter = XmlWriter.Create(stringBuilder, settings))
                {
                    using (XmlDictionaryWriter xmlDictionaryWriter = XmlDictionaryWriter.CreateDictionaryWriter(xmlWriter))
                    {
                        dataContractSerializer.WriteObject(xmlDictionaryWriter, toSerialize);
                        xmlDictionaryWriter.Flush();
                        tmpStr = stringBuilder.ToString();
                    }
                }
            });

            if (ex == null)
            {
                xmlString = tmpStr;
            }
            return(ex);
        }
コード例 #3
0
        // Token: 0x06000668 RID: 1640 RVA: 0x00017AA0 File Offset: 0x00015CA0
        public static Exception DeserializeFromXmlString <T>(string xml, out T deserializedObj)
        {
            deserializedObj = default(T);
            T         tmpObj = default(T);
            Exception ex     = DataContractSerializeHelper.HandleException(delegate
            {
                DataContractSerializer dataContractSerializer = new DataContractSerializer(typeof(T));
                using (StringReader stringReader = new StringReader(xml))
                {
                    using (XmlReader xmlReader = XmlReader.Create(stringReader))
                    {
                        tmpObj = (T)((object)dataContractSerializer.ReadObject(xmlReader));
                    }
                }
            });

            if (ex == null)
            {
                deserializedObj = tmpObj;
            }
            return(ex);
        }
コード例 #4
0
        // Token: 0x0600066A RID: 1642 RVA: 0x00017CB0 File Offset: 0x00015EB0
        public static Exception DeserializeFromXmlFile <T>(string fileFullPath, out T deserializedObj)
        {
            deserializedObj = default(T);
            T         tmpObj = default(T);
            Exception ex     = DataContractSerializeHelper.HandleException(delegate
            {
                using (FileStream fileStream = File.OpenRead(fileFullPath))
                {
                    using (XmlDictionaryReader xmlDictionaryReader = XmlDictionaryReader.CreateTextReader(fileStream, new XmlDictionaryReaderQuotas()))
                    {
                        DataContractSerializer dataContractSerializer = new DataContractSerializer(typeof(T));
                        tmpObj = (T)((object)dataContractSerializer.ReadObject(xmlDictionaryReader, true));
                    }
                }
            });

            if (ex == null)
            {
                deserializedObj = tmpObj;
            }
            return(ex);
        }