Créer les types d’objet localement ou à distant

Author:

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

using System;
using System.Reflection;
using System.Text;

public class MonType
{
    public void Afficher(int x)
    {
        Console.WriteLine(x);
    }
}

public class Example
{
    static void Main()
    {
        Object o = Activator.CreateInstance(typeof(StringBuilder));
        StringBuilder sb = (StringBuilder) o;
        sb.Append("Bonjour, là.");
        Console.WriteLine(sb);

        System.Runtime.Remoting.ObjectHandle oh = Activator.CreateInstanceFrom(Assembly.GetEntryAssembly().CodeBase, typeof(MonType).FullName);

        MonType st = (MonType) oh.Unwrap();

        st.Afficher(5);
    }
}

Leave a Reply

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