Created
May 28, 2010 22:34
-
-
Save jfromaniello/417842 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Reflection; | |
using System.Text; | |
using NUnit.Framework; | |
using PostSharp.Aspects; | |
using PostSharp.Aspects.Advices; | |
using PostSharp.Aspects.Dependencies; | |
using PostSharp.Extensibility; | |
namespace PostSharpMethodExecutionTagIssue | |
{ | |
[TestFixture] | |
public class TestCase | |
{ | |
[SampleAspect] | |
public class Test | |
{ | |
public void SayHello() | |
{ | |
Console.WriteLine("hello"); | |
} | |
} | |
[Serializable] | |
[AttributeUsage(AttributeTargets.Class, Inherited = true, AllowMultiple = false)] | |
[MulticastAttributeUsage( | |
MulticastTargets.Class, | |
TargetMemberAttributes = MulticastAttributes.Public, | |
AllowMultiple = false, | |
PersistMetaData = true)] | |
public class SampleAspectAttribute : InstanceLevelAspect | |
{ | |
private static readonly object methodMark = new object(); | |
[AspectTypeDependency(AspectDependencyAction.Commute, typeof(SampleAspectAttribute))] | |
[MethodPointcut("GetMethods")] | |
[OnMethodEntryAdvice] | |
public void OnEntry(MethodExecutionArgs eventArgs) | |
{ | |
eventArgs.MethodExecutionTag = methodMark; | |
} | |
[AspectTypeDependency(AspectDependencyAction.Commute, typeof(SampleAspectAttribute))] | |
[MethodPointcut("GetMethods")] | |
[OnMethodSuccessAdvice] | |
public void OnSuccess(MethodExecutionArgs eventArgs) | |
{ | |
Assert.AreSame(methodMark, eventArgs.MethodExecutionTag); | |
} | |
public IEnumerable<MethodInfo> GetMethods(Type type) | |
{ | |
return type.GetMethods(BindingFlags.NonPublic | BindingFlags.Public | |
| BindingFlags.Instance | BindingFlags.Static) | |
.Where(m => m.DeclaringType == type); | |
} | |
} | |
[Test] | |
public void should_work() | |
{ | |
var test = new Test(); | |
test.SayHello(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment