Supplement of reflection

Source: Internet
Author: User

Supplement of reflection

Load the Assembly and obtain various items

The code is very clear.

Using System;
Using System. Collections. Generic;
Using System. Text;
Using System. Reflection;

Namespace FanShe
{
Public class Test
{
Assembly myAssembly = null;

Public Test ()
{
// Method 1:
// MyAssembly = Assembly. LoadFrom (@ "E: \ study \ TestDemo \ FanShe \ bin \ Debug \ FanShe.exe"); // path

// Method 2
MyAssembly = Assembly. Load ("FanSheDll"); // note that the Assembly name is "FanSheDll" instead of "FanShe. Dll ".

}

Public void Start ()
{
Assembly [] assemblys = AppDomain. CurrentDomain. GetAssemblies (); // obtain all the current Assembly

Foreach (Assembly item in assemblys)
{
This. getreflectioninfo (item );
}
}

// Define a method to obtain the reflected content
Private void getreflectioninfo (Assembly myassembly)
{
Type [] typearr = myAssembly. GetTypes (); // obtain the Type
Foreach (Type type in typearr) // obtain detailed information for each Type
{
// Obtain the structure information of the type
ConstructorInfo [] myconstructors = type. GetConstructors ();

// Obtain the field information of the type.
FieldInfo [] myfields = type. GetFields ();

// Obtain method information
MethodInfo [] myMethodInfo = type. GetMethods ();

// Obtain the Property Information
PropertyInfo [] myproperties = type. GetProperties ();

// Obtain event information
EventInfo [] Myevents = type. GetEvents ();
}
}

}
}

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.