Là một workaround bạn có thể thực hiện CLS của riêng bạn phù ModuleExportAttribute
trong đó sử dụng một danh sách dấu phẩy tách ra thay vì một mảng chuỗi:
[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; }
}
Cách sử dụng:
[StringListModuleExport(typeof(ModuleA), DependsOnModuleNameList = "ModuleB,ModuleC")]
public class ModuleA : IModule
{
public void Initialize()
{
Debug.WriteLine("ModuleA init");
}
}
Trong khi làm việc này, tôi thực sự đã hy vọng cho một giải pháp mà không cần phải mở rộng từ lớp hiện tại. Nhưng, có lẽ đó là cách duy nhất (bên ngoài ngăn chặn cảnh báo). –