473,473 Members | 1,692 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Searching for attributes

I want to implement custom attributes. They can be used in several
assemblies. I want these attributes to register somehow. So I need the
attributes constructor to be called when an attributes is assigned to a
class (in several assemblies).

I found out, that the construtor is only called, when I "search" for
custom attributes in an assembly. Can this be done another way? If not,
how can I "search" in all assemblies?

--
Sleepless in Berlin
Wernfried
Nov 16 '05 #1
3 1625
If I understand you correctly, you can write a static Register method for
your attribute and call it the first thing your first assembly is run, and
write a static constructor for your attribute. Here is an example:

public class MyCustomAttribute : Attribute
{
static MyCustomAttribute()
{
Console.WriteLine("MyCustomAttribute constructor called");
}

public static vois Register()
{
// Do something to register the attribute
}
}

[MyCustom]
public class A
{
public A()
{
}

public void Search()
{
Console.WriteLine("Search started...");
// Write your search code here
}

public static void Main()
{
// This can be called in the init method of an assembly
MyCustomAttribute.Register();
A a = new A();
a.Search();
}
}

Angie

"Wernfried Schwenkner" <we*************************@sesa.de> wrote in
message news:oq***********@news.bln.sesa.de...
I want to implement custom attributes. They can be used in several
assemblies. I want these attributes to register somehow. So I need the
attributes constructor to be called when an attributes is assigned to a
class (in several assemblies).

I found out, that the construtor is only called, when I "search" for
custom attributes in an assembly. Can this be done another way? If not,
how can I "search" in all assemblies?

--
Sleepless in Berlin
Wernfried

Nov 16 '05 #2
In article <zs********************@comcast.com>, ay*****@yahoo.com
says...
If I understand you correctly, you can write a static Register method for
your attribute and call it the first thing your first assembly is run, and
write a static constructor for your attribute. Here is an example:


As far as I know, a static constructor is called only once. And I want
to register the class the attributed is assigned on, not the attribute.

It is no problem to search an assembly for all occurences of my custom
attribute. But I don't know how to detect all the assemblies of my
application.
--
Sleepless in Berlin
Wernfried
Nov 16 '05 #3
Wernfried Schwenkner <we*************************@sesa.de> wrote:
It is no problem to search an assembly for all occurences of my custom
attribute. But I don't know how to detect all the assemblies of my
application.


You can find all the assemblies loaded within any particular AppDomain
using AppDomain.GetAssemblies. If you can get in early enough, you
could also just subscribe to the AppDomain.AssemblyLoad event, and fix
things up every time an assembly is loaded.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4

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

Similar topics

50
by: Dan Perl | last post by:
There is something with initializing mutable class attributes that I am struggling with. I'll use an example to explain: class Father: attr1=None # this is OK attr2= # this is wrong...
3
by: Michael Hertz | last post by:
I have hundreds of samples of XML documents on my harddisc. But all of them lack the one or another feature of XML. Some XML documents have no attributes some others are rather flat (nesting...
7
by: Info 3000 | last post by:
Hello, I'm beginner in XML. I have just a little question : I understand that I can write : <Book> <Title> A nice day </Title> <Author> James Nicepen </Author> </Book>
2
by: Jack | last post by:
Hi, I have come to point in my db design where I'm trying to figure which is the best approach in making it generic (does this really matter?!?) Senario - I have a table called JOBS and this...
3
by: googleboy | last post by:
Hi there. I have defined a class called Item with several (about 30 I think) different attributes (is that the right word in this context?). An abbreviated example of the code for this is: ...
0
by: Wernfried Schwenkner | last post by:
I want to implement custom attributes. They can be used in several assemblies. I want these attributes to register somehow. So I need the attributes constructor to be called when an attributes is...
0
by: vissuyk | last post by:
Hi, I am new to xsd, any help is greatly appreciated. I will have customers define xsd. In there they will designate an attribute to be of certian type (e.g some:transid). When I see this in...
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...
0
by: richardaz | last post by:
I have been working on a project to search for 250,000 different records in ActiveDirectory. The process takes a long time and I have tried everything to make it faster. Currently using...
2
by: cloftis | last post by:
Using VS2003, VB and MSHTML, Using an HTMLSpanElement I want to enumerate the attributes of a SPAN tag. 1 'For testing sake 2 Dim strMarkup as String = "<span attr1='somevalue'...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
1
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,...
1
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
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
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 ...

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.