İlk defa, kendimi manuel olarak derleme taraması yapmak zorundaydım. BenÖzel nitelikler için tüm sınıfları ve yöntemleri taramak için en iyi yöntemler
var methodsWithAttributes =
(from assembly in AppDomain.CurrentDomain.GetAssemblies()
from type in assembly.GetTypes()
from method in type.GetMethods()
let attributes = method.GetCustomAttributes(typeof(SomeAttribute), true)
where attributes != null && attributes.Length > 0
select new { Type = type, Method = method,
Attributes = attributes.Cast<SomeAttribute>() })
.ToList();
Tek bir taramada Bunu yapmak için şu 2 birleştirmeyi deneyin veya Should yöntem seviyesine dışarı genişletmek için yeterince basitti
var typesWithMyAttribute =
(from assembly in AppDomain.CurrentDomain.GetAssemblies()
from type in assembly.GetTypes()
let attributes = type.GetCustomAttributes(typeof(SomeAttribute), true)
where attributes != null && attributes.Length > 0
select new { Type = type, Attributes = attributes.Cast<SomeAttribute>() })
.ToList();
Bana ayarlamak hangi C# - how enumerate all classes with custom class attribute? geldi sadece erken optimizasyona mı düşüyor? (tarama sadece uygulama başlangıcında yürütülür)
Metotlarda türden çok daha fazla yöntem bulunduğundan, yöntemlerin taranması için daha uygun olan farklı bir şey var mı?
Ben meclisleri ve türlerini numaralandıran meclisleri ve türleri önbelleğe olacak şekilde, bulma ve özelliklerini başlatmasını çok daha hızlı olacak bahse gidiyorum anlamsız olacak. – Gabe