Implementing an Interface Visual Debug page using C # Reflection

Source: Internet
Author: User

Directly on the code, referencing CommTools.dll, including the ASPX display page and Aspx.cs getting the reflection data source code

1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingsystem.web;5 usingSystem.Web.UI;6 usingSystem.Web.UI.WebControls;7 usingCommtools;8 9 namespaceWebappreflectorTen { One      Public Partial classWebForm1:System.Web.UI.Page A     { -         protected voidPage_Load (Objectsender, EventArgs e) -         { the             Const stringNameSpace ="Commtools"; -  -             //methods for obtaining commtools.webutils, including Get,set -             varThe AppDomain.CurrentDomain.GetAssemblies (). FirstOrDefault (t =t.fullname.contains (NameSpace)); +             if(TheNULL) {Response.Write ("No Assembly");return; } -             varMethods =. GetType (string. Format ("{0}. {1}", NameSpace,"webutils")). GetMethods (); +Ddlmethds.datasource =methods; A Ddlmethds.databind (); at  -             //get the properties of Commtools.webutils -             varMembers = to-do. GetType (string. Format ("{0}. {1}", NameSpace,"webutils")). GetProperties (); -Ddlmembers.datasource =Members ; - Ddlmembers.databind (); -  in             //gets the request parameter name, type, return value type, public static T get<t> (string url) of the method (Get<t> of the Commtools.webutils Class) -             varThismethod = methods. FirstOrDefault (t = T.name = ="Get"); to             varReqparams =thismethod.getparameters (); +DdlParams.Items.AddRange (reqparams.select (t =NewListItem (T.name +"|"+t.parametertype.name)). ToArray ()); -Response.Write ("return value type"+ thisMethod.ReturnType.ToString () +"<br/>");//Empty:thisMethod.ReturnParameter.Name the              *         } $     }Panax Notoginseng}
View Code
1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingsystem.web;5 usingSystem.Web.UI;6 usingSystem.Web.UI.WebControls;7 usingCommtools;8 9 namespaceWebappreflectorTen { One      Public Partial classWebForm1:System.Web.UI.Page A     { -         protected voidPage_Load (Objectsender, EventArgs e) -         { the             Const stringNameSpace ="Commtools"; -  -             //methods for obtaining commtools.webutils, including Get,set -             varThe AppDomain.CurrentDomain.GetAssemblies (). FirstOrDefault (t =t.fullname.contains (NameSpace)); +             if(TheNULL) {Response.Write ("No Assembly");return; } -             varMethods =. GetType (string. Format ("{0}. {1}", NameSpace,"webutils")). GetMethods (); +Ddlmethds.datasource =methods; A Ddlmethds.databind (); at  -             //get the properties of Commtools.webutils -             varMembers = to-do. GetType (string. Format ("{0}. {1}", NameSpace,"webutils")). GetProperties (); -Ddlmembers.datasource =Members ; - Ddlmembers.databind (); -  in             //gets the request parameter name, type, return value type, public static T get<t> (string url) of the method (Get<t> of the Commtools.webutils Class) -             varThismethod = methods. FirstOrDefault (t = T.name = ="Get"); to             varReqparams =thismethod.getparameters (); +DdlParams.Items.AddRange (reqparams.select (t =NewListItem (T.name +"|"+t.parametertype.name)). ToArray ()); -Response.Write ("return value type"+ thisMethod.ReturnType.ToString () +"<br/>");//Empty:thisMethod.ReturnParameter.Name the  *             //Calculate and display toMD5 (123) $             varAmethod =. GetType (string. Format ("{0}. {1}", NameSpace,"stringopertion")). GetMethod ("toMD5");Panax Notoginseng             ObjectRspentity = Amethod.invoke (NULL,New[] {"123" }); -Response.Write ("toMD5 (123):"+ rspentity +"<br/>"); the              +         } A     } the}
View Code

With reflection, you can get all the methods inside an assembly, the parameters of each method, the type, and so on. Combined with HTML control unique naming, make HTTP GET or POST request parameters, can do an interface visual debugging page.

Main idea: Get multiple methods inside the DLL, bind display = "Select a method, get the property inside the method, display it with a unique HTML ID (simple Type direct display Txt,bool, enumerate display DDL, complex type display answer large text box, fill in JSON to the user), For entity comments Read Comment xml= manually assigned, use reflection assignment for request parameters (for different types of assignment), can be called by local direct DLL, or remote HTTP JSON request = "Get results directly JSON serialized display

Implementing an Interface Visual Debug page using C # Reflection

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.