Minor changes to improve testability of helpers
[castle.git] / MonoRail / Castle.MonoRail.Framework / Configuration / TypeLoadUtil.cs
blobd155f23bf47a9fc0f918c0a31c18604235519063
1 // Copyright 2004-2007 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.MonoRail.Framework.Configuration
17 using System;
18 using System.Configuration;
19 using System.Reflection;
21 internal class TypeLoadUtil
23 private static Assembly thisAssembly = typeof(TypeLoadUtil).Assembly;
25 public static Type GetType(String typeName)
27 return GetType(typeName, false);
30 public static Type GetType(String typeName, bool ignoreError)
32 Type loadedType = Type.GetType(typeName, false, false);
34 if (loadedType == null && !ignoreError)
36 String message = String.Format("The type {0} could not be found", typeName);
37 throw new ConfigurationErrorsException(message);
40 return loadedType;
43 /// <summary>
44 /// Hack to allow MR to work when the main assemblies are on
45 /// GAC. This method returns the complete name.
46 /// </summary>
47 /// <param name="typeName"></param>
48 /// <returns></returns>
49 public static String GetEffectiveTypeName(string typeName)
51 String assemblyName = thisAssembly.GetName().Name;
52 String assemblyFullName = thisAssembly.GetName().FullName;
54 return typeName + assemblyFullName.Substring(assemblyName.Length);