- Assembly
Assembly assembly = Assembly.LoadFrom(@"F:\C#\工程文件\ConsoleTest\ConsoleApp1\ReflectionClass\bin\Debug\ReflectionClass.dll");
foreach (var item in assembly.GetTypes())
{
Console.WriteLine("{0}", item.Name);
}
foreach (var item in assembly.GetModules())
{
Console.WriteLine("{0}", item.Name);
}
foreach (var item in assembly.GetTypes())
{
Console.WriteLine("{0}", item.Name);
}
- Type
Type type = assembly.GetType("MyReflection.Class1");
- Activator
object objectTest3 = Activator.CreateInstance(type, new object[] { "58"});
object objectTest1 = Activator.CreateInstance(type) ;
- MethodInfo
type.GetProperty("str").SetValue(objectTest1,"666");
Console.WriteLine("{0}", type.GetProperty("str").GetValue(objectTest1));
MethodInfo methodInfo = type.GetMethod("Show1", new Type[] { });
object[] pa = new object[] { };
methodInfo.Invoke(objectTest1, null);
MethodInfo methodInfo2 = type.GetMethod("Show1", new Type[] { typeof(string) });
object[] pa2 = new object[] {"789" };
methodInfo2.Invoke(objectTest1, pa2);
type.GetMethod("Show2").Invoke(objectTest1, new object[] { "888" });
MethodInfo methodInfo3 = type.GetMethod("Show2", new Type[] { typeof(string) });
object[] pa3 = new object[] { "789" };
methodInfo3.Invoke(objectTest1, pa3);
string str=(string) type.GetMethod("Show3").Invoke(objectTest1, new object[] { "888" });
MethodInfo methodInfo4 = type.GetMethod("Show3", new Type[] { typeof(string) });
object[] pa4 = new object[] { "789" };
string str4= (string)methodInfo4.Invoke(objectTest1, pa4);