Im trying to export all classes which implement an IJob
interface while also passing metadata at the individual class level. What 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 does not pass my metadata but if I remove the InheritedExport
attribute and add an Export
attribute to the individual implementation of IJob it works fine...