[英]managed extensible framework and AssemblyInfo.cs
是否可以使用Assembly属性将信息添加到AssemblyInfo.cs
,例如assembly:MyProjectAssembly,
这样,当MEF扫描rutime文件夹中的程序集时,它将仅扫描以MyProjectAssembly
装饰的程序集。
我不认为MEF具有此功能。 我不确定100%。
您可以做的是使用Mono.Cecil ,它是System.Reflection的非常强大的替代品。 Mono.Cecil
允许您检查(并且重写,但这是另一回事).NET程序集,而无需加载它们。 这意味着您可以轻松添加所需的功能。 例如:
public static bool AssemblyIncludesCustomAttribute(string assemblyPath, string customAttributeName)
{
if (assemblyPath == null) throw new ArgumentNullException("assemblyPath");
if (customAttributeName == null) throw new ArgumentNullException("customAttributeName");
AssemblyDefinition assemblyDef = AssemblyDefinition.ReadAssembly(assemblyPath);
return assemblyDef.CustomAttributes.Any(ca => ca.AttributeType.FullName == customAttributeName);
}
然后像这样使用它:
var catalog = new AggregateCatalog();
string dirPath = @".\Extensions";
foreach (string assemblyFile in Directory.EnumerateFiles(dirPath, "*.dll"))
{
if (AssemblyIncludesCustomAttribute("Blah.dll", "System.Reflection.AssemblyConfigurationAttribute"))
{
catalog.Catalogs.Add(new AssemblyCatalog(assemblyFile));
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.