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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T18:09:00+00:00 2026-05-29T18:09:00+00:00

say I have the attribute: public class Column_Attribute : Attribute { public string DbType

  • 0

say I have the attribute:

public class Column_Attribute : Attribute
{
    public string DbType { get; set; }
    public bool IsPrimaryKey { get; set; }
}

then I can apply that attribute to a property as:

 [Column_Attribute(DbType = "Integer", IsPrimaryKey = true)]
 public int Id { get; set; }   

Now how can I get information about the property Id from the attribute class. In other words I want to do something like:

public class Column_Attribute : Attribute
{
    // constructor
    public Column_Attribute(){
      // if the property has the name Id do something...
      // OR
      // if this is an attribute of a property do something
      // if this is an attribute of a field do something else

      // If this attribute is targeting a property that is a string do something
    }

    public string DbType { get; set; }
    public bool IsPrimaryKey { get; set; }
}

I actually need to know if the attribute is being applied to a property that is a string.

I know how to do that with reflection but I want to do that inside the attribute class. Is that possible. Hope I am explaining myself correctly

  • 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-29T18:09:01+00:00Added an answer on May 29, 2026 at 6:09 pm

    You cannot do that without reflection because the code in the constructor will not be executed until you call GetCustomAttributes(), which is a part of reflection.

    see http://msdn.microsoft.com/en-us/library/z919e8tw(v=vs.80).aspx

    Calling GetCustomAttributes on SampleClass causes an Author object to
    be constructed and initialized as above

    If you want your attribute class to contain the processing code, you could create a method receiving the property name. The property name will be available at the time of calling GetCustomAttributes().

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

Sidebar

Related Questions

Say I have this class: [AttributeUsage(AttributeTargets.Method)] public class MyAttribute : Attribute { public MyAttribute()
Lets say I have two classes: class A { [SortOrder(3)] public string Name {
Let's say I have a class; public class Car { public List<Passenger> Passengers {get;
Lets say have this immutable record type: public class Record { public Record(int x,
Say I have a class named Frog, it looks like: public class Frog {
Say I have: [Attribute1(Order=0)] public class Controller1 { [Attribute2] [Attribute3] public ActionResult Action1() {
Say I have a situation like so: [MyAttribute] public class MyClass { } [AttributeUssage(AttributeTargets.Class)]
I have a Spring bean, let's say: @TransactionAttribute(TransactionAttributeType.REQUIRED) public class AImpl implements A {
Let's say I have two EJBs A and B: public class A implements AInterface
Say I have a class with any number of properties of any type public

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.