[Mono-list] Instantiating all classes from a namespace

Chris Howie cdhowie at gmail.com
Sun Oct 5 09:49:54 EDT 2008

On Mon, Sep 29, 2008 at 4:46 PM, Esdras Beleza <linux at esdrasbeleza.com> wrote:
> The question is: how can I iterate inside a namespace classlist, and create
> a new instance of each class of it?

There is no cut and dried way to do this, but you can do something like this:

IEnumerable<Type> GetTypesInNamespace(string namespace) {
    foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()) {
        foreach (Type type in assembly.GetTypes()) {
            if (type.Namespace == namespace)
                yield return type;

Or you can do something LINQy.  :)

Chris Howie

More information about the Mono-list mailing list