Updated vs2005 projects for AllTypesOf<> registration updates.
[castle.git] / InversionOfControl / Castle.MicroKernel / Registration / Strategies / AllTypesOf.cs
blob8a06e65a60f35147e464233d98133f898a65e7ab
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.MicroKernel.Registration
17 using System;
18 using System.IO;
19 using System.Reflection;
20 using System.Collections.Generic;
22 /// <summary>
23 /// The starting point to describe types to register.
24 /// </summary>
25 /// <typeparam name="T">The base type to match against.</typeparam>
26 public static class AllTypesOf<T>
28 /// <summary>
29 /// Prepares to register types from an assembly.
30 /// </summary>
31 /// <param name="assemblyName">The assembly name.</param>
32 /// <returns>The corresponding <see cref="TypesDescriptor{T}"/></returns>
33 public static TypesDescriptor<T> FromAssembly(string assemblyName)
35 Assembly assembly;
36 String extension = Path.GetExtension(assemblyName);
38 if (extension == ".dll" || extension == ".exe")
40 if (Path.GetDirectoryName(assemblyName) == AppDomain.CurrentDomain.BaseDirectory)
42 assembly = Assembly.Load(Path.GetFileNameWithoutExtension(assemblyName));
44 else
46 assembly = Assembly.LoadFile(assemblyName);
49 else
51 assembly = Assembly.Load(assemblyName);
54 return FromAssembly(assembly);
57 /// <summary>
58 /// Prepares to register types from an assembly.
59 /// </summary>
60 /// <param name="assembly">The assembly.</param>
61 /// <returns>The corresponding <see cref="TypesDescriptor{T}"/></returns>
62 public static TypesDescriptor<T> FromAssembly(Assembly assembly)
64 if (assembly == null)
66 throw new ArgumentNullException("assembly");
68 return From(assembly.GetExportedTypes());
71 /// <summary>
72 /// Prepares to register types from a list of types.
73 /// </summary>
74 /// <param name="types">The list of types.</param>
75 /// <returns>The corresponding <see cref="TypesDescriptor{T}"/></returns>
76 public static TypesDescriptor<T> From(IEnumerable<Type> types)
78 return new TypesDescriptor<T>(types);
81 /// <summary>
82 /// Prepares to register types from a list of types.
83 /// </summary>
84 /// <param name="types">The list of types.</param>
85 /// <returns>The corresponding <see cref="TypesDescriptor{T}"/></returns>
86 public static TypesDescriptor<T> Pick( IEnumerable<Type> types )
88 return new TypesDescriptor<T>( types );
91 /// <summary>
92 /// Prepares to register types from a list of types.
93 /// </summary>
94 /// <param name="types">The list of types.</param>
95 /// <returns>The corresponding <see cref="TypesDescriptor{T}"/></returns>
96 public static TypesDescriptor<T> From( params Type[] types )
98 return new TypesDescriptor<T>( types );