view Xml/XmlResourceResolver.cs @ 116:07660ac09a5f

Merge heads, but keep de0ed24eb961/IBBoard
author IBBoard <dev@ibboard.co.uk>
date Tue, 26 Jun 2012 20:09:01 +0100
parents de0ed24eb961 7ca4acc659bb
children e53bf3356914
line source
1 using System;
2 using System.Xml;
3 using System.Reflection;
4 using System.Collections.Generic;
5 using System.IO;
6 using System.Net;
8 namespace IBBoard.Xml
9 {
10 public class XmlResourceResolver : XmlUrlResolver
11 {
12 private Assembly assm;
13 private Dictionary<string, string> relativeToUriMap = new Dictionary<string, string>();
15 public XmlResourceResolver(Assembly assembly)
16 {
17 assm = assembly;
18 }
20 public void AddMapping(string relativeURI, string resourceName)
21 {
22 relativeToUriMap[relativeURI] = resourceName;
23 }
25 public override object GetEntity(Uri absoluteUri, string role, Type ofObjectToReturn)
26 {
27 string absoluteUriString = absoluteUri.ToString();
29 if (relativeToUriMap.ContainsKey(absoluteUriString))
30 {
31 string file = relativeToUriMap[absoluteUriString];
32 Stream stream = assm.GetManifestResourceStream(file);
33 return stream;
34 }
36 return base.GetEntity(absoluteUri, role, ofObjectToReturn);
37 }
38 }
39 }