I'm create the class
public class MarkerAttribute : Attribute
{
}
and set this attribute in MyTestClass
[Marker]
public class MyTestsClass
{
}
How can I receive the names of all classes which have this attribute in my project?
Thank you.
I'm create the class
public class MarkerAttribute : Attribute
{
}
and set this attribute in MyTestClass
[Marker]
public class MyTestsClass
{
}
How can I receive the names of all classes which have this attribute in my project?
Thank you.
You can get the types that have the attribute using reflection like this:
using System;
using System.Reflection;
public class MarkerAttribute : Attribute {
}
[Marker]
class Program {
static void Main(string[] args) {
foreach (Type type in Assembly.GetExecutingAssembly().GetTypes()) {
foreach (Attribute attribute in type.GetCustomAttributes()) {
MarkerAttribute markerAttribute = attribute as MarkerAttribute;
if (markerAttribute != null) {
Console.WriteLine(type.FullName);
}
}
}
}
}