当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > .net 里面 protected private 的变量也可以访问(新发现)。

ASP.NET
在word中如何控制graph控件
把一个int数组的数字从小到大排列(C#)
Asp组件高级入门与精通系列之三
连接MYSQL数据库的方法及示例
SharePoint Portal Server之常见问题
软件开发中运用到的编号
VB程序员眼中的C#7
公农历转换VB类
VB程序员眼中的C#6
优化VB.NET应用程序的性能1
C#初学乍练-文本替换工具命令行版
如何得到某集合的所有子集合
VB程序员眼中的C#3
Shared Source CLI Essentials第一章第二部分
在ASP.NET使用javascript的一点小技巧
用户 'NT AUTHORITY\NETWORK SERVICE' 登录失败解决方法
开始使用SQLServer2005,没用过MSDE,一开始还不知道怎么下手呢,呵呵
我的ASP.net学习历程有关于.dll文件的迷惑
在图片上写字 C#
Shared Source CLI Essentials第一章第一部分

ASP.NET 中的 .net 里面 protected private 的变量也可以访问(新发现)。


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 57 ::
收藏到网摘: n/a


通过 原数据可以访问,我是访问后,才发现自己怎么都操作私有字段了呢
参考代码
public class L3Data : System.ComponentModel.Component { private System.ComponentModel.Container components = null; private Page _page; private ArrayList LiteralList = new ArrayList(); public L3Data(System.ComponentModel.IContainer container) { container.Add(this); InitializeComponent(); }
public L3Data() { InitializeComponent(); } protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region 组件设计器生成的代码 private void InitializeComponent() { components = new System.ComponentModel.Container(); } #endregion #region Property public Page Page { get{return this._page;} set { this._page = value; Type type = _page.GetType(); type = type.BaseType; System.Web.UI.WebControls.Literal literal = new Literal(); System.Reflection.FieldInfo[] fields = type.GetFields(BindingFlags.NonPublic|(BindingFlags.Static | BindingFlags.Instance)); foreach(System.Reflection.FieldInfo field in fields) { if(field.FieldType.Equals(literal.GetType())) this.LiteralList.Add(field); } int count =0; foreach(FieldInfo field in this.LiteralList) { count++; object obj = field.GetValue(this.Page); literal = (Literal)obj; if(literal.Text.Equals("wx")) literal.Text ="I can see you"; else { literal.Text="wangxing"+count.ToString(); } } } } #endregion }.