C# 托管可扩展框架和AssemblyInfo.cs
是否可以将信息添加到C# 托管可扩展框架和AssemblyInfo.cs,c#,mef,C#,Mef,是否可以将信息添加到AssemblyInfo.cs使用assembly属性,例如assembly:MyProjectAssembly, 因此,当MEF扫描rutime文件夹中的程序集时,它将只扫描那些用MyProjectAssembly装饰的程序集,我认为MEF没有此功能。但我不是100%肯定 您可以做的是使用,这是一个非常强大的System.Reflection替代品Mono.Cecil允许您在不加载.NET程序集的情况下检查(和重写,但那是另一回事)。这意味着您可以轻松添加所需的功能。例如:
AssemblyInfo.cs
使用assembly属性,例如assembly:MyProjectAssembly,
因此,当MEF扫描rutime文件夹中的程序集时,它将只扫描那些用
MyProjectAssembly
装饰的程序集,我认为MEF没有此功能。但我不是100%肯定
您可以做的是使用,这是一个非常强大的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));
}
}