473,503 Members | 1,633 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

question about custom attributes

M
Is it possible to define an attribute that describes a property of a
class at runtime?

For example, you have a class called "employee", and it has a property
"name". The "name" property has an attribute that tells any calling
code whether or not this property is "writable" and/or "readable", even
though this property has both get/set accessors.

Maybe there is another way to do this, and I just don't have enough
experience.

Any help is appreciated.

Nov 15 '05 #1
1 1094
M
Is the following possible? If so, is this the proper way to do it?

[AttributeUsage(AttributeTarget.Property,Inherited= true,AllowMultiple=true)]

public class SecurityInfoAttribute : Attribute
{
// Private Data
private int readable;
private int writable;
// Constructor
public SecurityInfoAttribute(int readable, int writable)
{
this.security_readable = 0;
this.security_writable = 0;

}

public int Readable
{
get
{
return readable;
}
set
{
readable = value;
}
}

public int Writable
{
get
{
return writable;
}
set
{
writable = value;
}
}
}

public class employee {

string name;
[SecurityInfo(getReadSecurityInfo(userId), getWriteSecurityInfo(userId))]
string Name{get{return name;}set{name = value;}}

}

And then examine the name property of this object from within the client
code in order to show it to that user or not, based on the security info
attribute.
M wrote:
Is it possible to define an attribute that describes a property of a
class at runtime?

For example, you have a class called "employee", and it has a property
"name". The "name" property has an attribute that tells any calling
code whether or not this property is "writable" and/or "readable", even
though this property has both get/set accessors.

Maybe there is another way to do this, and I just don't have enough
experience.

Any help is appreciated.


Nov 15 '05 #2

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

Similar topics

2
1683
by: wzhang | last post by:
Hi, I would like to add some custom elements to svg files and also some custom attributes to certain svg elements. Should I create a DTD to include the cumtom elements and attributes? ...
19
1725
by: Mark Johnson | last post by:
Oddly enough, in searching Google for web and ngs, I could find only a handful of articles on this problem. I wonder if it's one not typically encountered? I wanted to have three divs that could...
5
454
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
2127
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
4174
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
3520
by: The Developer | last post by:
Hi All, I have a web application where I am adding a custom attribute to my ASP.NET text box control and changing value of that attribute at client side using JavaScript. My problem is that...
3
3166
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
2508
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
1358
by: raj | last post by:
I know what interfaces are and what they used for etc. Today i am learning about serilization. I know to mark the class "serializable" and implement ISerializable interface, and then implement...
2
4254
by: Hayden Kirk | last post by:
Hi Guys, I was just wondering if someone can point me in the right direction to find information on how to store extra attributes in the sql database instead of the app.config? As of now, you...
0
7202
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
7330
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7460
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5014
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1512
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
380
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.