This article mainly introduces the simple application of ASP, combined with a complete example to analyze the principle of ASP and simple use of the method, the need for friends can refer to the following
This example describes the simple application of ASP. Share to everyone for your reference, as follows:
Reflection provides objects (type types) that encapsulate assemblies, modules, and types. You can use reflection to dynamically create an instance of a type, bind the type to an existing object, or get the type from an existing object and call its methods or access its fields and properties. If you use attributes in your code, you can use reflection to access them. ----This is the simplest understanding of reflection. Here is one of the simplest examples to tell about the application of reflection technology!
One. Declares an interface that contains a virtual method. As follows
Using system;using system.collections.generic;using system.linq;using system.text;namespace ConsoleApplication1{ Public Interface Ireflect { void Run (string name);} }
Two. Implement the interface and implement the methods in the interface. As follows
Using system;using system.collections.generic;using system.linq;using system.text;namespace ConsoleApplication1{ Public class Reflect:ireflect {public void Run (string name) { Console.WriteLine (name+ "started running!"); }}}
Three. Create an instance of the type by using reflection technology and invoke the method of the instance. As follows
Using system;using system.collections.generic;using system.linq;using system.text;using System.Reflection;namespace consoleapplication1{ class program { static void Main (string[] args) { Ireflect rec = (ireflect) Assembly.Load ("ConsoleApplication1"). CreateInstance ("Consoleapplication1.reflect"); Rec. Run ("AAA"); Console.ReadLine ();}}}
Such a simple example is done, and the result is "AAA started running." The named control that is reflected is system.reflection, and you must refer to the named control when you use it, the object that the named control long uses is assembly, which contains many static methods. where load is typical. CreateInstance is used to create an instance of an object.