What do lines like [COMImport] do?

  • Thread starter Thread starter SM
  • Start date Start date
S

SM

I found a COM interop code sample and came across these lines of code:

[ComImport]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("FC4801A3-2BA9-11CF-A229-00AA003D7352")]

What do those type of lines encapsuled in [] brackets do? I already tried
to find an answer using web search but no success. :(

Thanks for any help.
 
These are so called attributes. They usually emit metadata about a class, a
class member or an assembly which is then used by the JIT compiler, CLR or
even in other parts of the program. In your particular example, the
attributes instruct the runtime to forward calls to the class they apply to
to a COM object with the specified GUID and interface type.

P.S. You should consult MSDN on topics such as ComImportAttribute,
GuidAttribute and InterfaceTypeAttribute to find out their *exact* meaning
as my response is rather generic.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

SM said:
I found a COM interop code sample and came across these lines of code:

[ComImport]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("FC4801A3-2BA9-11CF-A229-00AA003D7352")]

What do those type of lines encapsuled in [] brackets do? I already tried
to find an answer using web search but no success. :(

Thanks for any help.
adress.
 
Back
Top