NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

20.1.1 The COMImport attribute

When placed on a class, the COMImport attribute marks the class as an externally implemented COM class. Such a class declaration enables the use of a C# name to refer to a COM class.

[AttributeUsage(AttributeTargets.Class)]
public class COMImportAttribute: System.Attribute
{
   public COMImportAttribute() {…}
}

A class that is decorated with the COMImport attribute is subject to the following restrictions:

The example

[COMImport, Guid("00020810-0000-0000-C000-000000000046")]
class Worksheet {}
class Test
{
   static void Main() {
      Worksheet w = new Worksheet();   // Creates an Excel worksheet
   }
}

declares a class Worksheet as a class imported from COM that has a CLSID of "00020810-0000-0000-C000-000000000046". Instantiating a Worksheet instance causes a corresponding COM instantiation.