国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

C# AOP微型框架實現(二)

2024-07-21 02:17:55
字體:
來源:轉載
供稿:網友
 

3. aopproxyattribute  aop代理特性

/****************************** aopproxyattribute   ************************************

using system;
using system.runtime.remoting ;
using system.runtime.remoting.proxies ;


namespace enterpriseserverbase.aop
{
 /// <summary>
 /// aopproxyattribute
 /// aop代理特性,如果一個類想實現具體的aop,只要實現aopproxybase和iaopproxyfactory,然后加上該特性即可。
 /// 2005.04.11
 /// </summary>
 
 [attributeusage(attributetargets.class ,allowmultiple = false)]
 public class aopproxyattribute : proxyattribute
 {
  private iaopproxyfactory proxyfactory = null ;

  public aopproxyattribute(type factorytype)
  {
   this.proxyfactory = (iaopproxyfactory)activator.createinstance(factorytype) ;   
  }

  #region createinstance
  /// <summary>
  /// 獲得目標對象的自定義透明代理
  /// </summary>
  public override marshalbyrefobject createinstance(type servertype)//servertype是被aopproxyattribute修飾的類
  {
   //未初始化的實例的默認透明代理
   marshalbyrefobject target =  base.createinstance (servertype); //得到位初始化的實例(ctor未執行)
   object[] args = {target ,servertype} ;
   //aopproxybase rp = (aopproxybase)activator.createinstance(this.realproxytype ,args) ; //activator.createinstance在調用ctor時通過了代理,所以此處將會失敗
   
   //得到自定義的真實代理
   aopproxybase rp = this.proxyfactory.createaopproxyinstance(target ,servertype) ;//new aopcontrolproxy(target ,servertype) ;
   return (marshalbyrefobject)rp.gettransparentproxy() ;
  }
  #endregion
 }
}

4 .methodaopswitcherattribute.cs

/**************************** methodaopswitcherattribute.cs *************************

using system;

namespace enterpriseserverbase.aop
{
 /// <summary>
 /// methodaopswitcherattribute 用于決定一個被aopproxyattribute修飾的class的某個特定方法是否啟用截獲 。
 /// 創建原因:絕大多數時候我們只希望對某個類的一部分method而不是所有method使用截獲。
 /// 使用方法:如果一個方法沒有使用methodaopswitcherattribute特性或使用methodaopswitcherattribute(false)修飾,
 ///       都不會對其進行截獲。只對使用了methodaopswitcherattribute(true)啟用截獲。
 /// 2005.05.11
 /// </summary>
 [attributeusage(attributetargets.method ,allowmultiple = false )]
 public class methodaopswitcherattribute : attribute
 {
  private bool useaspect = false ;

  public methodaopswitcherattribute(bool useaop)
  {   
   this.useaspect = useaop ;
  }

  public bool useaspect
  {
   get
   {
    return this.useaspect ;
   }
  }
 }
}



發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 横峰县| 奉新县| 鹿泉市| 武定县| 云和县| 华安县| 鱼台县| 新沂市| 康马县| 隆尧县| 白玉县| 金溪县| 文昌市| 隆回县| 盘锦市| 海门市| 台北市| 西安市| 眉山市| 青州市| 兴文县| 延庆县| 积石山| 阿拉善盟| 乐清市| 柳河县| 西城区| 平江县| 珠海市| 康乐县| 阳春市| 祥云县| 高唐县| 区。| 临泉县| 罗江县| 平和县| 政和县| 澜沧| 钟祥市| 九江市|