Fixing an issue with output parameters that are of type IntPtr
[castle.git] / Core / Castle.Core / Resource / AssemblyBundleResource.cs
blob63db8d0e6b40ee002f9d79875f015f496d5fce8d
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.Globalization;
19 using System.IO;
20 using System.Reflection;
21 using System.Resources;
22 using System.Text;
24 public class AssemblyBundleResource : AbstractResource
26 private readonly CustomUri resource;
27 private readonly CultureInfo ci;
29 public AssemblyBundleResource(CustomUri resource) : this(resource, CultureInfo.InvariantCulture)
33 public AssemblyBundleResource(CustomUri resource, CultureInfo ci)
35 this.resource = resource;
36 this.ci = ci;
39 public override TextReader GetStreamReader()
41 Assembly assembly = ObtainAssembly(resource.Host);
43 #if SILVERLIGHT
44 string[] paths = resource.Path.Split(new char[] { '/' }).FindAll(s => !string.IsNullOrEmpty(s));
45 #else
46 string[] paths = resource.Path.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
47 #endif
49 if (paths.Length != 2)
51 throw new ResourceException("AssemblyBundleResource does not support paths with more than 2 levels in depth. See " + resource.Path);
54 ResourceManager rm = new ResourceManager(paths[0], assembly);
56 return new StringReader(rm.GetString(paths[1]));
59 public override TextReader GetStreamReader(Encoding encoding)
61 return GetStreamReader();
64 public override IResource CreateRelative(string relativePath)
66 throw new System.NotImplementedException();
69 public override void Dispose()
73 private Assembly ObtainAssembly(string assemblyName)
75 try
77 return Assembly.Load(assemblyName);
79 catch(Exception ex)
81 String message = String.Format("The assembly {0} could not be loaded", assemblyName);
82 throw new ResourceException(message, ex);