动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
   .Net → 阅读文章

 .net 里面 protected private 的变量也可以访问

作者:郁郁小蝎 来源:中国站长学院 
阅读 2724 人次 , 2006-2-15 14:31:00 

通过 原数据可以访问,我是访问后,才发现自己怎么都操作私有字段了呢

参考代码

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
 }.

  
 
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:挤压造型Extrusion的节点说明和应用实例
· 下一篇:signlog 登陆实现
· 用VS.NET打开或创建web项目出错的解决办法
· ADO.NET2.0的十大新特性
· BEA WebLogic 暴露源代码漏洞
· 使用SQLDMO从SQL Server中获取信息
· 关于C#下写的Web Service 服务在Delphi下调用时的问题


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077