CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2008
    Posts
    26

    Do have this sequence correct?

    namespace.object.method.attribute

    For insatance if i'm "using System;" namespace its then object.method, the question is to use attributes is it then object.method.attribute?


    Ya, <-- n00b so thx for any help hehe

  2. #2
    Join Date
    Nov 2002
    Location
    .NET 3.5 VS2008
    Posts
    1,039

    Re: Do have this sequence correct?

    What do you mean by attritube? Do you mean an attribute to the class? Is so it is object.attribute. What material are you using to learn?

  3. #3
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    Re: Do have this sequence correct?

    If you mean the attribute with which the method is annotated (e.g. [OperationContract]), then you have to use reflection to obtain it. Like this:
    Code:
    Type t = Type.GetType("namespace.object"); // assume by object you mean class
    MethodInfo mi = t.GetMethod("YourMethodName");
    object[] attrs = mi.GetCustomAttributes(false);
    // and now, you can iterate over attrs and investigate them
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured