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

  • SEARCH
  • Home
  • 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 790863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:44:39+00:00 2026-05-14T21:44:39+00:00

I have an attribute lets call it SomeAttribute and a class i need to

  • 0

I have an attribute lets call it SomeAttribute and a class i need to make sure the class is passed a type which has SomeAttribute. So this is how i do it now:

public class Test()
{
    public Test(SomeType obj)
    {
        if(!obj.GetType().IsDefined(typeof(SomeAttribute), false))
        {
            throw new ArgumentException("Errormessage");
        }
    }
}

But this means that i don’t get any errors at compile time but somewhere at runtime, if obj does not have the attribute. Is there a way to specify in the method declaration that the parameter must have some attribute ? So i get errors i compile time when using the wrong parameters, or do i have to use an empty interface ?

  • 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-14T21:44:39+00:00Added an answer on May 14, 2026 at 9:44 pm

    No, there’s no way of requiring an attribute – but you could always write unit tests to scan through your assemblies and check that the appropriate attributes had been applied – assuming you can actually detect this requirement.

    It sounds somewhat odd though – could you give some more details as to why you’re using this scheme? Perhaps another approach would be more appropriate, such as another parameter to describe the extra data you’re interested in.

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

Sidebar

Ask A Question

Stats

  • Questions 508k
  • Answers 509k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer As far as I know, there's a SendAsync method in… May 16, 2026 at 4:31 pm
  • Editorial Team
    Editorial Team added an answer WPF is very advanced GUI framework, it gives more flexibility… May 16, 2026 at 4:31 pm
  • Editorial Team
    Editorial Team added an answer Struts binds the request parameters onto the ActionForm object based… May 16, 2026 at 4:31 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have an AUDIO class. This audio has a SOUND_A subclass and a SOUND_B
I have a some code that gets passed a class derived from a certain
Lets say I have three django model classes - lets call them A, B
I have an abstract class. Let's call it Lifeform. It looks something like: public
I can't see why this isn't working. I have two entities, let's call them
Lets say I have this XML file: <weather> <temp>24.0</temp> <current-condition iconUrl=http://....>Sunny</current-condition> </weather> I'm trying
I have a VS 2005/MSBuild 2.0 project (let's call it Project A) that I
I have three pages on my site. Let's call them home, page2, and page3.
I have a very basic question about binding between controls. I have a class
Sorry for the bad title, but I have no idea how to put this

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.