473,385 Members | 1,782 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,385 software developers and data experts.

Custom Attributes

Could someone please give me a practical example of how you HAVE used custom
attributes ... not just how you COULD use them. I understand the syntax,
but am not able to visualize a good use for them.

Thanks in advance.

Mark
Nov 17 '05 #1
4 2038
Mark,

I've used them extensively on enumeration values, used in a class
factory pattern (I use the enumeration value as the key). It definitely is
a better way to store comples static information, IMO. This way, you don't
have to go through the mess of populating your data structures and creating
the backing store for them.

That's just one use. I've used them to provide interception-like
capabilities, as well as in plug in architectures (to indicate how a type
will fit into the architecture, and provide some default capabilities).

There are plenty of uses out there for attributes. It's really a great
feature to have in the framework, since the uses are pretty vast.

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

"mark" <fi******@removethisforspam.umn.edu> wrote in message
news:eu*************@TK2MSFTNGP15.phx.gbl...
Could someone please give me a practical example of how you HAVE used
custom attributes ... not just how you COULD use them. I understand the
syntax, but am not able to visualize a good use for them.

Thanks in advance.

Mark

Nov 17 '05 #2
In message <eu*************@TK2MSFTNGP15.phx.gbl>, mark
<fi******@removethisforspam.umn.edu> writes
Could someone please give me a practical example of how you HAVE used custom
attributes ... not just how you COULD use them. I understand the syntax,
but am not able to visualize a good use for them.


I wrote a program for my former employer which generated install scripts
to add our framework components to the Global Assembly Cache and to
register in COM+ those which needed it. I created custom attributes with
which to mark assemblies to indicate which server the components were to
be installed upon and whether they were to be installed in COM+.

--
Steve Walker
Nov 17 '05 #3
Hello Mark,

Attributes are also used for Aspect Oriented Programming, you can intercept
calls to a specific method and run some custom code before or after the execution.
Here is an open source project for AOP in c#:
http://www.castleproject.org/index.php/AspectSharp

Regards,
-----
Ariel Popovsky
Could someone please give me a practical example of how you HAVE used
custom attributes ... not just how you COULD use them. I understand
the syntax, but am not able to visualize a good use for them.

Thanks in advance.

Mark

Nov 17 '05 #4
I agree with Nicholas, it's a fantastic feature to have in the framework

As another example, very early on in my .NET development, I created a
generic data access layer that used attributes to map properties and fields
of a class to a table and columns of a table. It's not really the most
efficient way to handle it (reflection can be expensive, in terms of
performance), but it was a good solution at the time.

When I first started doing C# programming and I read about attributes and
reflection, I thought, "Well, that sounds kind of neat, but I don't really
see how useful it could be." Now I don't know how I ever got by without it.

Pete
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:OQ*************@TK2MSFTNGP15.phx.gbl...
Mark,

I've used them extensively on enumeration values, used in a class
factory pattern (I use the enumeration value as the key). It definitely
is a better way to store comples static information, IMO. This way, you
don't have to go through the mess of populating your data structures and
creating the backing store for them.

That's just one use. I've used them to provide interception-like
capabilities, as well as in plug in architectures (to indicate how a type
will fit into the architecture, and provide some default capabilities).

There are plenty of uses out there for attributes. It's really a great
feature to have in the framework, since the uses are pretty vast.

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

"mark" <fi******@removethisforspam.umn.edu> wrote in message
news:eu*************@TK2MSFTNGP15.phx.gbl...
Could someone please give me a practical example of how you HAVE used
custom attributes ... not just how you COULD use them. I understand the
syntax, but am not able to visualize a good use for them.

Thanks in advance.

Mark


Nov 17 '05 #5

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

Similar topics

5
by: Doug Holland | last post by:
Often you see code where an empty interface is used to indicate something about the class that realizes it. In the .NET world this can be done with custom attributes too, so which is better: ...
3
by: xAvailx | last post by:
I apologize ahead of time for the long post... Background: Working on a CRM type custom application. The application is for an event management company. The company will provide the application...
8
by: nicolas.sanguinetti | last post by:
Hi, I want to add custom attributes to my xhtml documents to use with my DOM scripts. For example, I want to have some tags -say, the <h1>- have an attribute and a . The thing is that I also...
1
by: Bret Pehrson | last post by:
I've converted a non-trivial C++ library to managed, and get the following unhelpful linker error: Assignment.obj : error LNK2022: metadata operation failed (80131195) : Custom attributes are...
3
by: Edward Diener | last post by:
I understand the syntax of custom attributes, but I have no idea what they are supposed to do. Anyone care to give me a clue as to their functionality ?
1
by: Tamas Demjen | last post by:
I started to experiment with VC++ 2005 Beta1. So far everything went fine, and already have a working project, but soon I realized that the compiler was ancient (not supporting half of the C++/CLI...
3
by: Mark R. Dawson | last post by:
Hi all, I am trying to get custom attributes from a property. I can do this if I pass in the name of the property i.e. "Name" to the reflection methods, but if I pass in set_Name which is what...
2
by: prabhupr | last post by:
Hi Folks I was reading this article (http://www.dotnetbips.com/articles/displayarticle.aspx?id=32) on "Custom Attribute", written by Bipin. The only thing I did not understand in this article...
5
by: =?Utf-8?B?cGFnYXRlcw==?= | last post by:
Hello All, I am sure that I am just overlooking something, but here's something I can't quite get right... I want to be able to get the value of a parameter of an unknown custom attribute at...
1
camel
by: camel | last post by:
Apologies if foolish question, but I somewhat expected Custom Attributes (i.e. inheriting from System.Attribute) decorating class properties to come through via WSDL to the proxy the same as...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.