AttributeUsage question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Henrik Dahl

    #1

    AttributeUsage question

    Hello!

    I'm making my own attribute. I've observed that the AttributeUsage attribute
    may only be applied to classes which derive from System.Attribut e. How do I
    make my attribute in a resembling way, so it may only be applied to classes
    which implement a certain interface?


    Best regards,

    Henrik Dahl


  • Mattias Sjögren

    #2
    Re: AttributeUsage question

    >I'm making my own attribute. I've observed that the AttributeUsage attribute[color=blue]
    >may only be applied to classes which derive from System.Attribut e. How do I
    >make my attribute in a resembling way, so it may only be applied to classes
    >which implement a certain interface?[/color]

    You can't. AttributeUsage gets special treatment from the compiler.



    Mattias

    --
    Mattias Sjögren [MVP] mattias @ mvps.org
    http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
    Please reply only to the newsgroup.

    Comment

    • Henrik Dahl

      #3
      Re: AttributeUsage question

      OK.

      Do you know if it's possible, for a specific instance of an attribute, to
      figure out what it's actually attributing (execpt e.g. reflection driven
      traversal in some exhaustive way of course)?


      Best regards,

      Henrik Dahl

      "Mattias Sjögren" <mattias.dont.w ant.spam@mvps.o rg> wrote in message
      news:u9Z4NCLUFH A.1040@TK2MSFTN GP10.phx.gbl...[color=blue][color=green]
      > >I'm making my own attribute. I've observed that the AttributeUsage[/color][/color]
      attribute[color=blue][color=green]
      > >may only be applied to classes which derive from System.Attribut e. How do[/color][/color]
      I[color=blue][color=green]
      > >make my attribute in a resembling way, so it may only be applied to[/color][/color]
      classes[color=blue][color=green]
      > >which implement a certain interface?[/color]
      >
      > You can't. AttributeUsage gets special treatment from the compiler.
      >
      >
      >
      > Mattias
      >
      > --
      > Mattias Sjögren [MVP] mattias @ mvps.org
      > http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
      > Please reply only to the newsgroup.[/color]


      Comment

      • Mattias Sjögren

        #4
        Re: AttributeUsage question

        [color=blue]
        >Do you know if it's possible, for a specific instance of an attribute, to
        >figure out what it's actually attributing (execpt e.g. reflection driven
        >traversal in some exhaustive way of course)?[/color]

        No it isn't, unless you pass it that information.



        Mattias

        --
        Mattias Sjögren [MVP] mattias @ mvps.org
        http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
        Please reply only to the newsgroup.

        Comment

        • Henrik Dahl

          #5
          Re: AttributeUsage question

          Thank you again!

          I think it would be rather convenient with a read only property of
          System.Attribut e for giving this.


          Best regards,

          Henrik Dahl

          "Mattias Sjögren" <mattias.dont.w ant.spam@mvps.o rg> wrote in message
          news:ON2z2SLUFH A.2892@TK2MSFTN GP14.phx.gbl...[color=blue]
          >[color=green]
          > >Do you know if it's possible, for a specific instance of an attribute, to
          > >figure out what it's actually attributing (execpt e.g. reflection driven
          > >traversal in some exhaustive way of course)?[/color]
          >
          > No it isn't, unless you pass it that information.
          >
          >
          >
          > Mattias
          >
          > --
          > Mattias Sjögren [MVP] mattias @ mvps.org
          > http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
          > Please reply only to the newsgroup.[/color]


          Comment

          • Mattias Sjögren

            #6
            Re: AttributeUsage question

            Henrik,
            [color=blue]
            >I think it would be rather convenient with a read only property of
            >System.Attribu te for giving this.[/color]

            Yeah, you're not the first person to ask for it. If it hasn't been
            done already, why don't you post a suggestion over at the Product
            Feedback Center http://lab.msdn.microsoft.com/productfeedback/



            Mattias

            --
            Mattias Sjögren [MVP] mattias @ mvps.org
            http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
            Please reply only to the newsgroup.

            Comment

            Working...