C # Reflection

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.