.NET C#: Is it possible to import TLB (semi-)automatically and add PreserveSig to one type?
I have this large IDL that I am importing into a C# project.
Everything was fine until I had to use one interface that is not quite compatible with HRESULT -> COMException conversion (I can go into details here but that shouldn't be relevant).
Is it possible to add PreserveSig to that one type somehow? I would like to avoid the option of declaring all COM interfaces manually in C#. If there was a way to get a c#开发者_如何学Python source file instead of assembly from tlbimp, that would suit me, but AFAIK there is no such way.
Any other options? Thanks.
You could decompile the interop library with Ildasm.exe
, edit the declaration and put it back again with ilasm.exe. Use a sample C# declaration to know how to edit it.
Or you could just declare that one interface in C#. The name doesn't matter, only the GUID has to match. Open the interop library in Reflector and copy/paste the interface declaration into your C# code. Change the interface name and modify the method that causes the problem.
精彩评论