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

ASP.NET
部署ASP.NET的三大技术(2)
部署ASP.NET的三大技术(3)
部署ASP.NET的三大技术(4)
部署ASP.NET的三大技术(5)
部署ASP.NET的三大技术(6)
ASP.NET可交互式位图窗体设计(1)
ASP.NET可交互式位图窗体设计(2)
ASP.NET可交互式位图窗体设计(3)
ASP.NET可交互式位图窗体设计(4)
ASP.NET可交互式位图窗体设计(5)
ASP.NET可交互式位图窗体设计(6)
ASP.NET可交互式位图窗体设计(7)
ASP.NET可交互式位图窗体设计(8)
ASP.NET可交互式位图窗体设计(9)
ADO.NET2.0的十大新特性
用Asp.net实现基于XML的留言簿之一
用Asp.net实现基于XML的留言簿之二
用Asp.net实现基于XML的留言簿之三
用Asp.net实现基于XML的留言簿之四
在ASP.NET中使用.NET组件

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 43 ::
收藏到网摘: 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
 }.