Fixing an issue with output parameters that are of type IntPtr
[castle.git] / InversionOfControl / Castle.MicroKernel / Registration / Strategies / AllTypesOf.cs
blob31a48fa20614d076c7e552f1682c04332d35b6aa
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 /// Describes a set of components to register in the kernel.
24 /// </summary>
25 public class AllTypes
27 private readonly Type basedOn;
29 internal AllTypes(Type basedOn)
31 this.basedOn = basedOn;
34 /// <summary>
35 /// Prepares to register types from an assembly.
36 /// </summary>
37 /// <param name="assemblyName">The assembly name.</param>
38 /// <returns>The corresponding <see cref="TypesDescriptor"/></returns>
39 public TypesDescriptor FromAssemblyNamed(string assemblyName)
41 Assembly assembly;
42 String extension = Path.GetExtension(assemblyName);
44 if (extension == ".dll" || extension == ".exe")
46 if (Path.GetDirectoryName(assemblyName) == AppDomain.CurrentDomain.BaseDirectory)
48 assembly = Assembly.Load(Path.GetFileNameWithoutExtension(assemblyName));
50 else
52 assembly = Assembly.LoadFile(assemblyName);
55 else
57 assembly = Assembly.Load(assemblyName);
60 return FromAssembly(assembly);
63 /// <summary>
64 /// Prepares to register types from an assembly.
65 /// </summary>
66 /// <param name="assembly">The assembly.</param>
67 /// <returns>The corresponding <see cref="TypesDescriptor"/></returns>
68 public TypesDescriptor FromAssembly(Assembly assembly)
70 if (assembly == null)
72 throw new ArgumentNullException("assembly");
74 return From(assembly.GetExportedTypes());
77 /// <summary>
78 /// Prepares to register types from a list of types.
79 /// </summary>
80 /// <param name="types">The list of types.</param>
81 /// <returns>The corresponding <see cref="TypesDescriptor"/></returns>
82 public TypesDescriptor From(IEnumerable<Type> types)
84 return new TypesDescriptor(basedOn, types);
87 /// <summary>
88 /// Prepares to register types from a list of types.
89 /// </summary>
90 /// <param name="types">The list of types.</param>
91 /// <returns>The corresponding <see cref="TypesDescriptor"/></returns>
92 public TypesDescriptor Pick(IEnumerable<Type> types)
94 return new TypesDescriptor(basedOn, types);
97 /// <summary>
98 /// Prepares to register types from a list of types.
99 /// </summary>
100 /// <param name="types">The list of types.</param>
101 /// <returns>The corresponding <see cref="TypesDescriptor"/></returns>
102 public TypesDescriptor From(params Type[] types)
104 return new TypesDescriptor(basedOn, types);
107 /// <summary>
108 /// Describes all the types based on <see cref="basedOn"/>
109 /// </summary>
110 /// <param name="basedOn">The base type.</param>
111 /// <returns></returns>
112 public static AllTypes Of(Type basedOn)
114 return new AllTypes(basedOn);
117 /// <summary>
118 /// Describes all the types based on type T.
119 /// </summary>
120 /// <typeparam name="T">The base type.</typeparam>
121 /// <returns></returns>
122 public static AllTypes Of<T>()
124 return new AllTypes(typeof(T));
127 /// <summary>
128 /// Describes any types that are supplied.
129 /// </summary>
130 /// <returns></returns>
131 public static AllTypes Pick()
133 return Of<object>();