0

Let's say I have an interface:

namespace MyCompany.Security
{
    public interface IMySecurable
    {
        string GetContext();
    }
}

Which is implemented by a number of classes, e.g.

namespace MyCompany.Repositories
{
    using System.Collections.Generic;
    using MyCompany.Security;

    public class MyRepository : IMySecurable
    {
        public IEnumerable<string> GetAll()
        {
            // Repository logic
        }

        string IMySecurable.GetContext()
        {
            // Logic here
        }
    }
}

I'm using PostSharp attribute multicasting to apply my aspect (MySecurityAspect) to each class in a namespace.

[assembly: MySecurityAspect(AttributeTargetTypes = "MyCompany.Repositories.*", AttributePriority = 1)]

However I'm unable to figure out how to exclude explicit interface method implementations i.e.

string IMySecurable.GetContext()
{
    // Logic here
}

I have tried following the documentation here, using this statement:

[assembly: MySecurityAspect(AttributeTargetMembers = "GetContext", AttributeExclude = true, AttributePriority = 2)]

However this doesn't seem to work.

How can I exclude methods using attribute multicasting when they are explicit interface implementations?

Brett Postin
  • 11,215
  • 10
  • 60
  • 95

1 Answers1

0

According to http://support.sharpcrafters.com/discussions/questions/306-suppress-some-exception-logging-in-diagnostic-toolkit-configuration

The attribute with exclude set to true effects only what was processed to the point of occurrence of the exclude i.e. exclude will effect only attributes occurring prior to exclude.

In other words, order of attributes is important.

If it wouldn't help, ask the question directly on http://support.sharpcrafters.com.

BTW: I found that to specify Postsharp aspects in PSProj file is more flexible, than adding attributes in a code.

Michael Freidgeim
  • 26,542
  • 16
  • 152
  • 170
  • Thanks for the suggestion although it doesn't really help. I have a support request open [here](http://support.sharpcrafters.com/discussions/questions/521-override-base-class-aspect-in-derived-class). – Brett Postin Aug 12 '13 at 09:30