C # implement a mechanism similar to MVC routing through reflection,

Source: Internet
Author: User

C # implement a mechanism similar to MVC routing through reflection,

Recently, a function similar to MVC routing is encapsulated. // MVC routing mechanism first find Controller Action

 

 

  • What is reflection?

Reflection (Reflection) is. NET, which can be obtained at runtime through radiation. NET, including methods, attributes, events, and constructor. You can also obtain the name, qualifier, and parameters of each member. With reflection, you can be familiar with every type. If you obtain information about the constructor, you can directly create an object, even if the object type is unknown during compilation.

  • Implementation

First, load according to the DLL name, then reflect the type-based search class, and find the method based on the method name. It may be difficult for the author to write a few questions. I hope you can give more comments. To help me improve. Thank you!

The following code

1 // obtain the Assembly name if the configuration Assembly name is null, use the current Assembly name 2 var assemblyName = ConfigurationManager. etettings ["asseName"] = null? Assembly. getExecutingAssembly (). getName (). name: ConfigurationManager. appSettings ["asseName"]. toString (); 3 var className = "className"; // class name 4 var methodName = "methodName"; // method name 5 6 if (string. isNullOrEmpty (assemblyName) 7 throw new Exception ("assembly name cannot be blank"); 8 if (string. isNullOrEmpty (className) 9 throw new Exception ("class name cannot be blank"); 10 11 // reflect the specified DLL, and find the class access modifier according to the class name must be public12 Type = Assembly. loa D (assemblyName). GetExportedTypes (). FirstOrDefault (13 o => o. Name. IndexOf (domainResourceIndex, StringComparison. OrdinalIgnoreCase)> = 0); 14 15 if (type! = Null) 16 {17 // create an instance of the Class 18 object obj = (object) Activator. createInstance (type); 19 // based on the input method name, find Method 20 MethodInfo pMethod = type. getMethod (methodName); 21 22 if (pMethod! = Null) 23 {24 // execute 25 pMethod. invoke (obj, new object [] {request, response}); 26} 27 else28 {29 throw new Exception ("No Method Found "); 30} 31} 32 else33 {34 throw new Exception ("no class found"); 35}

 

Reprinted please indicate http://www.cnblogs.com/cainiaodage/p/3924165.html


Symbol in C Language <Yes

Left shift operator (<)

Removes all the binary bits of an operation object from the left and adds 0 to the right ).

For example, a = a <2 shifts the binary bits of a two places to the left and complements 0 to the right,

Move 1 to the left and then a = a * 2;

If the left shift does not include 1 in the Discard high position, then shifts one bit left, which is equivalent to multiplying the number by 2.
Shift right operator (>)

Shifts all the binary bits of a number to several places to the right, and adds 0 to the left of the positive number, 1 to the left of the negative number, and discards the right of the negative number.

The operand shifts one digit to the right, which is equivalent to dividing the number by 2.

For example, a = a> 2 shifts the binary bit of a two places to the right,

0 or 1 to see whether the number is positive or negative.

Symbol in C Language <Yes

Left shift operator (<)

Removes all the binary bits of an operation object from the left and adds 0 to the right ).

For example, a = a <2 shifts the binary bits of a two places to the left and complements 0 to the right,

Move 1 to the left and then a = a * 2;

If the left shift does not include 1 in the Discard high position, then shifts one bit left, which is equivalent to multiplying the number by 2.
Shift right operator (>)

Shifts all the binary bits of a number to several places to the right, and adds 0 to the left of the positive number, 1 to the left of the negative number, and discards the right of the negative number.

The operand shifts one digit to the right, which is equivalent to dividing the number by 2.

For example, a = a> 2 shifts the binary bit of a two places to the right,

0 or 1 to see whether the number is positive or negative.

Related Article

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.