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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:06:14+00:00 2026-06-05T12:06:14+00:00

I’ve never used C# attributes, but understand that they are the rough equivalent of

  • 0

I’ve never used C# attributes, but understand that they are the rough equivalent of Java annotations.

If I proceed with the port using attributes to replace annotations, what do I need to know? What’s going to be the same? Different? What’s going to bite me?

As for as my research i found that

C# uses the ConditionalAttribute attribute that is driven from compile time symbols

i just want to know whether can we write annotation on our own and
which versions of dotnet supports it?

It is appreciated that if i got any samples or documents to read

Waiting for your valuable response and comments

  • 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-06-05T12:06:15+00:00Added an answer on June 5, 2026 at 12:06 pm

    Yes, you can write your own attributes – you just inherit from Attribute, i.e.

    public class FooAttribute : Attribute {
        public int Bar {get;set;}
    }
    

    then you can attach that:

    [Foo(Bar=12)]
    public int X {get;set;}
    

    (see also AttributeUsageAttribute if you want to limit what it can be applied to – for example to classes, fields, interfaces, etc)

    Note that while some attributes (ConditionalAttribute, ObsoleteAttribute, etc) have meaning to the compiler, you cannot write your own compile-time features with attributes, except via 3rd-party tools such as PostSharp. What you can do is check for the attribute at runtime via reflection (in particular, Attribute.GetCustomAttribute[s]), and react accordingly with code. Most attributes are used in this way by reflection.

    foreach(var prop in type.GetProperties()) {
        var foo = (FooAttribute)Attribute.GetCustomAttribute(
                            prop, typeof(FooAttribute));
        if(foo != null) {
            Console.WriteLine("{0} has Foo.Bar: {1}", prop.Name, foo.Bar);
        }
    }
    

    All versions of .NET support attributes, although in some of the limited frameworks you might find some of the BCL attributes are missing if not required. For example, DataContractAttribute doesn’t exist on a platform that doesn’t support WCF via DataContractSerializer.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have thousands of HTML files to process using Groovy/Java and I need to
I am using Paperclip to handle profile photo uploads in my app. They upload
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

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.