MrAdvice icon indicating copy to clipboard operation
MrAdvice copied to clipboard

Excluding properties weaving attribute on the level of class

Open hhblaze opened this issue 8 years ago • 8 comments

Some more optimization thoughts (may be it's already possible, but I don't know how to achieve that).

In my scenario the advice is applied on the complete assembly. I have only one IMethod advice, but it's applied to all methods, properties and .actors after weaving (it is correct). Mentioned method (with dropped down performance) has a loop inside that creates 1000 objects of one type. This type is a POCO class with 20 properties and a constructor. Properties are quite simple, something like "public bool MyProperty {get; set;}" and I am ready to declare them as safe. Mr.Advice applies the advice on each of them. I would like to exclude those properties from weaving, but without un-decorating each of them. I know that there is an exclusion attribute in Mr.Advice, but is there a way to exclude from weaving class only properties leaving methods? So, such attribute must be on the level of a class.

taken from https://github.com/ArxOne/MrAdvice/issues/97#issuecomment-286679643

hhblaze avatar Mar 15 '17 10:03 hhblaze

You can try [ExcludePointcut("*.get_@","*.set_@")] on your advice, this will exclude methods whose name starts with set_ and get_ from it.

picrap avatar Mar 15 '17 14:03 picrap

Very well, thank you!

hhblaze avatar Mar 15 '17 16:03 hhblaze

Did it work? If yes, you can close the issue.

picrap avatar Mar 16 '17 07:03 picrap

This technique is very useful.

I need a bit other scenario, by default all assembly properties must be weaved by the aspect - it's important from security point of view and code observation. But, actually there is no necessity to weave such "public bool MyProperty {get;set}", for try-catch aspect. In such, "public bool MyProperty { get { return _myprop == "test" }}" (in this strange example _myprop can be null and it should lead to unhandled exception), such try-catch aspect with logging is very important here. From the statistic point of view, "passive" properties like "public bool MyProperty {get;set}" are most common. I close the issue with the soaring in the air: ... would be cool, if Mr.Aspect could distinguish between passive and active properties (by signature..don't know) and could apply corresponding configured behaviors..

hhblaze avatar Mar 16 '17 09:03 hhblaze

Do you mean use the [CompilerGenerated] as a selection criterion? So for example we could include or exclude everything that was generated.

picrap avatar Mar 16 '17 09:03 picrap

[CompilerGenerated] looks like a good idea!

hhblaze avatar Mar 16 '17 09:03 hhblaze

I think, that behavior must be specified per aspect how to react on [CompilerGenerated].

hhblaze avatar Mar 16 '17 09:03 hhblaze

Yes, using the [ExcludePointcut] (or [IncludePointcut]).

picrap avatar Mar 16 '17 09:03 picrap