473,327 Members | 2,025 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Properties, attributes and marker interfaces

Hi all,

I'm a little bit consfused as to when to use each of these options.
For example, if i want to decorate a class with some information,
I could decalre a const or read only field and have this information both at
run time and write time (compile time ;)), just like an attribute. And another
option is to use a marker interface to mark (decorate it).
So, when exactly should I use attributes?
I'm probably missing something here.

Thanks,
Ben
Dec 6 '07 #1
1 1769
Ben,

Attributes are used to provide additional metadata about the member that
they are applied to. Also, you can look that information up for the type at
runtime. With this, you can develop patterns of attribute usage from which
you can develop frameworks.

Take the Description attribute in the System.ComponentModel namespace.
If you apply the Description attribute to a member, it provides a
description for that member (of the type, not the instance).

The DataContract and DataMember attributes are used with the new
serialization model in .NET 3.0 to indicate what fields should be
serialized. Attributes are used in WCF to indicate what members of a
contract are exposed, and how.

In the end, an attribute is a part of the type definition, it is a piece
of data which is attached to a member of the type.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Ben" <Be*@discussions.microsoft.comwrote in message
news:EC**********************************@microsof t.com...
Hi all,

I'm a little bit consfused as to when to use each of these options.
For example, if i want to decorate a class with some information,
I could decalre a const or read only field and have this information both
at
run time and write time (compile time ;)), just like an attribute. And
another
option is to use a marker interface to mark (decorate it).
So, when exactly should I use attributes?
I'm probably missing something here.

Thanks,
Ben

Dec 6 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

25
by: Haines Brown | last post by:
I have a table with three columns, and I want the data in the first column to align left, while that in the remaining columns to align right: #testTable { text-align: right; } #leftcol {...
2
by: Haines Brown | last post by:
I have a list defined in a stylesheet that includes: li.down { list-style-image: url(../bin/arrow-f.png); } <ul> <li class="down">list item text </li> </ul>
2
by: Paul Selormey | last post by:
I have looked through the documents but could not find any information on this. Is anything like static properties in interfaces? If not, how do I define property in interface to be made static...
3
by: Martin Montgomery | last post by:
I have, for example, a property called myProperty. I would like, when using a property grid to display the property name as "My Property". Is this possible. Is there an attribute etc Thank ...
6
by: ~~~ .NET Ed ~~~ | last post by:
Yes, I think so at least... In C# you *can* have static properties which are quite useful when used properly. Now imagine the scenario where you need the ability (sp?) to implement a variety of...
2
by: Chris Fink | last post by:
I was wondering how the INamingContainer interface works when you are not required to implement any methods to perform the work. My understanding of interfaces is that they are a contract and you...
8
by: Chuck Bowling | last post by:
Is there any justification - from an OOP perspective - for wrapping an attribute in a Property beyond the ability to restrict access? private int myInt; public int MyInt { get { return...
9
by: Mark Jones | last post by:
This rather cryptic title is actually a .net oop noob question. Example: My customer object has a public property called .name which is a string. I would like to be able to reference...
20
by: Artur Siekielski | last post by:
Hi. I would like to have declarative properties in Python, ie. something like slots definitions in defclass in Common Lisp. It seems that even Java will have it, using a library (...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.