AOP Practice with AspectWeaver0.6 - DebugPropertyValueModifying
来源:互联网 发布:数据统计怎么做 编辑:程序博客网 时间:2024/05/22 10:48
In No Buzzword AOP --- When we don't have aop, idior described a property debugging situation.
This is the AOP way based on AspectWeaver0.6.
DebugPropertyModifyingAspect.cs:
using System;
using AspectWeaver.Aspects;
namespace TestAspects
{
public class DebugPropertyModifyingAspect : Aspect
{
[InlineAtStart("//Method[starts-with(@name, 'set_')]"), InlineBeforeReturn("//Method[starts-with(@name, 'set_')]")]
public void CodeForPrintPropertyValue()
{
string contextInfo = GetContextInfo();
string propertyName = contextInfo.Substring(contextInfo.IndexOf("_") + 1, contextInfo.IndexOf("(") - contextInfo.IndexOf("_") - 1);
Console.WriteLine(string.Format("{0}={1}", propertyName, this.GetType().GetProperty(propertyName).GetValue(this, null)));
}
}
}
using AspectWeaver.Aspects;
namespace TestAspects
{
public class DebugPropertyModifyingAspect : Aspect
{
[InlineAtStart("//Method[starts-with(@name, 'set_')]"), InlineBeforeReturn("//Method[starts-with(@name, 'set_')]")]
public void CodeForPrintPropertyValue()
{
string contextInfo = GetContextInfo();
string propertyName = contextInfo.Substring(contextInfo.IndexOf("_") + 1, contextInfo.IndexOf("(") - contextInfo.IndexOf("_") - 1);
Console.WriteLine(string.Format("{0}={1}", propertyName, this.GetType().GetProperty(propertyName).GetValue(this, null)));
}
}
}
Open "DebugPropertyValueModifying/DebugPropertyValueModifying.sln" to rebuild all projects.
Run "DebugPropertyValueModifying/TestConsole/bin/Debug/TestConsole.exe" before and after weaving.
Execute "DebugPropertyValueModifying/DoWeave.bat" to do the weaving.
TestConsole.exe running result before weaving:
Running OK!
Press any key to continue...
TestConsole.exe running result after weaving:
Name=
Name=name1
Name=name1
Name=name2
ID=0
ID=1
ID=1
ID=2
Speed=0
Speed=10
Speed=10
Speed=100.5
Speed=100.5
Speed=1221.12
Running OK!
Press any key to continue...
Download Source Code
- AOP Practice with AspectWeaver0.6 - DebugPropertyValueModifying
- Spring with AOP
- aop with annotation
- [CSS3 Practice] Slides Effect With Pure CSS3
- AOP - Interception with Unity 2.0
- english practice No.6
- practice
- practice
- Use Case Driven Object Modeling with UML: Theory and Practice
- some practice with django (still before the real world appears..)
- Best game to practice regular expression with fun
- Pat(Advanced Level)Practice--1023(Have Fun with Numbers)
- Pat(Advanced Level)Practice--1067(Sort with Swap(0,*))
- BDD practice with Beaf - next generation acceptable testing
- Penetration Testing Skills Practice with Metasploitable (Beginner Guide)
- Best Practice 6 Use JDBC connection pooling
- Best Practice 6 Use JDBC connection pooling
- Win32 GDI - Practice (I) Draw Arc with Two Points and Arc Radius
- 关于本Blog内容的声明、今后的发展方向及Teddy的其他相关站点
- AJAX设计模式实践 之 可刷新Ajax应用范例+Framework
- AJAX设计模式 之 怎样构建一个可刷新的无刷新应用
- 让人哭笑不得的“Unable to load one or more of the types in the assembly”问题的解决!
- 国庆庆祝一下
- AOP Practice with AspectWeaver0.6 - DebugPropertyValueModifying
- 从Design Pattern浅谈AOP
- 滑雪
- AOP编程实践之AspectWeaverSample1.0
- 高精度计时器---QueryPerformanceFrequency()与QueryPerformanceCounter()的使用
- Teddy's Aspect Weaver Version 0.6
- Teddy's Aspect Weaver Version 0.5
- Teddy's Aspect Weaver Version 0.3 with Great Updating and Fixing, Especially the Implementing of Getting Runtime Method Context
- Teddy's Aspect Weaver Version 0.2 with Additional Custom Attribute Way Configuration