【Asp.Net】反射技术
2017-03-26 22:36
253 查看
主程序
Test0326.dll 程序集代码
参考链接:
http://www.cnblogs.com/wangshenhe/p/3256657.html
using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Test0326; namespace WebApplication19 { public partial class WebForm1 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Assembly myAssembly = Assembly.LoadFrom(Server.MapPath("bin/Test0326.dll")); //获取类型信息 Type t = myAssembly.GetType("Test0326.TestClass"); //构造器的参数 object[] constuctParms = new object[] {"timmy"}; //根据类型创建对象 object dObj = Activator.CreateInstance(t, constuctParms); //获取方法的信息 MethodInfo method = t.GetMethod("GetValue"); //调用方法的一些标志位,这里的含义是Public并且是实例方法,这也是默认的值 BindingFlags flag = BindingFlags.Public | BindingFlags.Instance; //GetValue方法的参数 object[] parameters = new object[] { "Hi" }; //调用方法,用一个object接收返回值 TextBox1.Text = method.Invoke(dObj, flag, Type.DefaultBinder, parameters, null) as string; } } }
Test0326.dll 程序集代码
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Test0326 { public class TestClass { private string _value; public TestClass() { } public TestClass(string value) { _value = value; } public string GetValue(string prefix) { if (_value == null) return "NULL"; else return prefix + " : " + _value; } public string Value { set { _value = value; } get { if (_value == null) return "NULL"; else return _value; } } } }
参考链接:
http://www.cnblogs.com/wangshenhe/p/3256657.html
相关文章推荐
- asp.net通过反射技术实现Ajax(3)--第一个简单的例子
- asp.net的反射技术
- 如何使用反射技术实现ASP.NET国际化站点
- 使用反射技术在asp.net页间传递对象
- 使用反射技术在asp.net页间传递对象
- asp.net通过反射技术实现Ajax
- asp.net通过反射技术实现Ajax(2)--前台javascript封装的Ajax对象
- 使用反射将业务对象绑定到 ASP.NET 窗体控件(转自MSDN)
- 用asp.net轻松打造功能完备的分页技术!!
- ASP.NET重用代码技术 - 代码绑定技术
- ASP.NET的层次数据显示技术
- [导入]ASP.NET技术内幕的电子书中文版
- 转贴一篇:ASP.NET重用代码技术 - 用户控件技术
- ASP.NET的缓存技术
- 项目技术经验总结一:asp.net+oracle部署,防火墙端口开设
- ASP.NET中取代ASP的RS(Remote Scripting)技术的Framework
- ASP.NET重用代码技术 - 代码绑定技术
- ASP.NET技术内幕[强烈推荐]
- Asp.net小技术总结2
- [导入]ASP.NET重用代码技术 - 用户控件技术