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. custom attribute question

custom attribute question

Scheduled Pinned Locked Moved C#
questionhelptutorial
3 Posts 2 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.
  • S Offline
    S Offline
    sharkfish
    wrote on last edited by
    #1

    Is it possible to define an attribute that describes a property of a class at runtime? For example, you have a class called "employee", and it has a property "name". The "name" property has an attribute that tells any calling code whether or not this property is "writable" and/or "readable", even though this property has both get/set accessors. Maybe there is another way to do this, and I just don't have enough experience. Any help is appreciated.

    A 1 Reply Last reply
    0
    • S sharkfish

      Is it possible to define an attribute that describes a property of a class at runtime? For example, you have a class called "employee", and it has a property "name". The "name" property has an attribute that tells any calling code whether or not this property is "writable" and/or "readable", even though this property has both get/set accessors. Maybe there is another way to do this, and I just don't have enough experience. Any help is appreciated.

      A Offline
      A Offline
      Alex Korchemniy
      wrote on last edited by
      #2

      For what you are trying to do, I suggest that you should try to avoid using attributes

      S 1 Reply Last reply
      0
      • A Alex Korchemniy

        For what you are trying to do, I suggest that you should try to avoid using attributes

        S Offline
        S Offline
        sharkfish
        wrote on last edited by
        #3

        Is there a way to set a property of a property, at runtime, then? This is what I REALLY want to do, but I believe this is not possible: [AttributeUsage(AttributeTarget.Property,Inherited=true,AllowMultiple=true)] public class SecurityInfoAttribute : Attribute { // Private Data private int readable; private int writable; // Constructor public SecurityInfoAttribute(int readable, int writable) { this.security_readable = 0; this.security_writable = 0; } public int Readable { get { return readable; } set { readable = value; } } public int Writable { get { return writable; } set { writable = value; } } } public class employee { string name; [SecurityInfo(getReadSecurityInfo(userId), getWriteSecurityInfo(userId))] string Name{get{return name;}set{name = value;}} }

        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