From 4500ba2b18aa96fcc0dceaf445794131d71bd308 Mon Sep 17 00:00:00 2001
From: Kevin <1985088337@qq.com>
Date: Sun, 19 Feb 2017 20:05:35 +0800
Subject: [PATCH] =?UTF-8?q?XmlExtention=E6=8A=BD=E7=A6=BB=E5=88=B0?=
=?UTF-8?q?=E5=8D=95=E7=8B=AC=E6=96=87=E4=BB=B6=E4=B8=AD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
OSS.Common/Extention/ConvertExtention.cs | 81 ----------------------
OSS.Common/Extention/XmlExtention.cs | 87 ++++++++++++++++++++++++
OSS.Common/OSS.Common.csproj | 1 +
3 files changed, 88 insertions(+), 81 deletions(-)
create mode 100644 OSS.Common/Extention/XmlExtention.cs
diff --git a/OSS.Common/Extention/ConvertExtention.cs b/OSS.Common/Extention/ConvertExtention.cs
index 0fab1c4..fe59641 100644
--- a/OSS.Common/Extention/ConvertExtention.cs
+++ b/OSS.Common/Extention/ConvertExtention.cs
@@ -13,10 +13,7 @@
#endregion
using System;
using System.Collections.Generic;
-using System.IO;
using System.Text;
-using System.Xml;
-using System.Xml.Serialization;
namespace OSS.Common.Extention
{
@@ -564,82 +561,4 @@ namespace OSS.Common.Extention
}
}
-
-
- ///
- /// xml 转化扩展
- ///
- public static class XmlConvertExtention
- {
- ///
- /// 对象序列化成xml字符串
- ///
- ///
- ///
- public static string SerializeToXml(this object t)
- {
- string result = string.Empty;
- MemoryStream stream = null;
- StreamReader streamReader = null;
- try
- {
- var serializer = new XmlSerializer(t.GetType());
-
- stream = new MemoryStream();
- serializer.Serialize(stream, t);
-
- stream.Position = 0;
- streamReader = new StreamReader(stream);
- result = streamReader.ReadToEnd();
- }
- finally
- {
- streamReader?.Dispose();
- stream?.Dispose();
- }
- return result;
- }
-
- ///
- /// xml字符串转化到对象
- ///
- ///
- ///
- ///
- public static TT DeserializeXml(this string xml)
- where TT:class
- {
- return DeserializeXml(xml, typeof(TT)) as TT;
- }
-
- ///
- /// xml字符串转化到对象
- ///
- ///
- ///
- public static object DeserializeXml(this string xml,Type type)
- {
- object result = null;
- MemoryStream stream = null;
- StreamWriter writer = null;
- try
- {
- stream = new MemoryStream();
-
- writer = new StreamWriter(stream);
- writer.Write(xml);
- writer.Flush();
-
- stream.Position = 0;
- var deSer = new XmlSerializer(type);
- result = deSer.Deserialize(stream);
- }
- finally
- {
- writer?.Dispose();
- stream?.Dispose();
- }
- return result;
- }
- }
}
diff --git a/OSS.Common/Extention/XmlExtention.cs b/OSS.Common/Extention/XmlExtention.cs
new file mode 100644
index 0000000..27f7136
--- /dev/null
+++ b/OSS.Common/Extention/XmlExtention.cs
@@ -0,0 +1,87 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Xml.Serialization;
+
+namespace OSS.Common.Extention
+{
+ ///
+ /// xml 转化扩展
+ ///
+ public static class XmlConvertExtention
+ {
+ ///
+ /// 对象序列化成xml字符串
+ ///
+ ///
+ ///
+ public static string SerializeToXml(this object t)
+ {
+ string result = string.Empty;
+ MemoryStream stream = null;
+ StreamReader streamReader = null;
+ try
+ {
+ var serializer = new XmlSerializer(t.GetType());
+
+ stream = new MemoryStream();
+ serializer.Serialize(stream, t);
+
+ stream.Position = 0;
+ streamReader = new StreamReader(stream);
+ result = streamReader.ReadToEnd();
+ }
+ finally
+ {
+ streamReader?.Dispose();
+ stream?.Dispose();
+ }
+ return result;
+ }
+
+ ///
+ /// xml字符串转化到对象
+ ///
+ ///
+ ///
+ ///
+ public static TT DeserializeXml(this string xml)
+ where TT : class
+ {
+ return DeserializeXml(xml, typeof(TT)) as TT;
+ }
+
+ ///
+ /// xml字符串转化到对象
+ ///
+ ///
+ ///
+ public static object DeserializeXml(this string xml, Type type)
+ {
+ object result = null;
+ MemoryStream stream = null;
+ StreamWriter writer = null;
+ try
+ {
+ stream = new MemoryStream();
+
+ writer = new StreamWriter(stream);
+ writer.Write(xml);
+ writer.Flush();
+
+ stream.Position = 0;
+ var deSer = new XmlSerializer(type);
+ result = deSer.Deserialize(stream);
+ }
+ finally
+ {
+ writer?.Dispose();
+ stream?.Dispose();
+ }
+ return result;
+ }
+ }
+}
diff --git a/OSS.Common/OSS.Common.csproj b/OSS.Common/OSS.Common.csproj
index 14231fe..fcf128d 100644
--- a/OSS.Common/OSS.Common.csproj
+++ b/OSS.Common/OSS.Common.csproj
@@ -58,6 +58,7 @@
+