Best use of reflection-class name method name for parameter call instance demo

Source: Internet
Author: User

First of all, we will say that reflection is inefficient, but can most frameworks reduce reflection? Reflection can be used easily when it brings us code. If there is anything inappropriate, I hope you can point it out.

1. The project structure is as follows: a ClassLb class library project, a testReflect webform project for testing, and testReflect adds references to the ClassLb Class Library Project

2. I added two very simple classes to the ClassLb class library project. The Code is as follows:

    Insert( a,  a +  + b +    Update( a,  a +  + b +     Insert( a,     Update( a,  

3. The webform project's test code in Default. aspx. cs is as follows: Note: add the namespace using System. Reflection;

                                              Type AccessType( assemblyName, = = (assembly ==   Exception(= assembly.GetType(assemblyName +  + (type ==   Exception(
                                                                         ExecuteMethod( assemblyName,  typeName,  method,   returnObject = == type.InvokeMember(method, BindingFlags.Default | BindingFlags.InvokeMethod, , 

4. The test code is as follows:

  Page_Load( a = ExecuteMethod(, , , , +  b = ExecuteMethod(, , , , +  c = ExecuteMethod(, , , , +  d = ExecuteMethod(, , , , + 

5. Execution result:

6. I learned from my experiences that my previous project used Jquery to call webservice through ajax, and webservice to call the class library method. Each object has the addition, deletion, modification, and query operations, in webservice, I need to create four operation methods for ajax to call. I have written a lot of WebServices, and each webservice has several other methods, which wastes a lot of time, when I use the reflection shown above, I only need to use a webservice and a method. When ajax is called at the front end, I can input the corresponding parameters, which will greatly improve the development speed, this is just my experience. If you have a better way, please share it with you.

 

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.