473,411 Members | 2,210 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,411 software developers and data experts.

how to force which types custom attribute can be used with?

Hi!
I want to create my own custom attribute. And want it to be used only to
attribute class that inherrits from System.Windows.Forms.Control. Is it
possible to specify such constraint?.. If it is not possible in
compile-time, maybe I can check it in run-time, but I do not know how to
access atrributed type from Attribute constructor (and maybe throw some
exception).

Grtx
Paul
Nov 16 '05 #1
3 1441

"Pawe3" <no*****@nowhere.com> wrote in message
news:41********@news.home.net.pl...
Hi!
I want to create my own custom attribute. And want it to be used only to
attribute class that inherrits from System.Windows.Forms.Control. Is it
possible to specify such constraint?.. If it is not possible in
compile-time, maybe I can check it in run-time, but I do not know how to
access atrributed type from Attribute constructor (and maybe throw some
exception).
No, its not possible to constrain an attribute to a given type. I also do
not think it is possible to check the applied type at runtime.

You could write an fxcop rule to achieve such, however, and integrate fxcop
into your build process.
Grtx
Paul

Nov 16 '05 #2
Hi Paul,

Thank you for your posting. Regarding on the issue, I am
finding proper resource to assist you and we will update as soon as posible.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security(This posting is provided "AS IS",
with no warranties, and confers no rights.)

Nov 16 '05 #3
Thanks for Daniel's quick response!

Hi Paul,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to create your own attribute
and apply it to certain classes. And you need the attribute cannot be
applied to classes other than those inherited from
System.Windows.Form.Control. If there is any misunderstanding, please feel
free to let me know.

I agree with Daniel's suggestion that we cannot check this constraint in
.NET framework. attributes can be applied to any class definitions. So I
think using fxcop might be the best workaround. FxCop can be downloaded
from the following link:

http://www.gotdotnet.com/team/fxcop/

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #4

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

Similar topics

1
by: nospam | last post by:
Hi, I have used the xsd tool to generate a class from a schema. I then use the XmlSerializer class to write an object to an XML file. So far so good. However attributes that are set to...
3
by: Ryan Moore | last post by:
I am trying to "tune" some user controls in ASP.NET for optimal caching. Is it possible to do a vary by param - on a Session Variable, so the page caches when a Session variable stays the same,...
21
by: One Handed Man \( OHM - Terry Burns \) | last post by:
When using a custom control. In order to check and see if values have changed one has to implement the IPostBackDataCollection interface. The values returned for the control seem to be simply a...
7
by: Julian Jelfs | last post by:
Hi, I had an aspx pag in .Net 1.1 with a label on it. As such I had a code behind page with a declaration for that label. When I convert to Asp.Net 2.0 the code behind is converted to a...
0
by: Brian Young | last post by:
Hi all. I'm using the Property Grid control in a control to manage a windows service we have developed here. The windows service runs a set of other jobs that need to be managed. The control...
19
by: Dennis | last post by:
I have a public variable in a class of type color declared as follows: public mycolor as color = color.Empty I want to check to see if the user has specified a color like; if mycolor =...
9
by: wardy1975 | last post by:
Hi All, Looking for a little expert advice on a few web standards issues. I am currently trying to understand the impact of web standards for a web application I work with. I have been doing a...
13
by: anil.rita | last post by:
When the user chooses an AV file to play, based upon the type of file, I want to use the default installed media player to play it. I am wondering if this is a good way - any alternatives,...
3
by: Tomasz J | last post by:
Hello Developers, I have a control derived from System.Web.UI.WebControls.WebControl. Control has this property: public string Value { set { _value = value; } get { return _value; }
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.