How can I create com object instance using the class name, for a child object to get property values
Posted on 2012-09-05
I need to create an instance of a com object (say a PowerPoint shape) using the fully qualified class name ("Microsoft.Office.Interop.PowerPoint.Shape"). I am wanting to enumerate through all properties of a shape and also get the values for child objects. I have the first part working fine, meaning I can get the values for properties for a shape object. Where I am stuck is getting the properties for child objects of a shape.
For example: if the shape is a textbox object I want to get the values for each property in the "fonts" object. I need to be able to create an instance of the fonts object to get the font specific properties (name, size, bold, etc.)
As this is a com interface object the System.Type returns "System.__ComObject". By enumerating the PropertyInfo collection I can get the fully qualified class name for each property and get the System.Type for the property.
I have tried to get the instance by enumerating the assemblies using Assembly.GetExecutingAssembly().GetReferencedAssemblies() but the class name is not in the list to be able to load the instance for the class type.
I need to be able to loop through not only the shape object, but all child objects as well and list the property values. I have already defined what properties are applicable for each object type, I just need to be able to dynamically creat the child object instance.
I anyone has any suggestions on accomplishing this, other that a huge case block for each posible object type, it would be greatly appreciated.
I am working in Visual Studio 2010, VB.net, Reflection, PowerPoint 2010, Win7