Fixing an issue with output parameters that are of type IntPtr
[castle.git] / Core / Castle.Core / Resource / ConfigResource.cs
blobc87a9cb84ae26bf3e9c149a3eb7a9e38d9e17f84
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.Core.Resource
17 using System;
18 using System.Configuration;
19 using System.IO;
20 using System.Text;
21 using System.Xml;
23 #if !SILVERLIGHT
25 public class ConfigResource : AbstractResource
27 private readonly XmlNode configSectionNode;
28 private string sectionName;
30 public ConfigResource() : this("castle")
34 public ConfigResource(CustomUri uri) : this(uri.Host)
38 public ConfigResource(String sectionName)
40 this.sectionName = sectionName;
42 XmlNode node = (XmlNode) ConfigurationManager.GetSection(sectionName);
44 if (node == null)
46 String message = String.Format(
47 "Could not find section '{0}' in the configuration file associated with this domain.", sectionName);
48 throw new ConfigurationErrorsException(message);
51 // TODO: Check whether it's CData section
52 configSectionNode = node;
55 public override TextReader GetStreamReader()
57 return new StringReader(configSectionNode.OuterXml);
60 public override TextReader GetStreamReader(Encoding encoding)
62 throw new NotSupportedException("Encoding is not supported");
65 public override IResource CreateRelative(String relativePath)
67 return new ConfigResource(relativePath);
70 public override void Dispose()
74 public override string ToString()
76 return String.Format("ConfigResource: [{0}]", sectionName);
80 #endif