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