How to keep XmlSerializer from killing NewLines in Strings?

后端 未结 5 1906
迷失自我
迷失自我 2020-12-08 07:00

Suppose I have a simple Class with just one Member a String.

public class Abc
{
    private String text;

    public String Text
    {
        get { return          


        
5条回答
  •  长情又很酷
    2020-12-08 07:11

    public class BinarySerialize where T : new() { public static string Serialize(T options, string path) {

                var xml = "";
                try
                {
                    File.Delete(path);
                }
                catch (Exception)
                {
    
    
                }
    
                try
                {
                    using (var fs = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.ReadWrite))
                    {
                        var bf = new BinaryFormatter();
    
    
                        bf.Serialize(fs, options);
                    }
    
    
                }
                catch (Exception ex)
                {
    
                    return ex.Message;
                }
    
    
    
                return xml;
    
    
    
    
    
            }
    
            public static T Deserialize(string path)
            {
                T filteroptions;
                using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    var bf = new BinaryFormatter();
                    filteroptions = (T)bf.Deserialize(fs);
                }
                return filteroptions;
    
            }
        }
    

提交回复
热议问题