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. Inheriting attributes

Inheriting attributes

Scheduled Pinned Locked Moved C#
helpquestiondiscussion
2 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.
  • C Offline
    C Offline
    cnurse
    wrote on last edited by
    #1

    I've developed a simple attribute EwBindSkipAttr which is then used on an abstract member of a class, in the hope that all derived classes which must then implement this member will inherit the attribute on their overriding members. This seems to be correctly implemented...the documentation states that the default is for derived and overriding members to inherit attributes. Here's my simple attribute in use... /// /// Return DDL wrapper for table /// [EwBindSkipAttr] public abstract DataDDL DDL{get;} The problem is that in the derived classes I have behaviour which indicates that the attribute has not been inherited. Any thoughts please? Nursey

    H 1 Reply Last reply
    0
    • C cnurse

      I've developed a simple attribute EwBindSkipAttr which is then used on an abstract member of a class, in the hope that all derived classes which must then implement this member will inherit the attribute on their overriding members. This seems to be correctly implemented...the documentation states that the default is for derived and overriding members to inherit attributes. Here's my simple attribute in use... /// /// Return DDL wrapper for table /// [EwBindSkipAttr] public abstract DataDDL DDL{get;} The problem is that in the derived classes I have behaviour which indicates that the attribute has not been inherited. Any thoughts please? Nursey

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      Attributes are inheritted by nature, but code which gets and uses these attributes - like MemberInfo.GetCustomAttributes - provide parameters that specify whether or not the calling code wants to get inheritted parameters. What behavior is this that you mention? There's many things that can contribute to problems you're facing. Remember, attributes don't provide functionality to Types, they merely extend the metadata of a Type so that if something asks for it the attribute and its data is returned. Simply attributing your class with a custom attribute certainly won't do anything if nothing asks for it and uses it.

      Microsoft MVP, Visual C# My Articles

      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