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 349021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:25:10+00:00 2026-05-12T11:25:10+00:00

I am trying to determine the type of a property which an attribute relates

  • 0

I am trying to determine the type of a property which an attribute relates to, from within the attributes constructor. More specificity I am looking for the class which contains the property.

my current constructor looks like this:

    public IndexedCategoryAttribute(Type DefiningClass, String HeaderText, int Index)
    {

        this._definingClass = DefiningClass;

however I want it to look like:

   public IndexedCategoryAttribute(String HeaderText, int Index)
    {

        PropertyInfo Info = ???
        this._definingClass = Info.DeclaringType;

I believe that this will provide safer code for users of the attribute since at present it requires a ‘typeof(MyClass)’ in the the Attribute definition, which opens the posiblity of the wrong type being supplied?

For further information, I am using this with the propertygrid. The type is used in a static Dictionary<Type, Dictionary<String, int>> for grouping category’s to the class they relate to.

  • 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-12T11:25:10+00:00Added an answer on May 12, 2026 at 11:25 am

    I don’t think attributes, when instantiated, can know the type or property to which they are being associated.

    The relationship goes the other way:

    • properties have attributes
    • types have attributes
    • methods have attributes

    Attributes do not “have” types.

    When building your grid, you should do the scan in the opposite direction from what you proposed. For each type in your set, you can reflect to determine the attributes attached to the type (or dive into attributes on the property), and if those attributes are your category attribute, add to the dictionary.

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

Sidebar

Related Questions

I want determine the type of an attribute in a class. I am using
I'm trying to retrieve a custom Attribute set on a page's class from inside
I'm trying to write a function in python, which will determine what type of
I'm trying to determine the current paper type selection on the default printer using
I am trying to determine a file's mime type. I've tried a few methods,
I am trying to map mediumblob in MYSQL with type='mediumblob' in Hibernate property file
I'm trying to figure out how to determine exactly what property name should be
Im trying to determine the mime type of an image: $image = $_FILES['image']; //code
I have this entity - I'm trying to determine the type of its properties
I'm trying to determine if the MethodInfo object that I get from a GetMethod

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.