Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ImportMany不使用自定义元数据属性_C#_Wpf_Mef_Caliburn.micro - Fatal编程技术网

C# ImportMany不使用自定义元数据属性

C# ImportMany不使用自定义元数据属性,c#,wpf,mef,caliburn.micro,C#,Wpf,Mef,Caliburn.micro,我已经在MEF中为ImportMany创建了一个自定义元数据属性,但ImportMany始终为null [MetadataAttribute] [AttributeUsage(AttributeTargets.Class ,AllowMultiple = false)] public class ModuleAttribute : ExportAttribute ,IModuleMetadata { public ModuleAttribute(string contract)

我已经在MEF中为ImportMany创建了一个自定义元数据属性,但ImportMany始终为null

[MetadataAttribute]
[AttributeUsage(AttributeTargets.Class ,AllowMultiple = false)]
public class ModuleAttribute : ExportAttribute ,IModuleMetadata
{
    public ModuleAttribute(string contract)
        : base(typeof(IScreen))
    {
        Name = contract;
        Region = Region.Sidebar;
        IsVisible = true;
    }

    public string Name { get; set; }
    public string Module { get; set; }
    public Region Region { get; set; }
    public string DisplayName { get; set; }
    public bool IsVisible { get; set; }
    public string Description { get; set; }
    public short Order { get; set; }
    public Permissions Permissions { get; set; }
}
下面是我如何导出我的类

[Module("Stock" ,Module = "Stock" ,Order = 1 ,Permissions = Permissions.View)]
    internal sealed class StockWorkSpaceViewModel : Screen
其中屏幕为
typeof(IScreen)

这是我的要价

[ImportMany]
public IEnumerable<Lazy<IScreen ,IModuleMetadata>> Modules { get; set; }
[ImportMany]
公共IEnumerable模块{get;set;}
谁能预测我会错在哪里

  • 检查ComponnetContainer.ComposeParts
  • 检查导出和导入属性必须相同
  • 检查自定义属性和惰性初始化中使用的接口。属性必须相同。这意味着customs属性类实现了延迟初始化隐式

  • 您还可以添加IModuleMetadata的声明吗?它有匹配的只读属性吗?昨天,当我从类中删除默认构造函数时,我能够导入。如果类有无参数构造函数和一些代码。导入不起作用。此外,我还必须从导出中删除合同名称,即,我必须使用合同类型导出。我还有一个名为设置的自定义导出,但现在ImportMany for Settings包括ModuleExport中的类型。我不知道为什么。两者都有不同的元数据接口,但契约类型相同。这里有太多可能出错的地方。如果你没有更多的代码,这将很难猜测。您可以尝试添加一个失败的完整示例。