1
// Copyright 2004-2008 Castle Project - http://www.castleproject.org/
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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
19 using System
.Reflection
;
20 using System
.Collections
.Generic
;
23 /// The starting point to describe types to register.
25 /// <typeparam name="T">The base type to match against.</typeparam>
26 public static class AllTypesOf
<T
>
29 /// Prepares to register types from an assembly.
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
)
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
));
46 assembly
= Assembly
.LoadFile(assemblyName
);
51 assembly
= Assembly
.Load(assemblyName
);
54 return FromAssembly(assembly
);
58 /// Prepares to register types from an assembly.
60 /// <param name="assembly">The assembly.</param>
61 /// <returns>The corresponding <see cref="TypesDescriptor{T}"/></returns>
62 public static TypesDescriptor
<T
> FromAssembly(Assembly assembly
)
66 throw new ArgumentNullException("assembly");
68 return From(assembly
.GetExportedTypes());
72 /// Prepares to register types from a list of types.
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
);
82 /// Prepares to register types from a list of types.
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
);
92 /// Prepares to register types from a list of types.
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
);