.net 如何判断DLL是否可见?
我有一个DLL,它的ComVisible属性可能设置为true,也可能不设置为true。我不确定它是如何构建的,或者具有什么属性?我只知道它是一个.NETDLL。简单地说,我如何判断它是否可见 对不起,如果这是重复的。我所有关于此的搜索都返回显示如何使DLL可见的结果。我知道怎么做。像这样的事.net 如何判断DLL是否可见?,.net,dll,comvisible,.net,Dll,Comvisible,我有一个DLL,它的ComVisible属性可能设置为true,也可能不设置为true。我不确定它是如何构建的,或者具有什么属性?我只知道它是一个.NETDLL。简单地说,我如何判断它是否可见 对不起,如果这是重复的。我所有关于此的搜索都返回显示如何使DLL可见的结果。我知道怎么做。像这样的事 Assembly asm = Assembly.GetExecutingAssembly(); //Assembly.LoadFile, Assembly.Load bool comVisible =
Assembly asm = Assembly.GetExecutingAssembly(); //Assembly.LoadFile, Assembly.Load
bool comVisible = asm.GetCustomAttributes()
.OfType<ComVisibleAttribute>()
.First()
.Value;
Assembly asm=Assembly.getExecutionGassembly()//Assembly.LoadFile,Assembly.Load
bool comVisible=asm.GetCustomAttributes()
第()类
.First()
价值
您可以使用反射检查程序集的外观:
private static bool IsComVisible(string assemblyPath)
{
var assembly = Assembly.LoadFile(assemblyPath);
var attributes = assembly.GetCustomAttributes(typeof(ComVisibleAttribute), false);
if (attributes.Length > 0)
{
return ((ComVisibleAttribute)attributes[0]).Value;
}
return false;
}
只需运行Tlbexp.exe。当找不到[ComVisible]的任何类型时,它会抱怨。出现错误:
方法“GetCustomAttributes”没有重载,该方法接受0个参数