c# - Finding Out what Interfaces are Queryable for a COM Object? -
i working esri's arcobjects com library, trying hard figure out type "selected" should be:
imxdocument doc = m_application.document imxdocument; object selected = doc.selecteditem; selecteditem returns comobject (not null), representing data type selected. not have faintest idea type supposed cast to. when debug it, don't see useful:
(watch debug after value set)
esri's arcobjects library huge, , pretty poorly documented, cannot figure out. went far manually check 50 or interfaces thought should be.
does have ideas how can figure out?
edit clarify documentation absolutely no help, neither forums.
after reading question, answers, , comments, may have write utility find answer brute force.
use reflection scrape list of interfaces out of interop assembly, loop on list , see if object supports each interface in turn.
update
some sample code:
object unknown = //your com object... type somecomobjecttype = typeof(exampletypeininteropassembly); assembly interopassembly = somecomobjecttype.assembly; func<type, bool> implementsinterface = iface => { try { marshal.getcominterfaceforobject(unknown, iface); return true; } catch (invalidcastexception) { return false; } }; list<type> supportedinterfaces = interopassembly. gettypes(). where(t => t.isinterface). where(implementsinterface). tolist(); if (supportedinterfaces.count > 0) { supportedinterfaces.foreach(console.writeline); } else { console.writeline("no supported interfaces found :("); }
Comments
Post a Comment