Créer une nouvelle instance d’un type spécifique

Author:

Charger,une,Assemblée,avec,un,nom
{filelink=17568}

using System;
using System.Reflection;

public class InstanceType : MarshalByRefObject
{
    public void PrintDomain()
    {
        Console.WriteLine("Exécution de l'objet dans AppDomain {0}",AppDomain.CurrentDomain.FriendlyName);
    }
}

class ExampleUtilisation
{
    public static void Main()
    {
        InstanceType TypeInstanceLocal = new InstanceType();
        TypeInstanceLocal.PrintDomain();
        AppDomain ad = AppDomain.CreateDomain("Nouveau Domaine");
        InstanceType remoteInstanceType = (InstanceType) ad.CreateInstanceAndUnwrap(Assembly.GetExecutingAssembly().FullName,"InstanceType");
        remoteInstanceType.PrintDomain();
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *