ow
This commit is contained in:
1 parent
31fbe199c1
commit
1c0c83af5f
469 files changed
+62544
-5
No files matched your search
@@ -0,0 +1,29 @@
|
||||
using System.Text;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace CloudBuilder.Util
|
||||
{
|
||||
public class SerializeHelper
|
||||
{
|
||||
public static string Serialize(object o)
|
||||
{
|
||||
if (o == null) return null;
|
||||
|
||||
XmlSerializer serializer = new XmlSerializer(o.GetType());
|
||||
|
||||
using (MemoryStream stream = new MemoryStream())
|
||||
{
|
||||
StreamWriter writer = new StreamWriter(stream, Encoding.UTF8);
|
||||
serializer.Serialize((TextWriter)writer, o);
|
||||
stream.Seek(0L, SeekOrigin.Begin);
|
||||
StreamReader reader = new StreamReader(stream, Encoding.UTF8);
|
||||
return reader.ReadToEnd();
|
||||
}
|
||||
}
|
||||
|
||||
public static void WriteAllText(string filePath, object o)
|
||||
{
|
||||
File.WriteAllText(filePath, Serialize(o));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user