Download LINQPad

Un éditeur léger qui permet d’exécuter du Linq mais aussi du C# et du VB.net.

On y trouve comment rediriger le chargement des assemblies nécessaires à un AppDomain (extrait de http://www.albahari.com/nutshell/ch16.aspx):

using System;
using System.IO;
using System.Reflection;
using System.Collections.Generic;

public class Loader
{
    static Dictionary<string, Assembly> libs
     = new Dictionary<string, Assembly>();

    static void Main()
    {
        AppDomain.CurrentDomain.AssemblyResolve += FindAssem;
        Program.Go();
    }

    static Assembly FindAssem(object sender, ResolveEventArgs args)
    {
        string shortName = new AssemblyName(args.Name).Name;
        if (libs.ContainsKey(shortName)) return libs[shortName];

        using (Stream s = Assembly.GetExecutingAssembly().
                 GetManifestResourceStream("Libs." + shortName + ".dll"))
        {
            byte[] data = new BinaryReader(s).ReadBytes((int)s.Length);
            Assembly a = Assembly.Load(data);
            libs[shortName] = a;
            return a;
        }
    }
}

public class Program
{
    public static void Go()
    {
        // Run main program...
    }
}

Download LINQPad

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s