public void Test_Serializable() { //测试Serializable对序列化的影响,将对象序列化成字符串 //BinarySerializer,json.net,XmlSerializer和LZ4 //结论:特性[Serializable]只对使用BinaryFormatter序列化(序列化成流)的时候有影响,其它的序列化不影响。 var input = new TestSerializableClass { Id = 1, Name = "aaa", CreatedTime = DateTime.Now }; //BinarySerializer var result1 = string.Empty; try { result1 = BinarySerializerHelper.Serialize(input); } catch (Exception ex) { } //json.net var result2 = string.Empty; try { result2 = input.ToJson(); } catch (Exception ex) { } //XmlSerializer var result3 = string.Empty; try { result3 = input.ToXml(); } catch (Exception ex) { } //LZ4 byte[] result4 = null; try { result4 = input.ToJson().LZ4Compress(); } catch (Exception ex) { } }
public bool SaveSurveyMain(string string_0, string string_1, SurveyMain surveyMain_0 = null) { if (surveyMain_0 == null) { surveyMain_0 = this.oSurveyMainDal.GetBySurveyId(string_0); } bool result; try { string text = string_1 + this.OutputPath; string text2 = "S" + string_0 + GClass0.smethod_0("HĪɧͣѵ"); string path = text + GClass0.smethod_0("]") + text2; if (!Directory.Exists(text)) { Directory.CreateDirectory(text); } int outPutType = this.OutPutType; if (outPutType != 2) { if (outPutType != 3) { XmlSerializer xmlSerializer = new XmlSerializer(typeof(SurveyMain)); FileStream stream = new FileStream(path, FileMode.Create, FileAccess.ReadWrite, FileShare.Read); xmlSerializer.Serialize(stream, surveyMain_0); } else { BinarySerializerHelper.Serialize <SurveyMain>(surveyMain_0, text, text2); } } else { XmlSerializerHelper.Serialize <SurveyMain>(surveyMain_0, text, text2); } result = true; } catch (Exception ex) { Logging.Error.WriteLog(GClass0.smethod_0("QŅɋ̦іեٵݧ࠻"), ex.Message); result = false; } return(result); }