c# - MEF not importing methods that has attribute which allows multiple -
created metadataattribute
allows using multiple.
[metadataattribute] [attributeusage(attributetargets.method, allowmultiple = true)] public class businesslogicmetadataattribute : exportattribute, ibusinesslogicmetadata { //...... }
then using getexports<t>()
import methods.
//..... var imported = _container.getexports<action<object, evantargs>, ibusinesslogicmetadata>("myplugin"); //.....
here plugin method:
[businesslogicmetadata("myplugin")] [businesslogicmetadata("myplugin1")] public void test(object sender, eventargs e) { //.... }
get exports not returning plugin method because of alowmultiple=true
in metadataattribute
. works fine if set metadataattribute allowmultiple = false , remove second attribute of plugin method.
why can't have 2 attributes on plugin method?
thanks help!
not sure if work particular case since don't know entire design , ultimate goal, since you're creating meta attrib , on, wrap flag enum (see enumeration types bit flags) in businesslogicmetadataattribute
, is, instead of using strings, use flags enum, below
[businesslogicmetadata(myflagenum.myplugin | myflagenum.myplugin1)] public void test(object sender, eventargs e) { //.... }
update: multiple exports without using flag enums, inherit attribute
instead of exportattribute, there few discussions problem around web
[metadataattribute] [attributeusage(attributetargets.method, allowmultiple = true)] public class businesslogicmetadataattribute : attribute, ibusinesslogicmetadata { //...... }
Comments
Post a Comment