Вопрос

I have a DLL that may or may not have its ComVisible attribute set to true. I'm not sure how it was built, or with what attributes? All I know is that it's a .Net DLL. Simply put, how can I tell if it is Com Visible?

Sorry if this is a duplicate. All of my searches about this return results that show how to make a DLL ComVisible. I know how to do that.

Это было полезно?

Решение

You could check the ComVisibleAttribute of the assembly using reflection:

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;
}

Другие советы

Something like this?

Assembly asm = Assembly.GetExecutingAssembly(); //Assembly.LoadFile, Assembly.Load

bool comVisible = asm.GetCustomAttributes()
                     .OfType<ComVisibleAttribute>()
                     .First()
                     .Value;
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top