forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNamedXmlDocument.cs
49 lines (43 loc) · 1.08 KB
/
NamedXmlDocument.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
40
41
42
43
44
45
46
47
48
49
using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using NHibernate.Cfg.MappingSchema;
namespace NHibernate.Cfg
{
public class NamedXmlDocument
{
private static readonly XmlSerializer mappingDocumentSerializer = new XmlSerializer(typeof (HbmMapping));
private readonly string name;
private readonly HbmMapping document;
static NamedXmlDocument() { }
public NamedXmlDocument(string name, XmlDocument document)
: this(name, document, mappingDocumentSerializer)
{
}
public NamedXmlDocument(string name, XmlDocument document, XmlSerializer serializer)
{
if (document == null)
{
throw new ArgumentNullException("document");
}
this.name = name;
if (document.DocumentElement == null)
{
throw new MappingException("Empty XML document:" + name);
}
using (var reader = new StringReader(document.DocumentElement.OuterXml))
{
this.document = (HbmMapping)serializer.Deserialize(reader);
}
}
public string Name
{
get { return name; }
}
public HbmMapping Document
{
get { return document; }
}
}
}