Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7056373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:51:34+00:00 2026-05-28T03:51:34+00:00

I need to create some custom attributes, to be used for my reflection functions.

  • 0

I need to create some custom attributes, to be used for my reflection functions.

Here is the usecase, as I see it:

  • the user creates some class and marks it with my special attribute ([ImportantAttribute] for example)
  • then the user does something with functions from my library. Those functions find classes with [ImportantAttribute] and do something with them

The main problem is that functions in my library expects, that classes wich was marked with [ImportantAttribute] inherit my interface (IMyInterface for example)

Is there any way to let user know if he mark his class with [ImportantAttribute] and forget to inherit IMyInterface during compilation, not in run time. Some way to specify that this attribute is only for classes that inherit IMyInterface.

Same with attributes for properties and fields.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T03:51:35+00:00Added an answer on May 28, 2026 at 3:51 am

    I’ve used the strategy you mention in a couple of the frameworks I’ve built with good success. One such example is for providing metadata to a plug-in infrastructure:

    [AttributeUsage(AttributeTargets.Class, AllowMultiple=false, Inherited=false)]
    public class PluginAttribute : Attribute
    {
        public string DisplayName { get; set; }
        public string Description { get; set; }
        public string Version { get; set; }
    }
    
    public interface IPlug
    {
        void Run(IWork work);
    }
    
    [Plugin(DisplayName="Sample Plugin", Description="Some Sample Plugin")]
    public class SamplePlug : IPlug
    {
        public void Run(IWork work) { ... }
    }
    

    Doing so allows me to figure out information about plug-ins without having to instantiate them and read metadata properties.

    In my experience in doing so, the only way I’ve found to enforce that both requirements are met is to perform runtime checks and make sure it is bold and <blink>blinking</blink> in the documentation. It is far from optimal but it is the best that can be done (that I’ve found). Then again I’m sure there is a better way to go about handling this but so far this has been pretty solid for me.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Into a class constructor, I need to create some objects on the fly and
I'm trying to create a form with some custom data attributes on the inputs:
I need to create some windows service which will execute every N period of
I need to create some mini-windows, like the ones shown in the image bellow,
When I am testing my DAL I need to create some database entities before
In a PHP project I'm working on we need to create some DAL extensions
For a Website I'm developing, I will need to create some graphics. I haven't
I have several web services I need to create for them some testing mechanism
I need to create an SQL query to insert some data into a table
I need to create a slide show of some images that can go full

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.