Teddy's Aspect Weaver Version 0.3 with Great Updating and Fixing, Especially the Implementing

Source: Internet
Author: User

[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 ");
Object [] args = GetArguments ();
Console. Write (string. Format ("Arguments: {0}, {1}, {2} \ 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 "));
Object [] locals = new object [] {p1, p2, p3 };
Console. Write (String. Format ("Arguments: {0}, {1}, {2} \ 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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.