CompoundAspect and adding OnMethodInvocation
5 posts • Page 1 of 1
CompoundAspect and adding OnMethodInvocation
I've written a simple Compoundaspect that adds an OnMethodinvocation. In my simple test program:
Only the call to Fred<int>.Add is woven, the call to List<int>.Add is not. Both methods appear to have the OnMethodInvocation aspect added.
- Code: Select all
static void Main(string[] args)
{
List<int> a = new List<int>();
a.Add(42);
Fred<int> b = new Fred<int>();
b.Add(42);
}
Only the call to Fred<int>.Add is woven, the call to List<int>.Add is not. Both methods appear to have the OnMethodInvocation aspect added.
- Code: Select all
[AttributeUsage(AttributeTargets.Assembly)]
[MulticastAttributeUsage(MulticastTargets.Assembly)]
public class apply : CompoundAspect
{
private void WeaveAdd(Type t, LaosReflectionAspectCollection collection)
{
foreach (MethodInfo m in t.GetMethods())
{
if (m.Name == "Add")
{
collection.AddAspect(m, new Hook());
}
}
}
public override void ProvideAspects(object element, LaosReflectionAspectCollection collection)
{
Assembly assy = element as Assembly;
foreach (Type t in assy.GetTypes())
{
if (t.Name.Contains("Fred"))
{
WeaveAdd(t, collection);
}
}
foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies())
{
foreach (Type t in a.GetTypes())
{
if (t.ToString().Contains("Generic.List`1["))
{
WeaveAdd(t, collection);
}
}
}
}
}
You do not have the required permissions to view the files attached to this post.
- ddignam
- Posts: 16
- Joined: Mon Apr 07, 2008 5:07 pm
- Full Name: Daniel Dignam
- Company: Solidworks
Re: CompoundAspect and adding OnMethodInvocation
If I do the weave via this approach
Then it works, so it can be achieved.
--
Dan
- Code: Select all
[assembly: ConsoleApplication2.Hook(AttributeTargetAssemblies = "mscorlib", AttributeTargetTypes = "System.Collections.Generic.List*", AttributeTargetMembers = "Add")]
Then it works, so it can be achieved.
--
Dan
- ddignam
- Posts: 16
- Joined: Mon Apr 07, 2008 5:07 pm
- Full Name: Daniel Dignam
- Company: Solidworks
Re: CompoundAspect and adding OnMethodInvocation
Gael Fraiteur, project leader
got good support? consider donating to the project.
got good support? consider donating to the project.
- gfraiteur
- Site Admin
- Posts: 673
- Joined: Tue Dec 18, 2007 3:09 pm
- Full Name: Gael Fraiteur
- Company: postsharp.org
Re: CompoundAspect and adding OnMethodInvocation
Thanks as ever for the great product and support!
I've also reported http://www.postsharp.org/tracker/view.php?id=231 which may be related. Applying an aspect to an external generic method can lead to a corrupt image being generated
--
Dan
- ddignam
- Posts: 16
- Joined: Mon Apr 07, 2008 5:07 pm
- Full Name: Daniel Dignam
- Company: Solidworks
Re: CompoundAspect and adding OnMethodInvocation
Hi Gael,
I installed 393 and the OnMethodInvocation is now being weaved, but I get an InvalidProgramException at runtime
I've reported this, with a reproducer, as
http://www.postsharp.org/tracker/view.php?id=233
--
Dan
- ddignam
- Posts: 16
- Joined: Mon Apr 07, 2008 5:07 pm
- Full Name: Daniel Dignam
- Company: Solidworks
5 posts • Page 1 of 1