using System.Collections.Generic;
using System.Xml.Serialization;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO.Compression;
get { return this.text; }
set { this.text = value; }
public static String SerializeObject(Object pObject)
String XmlizedString = null;
MemoryStream memoryStream = new MemoryStream();
XmlSerializer xs = new XmlSerializer(pObject.GetType());
XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.Unicode);
xs.Serialize(xmlTextWriter, pObject);
XmlizedString = Encoding.Unicode.GetString(memoryStream.ToArray());
return XmlizedString.Trim();
public static void Test()
var abc = new Abc { Text = "Line1\nLine2\r\nLine3\rLine4\n\rLineEnd" };
var xml = SerializeObject(abc);
Assert.IsTrue(xml.Count(c => c == '\n') == abc.Text.Count(c => c == '\n'));
Assert.IsTrue(xml.Count(c => c == '\r') == abc.Text.Count(c => c == '\r'));
Console.WriteLine("Environment.NewLine = {0}", System.Text.RegularExpressions.Regex.Escape(Environment.NewLine));
Console.WriteLine("\\r = {0}", ((byte)'\r').ToString("x2"));
Console.WriteLine("\\n = {0}", ((byte)'\n').ToString("x2"));
public static void Main()
Console.WriteLine("Environment version: {0} ({1})", System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription , GetNetCoreVersion());
Console.WriteLine("Failed with unhandled exception: ");
public static string GetNetCoreVersion()
var assembly = typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly;
var assemblyPath = assembly.CodeBase.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
int netCoreAppIndex = Array.IndexOf(assemblyPath, "Microsoft.NETCore.App");
if (netCoreAppIndex > 0 && netCoreAppIndex < assemblyPath.Length - 2)
return assemblyPath[netCoreAppIndex + 1];