Using System;
Using System.Collections.Generic;
Using System.Text;
Using System.Reflection;
Namespace ConsoleApplication1
{
Class Program
{
static void Main (string[] args)
{
String basepath = System.AppDomain.CurrentDomain.BaseDirectory.Replace (@ "\ \", @ "\");
Assembly asm = assembly.loadfrom ([email protected] "MyLib.dll");
MyClass m = new MyClass (1, 2);
Type type = asm. GetType (@ "Mylib.ct");
Type t = typeof (MyClass);
object[] Parm = new object[2];
Parm[0]=1;
parm[1]=2;
Object obj = Activator.CreateInstance (t, parm);
Object obj1 = Activator.CreateInstance (type, parm);
MethodInfo mth = T.getmethod ("sum");
MethodInfo mth1 = type. GetMethod ("sum");
int i= (int) mth. Invoke (Obj,null);
int j = (int) mth1. Invoke (obj1, NULL);
Console.WriteLine (j);
Console.readkey ();
}
}
Class MyClass
{
int x;
int y;
Public MyClass (int i, int j)
{
x = i;
y = j;
}
public int sum ()
{
return x + y;
}
public bool Isbetween (int i)
{
if (x < i && i < y) return true;
else return false;
}
public void Set (int a, int b)
{
x = A;
y = b;
}
public void Set (double A, double b)
{
x = (int) A;
y = (int) b;
}
public void Show ()
{
Console.WriteLine ("X:{0},y:{1}", X, y);
}
}
}
. NET Reflection Instances