c# - How do I create a `ITypeElement` with represents a closed generic type in a ReSharper plugin? -
i'm using resharper 8 sdk , want find inheritors of particular generic interface, generic type particular type. have asked more general question got of way there, able find implementation of icommandhandler<t> , not 1 implementation want, icommandhandler<testcommand>
this code have:
foreach (var psimodule in declaredelement.getpsiservices().modules.getmodules()) { ideclaredtype generictype = typefactory.createtypebyclrname("handlernavigationtest.icommandhandler`1", psimodule, theclass.resolvecontext); var generictypeelement = generictype.gettypeelement(); if (generictypeelement != null) { var thetype = typefactory.createtype(originaltypeelement); var commandhandlertype = typefactory.createtype(generictypeelement,thetype); var handlertypeelement = commandhandlertype.gettypeelement(); solution.getpsiservices().finder.findinheritors(handlertypeelement, searchdomainfactory.createsearchdomain(solution, true), inheritorsconsumer, nullprogressindicator.instance); var inheritedinstance= inheritorsconsumer.foundelements.first(); var sourcefile = inheritedinstance.getsourcefiles().first(); } } if tooltip commandhandlertype after line:
var commandhandlertype = typefactory.createtype(generictypeelement,thetype);
i see type correctly specified:

but when itypeelement type pass search using line
var handlertypeelement = commandhandlertype.gettypeelement(); i seem have lost type:

and search finds implementations of icommandhandler<t>.
so question is, how create itypeelement represents closed generic type want search for?
or alternatively: how can search returned collection of inheritors type has class started generic type parameter?
ah, makes sense. itypeelement instance of ideclaredelement, means it's has declaration - such class or interface declaration. when itype represents closed generic, it's made of itypeelement represents generic type (icommandhandler) , isubstitution represents resolved generic type parameters (anothercommand). when call itype.gettypeelement(), return type element part of type element/substitution pair, open generic declared element (because interface declaration can ever open).
i think might have take alternative approach, , find inheritors (implementors) of itypehandler<t> , filter them down in consumer. findresult passed consumer can downcast findresultinheritedelement, give declared element represents class implements itypehandler<t>. should able walk these elements' interfaces see implement, , accept find results implement correct t. think typeelementutil here super types (base types + interfaces) of declared element.
Comments
Post a Comment