ClassLibrary1.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace ClassLibrary1
{
public class Class1
{
public void hello(String name)
{
Console.WriteLine("hello {0}",name);
}
}
}
csc /target:library ClassLibrary1.cs
================================================================
ConsoleApplication1.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Assembly ass = Assembly.Load("ClassLibrary1");
Type[] ts = ass.GetTypes();
String classname = ts[0].FullName;
MethodInfo[] methodnames = ts[0].GetMethods();
String methodname = methodnames[0].Name;
object o = ass.CreateInstance(classname);
MethodInfo mi = ts[0].GetMethod(methodname);
object[] os = new object[1];
os[0] = "abc";
mi.Invoke(o, os);
Console.Read();
}
}
}
csc /target:exe ConsoleApplication1.cs
阅读(664) | 评论(0) | 转发(0) |