Teddy's Aspect Weaver Version 0.3 with Great Updating and Fixing, Especially the Implementing of Getting Runtime Method Context

[More about Teddy's Aspect Weaver]

Teddy's Aspect Weaver Version 0.3 [Updated: 2005/09/27]

Changes:
  - Add the geting context info and getting context arguments ability
  - Fix some internal XPath bugs
  - Fix BeforeConstructorCall/BeforeMethodCall bugs
  - Fix the ILML Library parsing method parameter name bug
  - Add the object instance in aspect local stack ability, which means you can new any object in aspect code only if the type of you object is defined or can be referenced in the base assembly
  - Move assembly AspectWeaver.Attributes code to assembly AspectWeaver.Aspects

Sample of Getting Runtime Method Context Info and Method Arguments

Configuration

<? xml version="1.0" encoding="utf-8"  ?>  
< Configuration  logFile ="LogWeaving.xml"  cleanTempFiles ="false" >
    
< BaseAssembly > ../TestLib/bin/Debug/TestLib.dll </ BaseAssembly >
    
< OutputAssembly > ../TestLib/bin/Debug/TestLib_output.dll </ OutputAssembly >
    
< AspectAssemblies >
        
< AspectAssembly  uniqueName ="TestAspectLib.dll"  path ="bin/Debug/TestAspectLib.dll"   />
    
</ AspectAssemblies >
    
< AdviceFiles >
        
< AdviceFile > Advice-Test.xml </ AdviceFile >
    
</ AdviceFiles >
</ Configuration >

TestClass.cs

using  System;

namespace  TestLib
{
    
public class TestClass
    
{
        
public void MethodToBeTestedGetContextInfoAndGetArgumments(object p1, string p2, int p3)
        
{
        }


        
public void MethodToTestGetContextInfoAndGetArgumments()
        
{
            MethodToBeTestedGetContextInfoAndGetArgumments(
"p1""p2", 3);
        }

    }

}

TestAspectClass.cs

using  System;
using  System.Reflection;
using  AspectWeaver.Aspects;

namespace  TestAspectLib
{
    
public class TestAspectClass : Aspect
    
{
        [InlineAtStart(
"//Method[@name='MethodToBeTestedGetContextInfoAndGetArgumments']")]
        
public void CodeToTestGetContextInfoAndGetArgumments()
        
{
            MethodBase contextInfo 
= GetContextInfo();
            Console.Write(contextInfo.ReflectedType.FullName 
+ "::" + contextInfo.Name + "/n/n");
            
object[] args = GetArguments();
            Console.Write(
string.Format("Arguments: {0}, {1}, {2}/n/n", args));
        }

    }

}

After Weaving Code (decompiled)

   public   class  TestClass
  
{
    
public void MethodToBeTestedGetContextInfoAndGetArgumments(object p1, string p2, int p3)
    
{
      MethodBase methodBase 
= base.GetType().GetMethod("MethodToBeTestedGetContextInfoAndGetArgumments");
      Console.Write(String.Concat(methodBase.ReflectedType.FullName, 
"::", methodBase.Name, "/n/n"));
      
object[] locals = new object[]{p1, p2, p3};
      Console.Write(String.Format(
"Arguments: {0}, {1}, {2}/n/n", locals));
    }


    
public void MethodToTestGetContextInfoAndGetArgumments()
    
{
      MethodToBeTestedGetContextInfoAndGetArgumments("p1""p2", 3);
    }

  }

Description

In the sample, we can see, if you call the GetContextInfo() and GetArguments() from aspect classes which inherited from AspectWeaver.Aspects.Aspect which defined the two methods, the weaved code be translated to local reflection code, no additional dependence. But it is interesting that in fact, there are not any code in the two methods' body at all. Do you know why? :^)

Download Source Code

AspectWeaver0.5.zip

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值