Я использую DotNet 2,0MethodInfo и делегаты
Я знаем, что со значением EventInfo, вы можете перебрать тип сборочных и найти все методы, которые соответствуют определению делегата EventInfo (EventInfo.EventHandlerType)
Есть ли способ узнать, какие доступные делегаты могут быть назначены данным MethodInfo в функции Delegate.CreateDelegate(), без первого цикла всех ссылочных ассемблеров, чтобы найти все определения делегата.
Или я застрял, выполнив следующие действия:
public bool MethodInfoDelegateSearch(MethodInfo mi) {
System.Collections.Generic.List<Type> delegateTypes = new System.Collections.Generic.List<Type>();
foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies())
foreach (Type t in a.GetTypes()) {
if (t.IsSubclassOf(typeof(Delegate)))
delegateTypes.Add(t);
}
for (int i = 0; i < delegateTypes.Count; i++) {
Type t = delegateTypes[i];
/*
* here is where to attempt match the delegate structure to the MethodInfo
* I can compare parameters or just attempt to create the delegate
*/
try {
Delegate.CreateDelegate(t, mi, true);
return true;
} catch {
}
}
return false;
}