Я использую дотнет 2.0
Я знаю, что со значением 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;
}