Today's study of C # Reflex, although a little dizzy at first, but understand the simple drop.
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Using System.Threading.Tasks;
Using System.Reflection;
Namespace Reflection
{
Class Program
{
static void Main (string[] args)
{
Assembly Assembly = Assembly.LoadFrom ("Reflection.exe");//assembly
Console.WriteLine (assembly);
Console.WriteLine ();
Type type1 = typeof (program);
Console.WriteLine (type1);
Console.WriteLine ();
Program program = new Program ();
Type type2 = program. GetType ();
Console.WriteLine (type2);
Console.WriteLine ();
Type type3 = Type.GetType ("Reflection.program", true, true);
Console.WriteLine (TYPE3);
Console.WriteLine ();
Type type4 = assembly. GetType ("Reflection.program");
Console.WriteLine (TYPE4);
Console.WriteLine ();
Type[] Type5 = assembly. GetTypes ();
foreach (var item in Type5)
{
Console.WriteLine (item);
}
Console.WriteLine ();
Type Type6 = typeof (Test);
Methodinfo[] Methodinfo=type6. GetMethods ();
foreach (var item in MethodInfo)
{
Console.WriteLine (item);
}
Console.WriteLine ();
Assembly assembly1 = Assembly.Load ("Reflection");
Type Type7 = assembly. GetType ("Reflection.test");
Object obj = Activator.CreateInstance (Type7);
MethodInfo methodinfo1 = Type7. GetMethod ("Say");
Methodinfo1. Invoke (obj, new object[] {"TC"});
Console.WriteLine ();
Type Type8 = typeof (Test);
propertyinfo[] PropertyInfo = Type8. GetProperties ();
foreach (var item in PropertyInfo)
{
Console.WriteLine (item);
}
Console.WriteLine ();
Assembly assembly2 = Assembly.Load ("Reflection");
Type type9 = assembly. GetType ("Reflection.test");
Object obj1 = Activator.CreateInstance (TYPE9);
PropertyInfo propertyinfo1 = Type9. GetProperty ("Name");
var name = Propertyinfo1. GetValue (Obj,null);
Console.WriteLine ();
}
}
Class Test
{
String name;
public void Say (string name)
{
Console.WriteLine ("Hello {0}", name);
}
public string Name
{
get {return name;}
set {this.name = value;}
}
}
}
C # Reflection