-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathXmlHandlers.cs
39 lines (34 loc) · 1.18 KB
/
XmlHandlers.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System.Data;
using System.Xml;
using System.Xml.Linq;
namespace Dapper
{
internal abstract class XmlTypeHandler<T> : SqlMapper.StringTypeHandler<T>
{
public override void SetValue(IDbDataParameter parameter, T value)
{
base.SetValue(parameter, value);
parameter.DbType = DbType.Xml;
}
}
internal sealed class XmlDocumentHandler : XmlTypeHandler<XmlDocument>
{
protected override XmlDocument Parse(string xml)
{
var doc = new XmlDocument();
doc.LoadXml(xml);
return doc;
}
protected override string Format(XmlDocument xml) => xml.OuterXml;
}
internal sealed class XDocumentHandler : XmlTypeHandler<XDocument>
{
protected override XDocument Parse(string xml) => XDocument.Parse(xml);
protected override string Format(XDocument xml) => xml.ToString();
}
internal sealed class XElementHandler : XmlTypeHandler<XElement>
{
protected override XElement Parse(string xml) => XElement.Parse(xml);
protected override string Format(XElement xml) => xml.ToString();
}
}