c# - MetaData with InheritedExport -


im trying export classes implement ijob interface while passing metadata @ individual class level. i've tried:

export:

[inheritedexport(typeof(ijob))] public interface ijob {     int run(); } 

import:

    [importmany]     public ienumerable<lazy<ijob, ijobmetadata>> jobs { get; set; } 

implementation:

[ignorejob(false)] public class myjob : ijob {     public int run()     {         return 5;     } } 

attribute setup:

[metadataattribute] [attributeusage(attributetargets.class, allowmultiple = false)] public class ignorejobattribute : exportattribute, ijobmetadata {     public ignorejobattribute(bool ignore)         : base(typeof(ijobmetadata))     {         ignore = ignore;     }      [defaultvalue(true)]     public bool ignore { get; set; } } 

the above not pass metadata if remove inheritedexport attribute , add export attribute individual implementation of ijob works fine...

take @ this: how use mef inherited export & metadata?

it turns out metadata associated export must available when inheritedexport being registered. mef treats exports made after inheriting given class same kind of export. therefore, metadata defined in subclass ignored.

so not able use inheritedexport in case, i'm afraid.

as can see, inherit exportattribute in ignorejobattribute, therefore, should able drop inheritedexportattribute on base class, long keep ignorejobattribute on every ijob define.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -