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