作为一种解决方法,您可以实现自己的 CLS 兼容ModuleExportAttribute
,它使用逗号分隔列表而不是字符串数组:
[MetadataAttribute]
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public class StringListModuleExportAttribute : ExportAttribute, IModuleExport
{
public StringListModuleExportAttribute(Type moduleType)
: base(typeof(IModule))
{
ModuleName = moduleType.Name;
ModuleType = moduleType;
}
public string ModuleName { get; private set; }
public Type ModuleType { get; private set; }
public InitializationMode InitializationMode { get; private set; }
public string[] DependsOnModuleNames
{
get
{
if (string.IsNullOrEmpty(DependsOnModuleNameList))
return new string[0];
return DependsOnModuleNameList.Split(new[] {","}, StringSplitOptions.RemoveEmptyEntries);
}
}
public string DependsOnModuleNameList { get; set; }
}
用法:
[StringListModuleExport(typeof(ModuleA), DependsOnModuleNameList = "ModuleB,ModuleC")]
public class ModuleA : IModule
{
public void Initialize()
{
Debug.WriteLine("ModuleA init");
}
}