Get ProgID from .NET assembly

I want to write a program to find all the cool .NET classes and their ProgIDs from the .NET assembly. What is the best way to do this?

+4
source share
1 answer

This will allow you to get ProgId, not ClassId, and also work if the entire assembly is marked visible:

Assembly assembly = Assembly.LoadFile("someassembly.dll"); bool defaultVisibility; object[] assemblyAttributes = assembly.GetCustomAttributes(typeof(ComVisibleAttribute),false); if (assemblyAttributes.Length == 0) defaultVisibility = false; else defaultVisibility = (assemblyAttributes[0] as ComVisibleAttribute).Value; foreach(Type type in assembly.GetTypes()) { bool isComVisible = defaultVisibility; object []attributes = type.GetCustomAttributes(typeof(ComVisibleAttribute),true); if (attributes.Length > 0) isComVisible = (attributes[0] as ComVisibleAttribute).Value; if (isComVisible) { attributes = type.GetCustomAttributes(typeof(ProgIdAttribute),true); if (attributes.Length >0) { Console.WriteLine(String.Format("Type {0} has ProgID {1}",type.Name,(attributes[0] as ProgIdAttribute).Value)); } } } 
+7
source

All Articles