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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:19:32+00:00 2026-05-13T10:19:32+00:00

Given a property in a class, with attributes – what is the fastest way

  • 0

Given a property in a class, with attributes – what is the fastest way to determine if it contains a given attribute? For example:

    [IsNotNullable]
    [IsPK]
    [IsIdentity]
    [SequenceNameAttribute("Id")]
    public Int32 Id
    {
        get
        {
            return _Id;
        }
        set
        {
            _Id = value;
        }
    }

What is the fastest method to determine that for example it has the “IsIdentity” attribute?

  • 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-13T10:19:32+00:00Added an answer on May 13, 2026 at 10:19 am

    There’s no fast way to retrieve attributes. But code ought to look like this (credit to Aaronaught):

    var t = typeof(YourClass);
    var pi = t.GetProperty("Id");
    var hasIsIdentity = Attribute.IsDefined(pi, typeof(IsIdentity));
    

    If you need to retrieve attribute properties then

    var t = typeof(YourClass);
    var pi = t.GetProperty("Id");
    var attr = (IsIdentity[])pi.GetCustomAttributes(typeof(IsIdentity), false);
    if (attr.Length > 0) {
        // Use attr[0], you'll need foreach on attr if MultiUse is true
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to know where is set a given PHP config property?
I am given: A class T which implements properties that are decorated with Attributes
Given that one can define a class in VB Script, is there any way
D2.0 classes have a __monitor class property that gives access to the class object's
I have given a table background image using css background-image property. The cells are
In VBA Help for the RefersTo Property, they give this example of listing all
Getting attributes using minidom in Python, one uses the attributes property. e.g. node.attributes[id].value So
Given these relationships: class Account < ActiveRecord::Base has_many :employments has_many :people, :through => :employments
Given an entity framework 4.0 code first entity public class MyEntity { [Key] public
I need to add a custom property to an Entity Framework class, however when

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.