国产探花免费观看_亚洲丰满少妇自慰呻吟_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 ;
   }
  }
 }
}



發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 石棉县| 惠东县| 包头市| 保靖县| 日土县| 务川| 师宗县| 西乌珠穆沁旗| 友谊县| 金阳县| 香港 | 丁青县| 石阡县| 阿拉善左旗| 深泽县| 萨嘎县| 怀宁县| 曲阳县| 徐汇区| 常州市| 屏东县| 六枝特区| 调兵山市| 南宁市| 崇礼县| 万山特区| 高淳县| 三亚市| 赤城县| 海宁市| 天镇县| 抚宁县| 油尖旺区| 陇川县| 丹巴县| 靖西县| 麻江县| 镇沅| 白朗县| 图木舒克市| 金沙县|