Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Reflection - dynamically adding custom attributes

Reflection - dynamically adding custom attributes

Scheduled Pinned Locked Moved C#
question
8 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    imak
    wrote on last edited by
    #1

    Is it possible to dynamically adding custom attributes to class methods or properties? If so any examples will be appreciated.

    N L A U C 5 Replies Last reply
    0
    • I imak

      Is it possible to dynamically adding custom attributes to class methods or properties? If so any examples will be appreciated.

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      No


      I know the language. I've read a book. - _Madmatt

      I 1 Reply Last reply
      0
      • N Not Active

        No


        I know the language. I've read a book. - _Madmatt

        I Offline
        I Offline
        Ian Shlasko
        wrote on last edited by
        #3

        Man, way to crush his dreams ;P

        Proud to have finally moved to the A-Ark. Which one are you in?
        Author of the Guardians Saga (Sci-Fi/Fantasy novels)

        1 Reply Last reply
        0
        • I imak

          Is it possible to dynamically adding custom attributes to class methods or properties? If so any examples will be appreciated.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Try This [^]

          I know nothing , I know nothing ...

          N 1 Reply Last reply
          0
          • I imak

            Is it possible to dynamically adding custom attributes to class methods or properties? If so any examples will be appreciated.

            A Offline
            A Offline
            AspDotNetDev
            wrote on last edited by
            #5

            Would compiling code at runtime suffice (e.g., creating a new class with methods/properties that have the custom attributes)? That can be done.

            [Forum Guidelines]

            1 Reply Last reply
            0
            • L Lost User

              Try This [^]

              I know nothing , I know nothing ...

              N Offline
              N Offline
              Not Active
              wrote on last edited by
              #6

              This is using codedom to write code dynamically not dynamically adding an attribute to existing code. They are not equal.


              I know the language. I've read a book. - _Madmatt

              1 Reply Last reply
              0
              • I imak

                Is it possible to dynamically adding custom attributes to class methods or properties? If so any examples will be appreciated.

                U Offline
                U Offline
                User 2676586
                wrote on last edited by
                #7

                don't kill the pianist, but I thing I did somethings related to this. It was some time ago and I don't have that resources, but here is the catch. There was a way to specify what property "descriptor" to use for a specific class. From that class, you call the default property descriptor and modify the returned list of attributes as you wish. Sorry if the terms are not quite accurate but they may bring up someone [else?] idea about how to do this.

                1 Reply Last reply
                0
                • I imak

                  Is it possible to dynamically adding custom attributes to class methods or properties? If so any examples will be appreciated.

                  C Offline
                  C Offline
                  Chris Trelawny Ross
                  wrote on last edited by
                  #8

                  If it's possible to dynamically add custom attributes to a class, you'll be jumping through so many hoops to do so that perhaps a better question to ask is: "am I trying to do something I shouldn't be trying to do?" Also, by attempting to do something so far "outside the box" of .Net programming as it was intended by MS that you'll potentially be creating a maintenance problem for whoever works on the code after you. If you need to dynamically decorate a type, property, etc. with attribute-like information, perhaps a wiser design is to implement your own repository of such information (perhaps a static Dictionary<MemberInfo, MyCustomAttribute>, or some such). If necessary, you can initialize it from the complier-built attributes, but that should be the end of your logic's relationship with attributes. Just a thought.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups