How to access Attribute data from within a method

rhh's Avatar


26 Jun, 2018 08:42 AM

I have the following code :

    public sealed class TraceAspect : OnMethodBoundaryAspect
           public Dictionary<string, object> tt
                = new Dictionary<string, object>();

        public override void OnEntry(MethodExecutionArgs args)
            tt.Add("WebServiceName", args.Method.DeclaringType.Namespace);
            for (int x = 0; x < args.Arguments.Count; x++)
                // ignore ref parameters
                if (!args.Method.GetParameters()[x].ParameterType.IsByRef)
                    tt.Add(args.Method.GetParameters()[x].Name, args.Arguments.GetArgument(x));


And this is used by my code in this way in a web service :

 public bool TestFunction(string CentralCode, string FromStreet, string FromZip, double FromLatitude, double FromLongitude, short FromZoneNo, string ToStreet, string ToZip, double ToLatitude, double ToLongitude, short ToZoneNo)


Now, how can I in TestFunction get the value of tt declared in my TraceAspect class ?

This is web services so multiple instances of the method can be active on the same time...


  1. Support Staff 1 Posted by PostSharp Techn... on 27 Jun, 2018 05:11 PM

    PostSharp Technologies's Avatar


    The behavior you're trying to achieve is not really compatible with the general design of PostSharp aspects and Aspect Oriented Programming. The aspects are normally used to augment the behavior of the target methods in an orthogonal way - the target methods are not supposed to be aware of the aspects applied.

    Could you please describe what is your end goal and why are you trying to implement this behavior? There may be another approach that better fits the design.

    Please also note that we can provide only commercial level support on this forum. We didn't find a commercial license associated with your email in our CRM. Please let us know if this is a mistake. Otherwise, we will be happy to answer your questions on StackOverflow website:

    Best regards,

  2. 2 Posted by rhh on 27 Jun, 2018 06:29 PM

    rhh's Avatar


    Thanks for your feedback.

    I have updated the question on stackoverflow as requested with another approach working almost ok, but not quite as I can't get the method to return desired results.


    Rolf Hjemdahl
    Transport Data Systems AS

    -----Opprinnelig melding-----
    Fra: PostSharp Technologies [mailto:[email blocked]]
    Sendt: onsdag 27. juni 2018 19.12
    Til: Rolf Hjemdal <[email blocked]>
    Emne: [PostSharp Support] How to access Attribute data from within a method

  3. Support Staff 3 Posted by PostSharp Techn... on 28 Jun, 2018 05:51 PM

    PostSharp Technologies's Avatar

    Closing discussion as the question is answered on StackOverflow:


  4. PostSharp Technologies closed this discussion on 28 Jun, 2018 05:51 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac