I’ve seen this quite a few times while using Office Interop classes
this.CustomXMLParts.Add(MyResources.Data, new Office.CustomXMLSchemaCollection());
If I hover over the CustomXMLSchemaCollection class, it shows up as an interface. Then how come I can do a new on it ? What gives? BTW this code compiles and works.
You are not creating an instance of the
CustomXMLSchemaCollectioninterface but an instance of theCustomXMLSchemaCollectionClasscoclass.The definition for
CustomXMLSchemaCollectioninterface is:This means that the designated coclass that implements the interface is
CustomXMLSchemaCollectionClass. My guess is that when the C# compiler sees the new forCustomXMLSchemaCollectioninterface it translates it to create a COM instance of theCustomXMLSchemaCollectionClassbased on the attributes provided with the interface.After writing this simple example:
I just ran ildasm and get the following MSIL:
As you can see the class that is constructed is
CustomXMLSchemaCollectionClassto prove my initial assumption.