.net - MethodInfo and Delegates -
i using dotnet 2.0
i know eventinfo value, can loop through assembly's types , find methods match eventinfo delegate definition ( eventinfo.eventhandlertype )
is there way find out available delegates given methodinfo can assigned in delegate.createdelegate() function without first looping through referenced assemblies find delegate definitions.
or stuck doing following:
public bool methodinfodelegatesearch( methodinfo mi ) { system.collections.generic.list<type> delegatetypes = new system.collections.generic.list<type>(); foreach ( assembly in appdomain.currentdomain.getassemblies() ) foreach ( type t in a.gettypes() ) { if ( t.issubclassof( typeof( delegate ) ) ) delegatetypes.add( t ); } ( int = 0; < delegatetypes.count; i++ ) { type t = delegatetypes[i]; /* * here attempt match delegate structure methodinfo * can compare parameters or attempt create delegate */ try { delegate.createdelegate( t, mi, true ); return true; } catch { } } return false; }
it sure sounds need loop through everything. want find "available" delegates work. function accepts delegate doesn't have links methods passed it, large search way find them all.
you reduce time spent searching checking types public/internal access.
Comments
Post a Comment